diff --git a/src/it/test-jar-generate-test-sources/invoker.properties b/src/it/test-jar-generate-test-sources/invoker.properties new file mode 100644 index 0000000..1dc843a --- /dev/null +++ b/src/it/test-jar-generate-test-sources/invoker.properties @@ -0,0 +1,18 @@ +# 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. + +invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:test-jar diff --git a/src/it/test-jar-generate-test-sources/pom.xml b/src/it/test-jar-generate-test-sources/pom.xml new file mode 100644 index 0000000..36b45c9 --- /dev/null +++ b/src/it/test-jar-generate-test-sources/pom.xml @@ -0,0 +1,63 @@ + + + + 4.0.0 + + org.apache.maven.its + test-jar-generate-test-sources + 1.0-SNAPSHOT + + Test for test-jar with generated test sources + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-source-plugin + @project.version@ + + + org.apache.maven.plugins + maven-antrun-plugin + 1.3 + + + generate-test-sources + + run + + generate-test-sources + + + + + target/generated-test-sources/ant + + + + + + + + diff --git a/src/it/test-jar-generate-test-sources/verify.bsh b/src/it/test-jar-generate-test-sources/verify.bsh new file mode 100644 index 0000000..45f27bd --- /dev/null +++ b/src/it/test-jar-generate-test-sources/verify.bsh @@ -0,0 +1,54 @@ +/* + * 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.*; +import java.util.*; +import java.util.jar.*; + +try +{ + File jarFile = new File( basedir, "target/test-jar-generate-test-sources-1.0-SNAPSHOT-test-sources.jar" ); + if ( !jarFile.isFile() ) + { + System.out.println( "FAILURE! Test sources JAR does not exist." ); + return false; + } + + JarFile jar = new JarFile( jarFile ); + + String[] includedEntries = { + "META-INF/MANIFEST.MF", + "GeneratedTest.java", + }; + for ( String included : includedEntries ) + { + if ( jar.getEntry( included ) == null ) + { + System.out.println( "FAILURE! Expected entry not found: " + included ); + return false; + } + } +} +catch( Exception ex ) +{ + ex.printStackTrace(); + return false; +} + +return true; diff --git a/src/main/java/org/apache/maven/plugins/source/TestSourceJarMojo.java b/src/main/java/org/apache/maven/plugins/source/TestSourceJarMojo.java index dd281dd..1976407 100644 --- a/src/main/java/org/apache/maven/plugins/source/TestSourceJarMojo.java +++ b/src/main/java/org/apache/maven/plugins/source/TestSourceJarMojo.java @@ -27,7 +27,7 @@ * @since 2.0.3 */ @Mojo(name = "test-jar", defaultPhase = "package") -@Execute(phase = "generate-sources") +@Execute(phase = "generate-test-sources") public class TestSourceJarMojo extends TestSourceJarNoForkMojo { // no op } diff --git a/src/test/java/org/apache/maven/plugins/source/TestSourceJarMojoTest.java b/src/test/java/org/apache/maven/plugins/source/TestSourceJarMojoTest.java index e0bc5fe..8ea2f06 100644 --- a/src/test/java/org/apache/maven/plugins/source/TestSourceJarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/source/TestSourceJarMojoTest.java @@ -25,6 +25,7 @@ import org.apache.maven.api.Project; import org.apache.maven.api.ProjectScope; import org.apache.maven.api.di.Provides; +import org.apache.maven.api.plugin.annotations.Execute; import org.apache.maven.api.plugin.testing.Basedir; import org.apache.maven.api.plugin.testing.InjectMojo; import org.apache.maven.api.plugin.testing.MojoParameter; @@ -35,6 +36,7 @@ import org.junit.jupiter.api.Test; import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -133,6 +135,12 @@ public void testIncludeMavenDescriptorWhenExplicitlyConfigured(AbstractSourceJar }); } + @Test + void testExecutePhase() { + Execute execute = TestSourceJarMojo.class.getAnnotation(Execute.class); + assertEquals("generate-test-sources", execute.phase()); + } + @Provides InternalSession createSession() { InternalSession session = SessionMock.getMockSession("target/local-repo");