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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]