forked from apache/maven
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MNG-7587] Add an IT for jsr330 components (apache#264)
- Loading branch information
Showing
10 changed files
with
389 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7587Jsr330.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
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 org.apache.maven.shared.verifier.Verifier; | ||
import org.apache.maven.shared.verifier.util.ResourceExtractor; | ||
import org.codehaus.plexus.util.Os; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.EnabledOnJre; | ||
import org.junit.jupiter.api.condition.JRE; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-7587">MNG-7587</a>. | ||
* Simply verifies that plexus component using JSR330 and compiled with JDK 17 bytecode can | ||
* work on maven. | ||
*/ | ||
class MavenITmng7587Jsr330 | ||
extends AbstractMavenIntegrationTestCase | ||
{ | ||
|
||
public MavenITmng7587Jsr330() | ||
{ | ||
// affected Maven versions: 3.9.2 and 4.0.0-alpha-5 | ||
super( "(3.9.2,3.999),(4.0.0-alpha-5,)" ); | ||
} | ||
|
||
/** | ||
* Verify components can be written using JSR330 on JDK 17. | ||
* | ||
* @throws Exception in case of failure | ||
*/ | ||
@Test | ||
@EnabledOnJre(JRE.JAVA_17) | ||
void testJdk17() throws Exception | ||
{ | ||
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-7587-jsr330").getAbsoluteFile(); | ||
|
||
final Verifier pluginVerifier = newVerifier( new File( testDir, "plugin" ).getPath() ); | ||
pluginVerifier.addCliArgument( "clean" ); | ||
pluginVerifier.addCliArgument( "install" ); | ||
pluginVerifier.addCliArgument( "-V" ); | ||
pluginVerifier.execute(); | ||
pluginVerifier.verifyErrorFreeLog(); | ||
|
||
final Verifier consumerVerifier = newVerifier( new File( testDir, "consumer" ).getPath() ); | ||
consumerVerifier.addCliArgument( "clean" ); | ||
consumerVerifier.addCliArgument( "verify" ); | ||
consumerVerifier.addCliArgument( "-V" ); | ||
consumerVerifier.execute(); | ||
consumerVerifier.verifyErrorFreeLog(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
its/core-it-suite/src/test/resources/mng-7587-jsr330/consumer/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
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. | ||
--> | ||
|
||
<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.mng7587</groupId> | ||
<artifactId>consumer</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.its.mng7587</groupId> | ||
<artifactId>plugin</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<executions> | ||
<execution> | ||
<id>touch</id> | ||
<goals> | ||
<goal>touch</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
</project> |
92 changes: 92 additions & 0 deletions
92
its/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
|
||
<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.mng7587</groupId> | ||
<artifactId>plugin</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>maven-plugin</packaging> | ||
|
||
<name>hello-maven-plugin Maven Plugin</name> | ||
|
||
<prerequisites> | ||
<maven>${maven.version}</maven> | ||
</prerequisites> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.version>3.8.6</maven.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-plugin-api</artifactId> | ||
<version>${maven.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-core</artifactId> | ||
<version>${maven.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.plugin-tools</groupId> | ||
<artifactId>maven-plugin-annotations</artifactId> | ||
<version>3.6.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>3.2.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>3.3.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.10.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-plugin-plugin</artifactId> | ||
<version>3.9.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.3.0</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<release>17</release> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-plugin-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>mojo-descriptor</id> | ||
<goals> | ||
<goal>descriptor</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
8 changes: 8 additions & 0 deletions
8
...te/src/test/resources/mng-7587-jsr330/plugin/src/main/java/sample/plugin/MyComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package sample.plugin; | ||
|
||
import javax.inject.Named; | ||
|
||
@Named | ||
public class MyComponent implements MyService { | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
...t-suite/src/test/resources/mng-7587-jsr330/plugin/src/main/java/sample/plugin/MyMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package sample.plugin; | ||
|
||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
|
||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugins.annotations.Component; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
/** | ||
* Goal which touches a timestamp file. | ||
*/ | ||
@Mojo( name = "touch", defaultPhase = LifecyclePhase.PROCESS_SOURCES ) | ||
public class MyMojo | ||
extends AbstractMojo | ||
{ | ||
/** | ||
* Location of the file. | ||
*/ | ||
@Parameter( defaultValue = "${project.build.directory}", property = "outputDir", required = true ) | ||
private File outputDirectory; | ||
|
||
@Component | ||
private MyService myService; | ||
|
||
@Override | ||
public void execute() | ||
throws MojoExecutionException | ||
{ | ||
File f = outputDirectory; | ||
|
||
if ( !f.exists() ) | ||
{ | ||
f.mkdirs(); | ||
} | ||
|
||
File touch = new File( f, "touch.txt" ); | ||
|
||
FileWriter w = null; | ||
try | ||
{ | ||
w = new FileWriter( touch ); | ||
|
||
w.write( "touch.txt" ); | ||
} | ||
catch ( IOException e ) | ||
{ | ||
throw new MojoExecutionException( "Error creating file " + touch, e ); | ||
} | ||
finally | ||
{ | ||
if ( w != null ) | ||
{ | ||
try | ||
{ | ||
w.close(); | ||
} | ||
catch ( IOException e ) | ||
{ | ||
// ignore | ||
} | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...uite/src/test/resources/mng-7587-jsr330/plugin/src/main/java/sample/plugin/MyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package sample.plugin; | ||
|
||
public interface MyService { | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
its/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/test/MyMojoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package sample.plugin; | ||
|
||
|
||
import org.apache.maven.plugin.testing.MojoRule; | ||
import org.apache.maven.plugin.testing.WithoutMojo; | ||
|
||
import org.junit.Rule; | ||
import static org.junit.Assert.*; | ||
import org.junit.Test; | ||
import java.io.File; | ||
|
||
public class MyMojoTest | ||
{ | ||
@Rule | ||
public MojoRule rule = new MojoRule() | ||
{ | ||
@Override | ||
protected void before() throws Throwable | ||
{ | ||
} | ||
|
||
@Override | ||
protected void after() | ||
{ | ||
} | ||
}; | ||
|
||
/** | ||
* @throws Exception if any | ||
*/ | ||
@Test | ||
public void testSomething() | ||
throws Exception | ||
{ | ||
File pom = new File( "target/test-classes/project-to-test/" ); | ||
assertNotNull( pom ); | ||
assertTrue( pom.exists() ); | ||
|
||
MyMojo myMojo = ( MyMojo ) rule.lookupConfiguredMojo( pom, "touch" ); | ||
assertNotNull( myMojo ); | ||
myMojo.execute(); | ||
|
||
File outputDirectory = ( File ) rule.getVariableValueFromObject( myMojo, "outputDirectory" ); | ||
assertNotNull( outputDirectory ); | ||
assertTrue( outputDirectory.exists() ); | ||
|
||
File touch = new File( outputDirectory, "touch.txt" ); | ||
assertTrue( touch.exists() ); | ||
|
||
} | ||
|
||
/** Do not need the MojoRule. */ | ||
@WithoutMojo | ||
@Test | ||
public void testSomethingWhichDoesNotNeedTheMojoAndProbablyShouldBeExtractedIntoANewClassOfItsOwn() | ||
{ | ||
assertTrue( true ); | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.