Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.File;
import java.util.Collection;

import org.apache.maven.shared.verifier.VerificationException;
import org.apache.maven.shared.verifier.Verifier;
import org.apache.maven.shared.verifier.util.ResourceExtractor;
import org.junit.jupiter.api.Test;
Expand All @@ -35,6 +36,10 @@ public MavenIT0085TransitiveSystemScopeTest() {
* when they are resolved transitively via another (non-system)
* dependency. Inherited scope should not apply in the case of
* system-scoped dependencies, no matter where they are.
* <p>
* Since 3.10.0-rc-2, repository-resolved models restrict property
* interpolation by default, so the opt-out flag is required for the
* legacy behavior and the default behavior causes a build failure.
*
* @throws Exception in case of failure
*/
Expand All @@ -51,6 +56,44 @@ public void testit0085() throws Exception {
verifier.addCliArgument("--settings");
verifier.addCliArgument("settings.xml");
verifier.addCliArgument("validate");

String mavenVersion = getMavenVersion() != null ? getMavenVersion().toString() : "";
if (mavenVersion.equals("3.10.0-rc-1") || matchesVersionRange("(,3.10.0)")) {
// Before restricted interpolation: full interpolation works without opt-out
verifier.execute();
verifier.verifyErrorFreeLog();
} else {
// With restricted interpolation: build fails without opt-out
try {
verifier.execute();
verifier.verifyErrorFreeLog();
fail("Build should not succeed without -Dmaven.model.dependencyInterpolation.full=true");
} catch (VerificationException e) {
verifier.verifyTextInLog("must specify an absolute path but is ${test.home}/system.jar");
}
}
}

/**
* Verify that system-scoped dependencies work correctly when the opt-out
* property {@code -Dmaven.model.dependencyInterpolation.full=true} is set.
*
* @throws Exception in case of failure
*/
@Test
public void testit0085WithFullInterpolation() throws Exception {
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/it0085");

Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.deleteDirectory("target");
verifier.deleteArtifacts("org.apache.maven.its.it0085");
verifier.getSystemProperties().setProperty("test.home", testDir.getAbsolutePath());
verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8");
verifier.addCliArgument("--settings");
verifier.addCliArgument("settings.xml");
verifier.addCliArgument("validate");
verifier.addCliArgument("-Dmaven.model.dependencyInterpolation.full=true");
verifier.execute();
verifier.verifyErrorFreeLog();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.File;
import java.util.Properties;

import org.apache.maven.shared.verifier.VerificationException;
import org.apache.maven.shared.verifier.Verifier;
import org.apache.maven.shared.verifier.util.ResourceExtractor;
import org.junit.jupiter.api.Test;
Expand All @@ -40,6 +41,10 @@ public MavenITmng3586SystemScopePluginDependencyTest() {
/**
* Test that plugin dependencies with scope system are part of the plugin class realm. This test checks
* dependencies that are declared in the plugin POM.
* <p>
* Since 3.10.0-rc-2, repository-resolved models restrict property
* interpolation by default, so the opt-out flag is required for the
* legacy behavior and the default behavior causes a build failure.
*
* @throws Exception in case of failure
*/
Expand All @@ -56,6 +61,48 @@ public void testitFromPlugin() throws Exception {
verifier.addCliArgument("--settings");
verifier.addCliArgument("settings.xml");
verifier.addCliArgument("validate");

String mavenVersion = getMavenVersion() != null ? getMavenVersion().toString() : "";
if (mavenVersion.equals("3.10.0-rc-1") || matchesVersionRange("(,3.10.0)")) {
// Before restricted interpolation: full interpolation works without opt-out
verifier.execute();
verifier.verifyErrorFreeLog();

Properties props = verifier.loadProperties("target/it.properties");
assertEquals("PASSED", props.getProperty("test"));
} else {
// With restricted interpolation: build fails without opt-out
try {
verifier.execute();
verifier.verifyErrorFreeLog();
fail("Build should not succeed without -Dmaven.model.dependencyInterpolation.full=true");
} catch (VerificationException e) {
verifier.verifyTextInLog("must specify an absolute path but is ${test.home}/tools.jar");
}
}
}

/**
* Test that plugin dependencies with scope system are part of the plugin class realm when the
* opt-out property {@code -Dmaven.model.dependencyInterpolation.full=true} is set.
* This test checks dependencies that are declared in the plugin POM.
*
* @throws Exception in case of failure
*/
@Test
public void testitFromPluginWithFullInterpolation() throws Exception {
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-3586/test-1");

Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.deleteDirectory("target");
verifier.deleteArtifacts("org.apache.maven.its.mng3586");
verifier.getSystemProperties().setProperty("test.home", testDir.getAbsolutePath());
verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8");
verifier.addCliArgument("--settings");
verifier.addCliArgument("settings.xml");
verifier.addCliArgument("validate");
verifier.addCliArgument("-Dmaven.model.dependencyInterpolation.full=true");
verifier.execute();
verifier.verifyErrorFreeLog();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.File;
import java.util.List;

import org.apache.maven.shared.verifier.VerificationException;
import org.apache.maven.shared.verifier.Verifier;
import org.apache.maven.shared.verifier.util.ResourceExtractor;
import org.junit.jupiter.api.Test;
Expand All @@ -39,6 +40,10 @@ public MavenITmng4379TransitiveSystemPathInterpolatedWithEnvVarTest() {
/**
* Test that the path of a system-scope dependency gets interpolated using environment variables during
* transitive dependency resolution.
* <p>
* Since 3.10.0-rc-2, repository-resolved models restrict property
* interpolation by default, so the opt-out flag is required for the
* legacy behavior and the default behavior causes a build failure.
*
* @throws Exception in case of failure
*/
Expand All @@ -55,6 +60,47 @@ public void testit() throws Exception {
verifier.addCliArgument("-s");
verifier.addCliArgument("settings.xml");
verifier.addCliArguments("validate");

String mavenVersion = getMavenVersion() != null ? getMavenVersion().toString() : "";
if (mavenVersion.equals("3.10.0-rc-1") || matchesVersionRange("(,3.10.0)")) {
// Before restricted interpolation: env var interpolation works without opt-out
verifier.execute();
verifier.verifyErrorFreeLog();

List<String> classpath = verifier.loadLines("target/classpath.txt", "UTF-8");
assertTrue(classpath.toString(), classpath.contains("pom.xml"));
} else {
// With restricted interpolation: build fails without opt-out
try {
verifier.execute();
verifier.verifyErrorFreeLog();
fail("Build should not succeed without -Dmaven.model.dependencyInterpolation.full=true");
} catch (VerificationException e) {
verifier.verifyTextInLog("must specify an absolute path but is ${env.MNG_4379_HOME}/pom.xml");
}
}
}

/**
* Test that the path of a system-scope dependency gets interpolated using environment variables when
* the opt-out property {@code -Dmaven.model.dependencyInterpolation.full=true} is set.
*
* @throws Exception in case of failure
*/
@Test
public void testitWithFullInterpolation() throws Exception {
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4379");

Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.deleteDirectory("target");
verifier.deleteArtifacts("org.apache.maven.its.mng4379");
verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8");
verifier.setEnvironmentVariable("MNG_4379_HOME", testDir.getAbsolutePath());
verifier.addCliArgument("-s");
verifier.addCliArgument("settings.xml");
verifier.addCliArguments("validate");
verifier.addCliArgument("-Dmaven.model.dependencyInterpolation.full=true");
verifier.execute();
verifier.verifyErrorFreeLog();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.File;
import java.util.Properties;

import org.apache.maven.shared.verifier.VerificationException;
import org.apache.maven.shared.verifier.Verifier;
import org.apache.maven.shared.verifier.util.ResourceExtractor;
import org.junit.jupiter.api.Test;
Expand All @@ -38,6 +39,10 @@ public MavenITmng4590ImportedPomUsesSystemAndUserPropertiesTest() {

/**
* Verify that imported POMs are processed using the same system/user properties as the importing POM.
* <p>
* Since 3.10.0-rc-2, repository-resolved models restrict property
* interpolation by default, so the opt-out flag is required for the
* legacy behavior and the default behavior causes a build failure.
*
* @throws Exception in case of failure
*/
Expand All @@ -55,6 +60,52 @@ public void testit() throws Exception {
verifier.addCliArgument("--settings");
verifier.addCliArgument("settings.xml");
verifier.addCliArgument("validate");

String mavenVersion = getMavenVersion() != null ? getMavenVersion().toString() : "";
if (mavenVersion.equals("3.10.0-rc-1") || matchesVersionRange("(,3.10.0)")) {
// Before restricted interpolation: full interpolation works without opt-out
verifier.execute();
verifier.verifyErrorFreeLog();

Properties props = verifier.loadProperties("target/pom.properties");
assertEquals("1", props.getProperty("project.dependencyManagement.dependencies"));
assertEquals("dep-a", props.getProperty("project.dependencyManagement.dependencies.0.artifactId"));
assertEquals(
new File(testDir, "pom.xml").getAbsoluteFile(),
new File(props.getProperty("project.dependencyManagement.dependencies.0.systemPath")));
} else {
// With restricted interpolation: build fails without opt-out
try {
verifier.execute();
verifier.verifyErrorFreeLog();
fail("Build should not succeed without -Dmaven.model.dependencyInterpolation.full=true");
} catch (VerificationException e) {
verifier.verifyTextInLog("must specify an absolute path but is ${test.dir}/${test.file}");
}
}
}

/**
* Verify that imported POMs are processed using the same system/user properties as the importing POM
* when the opt-out property {@code -Dmaven.model.dependencyInterpolation.full=true} is set.
*
* @throws Exception in case of failure
*/
@Test
public void testitWithFullInterpolation() throws Exception {
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4590");

Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.deleteDirectory("target");
verifier.deleteArtifacts("org.apache.maven.its.mng4590");
verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8");
verifier.setEnvironmentVariable("MAVEN_OPTS", "-Dtest.file=pom.xml");
verifier.addCliArgument("-Dtest.dir=" + testDir.getAbsolutePath());
verifier.addCliArgument("--settings");
verifier.addCliArgument("settings.xml");
verifier.addCliArgument("validate");
verifier.addCliArgument("-Dmaven.model.dependencyInterpolation.full=true");
verifier.execute();
verifier.verifyErrorFreeLog();

Expand Down
Loading