This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch maven-source-plugin-3.x
in repository https://gitbox.apache.org/repos/asf/maven-source-plugin.git
The following commit(s) were added to refs/heads/maven-source-plugin-3.x by
this push:
new 7005b6e Migration to JUnit 5 - avoid using AbstractMojoTestCase
7005b6e is described below
commit 7005b6e581bbf159163c50415f5ac7b3da681788
Author: Slawomir Jaranowski <[email protected]>
AuthorDate: Sun Dec 7 10:37:25 2025 +0100
Migration to JUnit 5 - avoid using AbstractMojoTestCase
---
pom.xml | 21 ++-
.../plugins/source/AbstractSourcePluginTest.java | 95 ++++++++++
.../source/AbstractSourcePluginTestCase.java | 186 --------------------
.../maven/plugins/source/SourceJarMojoTest.java | 194 ++++++++++++---------
.../plugins/source/TestSourceJarMojoTest.java | 139 ++++++++-------
.../source/stubs/DefaultArtifactHandlerStub.java | 59 -------
.../maven/plugins/source/stubs/Project001Stub.java | 126 -------------
.../maven/plugins/source/stubs/Project003Stub.java | 108 ------------
.../maven/plugins/source/stubs/Project005Stub.java | 94 ----------
.../maven/plugins/source/stubs/Project007Stub.java | 107 ------------
.../maven/plugins/source/stubs/Project009Stub.java | 109 ------------
.../maven/plugins/source/stubs/Project010Stub.java | 108 ------------
.../maven/plugins/source/stubs/ProjectStub.java | 57 ++++++
.../source/stubs/SourcePluginArtifactStub.java | 134 --------------
src/test/resources/unit/project-001/pom.xml | 24 ---
.../src/test/java/foo/project001/AppTest.java | 33 +---
src/test/resources/unit/project-003/pom.xml | 30 ----
.../src/test/java/foo/project003/AppTest.java | 33 +---
src/test/resources/unit/project-005/pom.xml | 14 --
src/test/resources/unit/project-007/pom.xml | 22 ---
src/test/resources/unit/project-009/pom.xml | 20 ---
src/test/resources/unit/project-010/pom.xml | 22 ---
.../src/test/java/foo/project010/AppTest.java | 33 +---
23 files changed, 361 insertions(+), 1407 deletions(-)
diff --git a/pom.xml b/pom.xml
index c5dd56e..359aec5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -79,6 +79,9 @@ under the License.
<properties>
<javaVersion>8</javaVersion>
<mavenVersion>3.9.11</mavenVersion>
+
+ <enforce.dependency.declarations>true</enforce.dependency.declarations>
+
<project.build.outputTimestamp>2025-11-22T22:27:16Z</project.build.outputTimestamp>
<version.maven-invoker-plugin>3.9.1</version.maven-invoker-plugin>
@@ -143,6 +146,13 @@ under the License.
<artifactId>plexus-utils</artifactId>
</dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>1</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
@@ -150,15 +160,14 @@ under the License.
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-compat</artifactId>
- <version>${mavenVersion}</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.7.36</version>
<scope>test</scope>
</dependency>
</dependencies>
diff --git
a/src/test/java/org/apache/maven/plugins/source/AbstractSourcePluginTest.java
b/src/test/java/org/apache/maven/plugins/source/AbstractSourcePluginTest.java
new file mode 100644
index 0000000..6b00aa5
--- /dev/null
+++
b/src/test/java/org/apache/maven/plugins/source/AbstractSourcePluginTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugins.source;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * @author Stephane Nicoll
+ */
+abstract class AbstractSourcePluginTest {
+
+ private static final String FINAL_NAME_PREFIX =
"maven-source-plugin-test-99.0";
+
+ protected String[] addMavenDescriptor(String... listOfElements) {
+ final String metainf = "META-INF/";
+ final String mavensource = "maven/groupId/maven-source-plugin-test";
+ int length = listOfElements.length;
+ String[] result = new String[length + 7];
+ System.arraycopy(listOfElements, 0, result, 0, length);
+ result[length] = metainf;
+ result[length + 1] = metainf + "MANIFEST.MF";
+ result[length + 2] = metainf + "maven/";
+ result[length + 3] = metainf + "maven/groupId/";
+ result[length + 4] = metainf + mavensource + "/";
+ result[length + 5] = metainf + mavensource + "/pom.properties";
+ result[length + 6] = metainf + mavensource + "/pom.xml";
+ return result;
+ }
+
+ protected void assertSourceArchive(final File testTargetDir) {
+ final File expectedFile = getSourceArchive(testTargetDir);
+ assertTrue(expectedFile.exists(), "Source archive does not exist[" +
expectedFile.getAbsolutePath() + "]");
+ }
+
+ protected void assertTestSourceArchive(final File testTargetDir) {
+ final File expectedFile = getTestSourceArchive(testTargetDir);
+ assertTrue(expectedFile.exists(), "Test source archive does not
exist[" + expectedFile.getAbsolutePath() + "]");
+ }
+
+ protected File getSourceArchive(final File testTargetDir) {
+ return new File(testTargetDir, FINAL_NAME_PREFIX + "-sources" +
".jar");
+ }
+
+ protected File getTestSourceArchive(final File testTargetDir) {
+ return new File(testTargetDir, FINAL_NAME_PREFIX + "-test-sources" +
".jar");
+ }
+
+ protected void assertJarContent(final File jarFile, final String[]
expectedFiles) throws IOException {
+ try (ZipFile jar = new ZipFile(jarFile)) {
+ Enumeration<? extends ZipEntry> entries = jar.entries();
+
+ if (expectedFiles.length == 0) {
+ assertFalse(entries.hasMoreElements(), "Jar file should not
contain any entry");
+ } else {
+ assertTrue(entries.hasMoreElements());
+
+ Set<String> expected = new
TreeSet<>(Arrays.asList(expectedFiles));
+
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = entries.nextElement();
+
+ assertTrue(expected.remove(entry.getName()), "Not
expecting " + entry.getName() + " in " + jarFile);
+ }
+
+ assertTrue(expected.isEmpty(), "Missing entries " + expected +
" in " + jarFile);
+ }
+ }
+ }
+}
diff --git
a/src/test/java/org/apache/maven/plugins/source/AbstractSourcePluginTestCase.java
b/src/test/java/org/apache/maven/plugins/source/AbstractSourcePluginTestCase.java
deleted file mode 100644
index 19d9e99..0000000
---
a/src/test/java/org/apache/maven/plugins/source/AbstractSourcePluginTestCase.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * 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.
- */
-package org.apache.maven.plugins.source;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-
-/**
- * @author Stephane Nicoll
- */
-public abstract class AbstractSourcePluginTestCase extends
AbstractMojoTestCase {
-
- protected static final String FINAL_NAME_PREFIX =
"maven-source-plugin-test-";
-
- protected static final String FINAL_NAME_SUFFIX = "-99.0";
-
- protected abstract String getGoal();
-
- /**
- * Execute the source plugin for the specified project.
- *
- * @param projectName the name of the project
- * @param classifier The classifier.
- * @throws Exception if an error occurred
- */
- protected void executeMojo(final String projectName, String classifier)
throws Exception {
- File testPom = new File(getBasedir(), getTestDir(projectName) +
"/pom.xml");
- AbstractSourceJarMojo mojo = (AbstractSourceJarMojo)
lookupMojo(getGoal(), testPom);
-
- // Without the following line the tests will fail, cause the
project.getFile() will result with null.
- mojo.getProject().setFile(testPom);
-
- setVariableValueToObject(mojo, "classifier", classifier);
-
- mojo.execute();
- }
-
- /**
- * Executes the specified projects and asserts the given artifacts.
- *
- * @param projectName the project to test
- * @param expectSourceArchive if a source archive is expected
- * @param expectTestSourceArchive if a test source archive is expected
- * @param expectedSourceFiles the expected files in the source
archive, if any
- * @param expectedTestSourceFiles the expected files in the test source
archive, if any
- * @param classifier the classifier.
- * @return the base directory of the project
- * @throws Exception if any error occurs
- */
- protected File doTestProject(
- final String projectName,
- boolean expectSourceArchive,
- boolean expectTestSourceArchive,
- final String[] expectedSourceFiles,
- final String[] expectedTestSourceFiles,
- String classifier)
- throws Exception {
- executeMojo(projectName, classifier);
- final File testTargetDir = getTestTargetDir(projectName);
-
- if (expectSourceArchive) {
- assertSourceArchive(testTargetDir, projectName);
- assertJarContent(getSourceArchive(testTargetDir, projectName),
expectedSourceFiles);
- }
-
- if (expectTestSourceArchive) {
- assertTestSourceArchive(testTargetDir, projectName);
- assertJarContent(getTestSourceArchive(testTargetDir, projectName),
expectedTestSourceFiles);
- }
-
- return testTargetDir;
- }
-
- /**
- * Executes the specified projects and asserts the given artifacts for a
source archive.
- *
- * @param projectName the project to test
- * @param expectedSourceFiles the expected files in the source archive, if
any
- * @param classifier the classifier.
- * @return the base directory of the project
- * @throws Exception if any error occurs
- */
- protected File doTestProjectWithSourceArchive(
- final String projectName, final String[] expectedSourceFiles,
String classifier) throws Exception {
- return doTestProject(projectName, true, false, expectedSourceFiles,
null, classifier);
- }
-
- /**
- * Executes the specified projects and asserts the given artifacts for a
test source archive.
- *
- * @param projectName the project to test
- * @param expectedTestSourceFiles the expected files in the test source
archive, if any
- * @param classifier the classifier.
- * @return the base directory of the project
- * @throws Exception if any error occurs
- */
- protected File doTestProjectWithTestSourceArchive(
- final String projectName, final String[] expectedTestSourceFiles,
String classifier) throws Exception {
- return doTestProject(projectName, false, true, null,
expectedTestSourceFiles, classifier);
- }
-
- protected void assertSourceArchive(final File testTargetDir, final String
projectName) {
- final File expectedFile = getSourceArchive(testTargetDir, projectName);
- assertTrue("Source archive does not exist[" +
expectedFile.getAbsolutePath() + "]", expectedFile.exists());
- }
-
- protected void assertTestSourceArchive(final File testTargetDir, final
String projectName) {
- final File expectedFile = getTestSourceArchive(testTargetDir,
projectName);
- assertTrue("Test source archive does not exist[" +
expectedFile.getAbsolutePath() + "]", expectedFile.exists());
- }
-
- protected File getSourceArchive(final File testTargetDir, final String
projectName) {
- return new File(testTargetDir, buildFinalSourceName(projectName) +
".jar");
- }
-
- protected File getTestSourceArchive(final File testTargetDir, final String
projectName) {
- return new File(testTargetDir, buildFinalTestSourceName(projectName) +
".jar");
- }
-
- protected String buildFinalSourceName(final String projectName) {
- return FINAL_NAME_PREFIX + projectName + FINAL_NAME_SUFFIX +
"-sources";
- }
-
- protected String buildFinalTestSourceName(final String projectName) {
- return FINAL_NAME_PREFIX + projectName + FINAL_NAME_SUFFIX +
"-test-sources";
- }
-
- protected File getTestDir(String projectName) throws IOException {
- File f = new File("target/test-classes/unit/" + projectName);
- if (!new File(f, "pom.xml").exists()) {
- throw new IllegalStateException("No pom file found in " +
f.getPath());
- }
- return f;
- }
-
- protected void assertJarContent(final File jarFile, final String[]
expectedFiles) throws IOException {
- ZipFile jar = new ZipFile(jarFile);
- Enumeration<? extends ZipEntry> entries = jar.entries();
-
- if (expectedFiles.length == 0) {
- assertFalse("Jar file should not contain any entry",
entries.hasMoreElements());
- } else {
- assertTrue(entries.hasMoreElements());
-
- Set<String> expected = new TreeSet<>(Arrays.asList(expectedFiles));
-
- while (entries.hasMoreElements()) {
- ZipEntry entry = entries.nextElement();
-
- assertTrue("Not expecting " + entry.getName() + " in " +
jarFile, expected.remove(entry.getName()));
- }
-
- assertTrue("Missing entries " + expected.toString() + " in " +
jarFile, expected.isEmpty());
- }
-
- jar.close();
- }
-
- protected File getTestTargetDir(String projectName) {
- return new File(getBasedir(), "target/test/unit/" + projectName +
"/target");
- }
-}
diff --git
a/src/test/java/org/apache/maven/plugins/source/SourceJarMojoTest.java
b/src/test/java/org/apache/maven/plugins/source/SourceJarMojoTest.java
index ac8f02a..71fdd35 100644
--- a/src/test/java/org/apache/maven/plugins/source/SourceJarMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/source/SourceJarMojoTest.java
@@ -18,108 +18,136 @@
*/
package org.apache.maven.plugins.source;
+import javax.inject.Inject;
+
import java.io.File;
+import org.apache.maven.api.di.Provides;
+import org.apache.maven.api.plugin.testing.Basedir;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoParameter;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.plugins.source.stubs.ProjectStub;
+import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
/**
* @author <a href="mailto:[email protected]">Maria Odea Ching</a>
*/
-public class SourceJarMojoTest extends AbstractSourcePluginTestCase {
- protected String getGoal() {
- return "jar";
- }
+@MojoTest
+class SourceJarMojoTest extends AbstractSourcePluginTest {
+
+ @TempDir
+ private File tempDir;
- private String[] addMavenDescriptor(String project, String[]
listOfElements) {
- final String metainf = "META-INF/";
- final String mavensource = "maven/source/maven-source-plugin-test-";
- int length = listOfElements.length;
- String[] result = new String[length + 5];
- System.arraycopy(listOfElements, 0, result, 0, length);
- result[length] = metainf + "maven/";
- result[length + 1] = metainf + "maven/source/";
- result[length + 2] = metainf + mavensource + project + "/";
- result[length + 3] = metainf + mavensource + project +
"/pom.properties";
- result[length + 4] = metainf + mavensource + project + "/pom.xml";
- return result;
+ @Inject
+ private MavenProject project;
+
+ @Provides
+ @SuppressWarnings("unused")
+ private MavenProject projectProvides() {
+ return new ProjectStub(tempDir);
}
- public void testDefaultConfiguration() throws Exception {
- doTestProjectWithSourceArchive(
- "project-001",
- addMavenDescriptor("project-001", new String[] {
- "default-configuration.properties",
- "foo/project001/App.java",
- "foo/project001/",
- "foo/",
- "META-INF/MANIFEST.MF",
- "META-INF/"
- }),
- "sources");
+ @Test
+ @InjectMojo(goal = "jar")
+ @Basedir("/unit/project-001")
+ void testDefaultConfiguration(SourceJarMojo mojo) throws Exception {
+
+ mojo.execute();
+
+ File target = new File(tempDir, "target");
+ assertSourceArchive(target);
+ assertJarContent(
+ getSourceArchive(target),
+ addMavenDescriptor(
+ "default-configuration.properties",
"foo/project001/App.java", "foo/project001/", "foo/"));
}
- public void testExcludes() throws Exception {
- doTestProjectWithSourceArchive(
- "project-003",
- addMavenDescriptor("project-003", new String[] {
- "default-configuration.properties",
- "foo/project003/App.java",
- "foo/project003/",
- "foo/",
- "META-INF/MANIFEST.MF",
- "META-INF/"
- }),
- "sources");
+ @Test
+ @InjectMojo(goal = "jar")
+ @Basedir("/unit/project-003")
+ void testExcludes(SourceJarMojo mojo) throws Exception {
+
+ project.getResources().get(0).addExclude("excluded-file.txt");
+
+ mojo.execute();
+
+ File target = new File(tempDir, "target");
+ assertSourceArchive(target);
+ assertJarContent(
+ getSourceArchive(target),
+ addMavenDescriptor(
+ "default-configuration.properties",
"foo/project003/App.java", "foo/project003/", "foo/"));
}
- public void testNoSources() throws Exception {
- executeMojo("project-005", "sources");
+ @Test
+ @InjectMojo(goal = "jar")
+ @Basedir("/unit/project-005")
+ void testNoSources(SourceJarMojo mojo) throws Exception {
+ mojo.execute();
+
// Now make sure that no archive got created
- final File expectedFile = getTestTargetDir("project-005");
+ final File expectedFile = new File(tempDir, "target");
assertFalse(
- "Source archive should not have been created[" +
expectedFile.getAbsolutePath() + "]",
- expectedFile.exists());
+ expectedFile.exists(),
+ "Source archive should not have been created[" +
expectedFile.getAbsolutePath() + "]");
}
- public void testIncludes() throws Exception {
- doTestProjectWithSourceArchive(
- "project-007",
- addMavenDescriptor("project-007", new String[] {
- "templates/configuration-template.properties",
- "foo/project007/App.java",
- "templates/",
- "foo/project007/",
- "foo/",
- "META-INF/MANIFEST.MF",
- "META-INF/"
- }),
- "sources");
+ @Test
+ @InjectMojo(goal = "jar")
+ @Basedir("/unit/project-007")
+ void testIncludes(AbstractSourceJarMojo mojo) throws Exception {
+ project.getResources().get(0).addInclude("templates/**");
+
+ mojo.execute();
+
+ File target = new File(tempDir, "target");
+ assertSourceArchive(target);
+ assertJarContent(
+ getSourceArchive(target),
+ addMavenDescriptor(
+ "templates/configuration-template.properties",
+ "foo/project007/App.java",
+ "templates/",
+ "foo/project007/",
+ "foo/"));
}
- public void testIncludePom() throws Exception {
- doTestProjectWithSourceArchive(
- "project-009",
- addMavenDescriptor("project-009", new String[] {
- "default-configuration.properties",
- "pom.xml",
- "foo/project009/App.java",
- "foo/project009/",
- "foo/",
- "META-INF/MANIFEST.MF",
- "META-INF/"
- }),
- "sources");
+ @Test
+ @InjectMojo(goal = "jar")
+ @Basedir("/unit/project-009")
+ @MojoParameter(name = "includePom", value = "true")
+ void testIncludePom(SourceJarMojo mojo) throws Exception {
+
+ mojo.execute();
+
+ File target = new File(tempDir, "target");
+ assertSourceArchive(target);
+ assertJarContent(
+ getSourceArchive(target),
+ addMavenDescriptor(
+ "default-configuration.properties",
+ "pom.xml",
+ "foo/project009/App.java",
+ "foo/project009/",
+ "foo/"));
}
- public void testIncludeMavenDescriptorWhenExplicitlyConfigured() throws
Exception {
- doTestProjectWithSourceArchive(
- "project-010",
- addMavenDescriptor("project-010", new String[] {
- "default-configuration.properties",
- "foo/project010/App.java",
- "foo/project010/",
- "foo/",
- "META-INF/MANIFEST.MF",
- "META-INF/"
- }),
- "sources");
+ @Test
+ @InjectMojo(goal = "jar")
+ @Basedir("/unit/project-010")
+ void testIncludeMavenDescriptorWhenExplicitlyConfigured(SourceJarMojo
mojo) throws Exception {
+ mojo.execute();
+
+ File target = new File(tempDir, "target");
+ assertSourceArchive(target);
+ assertJarContent(
+ getSourceArchive(target),
+ addMavenDescriptor(
+ "default-configuration.properties",
"foo/project010/App.java", "foo/project010/", "foo/"));
}
}
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 bcb7b34..435c093 100644
--- a/src/test/java/org/apache/maven/plugins/source/TestSourceJarMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/source/TestSourceJarMojoTest.java
@@ -18,81 +18,102 @@
*/
package org.apache.maven.plugins.source;
+import javax.inject.Inject;
+
import java.io.File;
+import org.apache.maven.api.di.Provides;
+import org.apache.maven.api.plugin.testing.Basedir;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.plugins.source.stubs.ProjectStub;
+import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
/**
* @author <a href="mailto:[email protected]">Maria Odea Ching</a>
*/
-public class TestSourceJarMojoTest extends AbstractSourcePluginTestCase {
+@MojoTest
+class TestSourceJarMojoTest extends AbstractSourcePluginTest {
+
+ @TempDir
+ private File tempDir;
+
+ @Inject
+ private MavenProject project;
- protected String getGoal() {
- return "test-jar";
+ @Provides
+ @SuppressWarnings("unused")
+ private MavenProject projectProvides() {
+ return new ProjectStub(tempDir);
}
- public void testDefaultConfiguration() throws Exception {
- doTestProjectWithTestSourceArchive(
- "project-001",
- new String[] {
- "test-default-configuration.properties",
- "foo/project001/AppTest.java",
- "foo/project001/",
- "foo/",
- "META-INF/MANIFEST.MF",
- "META-INF/",
- "META-INF/maven/",
- "META-INF/maven/source/",
-
"META-INF/maven/source/maven-source-plugin-test-project-001/",
-
"META-INF/maven/source/maven-source-plugin-test-project-001/pom.properties",
-
"META-INF/maven/source/maven-source-plugin-test-project-001/pom.xml"
- },
- "test-sources");
+ @Test
+ @InjectMojo(goal = "test-jar")
+ @Basedir("/unit/project-001")
+ void testDefaultConfiguration(TestSourceJarMojo mojo) throws Exception {
+ mojo.execute();
+
+ File target = new File(tempDir, "target");
+ assertTestSourceArchive(target);
+ assertJarContent(
+ getTestSourceArchive(target),
+ addMavenDescriptor(
+ "test-default-configuration.properties",
+ "foo/project001/AppTest.java",
+ "foo/project001/",
+ "foo/"));
}
- public void testExcludes() throws Exception {
- doTestProjectWithTestSourceArchive(
- "project-003",
- new String[] {
- "test-default-configuration.properties",
- "foo/project003/AppTest.java",
- "foo/project003/",
- "foo/",
- "META-INF/MANIFEST.MF",
- "META-INF/",
- "META-INF/maven/",
- "META-INF/maven/source/",
-
"META-INF/maven/source/maven-source-plugin-test-project-003/",
-
"META-INF/maven/source/maven-source-plugin-test-project-003/pom.properties",
-
"META-INF/maven/source/maven-source-plugin-test-project-003/pom.xml"
- },
- "test-sources");
+ @Test
+ @InjectMojo(goal = "test-jar")
+ @Basedir("/unit/project-003")
+ void testExcludes(TestSourceJarMojo mojo) throws Exception {
+ project.getTestResources().get(0).addExclude("excluded-file.txt");
+
+ mojo.execute();
+
+ File target = new File(tempDir, "target");
+ assertTestSourceArchive(target);
+ assertJarContent(
+ getTestSourceArchive(target),
+ addMavenDescriptor(
+ "test-default-configuration.properties",
+ "foo/project003/AppTest.java",
+ "foo/project003/",
+ "foo/"));
}
- public void testNoSources() throws Exception {
- executeMojo("project-005", "test-sources");
+ @Test
+ @InjectMojo(goal = "test-jar")
+ @Basedir("/unit/project-005")
+ void testNoSources(TestSourceJarMojo mojo) throws Exception {
+ mojo.execute();
// Now make sure that no archive got created
- final File expectedFile = getTestTargetDir("project-005");
+ File expectedFile = new File(tempDir, "target");
assertFalse(
- "Test source archive should not have been created[" +
expectedFile.getAbsolutePath() + "]",
- expectedFile.exists());
+ expectedFile.exists(),
+ "Test source archive should not have been created[" +
expectedFile.getAbsolutePath() + "]");
}
- public void testIncludeMavenDescriptorWhenExplicitlyConfigured() throws
Exception {
- doTestProjectWithTestSourceArchive(
- "project-010",
- new String[] {
- "test-default-configuration.properties",
- "foo/project010/AppTest.java",
- "foo/project010/",
- "foo/",
- "META-INF/MANIFEST.MF",
- "META-INF/",
- "META-INF/maven/",
- "META-INF/maven/source/",
-
"META-INF/maven/source/maven-source-plugin-test-project-010/",
-
"META-INF/maven/source/maven-source-plugin-test-project-010/pom.xml",
-
"META-INF/maven/source/maven-source-plugin-test-project-010/pom" + ".properties"
- },
- "test-sources");
+ @Test
+ @InjectMojo(goal = "test-jar")
+ @Basedir("/unit/project-010")
+ void
testIncludeMavenDescriptorWhenExplicitlyConfigured(AbstractSourceJarMojo mojo)
throws Exception {
+ mojo.execute();
+
+ File target = new File(tempDir, "target");
+ assertTestSourceArchive(target);
+ assertJarContent(
+ getTestSourceArchive(target),
+ addMavenDescriptor(
+ "test-default-configuration.properties",
+ "foo/project010/AppTest.java",
+ "foo/project010/",
+ "foo/"));
}
}
diff --git
a/src/test/java/org/apache/maven/plugins/source/stubs/DefaultArtifactHandlerStub.java
b/src/test/java/org/apache/maven/plugins/source/stubs/DefaultArtifactHandlerStub.java
deleted file mode 100755
index 506f23a..0000000
---
a/src/test/java/org/apache/maven/plugins/source/stubs/DefaultArtifactHandlerStub.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.
- */
-package org.apache.maven.plugins.source.stubs;
-
-/*
- * 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.artifact.handler.DefaultArtifactHandler;
-
-/**
- * @author pgier
- */
-public class DefaultArtifactHandlerStub extends DefaultArtifactHandler {
- private String language;
-
- public String getLanguage() {
- if (language == null) {
- language = "java";
- }
-
- return language;
- }
-
- public void setLanguage(String language) {
- this.language = language;
- }
-}
diff --git
a/src/test/java/org/apache/maven/plugins/source/stubs/Project001Stub.java
b/src/test/java/org/apache/maven/plugins/source/stubs/Project001Stub.java
deleted file mode 100644
index 773eeb9..0000000
--- a/src/test/java/org/apache/maven/plugins/source/stubs/Project001Stub.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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.
- */
-package org.apache.maven.plugins.source.stubs;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.maven.model.Build;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Resource;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.ReaderFactory;
-import org.codehaus.plexus.util.xml.XmlStreamReader;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-
-/**
- * @author <a href="mailto:[email protected]">Maria Odea Ching</a>
- */
-public class Project001Stub extends MavenProjectStub {
- private Build build;
-
- private List<Resource> resources;
-
- private List<Resource> testResources;
-
- public Project001Stub() {
- Model model;
-
- try {
- model = readModelFromFile(new File(getBasedir(),
"target/test-classes/unit/project-001/pom.xml"));
- setModel(model);
-
- setGroupId(model.getGroupId());
- setArtifactId(model.getArtifactId());
- setVersion(model.getVersion());
- setName(model.getName());
- setUrl(model.getUrl());
- setPackaging(model.getPackaging());
-
- Build build = new Build();
- build.setFinalName(getArtifactId() + "-" + getVersion());
- build.setDirectory(getBasedir() +
"/target/test/unit/project-001/target");
- setBuild(build);
-
- String basedir = getBasedir().getAbsolutePath();
- List<String> compileSourceRoots = new ArrayList<>();
- compileSourceRoots.add(basedir +
"/target/test-classes/unit/project-001/src/main/java");
- setCompileSourceRoots(compileSourceRoots);
-
- List<String> testCompileSourceRoots = new ArrayList<>();
- testCompileSourceRoots.add(basedir +
"/target/test-classes/unit/project-001/src/test/java");
- setTestCompileSourceRoots(testCompileSourceRoots);
-
- setResources(model.getBuild().getResources());
- setTestResources(model.getBuild().getTestResources());
-
- SourcePluginArtifactStub artifact =
- new SourcePluginArtifactStub(getGroupId(),
getArtifactId(), getVersion(), getPackaging(), null);
- artifact.setArtifactHandler(new DefaultArtifactHandlerStub());
- artifact.setType("jar");
- artifact.setBaseVersion("1.0-SNAPSHOT");
- setArtifact(artifact);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public Build getBuild() {
- return build;
- }
-
- public void setBuild(Build build) {
- this.build = build;
- }
-
- public List<Resource> getResources() {
- return this.resources;
- }
-
- public void setResources(List<Resource> resources) {
- this.resources = resources;
- }
-
- public List<Resource> getTestResources() {
- return testResources;
- }
-
- public void setTestResources(List<Resource> testResources) {
- this.testResources = testResources;
- }
-
- static Model readModelFromFile(File file) throws IOException,
XmlPullParserException {
- MavenXpp3Reader pomReader = new MavenXpp3Reader();
- XmlStreamReader reader = null;
- try {
- reader = ReaderFactory.newXmlReader(file);
- final Model model = pomReader.read(reader);
- reader.close();
- reader = null;
- return model;
- } finally {
- IOUtil.close(reader);
- }
- }
-}
diff --git
a/src/test/java/org/apache/maven/plugins/source/stubs/Project003Stub.java
b/src/test/java/org/apache/maven/plugins/source/stubs/Project003Stub.java
deleted file mode 100644
index c010351..0000000
--- a/src/test/java/org/apache/maven/plugins/source/stubs/Project003Stub.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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.
- */
-package org.apache.maven.plugins.source.stubs;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.maven.model.Build;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Resource;
-import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
-
-import static
org.apache.maven.plugins.source.stubs.Project001Stub.readModelFromFile;
-
-/**
- * @author <a href="mailto:[email protected]">Maria Odea Ching</a>
- */
-public class Project003Stub extends MavenProjectStub {
- private Build build;
-
- private List<Resource> resources;
-
- private List<Resource> testResources;
-
- public Project003Stub() {
- Model model;
-
- try {
- model = readModelFromFile(new File(getBasedir(),
"target/test-classes/unit/project-003/pom.xml"));
- setModel(model);
-
- setGroupId(model.getGroupId());
- setArtifactId(model.getArtifactId());
- setVersion(model.getVersion());
- setName(model.getName());
- setUrl(model.getUrl());
- setPackaging(model.getPackaging());
-
- Build build = new Build();
- build.setFinalName(getArtifactId() + "-" + getVersion());
- build.setDirectory(getBasedir() +
"/target/test/unit/project-003/target");
- setBuild(build);
-
- String basedir = getBasedir().getAbsolutePath();
- List<String> compileSourceRoots = new ArrayList<>();
- compileSourceRoots.add(basedir +
"/target/test-classes/unit/project-003/src/main/java");
- setCompileSourceRoots(compileSourceRoots);
-
- List<String> testCompileSourceRoots = new ArrayList<>();
- testCompileSourceRoots.add(basedir +
"/target/test-classes/unit/project-003/src/test/java");
- setTestCompileSourceRoots(testCompileSourceRoots);
-
- setResources(model.getBuild().getResources());
- setTestResources(model.getBuild().getTestResources());
-
- SourcePluginArtifactStub artifact =
- new SourcePluginArtifactStub(getGroupId(),
getArtifactId(), getVersion(), getPackaging(), null);
- artifact.setArtifactHandler(new DefaultArtifactHandlerStub());
- artifact.setType("jar");
- artifact.setBaseVersion("1.0-SNAPSHOT");
- setArtifact(artifact);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public Build getBuild() {
- return build;
- }
-
- public void setBuild(Build build) {
- this.build = build;
- }
-
- public List<Resource> getResources() {
- return resources;
- }
-
- public void setResources(List<Resource> resources) {
- this.resources = resources;
- }
-
- public List<Resource> getTestResources() {
- return testResources;
- }
-
- public void setTestResources(List<Resource> testResources) {
- this.testResources = testResources;
- }
-}
diff --git
a/src/test/java/org/apache/maven/plugins/source/stubs/Project005Stub.java
b/src/test/java/org/apache/maven/plugins/source/stubs/Project005Stub.java
deleted file mode 100644
index ee00cf6..0000000
--- a/src/test/java/org/apache/maven/plugins/source/stubs/Project005Stub.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.
- */
-package org.apache.maven.plugins.source.stubs;
-
-import java.io.File;
-import java.util.List;
-
-import org.apache.maven.model.Build;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Resource;
-import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
-
-import static
org.apache.maven.plugins.source.stubs.Project001Stub.readModelFromFile;
-
-/**
- * @author <a href="mailto:[email protected]">Maria Odea Ching</a>
- */
-public class Project005Stub extends MavenProjectStub {
- private Build build;
-
- private List<Resource> resources;
-
- private List<Resource> testResources;
-
- public Project005Stub() {
- Model model;
- try {
- model = readModelFromFile(new File(getBasedir(),
"target/test-classes/unit/project-005/pom.xml"));
- setModel(model);
-
- setGroupId(model.getGroupId());
- setArtifactId(model.getArtifactId());
- setVersion(model.getVersion());
- setName(model.getName());
- setUrl(model.getUrl());
- setPackaging(model.getPackaging());
-
- Build build = new Build();
- build.setFinalName(getArtifactId() + "-" + getVersion());
- build.setDirectory(getBasedir() +
"/target/test/unit/project-005/target");
- setBuild(build);
-
- SourcePluginArtifactStub artifact =
- new SourcePluginArtifactStub(getGroupId(),
getArtifactId(), getVersion(), getPackaging(), null);
- artifact.setArtifactHandler(new DefaultArtifactHandlerStub());
- artifact.setType("jar");
- artifact.setBaseVersion("1.0-SNAPSHOT");
- setArtifact(artifact);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public Build getBuild() {
- return build;
- }
-
- public void setBuild(Build build) {
- this.build = build;
- }
-
- public List<Resource> getResources() {
- return resources;
- }
-
- public void setResources(List<Resource> resources) {
- this.resources = resources;
- }
-
- public List<Resource> getTestResources() {
- return testResources;
- }
-
- public void setTestResources(List<Resource> testResources) {
- this.testResources = testResources;
- }
-}
diff --git
a/src/test/java/org/apache/maven/plugins/source/stubs/Project007Stub.java
b/src/test/java/org/apache/maven/plugins/source/stubs/Project007Stub.java
deleted file mode 100644
index 120cc5b..0000000
--- a/src/test/java/org/apache/maven/plugins/source/stubs/Project007Stub.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.
- */
-package org.apache.maven.plugins.source.stubs;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.maven.model.Build;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Resource;
-import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
-
-import static
org.apache.maven.plugins.source.stubs.Project001Stub.readModelFromFile;
-
-/**
- * @author <a href="mailto:[email protected]">Maria Odea Ching</a>
- */
-public class Project007Stub extends MavenProjectStub {
- private Build build;
-
- private List<Resource> resources;
-
- private List<Resource> testResources;
-
- public Project007Stub() {
- Model model;
- try {
- model = readModelFromFile(new File(getBasedir(),
"target/test-classes/unit/project-007/pom.xml"));
- setModel(model);
-
- setGroupId(model.getGroupId());
- setArtifactId(model.getArtifactId());
- setVersion(model.getVersion());
- setName(model.getName());
- setUrl(model.getUrl());
- setPackaging(model.getPackaging());
-
- Build build = new Build();
- build.setFinalName(getArtifactId() + "-" + getVersion());
- build.setDirectory(getBasedir() +
"/target/test/unit/project-007/target");
- setBuild(build);
-
- String basedir = getBasedir().getAbsolutePath();
- List<String> compileSourceRoots = new ArrayList<>();
- compileSourceRoots.add(basedir +
"/target/test-classes/unit/project-007/src/main/java");
- setCompileSourceRoots(compileSourceRoots);
-
- List<String> testCompileSourceRoots = new ArrayList<>();
- testCompileSourceRoots.add(basedir +
"/target/test-classes/unit/project-007/src/test/java");
- setTestCompileSourceRoots(testCompileSourceRoots);
-
- setResources(model.getBuild().getResources());
- setTestResources(model.getBuild().getTestResources());
-
- SourcePluginArtifactStub artifact =
- new SourcePluginArtifactStub(getGroupId(),
getArtifactId(), getVersion(), getPackaging(), null);
- artifact.setArtifactHandler(new DefaultArtifactHandlerStub());
- artifact.setType("jar");
- artifact.setBaseVersion("1.0-SNAPSHOT");
- setArtifact(artifact);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public Build getBuild() {
- return build;
- }
-
- public void setBuild(Build build) {
- this.build = build;
- }
-
- public List<Resource> getResources() {
- return resources;
- }
-
- public void setResources(List<Resource> resources) {
- this.resources = resources;
- }
-
- public List<Resource> getTestResources() {
- return testResources;
- }
-
- public void setTestResources(List<Resource> testResources) {
- this.testResources = testResources;
- }
-}
diff --git
a/src/test/java/org/apache/maven/plugins/source/stubs/Project009Stub.java
b/src/test/java/org/apache/maven/plugins/source/stubs/Project009Stub.java
deleted file mode 100644
index 3955a2e..0000000
--- a/src/test/java/org/apache/maven/plugins/source/stubs/Project009Stub.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.
- */
-package org.apache.maven.plugins.source.stubs;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.maven.model.Build;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Resource;
-import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
-
-import static
org.apache.maven.plugins.source.stubs.Project001Stub.readModelFromFile;
-
-/**
- * @author Dennis Lundberg
- */
-public class Project009Stub extends MavenProjectStub {
- private Build build;
-
- private List<Resource> resources;
-
- private List<Resource> testResources;
-
- public Project009Stub() {
- Model model;
-
- try {
- final File pomFile = new File(getBasedir(),
"target/test-classes/unit/project-009/pom.xml");
- model = readModelFromFile(pomFile);
- setModel(model);
- setFile(pomFile);
-
- setGroupId(model.getGroupId());
- setArtifactId(model.getArtifactId());
- setVersion(model.getVersion());
- setName(model.getName());
- setUrl(model.getUrl());
- setPackaging(model.getPackaging());
-
- Build build = new Build();
- build.setFinalName(getArtifactId() + "-" + getVersion());
- build.setDirectory(getBasedir() +
"/target/test/unit/project-009/target");
- setBuild(build);
-
- String basedir = getBasedir().getAbsolutePath();
- List<String> compileSourceRoots = new ArrayList<>();
- compileSourceRoots.add(basedir +
"/target/test-classes/unit/project-009/src/main/java");
- setCompileSourceRoots(compileSourceRoots);
-
- List<String> testCompileSourceRoots = new ArrayList<>();
- testCompileSourceRoots.add(basedir +
"/target/test-classes/unit/project-009/src/test/java");
- setTestCompileSourceRoots(testCompileSourceRoots);
-
- setResources(model.getBuild().getResources());
- setTestResources(model.getBuild().getTestResources());
-
- SourcePluginArtifactStub artifact =
- new SourcePluginArtifactStub(getGroupId(),
getArtifactId(), getVersion(), getPackaging(), null);
- artifact.setArtifactHandler(new DefaultArtifactHandlerStub());
- artifact.setType("jar");
- artifact.setBaseVersion("1.0-SNAPSHOT");
- setArtifact(artifact);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public Build getBuild() {
- return build;
- }
-
- public void setBuild(Build build) {
- this.build = build;
- }
-
- public List<Resource> getResources() {
- return resources;
- }
-
- public void setResources(List<Resource> resources) {
- this.resources = resources;
- }
-
- public List<Resource> getTestResources() {
- return testResources;
- }
-
- public void setTestResources(List<Resource> testResources) {
- this.testResources = testResources;
- }
-}
diff --git
a/src/test/java/org/apache/maven/plugins/source/stubs/Project010Stub.java
b/src/test/java/org/apache/maven/plugins/source/stubs/Project010Stub.java
deleted file mode 100644
index 90a5a4a..0000000
--- a/src/test/java/org/apache/maven/plugins/source/stubs/Project010Stub.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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.
- */
-package org.apache.maven.plugins.source.stubs;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.maven.model.Build;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Resource;
-import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
-
-import static
org.apache.maven.plugins.source.stubs.Project001Stub.readModelFromFile;
-
-public class Project010Stub extends MavenProjectStub {
- private Build build;
-
- private List<Resource> resources;
-
- private List<Resource> testResources;
-
- public Project010Stub() {
- Model model;
-
- try {
- model = readModelFromFile(new File(getBasedir(),
"target/test-classes/unit/project-010/pom.xml"));
- setModel(model);
-
- setFile(new File(getBasedir(),
"target/test-classes/unit/project-010/pom.xml"));
-
- setGroupId(model.getGroupId());
- setArtifactId(model.getArtifactId());
- setVersion(model.getVersion());
- setName(model.getName());
- setUrl(model.getUrl());
- setPackaging(model.getPackaging());
-
- Build build = new Build();
- build.setFinalName(getArtifactId() + "-" + getVersion());
- build.setDirectory(getBasedir() +
"/target/test/unit/project-010/target");
-
- setBuild(build);
-
- String basedir = getBasedir().getAbsolutePath();
- List<String> compileSourceRoots = new ArrayList<>();
- compileSourceRoots.add(basedir +
"/target/test-classes/unit/project-010/src/main/java");
- setCompileSourceRoots(compileSourceRoots);
-
- List<String> testCompileSourceRoots = new ArrayList<>();
- testCompileSourceRoots.add(basedir +
"/target/test-classes/unit/project-010/src/test/java");
- setTestCompileSourceRoots(testCompileSourceRoots);
-
- setResources(model.getBuild().getResources());
- setTestResources(model.getBuild().getTestResources());
-
- SourcePluginArtifactStub artifact =
- new SourcePluginArtifactStub(getGroupId(),
getArtifactId(), getVersion(), getPackaging(), null);
- artifact.setArtifactHandler(new DefaultArtifactHandlerStub());
- artifact.setType("jar");
- artifact.setBaseVersion("1.0-SNAPSHOT");
- setArtifact(artifact);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public Build getBuild() {
- return build;
- }
-
- public void setBuild(Build build) {
- this.build = build;
- }
-
- public List<Resource> getResources() {
- return resources;
- }
-
- public void setResources(List<Resource> resources) {
- this.resources = resources;
- }
-
- public List<Resource> getTestResources() {
- return testResources;
- }
-
- public void setTestResources(List<Resource> testResources) {
- this.testResources = testResources;
- }
-}
diff --git
a/src/test/java/org/apache/maven/plugins/source/stubs/ProjectStub.java
b/src/test/java/org/apache/maven/plugins/source/stubs/ProjectStub.java
new file mode 100644
index 0000000..b151421
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/source/stubs/ProjectStub.java
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugins.source.stubs;
+
+import java.io.File;
+
+import org.apache.maven.api.plugin.testing.MojoExtension;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.model.Resource;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * @author <a href="mailto:[email protected]">Maria Odea Ching</a>
+ */
+public class ProjectStub extends MavenProject {
+
+ public ProjectStub(File tempDir) {
+ setArtifact(new DefaultArtifact(
+ "groupId", "artifactId", "1.0", "compile", "jar", null, new
DefaultArtifactHandler("jar")));
+
+ setGroupId("groupId");
+ setArtifactId("maven-source-plugin-test");
+ setVersion("99.0");
+ getBuild().setFinalName("maven-source-plugin-test-99.0");
+ setFile(MojoExtension.getTestFile("pom.xml"));
+
+ getBuild().setDirectory(new File(tempDir, "target").getAbsolutePath());
+
+ addCompileSourceRoot(MojoExtension.getTestPath("src/main/java"));
+ addTestCompileSourceRoot(MojoExtension.getTestPath("src/test/java"));
+
+ Resource mainResource = new Resource();
+
mainResource.setDirectory(MojoExtension.getTestPath("src/main/resources"));
+ addResource(mainResource);
+
+ Resource testResource = new Resource();
+
testResource.setDirectory(MojoExtension.getTestPath("src/test/resources"));
+ addTestResource(testResource);
+ }
+}
diff --git
a/src/test/java/org/apache/maven/plugins/source/stubs/SourcePluginArtifactStub.java
b/src/test/java/org/apache/maven/plugins/source/stubs/SourcePluginArtifactStub.java
deleted file mode 100644
index b758a17..0000000
---
a/src/test/java/org/apache/maven/plugins/source/stubs/SourcePluginArtifactStub.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * 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.
- */
-package org.apache.maven.plugins.source.stubs;
-
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.plugin.testing.stubs.ArtifactStub;
-
-/**
- * @author <a href="mailto:[email protected]">Maria Odea Ching</a>
- */
-public class SourcePluginArtifactStub extends ArtifactStub {
-
- private String groupId;
-
- private String artifactId;
-
- private String version;
-
- private String type;
-
- private String classifier;
-
- private String baseVersion;
-
- private VersionRange versionRange;
-
- private ArtifactHandler handler;
-
- public SourcePluginArtifactStub(String groupId, String artifactId, String
version, String type, String classifier) {
- this.groupId = groupId;
- this.artifactId = artifactId;
- this.version = version;
- this.type = type;
- this.classifier = classifier;
- versionRange = VersionRange.createFromVersion(version);
- }
-
- public void setGroupId(String groupId) {
- this.groupId = groupId;
- }
-
- public String getGroupId() {
- return groupId;
- }
-
- public void setArtifactId(String artifactId) {
- this.artifactId = artifactId;
- }
-
- public String getArtifactId() {
- return artifactId;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setType(String packaging) {
- this.type = packaging;
- }
-
- public String getType() {
- return type;
- }
-
- public void setClassifier(String classifier) {
- this.classifier = classifier;
- }
-
- public String getClassifier() {
- return classifier;
- }
-
- public boolean hasClassifier() {
- return classifier != null;
- }
-
- public String getId() {
- String id = groupId + ":" + artifactId + ":" + type + ":";
-
- if (hasClassifier()) {
- id = id + getClassifier() + ":";
- }
-
- id = id + version;
-
- return id;
- }
-
- public VersionRange getVersionRange() {
- return versionRange;
- }
-
- public void setVersionRange(VersionRange versionRange) {
- this.versionRange = versionRange;
- }
-
- public String getBaseVersion() {
- return baseVersion;
- }
-
- public void setBaseVersion(String baseVersion) {
- this.baseVersion = baseVersion;
- }
-
- public ArtifactHandler getArtifactHandler() {
- return handler;
- }
-
- public void setArtifactHandler(ArtifactHandler handler) {
- this.handler = handler;
- }
-}
diff --git a/src/test/resources/unit/project-001/pom.xml
b/src/test/resources/unit/project-001/pom.xml
index d1c659b..67c9436 100644
--- a/src/test/resources/unit/project-001/pom.xml
+++ b/src/test/resources/unit/project-001/pom.xml
@@ -27,35 +27,11 @@ under the License.
<name>Maven</name>
<packaging>jar</packaging>
<url>http://maven.apache.org</url>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
<build>
- <resources>
- <resource>
-
<directory>target/test-classes/unit/project-001/src/main/resources</directory>
- </resource>
- </resources>
- <testResources>
- <testResource>
-
<directory>target/test-classes/unit/project-001/src/test/resources</directory>
- </testResource>
- </testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
- <configuration>
- <project
implementation="org.apache.maven.plugins.source.stubs.Project001Stub"/>
-
<outputDirectory>${basedir}/target/test/unit/project-001/target</outputDirectory>
- <finalName>maven-source-plugin-test-project-001-99.0</finalName>
- <reactorProjects/>
- </configuration>
</plugin>
</plugins>
</build>
diff --git
a/src/test/resources/unit/project-001/src/test/java/foo/project001/AppTest.java
b/src/test/resources/unit/project-001/src/test/java/foo/project001/AppTest.java
index d5a0e00..9ecbe8b 100644
---
a/src/test/resources/unit/project-001/src/test/java/foo/project001/AppTest.java
+++
b/src/test/resources/unit/project-001/src/test/java/foo/project001/AppTest.java
@@ -19,39 +19,8 @@ package foo.project001;
* under the License.
*/
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
/**
* Unit test for simple App.
*/
-public class AppTest
- extends TestCase
-{
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public AppTest( String testName )
- {
- super( testName );
- }
-
- /**
- * @return the suite of tests being tested
- */
- public static Test suite()
- {
- return new TestSuite( AppTest.class );
- }
-
- /**
- * Rigourous Test :-)
- */
- public void testApp()
- {
- assertTrue( true );
- }
+public class AppTest {
}
diff --git a/src/test/resources/unit/project-003/pom.xml
b/src/test/resources/unit/project-003/pom.xml
index e10189e..c203b62 100644
--- a/src/test/resources/unit/project-003/pom.xml
+++ b/src/test/resources/unit/project-003/pom.xml
@@ -26,41 +26,11 @@ under the License.
<version>99.0</version>
<name>Maven</name>
<packaging>jar</packaging>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
<build>
- <resources>
- <resource>
-
<directory>target/test-classes/unit/project-003/src/main/resources</directory>
- <excludes>
- <exclude>excluded-file.txt</exclude>
- </excludes>
- </resource>
- </resources>
- <testResources>
- <testResource>
-
<directory>target/test-classes/unit/project-003/src/test/resources</directory>
- <excludes>
- <exclude>excluded-file.txt</exclude>
- </excludes>
- </testResource>
- </testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
- <configuration>
- <project
implementation="org.apache.maven.plugins.source.stubs.Project003Stub"/>
-
<outputDirectory>${basedir}/target/test/unit/project-003/target</outputDirectory>
- <finalName>maven-source-plugin-test-project-003-99.0</finalName>
- <reactorProjects/>
- </configuration>
</plugin>
</plugins>
</build>
diff --git
a/src/test/resources/unit/project-003/src/test/java/foo/project003/AppTest.java
b/src/test/resources/unit/project-003/src/test/java/foo/project003/AppTest.java
index 06acafc..0475253 100644
---
a/src/test/resources/unit/project-003/src/test/java/foo/project003/AppTest.java
+++
b/src/test/resources/unit/project-003/src/test/java/foo/project003/AppTest.java
@@ -19,39 +19,8 @@ package foo.project003;
* under the License.
*/
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
/**
* Unit test for simple App.
*/
-public class AppTest
- extends TestCase
-{
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public AppTest( String testName )
- {
- super( testName );
- }
-
- /**
- * @return the suite of tests being tested
- */
- public static Test suite()
- {
- return new TestSuite( AppTest.class );
- }
-
- /**
- * Rigourous Test :-)
- */
- public void testApp()
- {
- assertTrue( true );
- }
+public class AppTest {
}
diff --git a/src/test/resources/unit/project-005/pom.xml
b/src/test/resources/unit/project-005/pom.xml
index d54018b..a881084 100644
--- a/src/test/resources/unit/project-005/pom.xml
+++ b/src/test/resources/unit/project-005/pom.xml
@@ -27,25 +27,11 @@ under the License.
<name>Maven</name>
<!-- POM packaging, no archive should be created -->
<packaging>pom</packaging>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
- <configuration>
- <project
implementation="org.apache.maven.plugins.source.stubs.Project005Stub"/>
-
<outputDirectory>${basedir}/target/test/unit/project-005/target</outputDirectory>
- <finalName>maven-source-plugin-test-project-005-99.0</finalName>
- <reactorProjects/>
- </configuration>
</plugin>
</plugins>
</build>
diff --git a/src/test/resources/unit/project-007/pom.xml
b/src/test/resources/unit/project-007/pom.xml
index f1dfb40..712c78c 100644
--- a/src/test/resources/unit/project-007/pom.xml
+++ b/src/test/resources/unit/project-007/pom.xml
@@ -26,33 +26,11 @@ under the License.
<version>99.0</version>
<name>Maven</name>
<packaging>jar</packaging>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
<build>
- <resources>
- <resource>
-
<directory>target/test-classes/unit/project-007/src/main/resources</directory>
- <includes>
- <include>templates/**</include>
- </includes>
- </resource>
- </resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
- <configuration>
- <project
implementation="org.apache.maven.plugins.source.stubs.Project007Stub"/>
-
<outputDirectory>${basedir}/target/test/unit/project-007/target</outputDirectory>
- <finalName>maven-source-plugin-test-project-007-99.0</finalName>
- <reactorProjects/>
- </configuration>
</plugin>
</plugins>
</build>
diff --git a/src/test/resources/unit/project-009/pom.xml
b/src/test/resources/unit/project-009/pom.xml
index 2562083..8b69f79 100644
--- a/src/test/resources/unit/project-009/pom.xml
+++ b/src/test/resources/unit/project-009/pom.xml
@@ -26,31 +26,11 @@ under the License.
<version>99.0</version>
<name>Maven</name>
<packaging>jar</packaging>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
<build>
- <resources>
- <resource>
-
<directory>target/test-classes/unit/project-009/src/main/resources</directory>
- </resource>
- </resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
- <configuration>
- <includePom>true</includePom>
- <project
implementation="org.apache.maven.plugins.source.stubs.Project009Stub"/>
-
<outputDirectory>${basedir}/target/test/unit/project-009/target</outputDirectory>
- <finalName>maven-source-plugin-test-project-009-99.0</finalName>
- <reactorProjects/>
- </configuration>
</plugin>
</plugins>
</build>
diff --git a/src/test/resources/unit/project-010/pom.xml
b/src/test/resources/unit/project-010/pom.xml
index 9972cea..c133a64 100644
--- a/src/test/resources/unit/project-010/pom.xml
+++ b/src/test/resources/unit/project-010/pom.xml
@@ -27,34 +27,12 @@ under the License.
<name>Maven</name>
<packaging>jar</packaging>
<url>http://maven.apache.org</url>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
<build>
- <resources>
- <resource>
-
<directory>target/test-classes/unit/project-010/src/main/resources</directory>
- </resource>
- </resources>
- <testResources>
- <testResource>
-
<directory>target/test-classes/unit/project-010/src/test/resources</directory>
- </testResource>
- </testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<configuration>
- <project
implementation="org.apache.maven.plugins.source.stubs.Project010Stub"/>
-
<outputDirectory>${basedir}/target/test/unit/project-010/target</outputDirectory>
- <finalName>maven-source-plugin-test-project-010-99.0</finalName>
- <reactorProjects/>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
</archive>
diff --git
a/src/test/resources/unit/project-010/src/test/java/foo/project010/AppTest.java
b/src/test/resources/unit/project-010/src/test/java/foo/project010/AppTest.java
index 06b6a16..bda86b8 100644
---
a/src/test/resources/unit/project-010/src/test/java/foo/project010/AppTest.java
+++
b/src/test/resources/unit/project-010/src/test/java/foo/project010/AppTest.java
@@ -19,39 +19,8 @@ package foo.project010;
* under the License.
*/
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
/**
* Unit test for simple App.
*/
-public class AppTest
- extends TestCase
-{
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public AppTest( String testName )
- {
- super( testName );
- }
-
- /**
- * @return the suite of tests being tested
- */
- public static Test suite()
- {
- return new TestSuite( AppTest.class );
- }
-
- /**
- * Rigourous Test :-)
- */
- public void testApp()
- {
- assertTrue( true );
- }
+public class AppTest {
}