Repository: maven-integration-testing
Updated Branches:
  refs/heads/MNG-6298 [created] 55db62ff5


[MNG-6298] 3.5.2: ClassNotFoundException: javax.annotation.security.RolesAllowed

Test for https://github.com/apache/maven/pull/139

Signed-off-by: Karl Heinz Marbaise <khmarba...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/maven-integration-testing/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/maven-integration-testing/commit/55db62ff
Tree: 
http://git-wip-us.apache.org/repos/asf/maven-integration-testing/tree/55db62ff
Diff: 
http://git-wip-us.apache.org/repos/asf/maven-integration-testing/diff/55db62ff

Branch: refs/heads/MNG-6298
Commit: 55db62ff59715248edf37b636821461d0f1081c4
Parents: 1797b9e
Author: Bengt Söderberg <bengt.soderb...@purplescout.se>
Authored: Mon Dec 4 19:49:17 2017 +0100
Committer: Karl Heinz Marbaise <khmarba...@apache.org>
Committed: Sun Dec 31 13:15:41 2017 +0100

----------------------------------------------------------------------
 .../MavenITmng6298RolesAllowedNotFoundTest.java | 83 ++++++++++++++++++++
 .../src/test/resources/mng-6298/pom.xml         | 82 +++++++++++++++++++
 .../apache/maven/plugins/Jsr250Component.java   | 60 ++++++++++++++
 .../org/apache/maven/plugins/Jsr250Mojo.java    | 52 ++++++++++++
 4 files changed, 277 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/55db62ff/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6298RolesAllowedNotFoundTest.java
----------------------------------------------------------------------
diff --git 
a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6298RolesAllowedNotFoundTest.java
 
b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6298RolesAllowedNotFoundTest.java
new file mode 100644
index 0000000..9767f90
--- /dev/null
+++ 
b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6298RolesAllowedNotFoundTest.java
@@ -0,0 +1,83 @@
+package org.apache.maven.it;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+
+import org.apache.maven.it.util.ResourceExtractor;
+
+/**
+ * This is a test set for <a 
href="https://issues.apache.org/jira/browse/MNG-6298";>MNG-6298</a>.
+ * Most of code reused from mng-6084. Bugfix came after release, old test case 
still valid for its release.
+ */
+public class MavenITmng6298RolesAllowedNotFoundTest
+    extends AbstractMavenIntegrationTestCase
+{
+
+    private File testDir;
+
+    public MavenITmng6298RolesAllowedNotFoundTest()
+    {
+        super( "[3.5.3,)" );
+    }
+
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        testDir = ResourceExtractor.simpleExtractResources( getClass(), 
"/mng-6298" );
+
+    }
+
+    protected void tearDown()
+        throws Exception
+    {
+
+        super.tearDown();
+    }
+
+    public void testRolesAllowedShouldNotResultInClassCastException()
+        throws Exception
+    {
+        //
+        // Build a plugin that uses JSR 250 annotations
+        //
+        Verifier v0 = newVerifier( testDir.getAbsolutePath(), "remote" );
+        v0.setAutoclean( false );
+        v0.deleteDirectory( "target" );
+        v0.deleteArtifacts( "org.apache.maven.its.mng6298" );
+        v0.executeGoal( "install" );
+        v0.verifyErrorFreeLog();
+        v0.resetStreams();
+
+        //
+        // Execute the JSR 250 plugin
+        //
+        Verifier v1 = newVerifier( testDir.getAbsolutePath(), "remote" );
+        v1.setAutoclean( false );
+        v1.executeGoal( 
"org.apache.maven.its.mng6298:jsr250-maven-plugin:0.0.1-SNAPSHOT:hello" );
+        v1.verifyErrorFreeLog();
+        v1.resetStreams();
+        v1.verifyTextInLog( "Hello! I am a component using JSR 250 with 
@PostConstruct support" );
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/55db62ff/core-it-suite/src/test/resources/mng-6298/pom.xml
----------------------------------------------------------------------
diff --git a/core-it-suite/src/test/resources/mng-6298/pom.xml 
b/core-it-suite/src/test/resources/mng-6298/pom.xml
new file mode 100644
index 0000000..e092ee4
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6298/pom.xml
@@ -0,0 +1,82 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.mng6298</groupId>
+  <artifactId>jsr250-maven-plugin</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <packaging>maven-plugin</packaging>
+
+  <name>JSR 250 Maven Plugin</name>
+  <url>http://maven.apache.org</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <mavenVersion>3.5.0</mavenVersion>
+    <mavenPluginPluginVersion>3.2</mavenPluginPluginVersion>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>javax.inject</groupId>
+      <artifactId>javax.inject</artifactId>
+      <version>1</version>
+    </dependency>
+    <dependency>
+      <groupId>javax.annotation</groupId>
+      <artifactId>jsr250-api</artifactId>
+      <version>1.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>${mavenVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugin-tools</groupId>
+      <artifactId>maven-plugin-annotations</artifactId>
+      <version>${mavenPluginPluginVersion}</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-plugin-plugin</artifactId>
+        <version>${mavenPluginPluginVersion}</version>
+        <configuration>
+          <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+        </configuration>
+        <executions>
+          <execution>
+            <id>mojo-descriptor</id>
+            <goals>
+              <goal>descriptor</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>help-goal</id>
+            <goals>
+              <goal>helpmojo</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.sonatype.plugins</groupId>
+        <artifactId>sisu-maven-plugin</artifactId>
+        <version>1.1</version>
+        <executions>
+          <execution>
+            <id>generate-index</id>
+            <goals>
+              <goal>main-index</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/55db62ff/core-it-suite/src/test/resources/mng-6298/src/main/java/org/apache/maven/plugins/Jsr250Component.java
----------------------------------------------------------------------
diff --git 
a/core-it-suite/src/test/resources/mng-6298/src/main/java/org/apache/maven/plugins/Jsr250Component.java
 
b/core-it-suite/src/test/resources/mng-6298/src/main/java/org/apache/maven/plugins/Jsr250Component.java
new file mode 100644
index 0000000..526e05c
--- /dev/null
+++ 
b/core-it-suite/src/test/resources/mng-6298/src/main/java/org/apache/maven/plugins/Jsr250Component.java
@@ -0,0 +1,60 @@
+package org.apache.maven.plugins;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+@Named
+@Singleton
+public class Jsr250Component
+{
+
+    @PostConstruct
+    public void init()
+    {
+        System.out.println();
+        System.out.println();
+        System.out.println( "Hello! I am a component using JSR 250 with 
@PostConstruct support" );
+        System.out.println();
+        System.out.println();
+    }
+
+    public void hello()
+    {
+        System.out.println();
+        System.out.println();
+        System.out.println( "Hello! I am a component that is being used via 
constructor injection! That's right, I'm a JSR 330 badass." );
+        System.out.println();
+        System.out.println();
+    }
+
+    @PreDestroy
+    public void cleanup()
+    {
+        System.out.println();
+        System.out.println();
+        System.out.println( "Hello! I am a component using JSR 250 with 
@PreDestroy support" );
+        System.out.println();
+        System.out.println();
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven-integration-testing/blob/55db62ff/core-it-suite/src/test/resources/mng-6298/src/main/java/org/apache/maven/plugins/Jsr250Mojo.java
----------------------------------------------------------------------
diff --git 
a/core-it-suite/src/test/resources/mng-6298/src/main/java/org/apache/maven/plugins/Jsr250Mojo.java
 
b/core-it-suite/src/test/resources/mng-6298/src/main/java/org/apache/maven/plugins/Jsr250Mojo.java
new file mode 100644
index 0000000..8cea40d
--- /dev/null
+++ 
b/core-it-suite/src/test/resources/mng-6298/src/main/java/org/apache/maven/plugins/Jsr250Mojo.java
@@ -0,0 +1,52 @@
+package org.apache.maven.plugins;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import javax.inject.Inject;
+import javax.annotation.security.RolesAllowed;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+
+@Mojo( name = "hello", defaultPhase = LifecyclePhase.VALIDATE, requiresProject 
= false )
+public class Jsr250Mojo
+    extends AbstractMojo
+{
+
+    private Jsr250Component component;
+
+    @Inject
+    public Jsr250Mojo( Jsr250Component component )
+    {
+        this.component = component;
+    }
+
+    public void execute()
+        throws MojoExecutionException
+    {
+        if (!(this instanceof RolesAllowed)) {
+            // triggers ClassNotFoundException if plugins lack access to 
javax.annotation.security
+        } else {
+            component.hello();
+        }
+    }
+}

Reply via email to