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

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

Reply via email to