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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to