This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/maven-remote-resources-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 0f9c144 Migrate RemoteResourcesMojoTest to JUnit 5 (#336)
0f9c144 is described below
commit 0f9c14401b8bb074fe9e74f700314aa5a56ba167
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Wed Oct 28 21:51:07 2026 +0100
Migrate RemoteResourcesMojoTest to JUnit 5 (#336)
Fixes #312. RemoteResourcesMojoTest uses the @MojoTest harness instead of
the deprecated AbstractMojoTestCase, and ModelInheritanceAssemblerTest moves to
JUnit 5. The temporary local repository is kept until #338 closes the bundle
jars the mojo leaves open.
Co-authored-by: Elliotte Rusty Harold <[email protected]>
---
pom.xml | 26 +-
.../remote/ModelInheritanceAssemblerTest.java | 4 +-
.../resources/remote/RemoteResourcesMojoTest.java | 765 +++++++++++----------
3 files changed, 409 insertions(+), 386 deletions(-)
diff --git a/pom.xml b/pom.xml
index fcc4a8d..714a4d6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -123,18 +123,6 @@ under the License.
<version>${resolverVersion}</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-resolver-provider</artifactId>
- <version>${mavenVersion}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.maven.resolver</groupId>
- <artifactId>maven-resolver-impl</artifactId>
- <version>${resolverVersion}</version>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
@@ -199,7 +187,7 @@ under the License.
<!-- test -->
<dependency>
- <!-- still required by AbstractMojoTestCase (deprecated,
PlexusTestCase/JUnit 3 based); see RemoteResourcesMojoTest -->
+ <!-- still required at test runtime by PlexusTestCase (JUnit 3 based),
used by the test stubs -->
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
@@ -211,9 +199,9 @@ under the License.
<scope>test</scope>
</dependency>
<dependency>
- <!-- runs RemoteResourcesMojoTest (AbstractMojoTestCase/PlexusTestCase,
JUnit 3 style) on the JUnit Platform -->
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
+ <!-- JUnit Platform engine that runs the JUnit 5 tests, discovered via
ServiceLoader -->
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -364,10 +352,10 @@ under the License.
<failOnWarning>true</failOnWarning>
<ignoredDependencies>
<ignoredDependency>org.slf4j:slf4j-simple:*</ignoredDependency>
- <!-- still needed at test runtime by the deprecated
AbstractMojoTestCase/PlexusTestCase (JUnit 3) -->
+ <!-- still needed at test runtime by PlexusTestCase (JUnit 3)
used by the test stubs -->
<ignoredDependency>junit:junit:*</ignoredDependency>
- <!-- JUnit Platform test engines, discovered via
ServiceLoader, never referenced from bytecode -->
-
<ignoredDependency>org.junit.vintage:junit-vintage-engine:*</ignoredDependency>
+ <!-- JUnit Platform test engine, discovered via ServiceLoader,
never referenced from bytecode -->
+
<ignoredDependency>org.junit.jupiter:junit-jupiter-engine:*</ignoredDependency>
</ignoredDependencies>
</configuration>
</execution>
diff --git
a/src/test/java/org/apache/maven/plugin/resources/remote/ModelInheritanceAssemblerTest.java
b/src/test/java/org/apache/maven/plugin/resources/remote/ModelInheritanceAssemblerTest.java
index fc64072..72d6977 100644
---
a/src/test/java/org/apache/maven/plugin/resources/remote/ModelInheritanceAssemblerTest.java
+++
b/src/test/java/org/apache/maven/plugin/resources/remote/ModelInheritanceAssemblerTest.java
@@ -18,9 +18,9 @@
*/
package org.apache.maven.plugin.resources.remote;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Unit tests for the SCM path normalization in {@link
ModelInheritanceAssembler}.
diff --git
a/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java
b/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java
index 30b2698..30b3a64 100644
---
a/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java
+++
b/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java
@@ -18,6 +18,8 @@
*/
package org.apache.maven.plugin.resources.remote;
+import javax.inject.Inject;
+
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -32,7 +34,6 @@ import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Calendar;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
@@ -41,11 +42,11 @@ import java.util.List;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoTest;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-import org.apache.maven.artifact.repository.MavenArtifactRepository;
-import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
@@ -54,162 +55,88 @@ import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.resources.remote.stub.ArtifactStub;
import org.apache.maven.plugin.resources.remote.stub.MavenProjectBuildStub;
import org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub;
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingResult;
-import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
-import org.eclipse.aether.DefaultRepositorySystemSession;
-import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
-import org.eclipse.aether.repository.LocalRepository;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.CleanupMode;
+import org.junit.jupiter.api.io.TempDir;
+
+import static
org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject;
+import static
org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
/**
* RemoteResources plugin Test Case
*/
-public class RemoteResourcesMojoTest extends AbstractMojoTestCase {
+@MojoTest(realRepositorySession = true)
+class RemoteResourcesMojoTest {
static final String DEFAULT_BUNDLE_POM_PATH =
"target/test-classes/unit/rrmojotest/bundle-plugin-config.xml";
static final String DEFAULT_PROCESS_POM_PATH =
"target/test-classes/unit/rrmojotest/process-plugin-config.xml";
- private static final String LOCAL_REPO = "target/local-repo/";
+ // NEVER: on Windows the mojo leaves the bundle jars open, so deleting
them fails
+ @TempDir(cleanup = CleanupMode.NEVER)
+ private File localRepo;
- @Override
- public void setUp() throws Exception {
- super.setUp();
- }
+ @Inject
+ private MavenSession session;
- @Override
- public void tearDown() throws Exception {}
+ @BeforeEach
+ void setUp() {
+ session.getRequest().setLocalRepositoryPath(localRepo);
+ }
/**
* check test environment
*
* @throws Exception if any exception occurs
*/
- public void testTestEnvironment() throws Exception {
- // Perform lookup on the Mojo to make sure everything is ok
- lookupProcessMojo();
+ @Test
+ void testTestEnvironment(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo) {
+ assertNotNull(mojo);
}
- public void testNoBundles() throws Exception {
+ @Test
+ void testNoBundles(@InjectMojo(goal = "process", pom =
DEFAULT_PROCESS_POM_PATH) ProcessRemoteResourcesMojo mojo)
+ throws Exception {
final MavenProjectResourcesStub project =
createTestProject("default-nobundles");
- final ProcessRemoteResourcesMojo mojo =
lookupProcessMojoWithDefaultSettings(project);
+ configureProcessMojo(mojo, project, new ArrayList<>());
setupDefaultProject(project);
mojo.execute();
}
- public void testFindReactorProjectMatchesTimestampedSnapshot() throws
Exception {
- MavenProject reactorProject = new MavenProject(new
org.apache.maven.model.Model());
- reactorProject.setGroupId("com.example");
- reactorProject.setArtifactId("reactor-project");
- reactorProject.setVersion("1.0-SNAPSHOT");
-
- Artifact artifact = new DefaultArtifact(
- "com.example",
- "reactor-project",
- VersionRange.createFromVersion("1.0-20260926.120000-1"),
- null,
- "jar",
- "",
- new DefaultArtifactHandler());
-
- assertSame(
- reactorProject,
- AbstractProcessRemoteResourcesMojo.findReactorProject(
- artifact, Collections.singletonList(reactorProject)));
-
- Artifact externalArtifact = new DefaultArtifact(
- "com.example",
- "external-project",
- VersionRange.createFromVersion("1.0"),
- null,
- "jar",
- "",
- new DefaultArtifactHandler());
- assertNull(AbstractProcessRemoteResourcesMojo.findReactorProject(
- externalArtifact, Collections.singletonList(reactorProject)));
- }
+ @Test
+ void testConfigureLocatorRequiresProjectFile(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo)
+ throws Exception {
+ final MavenProjectResourcesStub project =
createTestProject("default-null-pom");
+ configureProcessMojo(mojo, project, new ArrayList<>());
- public void testGetProjectsBuildsOnlyExternalArtifacts() throws Exception {
- MavenProjectResourcesStub project =
createTestProject("reactor-projects");
- ProcessRemoteResourcesMojo mojo =
lookupProcessMojoWithDefaultSettings(project);
setupDefaultProject(project);
+ project.setFile(null);
- MavenProject reactorProject = new MavenProject(new
org.apache.maven.model.Model());
- reactorProject.setGroupId("com.example");
- reactorProject.setArtifactId("reactor-project");
- reactorProject.setVersion("1.0-SNAPSHOT");
-
- Artifact reactorArtifact = new DefaultArtifact(
- "com.example",
- "reactor-project",
- VersionRange.createFromVersion("1.0-20260926.120000-1"),
- "compile",
- "jar",
- "",
- new DefaultArtifactHandler());
- Artifact externalArtifact = new DefaultArtifact(
- "com.example",
- "external-project",
- VersionRange.createFromVersion("1.0"),
- "compile",
- "jar",
- "",
- new DefaultArtifactHandler());
- project.setArtifacts(new
LinkedHashSet<>(Arrays.asList(reactorArtifact, externalArtifact)));
- reactorProject.setArtifact(reactorArtifact);
-
- MavenSession session = (MavenSession) getVariableValueFromObject(mojo,
"mavenSession");
- session.setProjects(Arrays.asList(project, reactorProject));
-
- MavenProject externalProject = new MavenProject(new
org.apache.maven.model.Model());
- externalProject.setGroupId("com.example");
- externalProject.setArtifactId("external-project");
- externalProject.setVersion("1.0");
- externalProject.setArtifact(externalArtifact);
-
- ProjectBuildingResult buildingResult = (ProjectBuildingResult)
Proxy.newProxyInstance(
- ProjectBuildingResult.class.getClassLoader(),
- new Class<?>[] {ProjectBuildingResult.class},
- new InvocationHandler() {
- @Override
- public Object invoke(Object proxy, Method method, Object[]
args) {
- if ("getProject".equals(method.getName())) {
- return externalProject;
- }
- return null;
- }
- });
- List<Artifact> builtArtifacts = new ArrayList<>();
- ProjectBuilder projectBuilder = (ProjectBuilder)
Proxy.newProxyInstance(
- ProjectBuilder.class.getClassLoader(), new Class<?>[]
{ProjectBuilder.class}, new InvocationHandler() {
- @Override
- public Object invoke(Object proxy, Method method, Object[]
args) {
- if ("build".equals(method.getName())
- && args != null
- && args.length == 2
- && args[0] instanceof Artifact) {
- builtArtifacts.add((Artifact) args[0]);
- return buildingResult;
- }
- return null;
- }
- });
- setVariableValueToObject(mojo, "projectBuilder", projectBuilder);
- setVariableValueToObject(mojo, "supplementModels", new HashMap<>());
-
- List<MavenProject> projects = mojo.getProjects();
-
- assertEquals(1, builtArtifacts.size());
- assertSame(externalArtifact, builtArtifacts.get(0));
- assertTrue(projects.contains(reactorProject));
- assertTrue(projects.contains(externalProject));
+ try {
+ mojo.execute();
+ fail("expected MojoExecutionException when the project has no POM
file");
+ } catch (MojoExecutionException e) {
+ assertTrue(e.getMessage().contains("no POM file"));
+ }
}
- public void testRemoteResourceCannotEscapeOutputDirectory() throws
Exception {
+ @Test
+ void testRemoteResourceCannotEscapeOutputDirectory() throws Exception {
File outputDirectory = new File("target/remote-resource-output");
File canonicalOutputDirectory = outputDirectory.getCanonicalFile();
@@ -236,14 +163,15 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
assertEquals(new File(outputDirectory,
"nested/resource.txt").getCanonicalFile(), outputFile);
}
- public void testRemoteResourceCannotEscapeOutputDirectoryThroughSymlink()
throws Exception {
+ @Test
+ void testRemoteResourceCannotEscapeOutputDirectoryThroughSymlink() throws
Exception {
Path temporaryDirectory =
Files.createTempDirectory("remote-resource-path");
Path outputDirectory =
Files.createDirectory(temporaryDirectory.resolve("output"));
Path outsideDirectory =
Files.createDirectory(temporaryDirectory.resolve("outside"));
try {
Files.createSymbolicLink(outputDirectory.resolve("external"),
outsideDirectory);
} catch (UnsupportedOperationException | IOException e) {
- return; // unsupported here; this JUnit 3 test cannot report a skip
+ assumeTrue(false, "not supported on this platform: " + e);
}
File output = outputDirectory.toFile();
@@ -257,7 +185,8 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
}
}
- public void
testRemoteResourceResolvesNestedSymlinksBeforeCheckingContainment() throws
Exception {
+ @Test
+ void testRemoteResourceResolvesNestedSymlinksBeforeCheckingContainment()
throws Exception {
Path temporaryDirectory =
Files.createTempDirectory("remote-resource-nested-path");
Path outputDirectory =
Files.createDirectory(temporaryDirectory.resolve("output"));
Path insideDirectory =
Files.createDirectory(outputDirectory.resolve("inside"));
@@ -266,7 +195,7 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
Files.createSymbolicLink(outputDirectory.resolve("inside-link"),
insideDirectory);
Files.createSymbolicLink(insideDirectory.resolve("outside-link"),
outsideDirectory);
} catch (UnsupportedOperationException | IOException e) {
- return; // unsupported here; this JUnit 3 test cannot report a skip
+ assumeTrue(false, "not supported on this platform: " + e);
}
File output = outputDirectory.toFile();
@@ -285,7 +214,8 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
}
}
- public void testRemoteResourceFailsClosedWhenPathCannotBeInspected()
throws Exception {
+ @Test
+ void testRemoteResourceFailsClosedWhenPathCannotBeInspected() throws
Exception {
Path temporaryDirectory =
Files.createTempDirectory("remote-resource-inaccessible-path");
Path outputDirectory =
Files.createDirectory(temporaryDirectory.resolve("output"));
Path restrictedDirectory =
Files.createDirectory(outputDirectory.resolve("restricted"));
@@ -295,20 +225,21 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
try {
originalPermissions =
EnumSet.copyOf(Files.getPosixFilePermissions(restrictedDirectory));
} catch (UnsupportedOperationException e) {
- return; // unsupported here; this JUnit 3 test cannot report a skip
+ assumeTrue(false, "not supported on this platform: " + e);
+ return;
}
try {
Files.createSymbolicLink(restrictedDirectory.resolve("external"),
outsideDirectory);
} catch (UnsupportedOperationException | IOException e) {
- return; // unsupported here; this JUnit 3 test cannot report a skip
+ assumeTrue(false, "not supported on this platform: " + e);
}
try {
Files.setPosixFilePermissions(
restrictedDirectory,
EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE));
} catch (UnsupportedOperationException e) {
- return; // unsupported here; this JUnit 3 test cannot report a skip
+ assumeTrue(false, "not supported on this platform: " + e);
}
try {
@@ -324,9 +255,12 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
}
}
- public void
testMalformedSupplementalModelFailsWithMojoExecutionException() throws
Exception {
+ @Test
+ void testMalformedSupplementalModelFailsWithMojoExecutionException(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo)
+ throws Exception {
final MavenProjectResourcesStub project =
createTestProject("default-malformedsupplement");
- final ProcessRemoteResourcesMojo mojo =
lookupProcessMojoWithDefaultSettings(project);
+ configureProcessMojo(mojo, project, new ArrayList<>());
setupDefaultProject(project);
@@ -350,34 +284,25 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
mojo.execute();
fail("Expected a MojoExecutionException for a malformed
supplemental model entry");
} catch (MojoExecutionException e) {
- assertTrue(e.getMessage(), e.getMessage().contains("Unable to
parse supplemental XML"));
- }
- }
-
- public void testConfigureLocatorRequiresProjectFile() throws Exception {
- final MavenProjectResourcesStub project =
createTestProject("default-null-pom");
- final ProcessRemoteResourcesMojo mojo =
lookupProcessMojoWithDefaultSettings(project);
-
- setupDefaultProject(project);
- project.setFile(null);
-
- try {
- mojo.execute();
- fail("expected MojoExecutionException when the project has no POM
file");
- } catch (MojoExecutionException e) {
- assertTrue(e.getMessage().contains("no POM file"));
+ assertTrue(e.getMessage().contains("Unable to parse supplemental
XML"), e.getMessage());
}
}
- public void testCreateBundle() throws Exception {
+ @Test
+ void testCreateBundle(@InjectMojo(goal = "bundle", pom =
DEFAULT_BUNDLE_POM_PATH) BundleRemoteResourcesMojo mojo)
+ throws Exception {
List<String> resources =
Arrays.asList("FILTER.txt.vm", "ISO-8859-1.bin.vm",
"PROPERTIES.txt.vm", "SIMPLE.txt", "UTF-8.bin.vm");
- buildResourceBundle("default-createbundle", null,
resources.toArray(new String[0]), null);
+ buildResourceBundle(mojo, "default-createbundle", null,
resources.toArray(new String[0]), null);
}
- public void testSimpleBundles() throws Exception {
+ @Test
+ void testSimpleBundles(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo,
+ @InjectMojo(goal = "bundle", pom = DEFAULT_BUNDLE_POM_PATH)
BundleRemoteResourcesMojo bundleMojo)
+ throws Exception {
final MavenProjectResourcesStub project =
createTestProject("default-simplebundles");
- final ProcessRemoteResourcesMojo mojo =
lookupProcessMojoWithSettings(project, new String[] {"test:test:1.0"});
+ configureProcessMojo(mojo, project, new
ArrayList<>(Arrays.asList("test:test:1.0")));
setupDefaultProject(project);
@@ -386,19 +311,22 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
File file = new File(path);
file.getParentFile().mkdirs();
- buildResourceBundle("default-simplebundles-create", null, new String[]
{"SIMPLE.txt"}, file);
+ buildResourceBundle(bundleMojo, "default-simplebundles-create", null,
new String[] {"SIMPLE.txt"}, file);
mojo.execute();
- file = (File) getVariableValueFromObject(mojo, "outputDirectory");
+ file = getVariableValueFromObject(mojo, "outputDirectory");
file = new File(file, "SIMPLE.txt");
assertTrue(file.exists());
}
- public void testSimpleBundlesWithType() throws Exception {
+ @Test
+ void testSimpleBundlesWithType(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo,
+ @InjectMojo(goal = "bundle", pom = DEFAULT_BUNDLE_POM_PATH)
BundleRemoteResourcesMojo bundleMojo)
+ throws Exception {
final MavenProjectResourcesStub project =
createTestProject("default-simplebundles");
- final ProcessRemoteResourcesMojo mojo =
- lookupProcessMojoWithSettings(project, new String[]
{"test:test:1.0:war"});
+ configureProcessMojo(mojo, project, new
ArrayList<>(Arrays.asList("test:test:1.0:war")));
setupDefaultProject(project);
@@ -407,19 +335,22 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
File file = new File(path);
file.getParentFile().mkdirs();
- buildResourceBundle("default-simplebundles-create", null, new String[]
{"SIMPLE.txt"}, file);
+ buildResourceBundle(bundleMojo, "default-simplebundles-create", null,
new String[] {"SIMPLE.txt"}, file);
mojo.execute();
- file = (File) getVariableValueFromObject(mojo, "outputDirectory");
+ file = getVariableValueFromObject(mojo, "outputDirectory");
file = new File(file, "SIMPLE.txt");
assertTrue(file.exists());
}
- public void testSimpleBundlesWithClassifier() throws Exception {
+ @Test
+ void testSimpleBundlesWithClassifier(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo,
+ @InjectMojo(goal = "bundle", pom = DEFAULT_BUNDLE_POM_PATH)
BundleRemoteResourcesMojo bundleMojo)
+ throws Exception {
final MavenProjectResourcesStub project =
createTestProject("default-simplebundles");
- final ProcessRemoteResourcesMojo mojo =
- lookupProcessMojoWithSettings(project, new String[]
{"test:test:1.0:jar:test"});
+ configureProcessMojo(mojo, project, new
ArrayList<>(Arrays.asList("test:test:1.0:jar:test")));
setupDefaultProject(project);
@@ -434,18 +365,50 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
File file = new File(path);
file.getParentFile().mkdirs();
- buildResourceBundle("default-simplebundles-create", null, new String[]
{"SIMPLE.txt"}, file);
+ buildResourceBundle(bundleMojo, "default-simplebundles-create", null,
new String[] {"SIMPLE.txt"}, file);
mojo.execute();
- file = (File) getVariableValueFromObject(mojo, "outputDirectory");
+ file = getVariableValueFromObject(mojo, "outputDirectory");
file = new File(file, "SIMPLE.txt");
assertTrue(file.exists());
}
- public void testClassLoaderIsClosedAfterExecution() throws Exception {
+ @Test
+ void testVelocityUTF8(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo,
+ @InjectMojo(goal = "bundle", pom = DEFAULT_BUNDLE_POM_PATH)
BundleRemoteResourcesMojo bundleMojo)
+ throws Exception {
+ final MavenProjectResourcesStub project =
createTestProject("default-utf8");
+ configureProcessMojo(mojo, project, new
ArrayList<>(Arrays.asList("test:test:1.2")));
+
+ setupDefaultProject(project);
+
+ String path = pathOf(new DefaultArtifact(
+ "test", "test", VersionRange.createFromVersion("1.2"), null,
"jar", "", new DefaultArtifactHandler()));
+
+ File file = new File(path);
+ file.getParentFile().mkdirs();
+ buildResourceBundle(bundleMojo, "default-utf8-create", "UTF-8", new
String[] {"UTF-8.bin.vm"}, file);
+
+ mojo.execute();
+
+ file = getVariableValueFromObject(mojo, "outputDirectory");
+ file = new File(file, "UTF-8.bin");
+ assertTrue(file.exists());
+
+ byte[] data = Files.readAllBytes(file.toPath());
+ byte[] expected =
"\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00DF".getBytes(StandardCharsets.UTF_8);
+ assertTrue(Arrays.equals(expected, data));
+ }
+
+ @Test
+ void testClassLoaderIsClosedAfterExecution(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo,
+ @InjectMojo(goal = "bundle", pom = DEFAULT_BUNDLE_POM_PATH)
BundleRemoteResourcesMojo bundleMojo)
+ throws Exception {
final MavenProjectResourcesStub project =
createTestProject("default-closeclassloader");
- final ProcessRemoteResourcesMojo mojo =
lookupProcessMojoWithSettings(project, new String[] {"test:test:1.0"});
+ configureProcessMojo(mojo, project, new
ArrayList<>(Arrays.asList("test:test:1.0")));
setupDefaultProject(project);
@@ -454,7 +417,7 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
File file = new File(path);
file.getParentFile().mkdirs();
- buildResourceBundle("default-closeclassloader-create", null, new
String[] {"SIMPLE.txt"}, file);
+ buildResourceBundle(bundleMojo, "default-closeclassloader-create",
null, new String[] {"SIMPLE.txt"}, file);
mojo.execute();
@@ -465,131 +428,303 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
assertNull(classLoader.getResource("SIMPLE.txt"));
}
- public void testProjectsDoesNotMutateProjectArtifactVersions() throws
Exception {
- final MavenProjectResourcesStub project =
createTestProject("default-nomutate");
- final ProcessRemoteResourcesMojo mojo =
lookupProcessMojoWithDefaultSettings(project);
+ @Test
+ void testVelocityISO88591(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo,
+ @InjectMojo(goal = "bundle", pom = DEFAULT_BUNDLE_POM_PATH)
BundleRemoteResourcesMojo bundleMojo)
+ throws Exception {
+ final MavenProjectResourcesStub project =
createTestProject("default-iso88591");
+ configureProcessMojo(mojo, project, new
ArrayList<>(Arrays.asList("test:test:1.3")));
setupDefaultProject(project);
- setVariableValueToObject(mojo, "supplementModels", new HashMap<>());
+ String path = pathOf(new DefaultArtifact(
+ "test", "test", VersionRange.createFromVersion("1.3"), null,
"jar", "", new DefaultArtifactHandler()));
- ArtifactStub snapshotArtifact = new ArtifactStub();
- snapshotArtifact.setGroupId("org.example");
- snapshotArtifact.setArtifactId("snapshot-dep");
- snapshotArtifact.setVersion("1.0-SNAPSHOT");
+ File file = new File(path);
+ file.getParentFile().mkdirs();
+ buildResourceBundle(
+ bundleMojo, "default-iso88591-create", "ISO-8859-1", new
String[] {"ISO-8859-1.bin.vm"}, file);
- project.setArtifacts(Collections.singleton(snapshotArtifact));
+ mojo.execute();
- mojo.getProjects();
+ file = getVariableValueFromObject(mojo, "outputDirectory");
+ file = new File(file, "ISO-8859-1.bin");
+ assertTrue(file.exists());
- assertEquals("1.0-SNAPSHOT", snapshotArtifact.getVersion());
- assertSame(snapshotArtifact, project.getArtifacts().iterator().next());
+ byte[] data = Files.readAllBytes(file.toPath());
+ byte[] expected =
"\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00DF".getBytes(StandardCharsets.ISO_8859_1);
+ assertTrue(Arrays.equals(expected, data));
}
- public void testUseProjectFilesRendersVelocityTemplate() throws Exception {
- final MavenProjectResourcesStub project =
createTestProject("default-useprojectfiles");
- final ProcessRemoteResourcesMojo mojo =
lookupProcessMojoWithSettings(project, new String[] {"test:test:1.4"});
+ @Test
+ void testFilteredBundles(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo,
+ @InjectMojo(goal = "bundle", pom = DEFAULT_BUNDLE_POM_PATH)
BundleRemoteResourcesMojo bundleMojo)
+ throws Exception {
+ final MavenProjectResourcesStub project =
createTestProject("default-filterbundles");
+ configureProcessMojo(mojo, project, new
ArrayList<>(Arrays.asList("test:test:1.1")));
setupDefaultProject(project);
- FileUtils.fileWrite(
- new File(project.getBasedir(),
"FILTER.txt.vm").getAbsolutePath(), "local override: $project.name");
-
String path = pathOf(new DefaultArtifact(
- "test", "test", VersionRange.createFromVersion("1.4"), null,
"jar", "", new DefaultArtifactHandler()));
+ "test", "test", VersionRange.createFromVersion("1.1"), null,
"jar", "", new DefaultArtifactHandler()));
File file = new File(path);
file.getParentFile().mkdirs();
- buildResourceBundle("default-useprojectfiles-create", null, new
String[] {"FILTER.txt.vm"}, file);
-
- setVariableValueToObject(mojo, "useProjectFiles", true);
+ buildResourceBundle(bundleMojo, "default-filterbundles-create", null,
new String[] {"FILTER.txt.vm"}, file);
+ mojo.execute();
+ // executing a second time (example: forked lifecycle) should still
work
mojo.execute();
- File outputFile = new File((File) getVariableValueFromObject(mojo,
"outputDirectory"), "FILTER.txt");
- String data = FileUtils.fileRead(outputFile);
- assertTrue(data.contains("local override: Test Project
default-useprojectfiles"));
+ file = getVariableValueFromObject(mojo, "outputDirectory");
+ file = new File(file, "FILTER.txt");
+ assertTrue(file.exists());
+
+ String data = FileUtils.fileRead(file);
+ assertTrue(data.contains("project.name: Test Project
default-filterbundles"));
+ assertTrue(data.contains("projectTimespan: 2007-2019"));
+ assertTrue(data.contains("projects: ["));
+ assertTrue(data.contains("projectsSortedByOrganization: {"));
}
- public void testVelocityUTF8() throws Exception {
- final MavenProjectResourcesStub project =
createTestProject("default-utf8");
- final ProcessRemoteResourcesMojo mojo =
lookupProcessMojoWithSettings(project, new String[] {"test:test:1.2"});
+ @Test
+ void testFilteredBundlesWithProjectProperties(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo,
+ @InjectMojo(goal = "bundle", pom = DEFAULT_BUNDLE_POM_PATH)
BundleRemoteResourcesMojo bundleMojo)
+ throws Exception {
+ final MavenProjectResourcesStub project =
createTestProject("default-filterbundles-two");
+ configureProcessMojo(
+ mojo, project, new
ArrayList<>(Arrays.asList("test-filtered-bundles:test-filtered-bundles:2")));
+ mojo.includeProjectProperties = true;
setupDefaultProject(project);
+ project.addProperty("testingPropertyOne", "maven");
+ project.addProperty("testingPropertyTwo", "rules");
+
String path = pathOf(new DefaultArtifact(
- "test", "test", VersionRange.createFromVersion("1.2"), null,
"jar", "", new DefaultArtifactHandler()));
+ "test-filtered-bundles",
+ "test-filtered-bundles",
+ VersionRange.createFromVersion("2"),
+ null,
+ "jar",
+ "",
+ new DefaultArtifactHandler()));
File file = new File(path);
file.getParentFile().mkdirs();
- buildResourceBundle("default-utf8-create", "UTF-8", new String[]
{"UTF-8.bin.vm"}, file);
+ buildResourceBundle(
+ bundleMojo, "default-filterbundles-two-create", null, new
String[] {"PROPERTIES.txt.vm"}, file);
mojo.execute();
+ // executing a second time (example: forked lifecycle) should still
work
+ mojo.execute();
+
+ file = getVariableValueFromObject(mojo, "outputDirectory");
+ file = new File(file, "PROPERTIES.txt");
- file = (File) getVariableValueFromObject(mojo, "outputDirectory");
- file = new File(file, "UTF-8.bin");
assertTrue(file.exists());
- byte[] data = Files.readAllBytes(file.toPath());
- byte[] expected =
"\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00DF".getBytes(StandardCharsets.UTF_8);
- assertTrue(Arrays.equals(expected, data));
+ String data = FileUtils.fileRead(file);
+ assertTrue(data.contains("maven"));
+ assertTrue(data.contains("rules"));
}
- public void testVelocityISO88591() throws Exception {
- final MavenProjectResourcesStub project =
createTestProject("default-iso88591");
- final ProcessRemoteResourcesMojo mojo =
lookupProcessMojoWithSettings(project, new String[] {"test:test:1.3"});
+ @Test
+ void testUseProjectFilesRendersVelocityTemplate(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo,
+ @InjectMojo(goal = "bundle", pom = DEFAULT_BUNDLE_POM_PATH)
BundleRemoteResourcesMojo bundleMojo)
+ throws Exception {
+ final MavenProjectResourcesStub project =
createTestProject("default-useprojectfiles");
+ configureProcessMojo(mojo, project, Arrays.asList("test:test:1.4"));
setupDefaultProject(project);
+ FileUtils.fileWrite(
+ new File(project.getBasedir(),
"FILTER.txt.vm").getAbsolutePath(), "local override: $project.name");
+
String path = pathOf(new DefaultArtifact(
- "test", "test", VersionRange.createFromVersion("1.3"), null,
"jar", "", new DefaultArtifactHandler()));
+ "test", "test", VersionRange.createFromVersion("1.4"), null,
"jar", "", new DefaultArtifactHandler()));
File file = new File(path);
file.getParentFile().mkdirs();
- buildResourceBundle("default-iso88591-create", "ISO-8859-1", new
String[] {"ISO-8859-1.bin.vm"}, file);
+ buildResourceBundle(bundleMojo, "default-useprojectfiles-create",
null, new String[] {"FILTER.txt.vm"}, file);
+
+ setVariableValueToObject(mojo, "useProjectFiles", true);
mojo.execute();
- file = (File) getVariableValueFromObject(mojo, "outputDirectory");
- file = new File(file, "ISO-8859-1.bin");
- assertTrue(file.exists());
+ File outputFile = new File((File) getVariableValueFromObject(mojo,
"outputDirectory"), "FILTER.txt");
+ String data = FileUtils.fileRead(outputFile);
+ assertTrue(data.contains("local override: Test Project
default-useprojectfiles"));
+ }
- byte[] data = Files.readAllBytes(file.toPath());
- byte[] expected =
"\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00DF".getBytes(StandardCharsets.ISO_8859_1);
- assertTrue(Arrays.equals(expected, data));
+ @Test
+ void testProjectsDoesNotMutateProjectArtifactVersions(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo)
+ throws Exception {
+ final MavenProjectResourcesStub project =
createTestProject("default-nomutate");
+ configureProcessMojo(mojo, project, Collections.emptyList());
+
+ setupDefaultProject(project);
+
+ setVariableValueToObject(mojo, "supplementModels", new HashMap<>());
+
+ ArtifactStub snapshotArtifact = new ArtifactStub();
+ snapshotArtifact.setGroupId("org.example");
+ snapshotArtifact.setArtifactId("snapshot-dep");
+ snapshotArtifact.setVersion("1.0-SNAPSHOT");
+
+ project.setArtifacts(Collections.singleton(snapshotArtifact));
+
+ mojo.getProjects();
+
+ assertEquals("1.0-SNAPSHOT", snapshotArtifact.getVersion());
+ assertSame(snapshotArtifact, project.getArtifacts().iterator().next());
}
- public void testFilteredBundles() throws Exception {
- final MavenProjectResourcesStub project =
createTestProject("default-filterbundles");
- final ProcessRemoteResourcesMojo mojo =
lookupProcessMojoWithSettings(project, new String[] {"test:test:1.1"});
+ @Test
+ void testValidateRejectsDescriptorWithEmptySegment(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo)
+ throws Exception {
+ final MavenProjectResourcesStub project =
createTestProject("default-validate");
+ configureProcessMojo(mojo, project,
Arrays.asList("org.example:dep::jar"));
+
+ try {
+ mojo.validate();
+ fail("Expected validate() to reject a resource bundle descriptor
with a missing version");
+ } catch (MojoExecutionException e) {
+ assertTrue(e.getMessage().contains("must specify a groupId,
artifactId"));
+ }
+ }
+
+ @Test
+ void testFindReactorProjectMatchesTimestampedSnapshot() throws Exception {
+ MavenProject reactorProject = new MavenProject(new
org.apache.maven.model.Model());
+ reactorProject.setGroupId("com.example");
+ reactorProject.setArtifactId("reactor-project");
+ reactorProject.setVersion("1.0-SNAPSHOT");
+
+ Artifact artifact = new DefaultArtifact(
+ "com.example",
+ "reactor-project",
+ VersionRange.createFromVersion("1.0-20260926.120000-1"),
+ null,
+ "jar",
+ "",
+ new DefaultArtifactHandler());
+
+ assertSame(
+ reactorProject,
+ AbstractProcessRemoteResourcesMojo.findReactorProject(
+ artifact, Collections.singletonList(reactorProject)));
+
+ Artifact externalArtifact = new DefaultArtifact(
+ "com.example",
+ "external-project",
+ VersionRange.createFromVersion("1.0"),
+ null,
+ "jar",
+ "",
+ new DefaultArtifactHandler());
+ assertNull(AbstractProcessRemoteResourcesMojo.findReactorProject(
+ externalArtifact, Collections.singletonList(reactorProject)));
+ }
+ @Test
+ void testGetProjectsBuildsOnlyExternalArtifacts(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo)
+ throws Exception {
+ MavenProjectResourcesStub project =
createTestProject("reactor-projects");
+ configureProcessMojo(mojo, project, Collections.emptyList());
setupDefaultProject(project);
- String path = pathOf(new DefaultArtifact(
- "test", "test", VersionRange.createFromVersion("1.1"), null,
"jar", "", new DefaultArtifactHandler()));
+ MavenProject reactorProject = new MavenProject(new
org.apache.maven.model.Model());
+ reactorProject.setGroupId("com.example");
+ reactorProject.setArtifactId("reactor-project");
+ reactorProject.setVersion("1.0-SNAPSHOT");
- File file = new File(path);
- file.getParentFile().mkdirs();
- buildResourceBundle("default-filterbundles-create", null, new String[]
{"FILTER.txt.vm"}, file);
+ Artifact reactorArtifact = new DefaultArtifact(
+ "com.example",
+ "reactor-project",
+ VersionRange.createFromVersion("1.0-20260926.120000-1"),
+ "compile",
+ "jar",
+ "",
+ new DefaultArtifactHandler());
+ Artifact externalArtifact = new DefaultArtifact(
+ "com.example",
+ "external-project",
+ VersionRange.createFromVersion("1.0"),
+ "compile",
+ "jar",
+ "",
+ new DefaultArtifactHandler());
+ project.setArtifacts(new
LinkedHashSet<>(Arrays.asList(reactorArtifact, externalArtifact)));
+ reactorProject.setArtifact(reactorArtifact);
- mojo.execute();
- // executing a second time (example: forked lifecycle) should still
work
- mojo.execute();
+ // the injected session is a mock, so the mojo gets a real one that
holds the reactor
+ MavenSession reactorSession = new MavenSession(
+ null,
+ session.getRepositorySession(),
+ new DefaultMavenExecutionRequest(),
+ new DefaultMavenExecutionResult());
+ reactorSession.setProjects(Arrays.asList(project, reactorProject));
+ setVariableValueToObject(mojo, "mavenSession", reactorSession);
- file = (File) getVariableValueFromObject(mojo, "outputDirectory");
- file = new File(file, "FILTER.txt");
- assertTrue(file.exists());
+ MavenProject externalProject = new MavenProject(new
org.apache.maven.model.Model());
+ externalProject.setGroupId("com.example");
+ externalProject.setArtifactId("external-project");
+ externalProject.setVersion("1.0");
+ externalProject.setArtifact(externalArtifact);
- String data = FileUtils.fileRead(file);
- assertTrue(data.contains("project.name: Test Project
default-filterbundles"));
- assertTrue(data.contains("projectTimespan: 2007-2019"));
- assertTrue(data.contains("projects: ["));
- assertTrue(data.contains("projectsSortedByOrganization: {"));
+ ProjectBuildingResult buildingResult = (ProjectBuildingResult)
Proxy.newProxyInstance(
+ ProjectBuildingResult.class.getClassLoader(),
+ new Class<?>[] {ProjectBuildingResult.class},
+ new InvocationHandler() {
+ @Override
+ public Object invoke(Object proxy, Method method, Object[]
args) {
+ if ("getProject".equals(method.getName())) {
+ return externalProject;
+ }
+ return null;
+ }
+ });
+ List<Artifact> builtArtifacts = new ArrayList<>();
+ ProjectBuilder projectBuilder = (ProjectBuilder)
Proxy.newProxyInstance(
+ ProjectBuilder.class.getClassLoader(), new Class<?>[]
{ProjectBuilder.class}, new InvocationHandler() {
+ @Override
+ public Object invoke(Object proxy, Method method, Object[]
args) {
+ if ("build".equals(method.getName())
+ && args != null
+ && args.length == 2
+ && args[0] instanceof Artifact) {
+ builtArtifacts.add((Artifact) args[0]);
+ return buildingResult;
+ }
+ return null;
+ }
+ });
+ setVariableValueToObject(mojo, "projectBuilder", projectBuilder);
+ setVariableValueToObject(mojo, "supplementModels", new HashMap<>());
+
+ List<MavenProject> projects = mojo.getProjects();
+
+ assertEquals(1, builtArtifacts.size());
+ assertSame(externalArtifact, builtArtifacts.get(0));
+ assertTrue(projects.contains(reactorProject));
+ assertTrue(projects.contains(externalProject));
}
- public void testFilteredAppendedResource() throws Exception {
+ @Test
+ void testFilteredAppendedResource(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo,
+ @InjectMojo(goal = "bundle", pom = DEFAULT_BUNDLE_POM_PATH)
BundleRemoteResourcesMojo bundleMojo)
+ throws Exception {
final MavenProjectResourcesStub project =
createTestProject("default-appended-filtered-resource");
- final ProcessRemoteResourcesMojo mojo =
lookupProcessMojoWithSettings(project, new String[] {"test:test:1.6"});
+ configureProcessMojo(mojo, project, Arrays.asList("test:test:1.6"));
setupDefaultProject(project);
@@ -598,6 +733,7 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
File bundleJar = new File(path);
bundleJar.getParentFile().mkdirs();
buildResourceBundle(
+ bundleMojo,
"default-appended-filtered-resource-create",
null,
new String[] {"BUNDLE_FILTER.txt.vm", "APPENDED_FILTER.txt"},
@@ -620,9 +756,13 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
assertTrue(bundleData.contains("project.name: Test Project
default-appended-filtered-resource"));
}
- public void testAppendedVelocityFailureIdentifiesTemplate() throws
Exception {
+ @Test
+ void testAppendedVelocityFailureIdentifiesTemplate(
+ @InjectMojo(goal = "process", pom = DEFAULT_PROCESS_POM_PATH)
ProcessRemoteResourcesMojo mojo,
+ @InjectMojo(goal = "bundle", pom = DEFAULT_BUNDLE_POM_PATH)
BundleRemoteResourcesMojo bundleMojo)
+ throws Exception {
final MavenProjectResourcesStub project =
createTestProject("default-appended-velocity-failure");
- final ProcessRemoteResourcesMojo mojo =
lookupProcessMojoWithSettings(project, new String[] {"test:test:1.5"});
+ configureProcessMojo(mojo, project, Arrays.asList("test:test:1.5"));
setupDefaultProject(project);
@@ -631,7 +771,11 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
File bundleJar = new File(path);
bundleJar.getParentFile().mkdirs();
buildResourceBundle(
- "default-appended-velocity-failure-create", null, new String[]
{"APPENDED_FILTER.txt"}, bundleJar);
+ bundleMojo,
+ "default-appended-velocity-failure-create",
+ null,
+ new String[] {"APPENDED_FILTER.txt"},
+ bundleJar);
File appendedResourcesDirectory = new File(project.getBasedir(),
"src/main/appended-resources");
appendedResourcesDirectory.mkdirs();
@@ -644,67 +788,17 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
mojo.execute();
fail("Expected the invalid appended template to fail rendering");
} catch (MojoExecutionException expected) {
- assertTrue(expected.getMessage(),
expected.getMessage().contains("APPENDED_FILTER.txt.vm"));
- }
- }
-
- public void testFilteredBundlesWithProjectProperties() throws Exception {
- final MavenProjectResourcesStub project =
createTestProject("default-filterbundles-two");
- final ProcessRemoteResourcesMojo mojo =
- lookupProcessMojoWithSettings(project, new String[]
{"test-filtered-bundles:test-filtered-bundles:2"});
-
- mojo.includeProjectProperties = true;
- setupDefaultProject(project);
-
- project.addProperty("testingPropertyOne", "maven");
- project.addProperty("testingPropertyTwo", "rules");
-
- String path = pathOf(new DefaultArtifact(
- "test-filtered-bundles",
- "test-filtered-bundles",
- VersionRange.createFromVersion("2"),
- null,
- "jar",
- "",
- new DefaultArtifactHandler()));
-
- File file = new File(path);
- file.getParentFile().mkdirs();
- buildResourceBundle("default-filterbundles-two-create", null, new
String[] {"PROPERTIES.txt.vm"}, file);
-
- mojo.execute();
- // executing a second time (example: forked lifecycle) should still
work
- mojo.execute();
-
- file = (File) getVariableValueFromObject(mojo, "outputDirectory");
- file = new File(file, "PROPERTIES.txt");
-
- assertTrue(file.exists());
-
- String data = FileUtils.fileRead(file);
- assertTrue(data.contains("maven"));
- assertTrue(data.contains("rules"));
- }
-
- public void testValidateRejectsDescriptorWithEmptySegment() throws
Exception {
- final MavenProjectResourcesStub project =
createTestProject("default-validate");
- final ProcessRemoteResourcesMojo mojo =
- lookupProcessMojoWithSettings(project, new String[]
{"org.example:dep::jar"});
-
- try {
- mojo.validate();
- fail("Expected validate() to reject a resource bundle descriptor
with a missing version");
- } catch (MojoExecutionException e) {
- assertTrue(e.getMessage().contains("must specify a groupId,
artifactId"));
+
assertTrue(expected.getMessage().contains("APPENDED_FILTER.txt.vm"),
expected.getMessage());
}
}
- protected void buildResourceBundle(String id, String sourceEncoding,
String[] resourceNames, File jarName)
+ private void buildResourceBundle(
+ BundleRemoteResourcesMojo mojo, String id, String sourceEncoding,
String[] resourceNames, File jarName)
throws Exception {
final MavenProjectResourcesStub project = createTestProject(id);
- final File resourceDir = new File(project.getBasedir() +
"/src/main/resources");
- final BundleRemoteResourcesMojo mojo =
lookupBundleMojoWithSettings(project, resourceDir, sourceEncoding);
+ final File resourceDir = new File(project.getBasedir(),
"src/main/resources");
+ configureBundleMojo(mojo, project, resourceDir, sourceEncoding);
setupDefaultProject(project);
@@ -717,7 +811,7 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
mojo.execute();
- File xmlFile = new File(project.getBasedir() +
"/target/classes/META-INF/maven/remote-resources.xml");
+ File xmlFile = new File(project.getBasedir(),
"target/classes/META-INF/maven/remote-resources.xml");
assertTrue(xmlFile.exists());
String data = FileUtils.fileRead(xmlFile);
@@ -753,18 +847,18 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
int fromIndex = 0;
for (String s : expected) {
int idx = actual.indexOf(s, fromIndex);
- assertTrue("expected \"" + s + "\" to occur in order in: " +
actual, idx >= 0);
+ assertTrue(idx >= 0, "expected \"" + s + "\" to occur in order in:
" + actual);
fromIndex = idx + s.length();
}
}
- protected MavenProjectResourcesStub createTestProject(final String
testName) throws Exception {
+ private MavenProjectResourcesStub createTestProject(final String testName)
throws Exception {
// this will automatically create the isolated
// test environment
return new MavenProjectResourcesStub(testName);
}
- protected void setupDefaultProject(final MavenProjectResourcesStub
project) throws Exception {
+ private void setupDefaultProject(final MavenProjectResourcesStub project)
throws Exception {
// put this on the root dir
project.addFile("pom.xml", MavenProjectBuildStub.ROOT_FILE);
project.setInceptionYear("2007");
@@ -772,88 +866,29 @@ public class RemoteResourcesMojoTest extends
AbstractMojoTestCase {
project.setupBuildEnvironment();
}
- protected BundleRemoteResourcesMojo lookupBundleMojo() throws Exception {
- File pomFile = new File(getBasedir(), DEFAULT_BUNDLE_POM_PATH);
- BundleRemoteResourcesMojo mojo = (BundleRemoteResourcesMojo)
lookupMojo("bundle", pomFile);
-
- assertNotNull(mojo);
-
- return mojo;
- }
-
- protected BundleRemoteResourcesMojo
lookupBundleMojoWithDefaultSettings(final MavenProject project)
+ private void configureBundleMojo(
+ BundleRemoteResourcesMojo mojo, MavenProject project, File
resourceDir, String sourceEncoding)
throws Exception {
- File resourceDir = new File(project.getBasedir() +
"/src/main/resources");
- return lookupBundleMojoWithSettings(project, resourceDir, null);
- }
-
- protected BundleRemoteResourcesMojo lookupBundleMojoWithSettings(
- final MavenProject project, File resourceDir, String
sourceEncoding) throws Exception {
- final BundleRemoteResourcesMojo mojo = lookupBundleMojo();
-
setVariableValueToObject(mojo, "resourcesDirectory", resourceDir);
setVariableValueToObject(
mojo, "outputDirectory", new
File(project.getBuild().getOutputDirectory()));
setVariableValueToObject(mojo, "sourceEncoding", sourceEncoding);
- return mojo;
- }
-
- protected ProcessRemoteResourcesMojo lookupProcessMojo() throws Exception {
- File pomFile = new File(getBasedir(), DEFAULT_PROCESS_POM_PATH);
- ProcessRemoteResourcesMojo mojo = (ProcessRemoteResourcesMojo)
lookupMojo("process", pomFile);
-
- assertNotNull(mojo);
-
- return mojo;
}
- protected ProcessRemoteResourcesMojo lookupProcessMojoWithSettings(final
MavenProject project, String[] bundles)
+ private void configureProcessMojo(ProcessRemoteResourcesMojo mojo,
MavenProject project, List<String> bundles)
throws Exception {
- return lookupProcessMojoWithSettings(project, new
ArrayList<>(Arrays.asList(bundles)));
- }
-
- protected ProcessRemoteResourcesMojo lookupProcessMojoWithSettings(
- final MavenProject project, ArrayList<String> bundles) throws
Exception {
- final ProcessRemoteResourcesMojo mojo = lookupProcessMojo();
-
- DefaultRepositorySystemSession reposession =
MavenRepositorySystemUtils.newSession();
- reposession.setLocalRepositoryManager(new
SimpleLocalRepositoryManagerFactory()
- .newInstance(reposession, new LocalRepository(new
File(LOCAL_REPO))));
-
- DefaultMavenExecutionRequest request = new
DefaultMavenExecutionRequest();
- request.setUserProperties(null);
- // request.setLocalRepository( reposession.getLocalRepository() );
- request.setGoals(Collections.singletonList("install"));
- request.setBaseDirectory(project.getBasedir());
- request.setStartTime(Calendar.getInstance().getTime());
-
- // TODO: get rid of this uglyness/legacy
- MavenArtifactRepository localRepository = new
MavenArtifactRepository();
- localRepository.setId("local");
- localRepository.setUrl(new File(LOCAL_REPO).toURI().toASCIIString());
- localRepository.setLayout(new DefaultRepositoryLayout());
- request.setLocalRepository(localRepository);
- MavenSession session =
- new MavenSession(getContainer(), reposession, request, new
DefaultMavenExecutionResult());
- session.setProjects(Collections.singletonList(project));
-
setVariableValueToObject(
mojo, "outputDirectory", new
File(project.getBuild().getOutputDirectory()));
setVariableValueToObject(mojo, "resourceBundles", bundles);
setVariableValueToObject(mojo, "mavenSession", session);
setVariableValueToObject(mojo, "project", project);
- return mojo;
- }
-
- protected ProcessRemoteResourcesMojo
lookupProcessMojoWithDefaultSettings(final MavenProject project)
- throws Exception {
- return lookupProcessMojoWithSettings(project, new ArrayList<>());
}
private String pathOf(Artifact artifact) {
- String path = LOCAL_REPO + artifact.getGroupId().replace(".", "/") +
"/"
- + artifact.getArtifactId() + "/"
- + artifact.getBaseVersion() + "/"
+ String path = localRepo.getPath() + File.separator
+ + artifact.getGroupId().replace(".", File.separator) +
File.separator
+ + artifact.getArtifactId() + File.separator
+ + artifact.getBaseVersion() + File.separator
+ artifact.getArtifactId() + "-" + artifact.getVersion();
if (artifact.getClassifier() != null &&
!artifact.getClassifier().isEmpty()) {
path = path + "-" + artifact.getClassifier();