You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "ascheman (via GitHub)" <gi...@apache.org> on 2026/06/17 16:24:11 UTC
[PR] [#12288] Add -P !profile deactivation regression guard [maven]
ascheman opened a new pull request, #12298:
URL: https://github.com/apache/maven/pull/12298
Hypersedes #12297 (which superseded #12291).
Starts from the head of #12297 and adds one additional integration
test, `testActiveByDefaultDeactivatedViaCli`, that guards the
`-P !profileId` deactivation path introduced in @gnodet's commit
"Address review feedback: fix activeByDefault deactivation and rename
IT". The fix logic itself is unchanged from #12297; this PR adds the
regression test to lock it in.
## What's new vs #12297
* `testActiveByDefaultDeactivatedViaCli` — runs `mvn install` with
`-P!aether-split-via-settings` and asserts the artifact lands at the
flat layout (not under the custom prefix), confirming the
`inactiveProfileId` guard works end-to-end.
* `deleteRecursivelyIfExists` private helper — clears any stale
`it-custom-prefix/` subtree before the deactivation run, so the
assertion is robust against test-execution order with sibling tests
installing under that same prefix.
## Verification
* Patched build: 3/3 ITs green.
* Without the deactivation guard in the fix (i.e. vanilla master):
`testActiveByDefaultProfile` is RED — the bug — and the deactivation
test trivially passes because the profile is silently dropped anyway.
So the new test specifically guards the fix-introduced deactivation
logic, not a pre-existing path.
Happy to fold the extra test into #12297 instead if you'd prefer to
keep it on a single PR; just say the word.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12288] Add -P !profile deactivation regression guard [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet merged PR #12298:
URL: https://github.com/apache/maven/pull/12298
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12288] Add -P !profile deactivation regression guard [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12298:
URL: https://github.com/apache/maven/pull/12298#discussion_r3436209651
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12288SettingsProfileAetherPropertiesTest.java:
##########
@@ -19,6 +19,8 @@
package org.apache.maven.it;
import java.io.File;
+import java.nio.file.Files;
+import java.util.Comparator;
import org.junit.jupiter.api.Test;
Review Comment:
Replace `Files`/`Comparator` imports with `FileUtils` (same one the `Verifier` uses internally):
```suggestion
import java.io.File;
import org.codehaus.plexus.util.FileUtils;
import org.junit.jupiter.api.Test;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12288] Add -P !profile deactivation regression guard [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12298:
URL: https://github.com/apache/maven/pull/12298#discussion_r3436301321
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12288SettingsProfileAetherPropertiesTest.java:
##########
@@ -65,6 +66,43 @@ public void testActiveProfilesList() throws Exception {
runAndAssertCustomPrefix("settings-active-profiles-list.xml");
}
+ @Test
+ public void testActiveByDefaultDeactivatedViaCli() throws Exception {
+ File testDir = extractResources("/settings-profile-aether-properties");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ verifier.setAutoclean(false);
+ verifier.setLogFileName("log-deactivation.txt");
+ verifier.deleteDirectory("target");
+ verifier.deleteArtifacts("org.apache.maven.its.settings.profile.aether");
+
+ // Sibling tests in this class install under the same custom prefix; clear it to
+ // avoid false positives if those tests ran first.
+ File customPrefixSubtree = new File(verifier.getLocalRepository(), "it-custom-prefix");
+ FileUtils.deleteDirectory(customPrefixSubtree);
+
+ verifier.addCliArgument("--settings");
+ verifier.addCliArgument("settings-active-by-default.xml");
+ verifier.addCliArgument("-P!aether-split-via-settings");
+ verifier.addCliArgument("install");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ File localRepo = new File(verifier.getLocalRepository());
+ String gavRelativePath = "org/apache/maven/its/settings/profile/aether/test-artifact/1.0/test-artifact-1.0.pom";
+ File flatLayout = new File(localRepo, gavRelativePath);
+ File customPrefix = new File(localRepo, "it-custom-prefix/" + gavRelativePath);
+
+ assertTrue(
+ flatLayout.exists(),
+ "Expected artifact at flat layout (profile deactivated via -P !), but not found at " + flatLayout);
+
+ assertFalse(
+ customPrefix.exists(),
+ "Found artifact at custom prefix " + customPrefix + " — deactivation via -P ! was ignored.");
+ }
+ }
Review Comment:
Stray closing brace left over from applying the previous suggestion — sorry about that!
```suggestion
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12288] Add -P !profile deactivation regression guard [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12298:
URL: https://github.com/apache/maven/pull/12298#discussion_r3434815332
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12288SettingsProfileAetherPropertiesTest.java:
##########
@@ -65,6 +67,52 @@ public void testActiveProfilesList() throws Exception {
runAndAssertCustomPrefix("settings-active-profiles-list.xml");
}
+ @Test
+ public void testActiveByDefaultDeactivatedViaCli() throws Exception {
+ File testDir = extractResources("/settings-profile-aether-properties");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ verifier.setAutoclean(false);
+ verifier.setLogFileName("log-deactivation.txt");
+ verifier.deleteDirectory("target");
+ verifier.deleteArtifacts("org.apache.maven.its.settings.profile.aether");
+
+ // Sibling tests in this class install under the same custom prefix; clear it to
+ // avoid false positives if those tests ran first.
+ File customPrefixSubtree = new File(verifier.getLocalRepository(), "it-custom-prefix");
+ deleteRecursivelyIfExists(customPrefixSubtree);
+
+ verifier.addCliArgument("--settings");
+ verifier.addCliArgument("settings-active-by-default.xml");
+ verifier.addCliArgument("-P!aether-split-via-settings");
+ verifier.addCliArgument("install");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ File localRepo = new File(verifier.getLocalRepository());
+ String gavRelativePath = "org/apache/maven/its/settings/profile/aether/test-artifact/1.0/test-artifact-1.0.pom";
+ File flatLayout = new File(localRepo, gavRelativePath);
+ File customPrefix = new File(localRepo, "it-custom-prefix/" + gavRelativePath);
+
+ assertTrue(
+ flatLayout.exists(),
+ "Expected artifact at flat layout (profile deactivated via -P !), but not found at " + flatLayout);
+
+ assertFalse(
+ customPrefix.exists(),
+ "Found artifact at custom prefix " + customPrefix + " — deactivation via -P ! was ignored.");
+ }
+
+ private static void deleteRecursivelyIfExists(File path) throws Exception {
+ if (!path.exists()) {
+ return;
+ }
+ Files.walk(path.toPath())
+ .sorted(Comparator.reverseOrder())
+ .map(java.nio.file.Path::toFile)
+ .forEach(File::delete);
+ }
Review Comment:
The `deleteRecursivelyIfExists` helper and the `java.nio.file.Files` / `java.util.Comparator` imports are unnecessary — other ITs in this suite already use `FileUtils.deleteDirectory()` for the same purpose (e.g. `MavenITmng7819FileLockingWithSnapshotsTest:83`, `MavenIT0108SnapshotUpdateTest:126`). It handles non-existent paths gracefully and is already on the classpath.
Replace the helper and its call site with:
```java
org.apache.commons.io.FileUtils.deleteDirectory(customPrefixSubtree);
```
and drop this method entirely.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12288] Add -P !profile deactivation regression guard [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12298:
URL: https://github.com/apache/maven/pull/12298#discussion_r3434815332
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12288SettingsProfileAetherPropertiesTest.java:
##########
@@ -65,6 +67,52 @@ public void testActiveProfilesList() throws Exception {
runAndAssertCustomPrefix("settings-active-profiles-list.xml");
}
+ @Test
+ public void testActiveByDefaultDeactivatedViaCli() throws Exception {
+ File testDir = extractResources("/settings-profile-aether-properties");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ verifier.setAutoclean(false);
+ verifier.setLogFileName("log-deactivation.txt");
+ verifier.deleteDirectory("target");
+ verifier.deleteArtifacts("org.apache.maven.its.settings.profile.aether");
+
+ // Sibling tests in this class install under the same custom prefix; clear it to
+ // avoid false positives if those tests ran first.
+ File customPrefixSubtree = new File(verifier.getLocalRepository(), "it-custom-prefix");
+ deleteRecursivelyIfExists(customPrefixSubtree);
+
+ verifier.addCliArgument("--settings");
+ verifier.addCliArgument("settings-active-by-default.xml");
+ verifier.addCliArgument("-P!aether-split-via-settings");
+ verifier.addCliArgument("install");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ File localRepo = new File(verifier.getLocalRepository());
+ String gavRelativePath = "org/apache/maven/its/settings/profile/aether/test-artifact/1.0/test-artifact-1.0.pom";
+ File flatLayout = new File(localRepo, gavRelativePath);
+ File customPrefix = new File(localRepo, "it-custom-prefix/" + gavRelativePath);
+
+ assertTrue(
+ flatLayout.exists(),
+ "Expected artifact at flat layout (profile deactivated via -P !), but not found at " + flatLayout);
+
+ assertFalse(
+ customPrefix.exists(),
+ "Found artifact at custom prefix " + customPrefix + " — deactivation via -P ! was ignored.");
+ }
+
+ private static void deleteRecursivelyIfExists(File path) throws Exception {
+ if (!path.exists()) {
+ return;
+ }
+ Files.walk(path.toPath())
+ .sorted(Comparator.reverseOrder())
+ .map(java.nio.file.Path::toFile)
+ .forEach(File::delete);
+ }
Review Comment:
Nit: `Files.walk()` returns a stream backed by a `DirectoryStream` that should be closed ([javadoc](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Files.html#walk(java.nio.file.Path,java.nio.file.FileVisitOption...))). On Windows especially, unclosed directory handles can interfere with subsequent deletions.
```suggestion
private static void deleteRecursivelyIfExists(File path) throws Exception {
if (!path.exists()) {
return;
}
try (var paths = Files.walk(path.toPath())) {
paths.sorted(Comparator.reverseOrder())
.map(java.nio.file.Path::toFile)
.forEach(File::delete);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12288] Add -P !profile deactivation regression guard [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12298:
URL: https://github.com/apache/maven/pull/12298#discussion_r3436209685
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12288SettingsProfileAetherPropertiesTest.java:
##########
@@ -65,6 +67,53 @@ public void testActiveProfilesList() throws Exception {
runAndAssertCustomPrefix("settings-active-profiles-list.xml");
}
+ @Test
+ public void testActiveByDefaultDeactivatedViaCli() throws Exception {
+ File testDir = extractResources("/settings-profile-aether-properties");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ verifier.setAutoclean(false);
+ verifier.setLogFileName("log-deactivation.txt");
+ verifier.deleteDirectory("target");
+ verifier.deleteArtifacts("org.apache.maven.its.settings.profile.aether");
+
+ // Sibling tests in this class install under the same custom prefix; clear it to
+ // avoid false positives if those tests ran first.
+ File customPrefixSubtree = new File(verifier.getLocalRepository(), "it-custom-prefix");
+ deleteRecursivelyIfExists(customPrefixSubtree);
+
+ verifier.addCliArgument("--settings");
+ verifier.addCliArgument("settings-active-by-default.xml");
+ verifier.addCliArgument("-P!aether-split-via-settings");
+ verifier.addCliArgument("install");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ File localRepo = new File(verifier.getLocalRepository());
+ String gavRelativePath = "org/apache/maven/its/settings/profile/aether/test-artifact/1.0/test-artifact-1.0.pom";
+ File flatLayout = new File(localRepo, gavRelativePath);
+ File customPrefix = new File(localRepo, "it-custom-prefix/" + gavRelativePath);
+
+ assertTrue(
+ flatLayout.exists(),
+ "Expected artifact at flat layout (profile deactivated via -P !), but not found at " + flatLayout);
+
+ assertFalse(
+ customPrefix.exists(),
+ "Found artifact at custom prefix " + customPrefix + " — deactivation via -P ! was ignored.");
+ }
+
+ private static void deleteRecursivelyIfExists(File path) throws Exception {
+ if (!path.exists()) {
+ return;
+ }
+ try (var paths = Files.walk(path.toPath())) {
+ paths.sorted(Comparator.reverseOrder())
+ .map(java.nio.file.Path::toFile)
+ .forEach(File::delete);
+ }
Review Comment:
Remove the custom helper — `FileUtils.deleteDirectory()` replaces it:
```suggestion
```
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12288SettingsProfileAetherPropertiesTest.java:
##########
@@ -65,6 +67,53 @@ public void testActiveProfilesList() throws Exception {
runAndAssertCustomPrefix("settings-active-profiles-list.xml");
}
+ @Test
+ public void testActiveByDefaultDeactivatedViaCli() throws Exception {
+ File testDir = extractResources("/settings-profile-aether-properties");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ verifier.setAutoclean(false);
+ verifier.setLogFileName("log-deactivation.txt");
+ verifier.deleteDirectory("target");
+ verifier.deleteArtifacts("org.apache.maven.its.settings.profile.aether");
+
+ // Sibling tests in this class install under the same custom prefix; clear it to
+ // avoid false positives if those tests ran first.
+ File customPrefixSubtree = new File(verifier.getLocalRepository(), "it-custom-prefix");
+ deleteRecursivelyIfExists(customPrefixSubtree);
+
+ verifier.addCliArgument("--settings");
+ verifier.addCliArgument("settings-active-by-default.xml");
+ verifier.addCliArgument("-P!aether-split-via-settings");
+ verifier.addCliArgument("install");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ File localRepo = new File(verifier.getLocalRepository());
+ String gavRelativePath = "org/apache/maven/its/settings/profile/aether/test-artifact/1.0/test-artifact-1.0.pom";
+ File flatLayout = new File(localRepo, gavRelativePath);
+ File customPrefix = new File(localRepo, "it-custom-prefix/" + gavRelativePath);
+
+ assertTrue(
+ flatLayout.exists(),
+ "Expected artifact at flat layout (profile deactivated via -P !), but not found at " + flatLayout);
+
+ assertFalse(
+ customPrefix.exists(),
+ "Found artifact at custom prefix " + customPrefix + " — deactivation via -P ! was ignored.");
+ }
+
+ private static void deleteRecursivelyIfExists(File path) throws Exception {
+ if (!path.exists()) {
+ return;
+ }
+ try (var paths = Files.walk(path.toPath())) {
+ paths.sorted(Comparator.reverseOrder())
+ .map(java.nio.file.Path::toFile)
+ .forEach(File::delete);
+ }
Review Comment:
Remove the custom helper — `FileUtils.deleteDirectory()` replaces it:
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12288] Add -P !profile deactivation regression guard [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12298:
URL: https://github.com/apache/maven/pull/12298#discussion_r3434368453
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12288SettingsProfileAetherPropertiesTest.java:
##########
@@ -65,6 +67,52 @@ public void testActiveProfilesList() throws Exception {
runAndAssertCustomPrefix("settings-active-profiles-list.xml");
}
+ @Test
+ public void testActiveByDefaultDeactivatedViaCli() throws Exception {
+ File testDir = extractResources("/settings-profile-aether-properties");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ verifier.setAutoclean(false);
+ verifier.setLogFileName("log-deactivation.txt");
+ verifier.deleteDirectory("target");
+ verifier.deleteArtifacts("org.apache.maven.its.settings.profile.aether");
+
+ // Sibling tests in this class install under the same custom prefix; clear it to
+ // avoid false positives if those tests ran first.
+ File customPrefixSubtree = new File(verifier.getLocalRepository(), "it-custom-prefix");
+ deleteRecursivelyIfExists(customPrefixSubtree);
+
+ verifier.addCliArgument("--settings");
+ verifier.addCliArgument("settings-active-by-default.xml");
+ verifier.addCliArgument("-P!aether-split-via-settings");
+ verifier.addCliArgument("install");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ File localRepo = new File(verifier.getLocalRepository());
+ String gavRelativePath = "org/apache/maven/its/settings/profile/aether/test-artifact/1.0/test-artifact-1.0.pom";
+ File flatLayout = new File(localRepo, gavRelativePath);
+ File customPrefix = new File(localRepo, "it-custom-prefix/" + gavRelativePath);
+
+ assertTrue(
+ flatLayout.exists(),
+ "Expected artifact at flat layout (profile deactivated via -P !), but not found at " + flatLayout);
+
+ assertFalse(
+ customPrefix.exists(),
+ "Found artifact at custom prefix " + customPrefix + " — deactivation via -P ! was ignored.");
+ }
+
+ private static void deleteRecursivelyIfExists(File path) throws Exception {
+ if (!path.exists()) {
+ return;
+ }
+ Files.walk(path.toPath())
+ .sorted(Comparator.reverseOrder())
+ .map(java.nio.file.Path::toFile)
+ .forEach(File::delete);
Review Comment:
Nit: `Files.walk()` returns a stream backed by a `DirectoryStream` that should be closed ([javadoc](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Files.html#walk(java.nio.file.Path,java.nio.file.FileVisitOption...))). On Windows especially, unclosed directory handles can interfere with subsequent deletions.
```suggestion
private static void deleteRecursivelyIfExists(File path) throws Exception {
if (!path.exists()) {
return;
}
try (var paths = Files.walk(path.toPath())) {
paths.sorted(Comparator.reverseOrder())
.map(java.nio.file.Path::toFile)
.forEach(File::delete);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12288] Add -P !profile deactivation regression guard [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12298:
URL: https://github.com/apache/maven/pull/12298#discussion_r3436295641
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12288SettingsProfileAetherPropertiesTest.java:
##########
@@ -65,6 +67,52 @@ public void testActiveProfilesList() throws Exception {
runAndAssertCustomPrefix("settings-active-profiles-list.xml");
}
+ @Test
+ public void testActiveByDefaultDeactivatedViaCli() throws Exception {
+ File testDir = extractResources("/settings-profile-aether-properties");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ verifier.setAutoclean(false);
+ verifier.setLogFileName("log-deactivation.txt");
+ verifier.deleteDirectory("target");
+ verifier.deleteArtifacts("org.apache.maven.its.settings.profile.aether");
+
+ // Sibling tests in this class install under the same custom prefix; clear it to
+ // avoid false positives if those tests ran first.
+ File customPrefixSubtree = new File(verifier.getLocalRepository(), "it-custom-prefix");
+ deleteRecursivelyIfExists(customPrefixSubtree);
+
+ verifier.addCliArgument("--settings");
+ verifier.addCliArgument("settings-active-by-default.xml");
+ verifier.addCliArgument("-P!aether-split-via-settings");
+ verifier.addCliArgument("install");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ File localRepo = new File(verifier.getLocalRepository());
+ String gavRelativePath = "org/apache/maven/its/settings/profile/aether/test-artifact/1.0/test-artifact-1.0.pom";
+ File flatLayout = new File(localRepo, gavRelativePath);
+ File customPrefix = new File(localRepo, "it-custom-prefix/" + gavRelativePath);
+
+ assertTrue(
+ flatLayout.exists(),
+ "Expected artifact at flat layout (profile deactivated via -P !), but not found at " + flatLayout);
+
+ assertFalse(
+ customPrefix.exists(),
+ "Found artifact at custom prefix " + customPrefix + " — deactivation via -P ! was ignored.");
+ }
+
+ private static void deleteRecursivelyIfExists(File path) throws Exception {
+ if (!path.exists()) {
+ return;
+ }
+ Files.walk(path.toPath())
+ .sorted(Comparator.reverseOrder())
+ .map(java.nio.file.Path::toFile)
+ .forEach(File::delete);
+ }
Review Comment:
Remove the custom helper — `FileUtils.deleteDirectory()` replaces it:
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12288] Add -P !profile deactivation regression guard [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12298:
URL: https://github.com/apache/maven/pull/12298#discussion_r3434368453
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12288SettingsProfileAetherPropertiesTest.java:
##########
@@ -65,6 +67,52 @@ public void testActiveProfilesList() throws Exception {
runAndAssertCustomPrefix("settings-active-profiles-list.xml");
}
+ @Test
+ public void testActiveByDefaultDeactivatedViaCli() throws Exception {
+ File testDir = extractResources("/settings-profile-aether-properties");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ verifier.setAutoclean(false);
+ verifier.setLogFileName("log-deactivation.txt");
+ verifier.deleteDirectory("target");
+ verifier.deleteArtifacts("org.apache.maven.its.settings.profile.aether");
+
+ // Sibling tests in this class install under the same custom prefix; clear it to
+ // avoid false positives if those tests ran first.
+ File customPrefixSubtree = new File(verifier.getLocalRepository(), "it-custom-prefix");
+ deleteRecursivelyIfExists(customPrefixSubtree);
+
+ verifier.addCliArgument("--settings");
+ verifier.addCliArgument("settings-active-by-default.xml");
+ verifier.addCliArgument("-P!aether-split-via-settings");
+ verifier.addCliArgument("install");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ File localRepo = new File(verifier.getLocalRepository());
+ String gavRelativePath = "org/apache/maven/its/settings/profile/aether/test-artifact/1.0/test-artifact-1.0.pom";
+ File flatLayout = new File(localRepo, gavRelativePath);
+ File customPrefix = new File(localRepo, "it-custom-prefix/" + gavRelativePath);
+
+ assertTrue(
+ flatLayout.exists(),
+ "Expected artifact at flat layout (profile deactivated via -P !), but not found at " + flatLayout);
+
+ assertFalse(
+ customPrefix.exists(),
+ "Found artifact at custom prefix " + customPrefix + " — deactivation via -P ! was ignored.");
+ }
+
+ private static void deleteRecursivelyIfExists(File path) throws Exception {
+ if (!path.exists()) {
+ return;
+ }
+ Files.walk(path.toPath())
+ .sorted(Comparator.reverseOrder())
+ .map(java.nio.file.Path::toFile)
+ .forEach(File::delete);
Review Comment:
Nit: `Files.walk()` returns a stream backed by a `DirectoryStream` that should be closed ([javadoc](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Files.html#walk(java.nio.file.Path,java.nio.file.FileVisitOption...))). On Windows especially, unclosed directory handles can interfere with subsequent deletions.
```suggestion
private static void deleteRecursivelyIfExists(File path) throws Exception {
if (!path.exists()) {
return;
}
try (var paths = Files.walk(path.toPath())) {
paths.sorted(Comparator.reverseOrder())
.map(java.nio.file.Path::toFile)
.forEach(File::delete);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12288] Add -P !profile deactivation regression guard [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12298:
URL: https://github.com/apache/maven/pull/12298#discussion_r3434815332
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12288SettingsProfileAetherPropertiesTest.java:
##########
@@ -65,6 +67,52 @@ public void testActiveProfilesList() throws Exception {
runAndAssertCustomPrefix("settings-active-profiles-list.xml");
}
+ @Test
+ public void testActiveByDefaultDeactivatedViaCli() throws Exception {
+ File testDir = extractResources("/settings-profile-aether-properties");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ verifier.setAutoclean(false);
+ verifier.setLogFileName("log-deactivation.txt");
+ verifier.deleteDirectory("target");
+ verifier.deleteArtifacts("org.apache.maven.its.settings.profile.aether");
+
+ // Sibling tests in this class install under the same custom prefix; clear it to
+ // avoid false positives if those tests ran first.
+ File customPrefixSubtree = new File(verifier.getLocalRepository(), "it-custom-prefix");
+ deleteRecursivelyIfExists(customPrefixSubtree);
+
+ verifier.addCliArgument("--settings");
+ verifier.addCliArgument("settings-active-by-default.xml");
+ verifier.addCliArgument("-P!aether-split-via-settings");
+ verifier.addCliArgument("install");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ File localRepo = new File(verifier.getLocalRepository());
+ String gavRelativePath = "org/apache/maven/its/settings/profile/aether/test-artifact/1.0/test-artifact-1.0.pom";
+ File flatLayout = new File(localRepo, gavRelativePath);
+ File customPrefix = new File(localRepo, "it-custom-prefix/" + gavRelativePath);
+
+ assertTrue(
+ flatLayout.exists(),
+ "Expected artifact at flat layout (profile deactivated via -P !), but not found at " + flatLayout);
+
+ assertFalse(
+ customPrefix.exists(),
+ "Found artifact at custom prefix " + customPrefix + " — deactivation via -P ! was ignored.");
+ }
+
+ private static void deleteRecursivelyIfExists(File path) throws Exception {
+ if (!path.exists()) {
+ return;
+ }
+ Files.walk(path.toPath())
+ .sorted(Comparator.reverseOrder())
+ .map(java.nio.file.Path::toFile)
+ .forEach(File::delete);
+ }
Review Comment:
The `deleteRecursivelyIfExists` helper and the `java.nio.file.Files` / `java.util.Comparator` imports are unnecessary — other ITs in this suite already use `FileUtils.deleteDirectory()` for the same purpose (e.g. `MavenITmng7819FileLockingWithSnapshotsTest:83`, `MavenIT0108SnapshotUpdateTest:126`). It handles non-existent paths gracefully and is already on the classpath.
Replace the helper and its call site with:
```java
org.apache.commons.io.FileUtils.deleteDirectory(customPrefixSubtree);
```
and drop this method entirely.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12288] Add -P !profile deactivation regression guard [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12298:
URL: https://github.com/apache/maven/pull/12298#discussion_r3436209651
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12288SettingsProfileAetherPropertiesTest.java:
##########
@@ -19,6 +19,8 @@
package org.apache.maven.it;
import java.io.File;
+import java.nio.file.Files;
+import java.util.Comparator;
import org.junit.jupiter.api.Test;
Review Comment:
Replace `Files`/`Comparator` imports with `FileUtils`:
```suggestion
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Test;
```
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12288SettingsProfileAetherPropertiesTest.java:
##########
@@ -65,6 +67,53 @@ public void testActiveProfilesList() throws Exception {
runAndAssertCustomPrefix("settings-active-profiles-list.xml");
}
+ @Test
+ public void testActiveByDefaultDeactivatedViaCli() throws Exception {
+ File testDir = extractResources("/settings-profile-aether-properties");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ verifier.setAutoclean(false);
+ verifier.setLogFileName("log-deactivation.txt");
+ verifier.deleteDirectory("target");
+ verifier.deleteArtifacts("org.apache.maven.its.settings.profile.aether");
+
+ // Sibling tests in this class install under the same custom prefix; clear it to
+ // avoid false positives if those tests ran first.
+ File customPrefixSubtree = new File(verifier.getLocalRepository(), "it-custom-prefix");
+ deleteRecursivelyIfExists(customPrefixSubtree);
Review Comment:
Use `FileUtils.deleteDirectory()` which handles non-existent paths gracefully:
```suggestion
FileUtils.deleteDirectory(customPrefixSubtree);
```
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12288SettingsProfileAetherPropertiesTest.java:
##########
@@ -65,6 +67,53 @@ public void testActiveProfilesList() throws Exception {
runAndAssertCustomPrefix("settings-active-profiles-list.xml");
}
+ @Test
+ public void testActiveByDefaultDeactivatedViaCli() throws Exception {
+ File testDir = extractResources("/settings-profile-aether-properties");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ verifier.setAutoclean(false);
+ verifier.setLogFileName("log-deactivation.txt");
+ verifier.deleteDirectory("target");
+ verifier.deleteArtifacts("org.apache.maven.its.settings.profile.aether");
+
+ // Sibling tests in this class install under the same custom prefix; clear it to
+ // avoid false positives if those tests ran first.
+ File customPrefixSubtree = new File(verifier.getLocalRepository(), "it-custom-prefix");
+ deleteRecursivelyIfExists(customPrefixSubtree);
+
+ verifier.addCliArgument("--settings");
+ verifier.addCliArgument("settings-active-by-default.xml");
+ verifier.addCliArgument("-P!aether-split-via-settings");
+ verifier.addCliArgument("install");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ File localRepo = new File(verifier.getLocalRepository());
+ String gavRelativePath = "org/apache/maven/its/settings/profile/aether/test-artifact/1.0/test-artifact-1.0.pom";
+ File flatLayout = new File(localRepo, gavRelativePath);
+ File customPrefix = new File(localRepo, "it-custom-prefix/" + gavRelativePath);
+
+ assertTrue(
+ flatLayout.exists(),
+ "Expected artifact at flat layout (profile deactivated via -P !), but not found at " + flatLayout);
+
+ assertFalse(
+ customPrefix.exists(),
+ "Found artifact at custom prefix " + customPrefix + " — deactivation via -P ! was ignored.");
+ }
+
+ private static void deleteRecursivelyIfExists(File path) throws Exception {
+ if (!path.exists()) {
+ return;
+ }
+ try (var paths = Files.walk(path.toPath())) {
+ paths.sorted(Comparator.reverseOrder())
+ .map(java.nio.file.Path::toFile)
+ .forEach(File::delete);
+ }
Review Comment:
Remove the custom helper — `FileUtils.deleteDirectory()` replaces it:
```suggestion
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12288] Add -P !profile deactivation regression guard [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12298:
URL: https://github.com/apache/maven/pull/12298#discussion_r3434785359
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12288SettingsProfileAetherPropertiesTest.java:
##########
@@ -65,6 +67,52 @@ public void testActiveProfilesList() throws Exception {
runAndAssertCustomPrefix("settings-active-profiles-list.xml");
}
+ @Test
+ public void testActiveByDefaultDeactivatedViaCli() throws Exception {
+ File testDir = extractResources("/settings-profile-aether-properties");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ verifier.setAutoclean(false);
+ verifier.setLogFileName("log-deactivation.txt");
+ verifier.deleteDirectory("target");
+ verifier.deleteArtifacts("org.apache.maven.its.settings.profile.aether");
+
+ // Sibling tests in this class install under the same custom prefix; clear it to
+ // avoid false positives if those tests ran first.
+ File customPrefixSubtree = new File(verifier.getLocalRepository(), "it-custom-prefix");
+ deleteRecursivelyIfExists(customPrefixSubtree);
+
+ verifier.addCliArgument("--settings");
+ verifier.addCliArgument("settings-active-by-default.xml");
+ verifier.addCliArgument("-P!aether-split-via-settings");
+ verifier.addCliArgument("install");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ File localRepo = new File(verifier.getLocalRepository());
+ String gavRelativePath = "org/apache/maven/its/settings/profile/aether/test-artifact/1.0/test-artifact-1.0.pom";
+ File flatLayout = new File(localRepo, gavRelativePath);
+ File customPrefix = new File(localRepo, "it-custom-prefix/" + gavRelativePath);
+
+ assertTrue(
+ flatLayout.exists(),
+ "Expected artifact at flat layout (profile deactivated via -P !), but not found at " + flatLayout);
+
+ assertFalse(
+ customPrefix.exists(),
+ "Found artifact at custom prefix " + customPrefix + " — deactivation via -P ! was ignored.");
+ }
+
+ private static void deleteRecursivelyIfExists(File path) throws Exception {
+ if (!path.exists()) {
+ return;
+ }
+ Files.walk(path.toPath())
+ .sorted(Comparator.reverseOrder())
+ .map(java.nio.file.Path::toFile)
+ .forEach(File::delete);
+ }
+
Review Comment:
Nit: `Files.walk()` returns a stream backed by a `DirectoryStream` that should be closed ([javadoc](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Files.html#walk(java.nio.file.Path,java.nio.file.FileVisitOption...))). On Windows especially, unclosed directory handles can interfere with subsequent deletions.
```suggestion
private static void deleteRecursivelyIfExists(File path) throws Exception {
if (!path.exists()) {
return;
}
try (var paths = Files.walk(path.toPath())) {
paths.sorted(Comparator.reverseOrder())
.map(java.nio.file.Path::toFile)
.forEach(File::delete);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#12288] Add -P !profile deactivation regression guard [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #12298:
URL: https://github.com/apache/maven/pull/12298#discussion_r3434785359
##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12288SettingsProfileAetherPropertiesTest.java:
##########
@@ -65,6 +67,52 @@ public void testActiveProfilesList() throws Exception {
runAndAssertCustomPrefix("settings-active-profiles-list.xml");
}
+ @Test
+ public void testActiveByDefaultDeactivatedViaCli() throws Exception {
+ File testDir = extractResources("/settings-profile-aether-properties");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ verifier.setAutoclean(false);
+ verifier.setLogFileName("log-deactivation.txt");
+ verifier.deleteDirectory("target");
+ verifier.deleteArtifacts("org.apache.maven.its.settings.profile.aether");
+
+ // Sibling tests in this class install under the same custom prefix; clear it to
+ // avoid false positives if those tests ran first.
+ File customPrefixSubtree = new File(verifier.getLocalRepository(), "it-custom-prefix");
+ deleteRecursivelyIfExists(customPrefixSubtree);
+
+ verifier.addCliArgument("--settings");
+ verifier.addCliArgument("settings-active-by-default.xml");
+ verifier.addCliArgument("-P!aether-split-via-settings");
+ verifier.addCliArgument("install");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ File localRepo = new File(verifier.getLocalRepository());
+ String gavRelativePath = "org/apache/maven/its/settings/profile/aether/test-artifact/1.0/test-artifact-1.0.pom";
+ File flatLayout = new File(localRepo, gavRelativePath);
+ File customPrefix = new File(localRepo, "it-custom-prefix/" + gavRelativePath);
+
+ assertTrue(
+ flatLayout.exists(),
+ "Expected artifact at flat layout (profile deactivated via -P !), but not found at " + flatLayout);
+
+ assertFalse(
+ customPrefix.exists(),
+ "Found artifact at custom prefix " + customPrefix + " — deactivation via -P ! was ignored.");
+ }
+
+ private static void deleteRecursivelyIfExists(File path) throws Exception {
+ if (!path.exists()) {
+ return;
+ }
+ Files.walk(path.toPath())
+ .sorted(Comparator.reverseOrder())
+ .map(java.nio.file.Path::toFile)
+ .forEach(File::delete);
+ }
+
Review Comment:
Nit: `Files.walk()` returns a stream backed by a `DirectoryStream` that should be closed ([javadoc](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Files.html#walk(java.nio.file.Path,java.nio.file.FileVisitOption...))). On Windows especially, unclosed directory handles can interfere with subsequent deletions.
```suggestion
private static void deleteRecursivelyIfExists(File path) throws Exception {
if (!path.exists()) {
return;
}
try (var paths = Files.walk(path.toPath())) {
paths.sorted(Comparator.reverseOrder())
.map(java.nio.file.Path::toFile)
.forEach(File::delete);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org