You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ma...@apache.org on 2022/11/05 09:27:17 UTC

[maven-integration-testing] branch maven-3.8.x updated: [MNG-7568] Test for deactivating profile defined in settings and project

This is an automated email from the ASF dual-hosted git repository.

martinkanters pushed a commit to branch maven-3.8.x
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git


The following commit(s) were added to refs/heads/maven-3.8.x by this push:
     new 9a4cba67f [MNG-7568] Test for deactivating profile defined in settings and project
9a4cba67f is described below

commit 9a4cba67fb1ddab4303476ad88b42776c1e0363f
Author: Piotrek Żygieło <pz...@users.noreply.github.com>
AuthorDate: Fri Oct 14 19:49:19 2022 +0200

    [MNG-7568] Test for deactivating profile defined in settings and project
---
 .../org/apache/maven/it/IntegrationTestSuite.java  |  1 +
 .../src/test/java/org/apache/maven/it/ItUtils.java | 21 ++++++++
 ...ng6981ProjectListShouldIncludeChildrenTest.java | 22 +-------
 ...enITmng7568SettingsProfileDeactivationTest.java | 59 ++++++++++++++++++++++
 .../mng-7568-inactive-profile-deactivation/pom.xml | 37 ++++++++++++++
 .../settings.xml                                   | 36 +++++++++++++
 6 files changed, 155 insertions(+), 21 deletions(-)

diff --git a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
index 089b4d1e1..ff2353bce 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
@@ -106,6 +106,7 @@ public class IntegrationTestSuite
         // Tests that don't run stable and need to be fixed
         // -------------------------------------------------------------------------------------------------------------
         // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
+        suite.addTestSuite( MavenITmng7568SettingsProfileDeactivationTest.class );
         suite.addTestSuite( MavenITmng7474SessionScopeTest.class );
         suite.addTestSuite( MavenITmng7529VersionRangeRepositorySelection.class );
         suite.addTestSuite( MavenITmng7443ConsistencyOfOptionalProjectsAndProfilesTest.class );
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/ItUtils.java b/core-it-suite/src/test/java/org/apache/maven/it/ItUtils.java
index 845c63de9..b92a0e5f4 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/ItUtils.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/ItUtils.java
@@ -23,6 +23,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.security.DigestInputStream;
 import java.security.MessageDigest;
+import java.util.List;
 
 /**
  * @author Benjamin Bentmann
@@ -65,4 +66,24 @@ class ItUtils
         return hash.toString();
     }
 
+    /**
+     * Throws an exception if the text <strong>is</strong> present in the log.
+     *
+     * @param verifier the verifier to use
+     * @param text the text to assert present
+     * @throws VerificationException if text is not found in log
+     */
+    static void verifyTextNotInLog( Verifier verifier, String text )
+            throws VerificationException
+    {
+        List<String> lines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
+
+        for ( String line : lines )
+        {
+            if ( Verifier.stripAnsi( line ).contains( text ) )
+            {
+                throw new VerificationException( "Text found in log: " + text );
+            }
+        }
+    }
 }
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6981ProjectListShouldIncludeChildrenTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6981ProjectListShouldIncludeChildrenTest.java
index a2ce8441f..831106286 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6981ProjectListShouldIncludeChildrenTest.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6981ProjectListShouldIncludeChildrenTest.java
@@ -20,6 +20,7 @@ package org.apache.maven.it;
  */
 
 import org.apache.maven.it.util.ResourceExtractor;
+import static org.apache.maven.it.ItUtils.verifyTextNotInLog;
 
 import java.io.File;
 import java.util.List;
@@ -65,25 +66,4 @@ public class MavenITmng6981ProjectListShouldIncludeChildrenTest
         verifier.executeGoal( "compile" );
         verifyTextNotInLog( verifier, "Building module-a-1 1.0" );
     }
-
-    /**
-     * Throws an exception if the text <strong>is</strong> present in the log.
-     *
-     * @param verifier the verifier to use
-     * @param text the text to assert present
-     * @throws VerificationException if text is not found in log
-     */
-    private void verifyTextNotInLog( Verifier verifier, String text )
-            throws VerificationException
-    {
-        List<String> lines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
-
-        for ( String line : lines )
-        {
-            if ( Verifier.stripAnsi( line ).contains( text ) )
-            {
-                throw new VerificationException( "Text found in log: " + text );
-            }
-        }
-    }
 }
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7568SettingsProfileDeactivationTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7568SettingsProfileDeactivationTest.java
new file mode 100644
index 000000000..d7769f46c
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7568SettingsProfileDeactivationTest.java
@@ -0,0 +1,59 @@
+package org.apache.maven.it;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.it.util.ResourceExtractor;
+import static org.apache.maven.it.ItUtils.verifyTextNotInLog;
+
+import java.io.File;
+
+public class MavenITmng7568SettingsProfileDeactivationTest
+        extends AbstractMavenIntegrationTestCase
+{
+    private static final String PROJECT_PATH = "/mng-7568-inactive-profile-deactivation";
+
+    public MavenITmng7568SettingsProfileDeactivationTest()
+    {
+        super( "[3.8.7,4)" );
+    }
+
+    /**
+     * This test verifies that deactivating a profile defined in settings and in project
+     * does not cause unnecessary warning.
+     *
+     * @throws Exception in case of failure
+     */
+    public void testDeactivatingProfileExistingInSettingsAndInProject() throws Exception
+    {
+        final File projectDir = ResourceExtractor.simpleExtractResources( getClass(), PROJECT_PATH );
+        final Verifier verifier = newVerifier( projectDir.getAbsolutePath() );
+
+        verifier.addCliOption( "-s" );
+        verifier.addCliOption( "settings.xml" );
+        verifier.addCliOption( "-P" );
+        verifier.addCliOption( "-k-profile" );
+        verifier.setLogFileName( "test-mng7568.txt" );
+
+        verifier.executeGoal( "validate" );
+        verifier.verifyErrorFreeLog();
+
+        verifyTextNotInLog( verifier, "[WARNING] The requested profile \"k-profile\" could not be activated because it does not exist." );
+    }
+}
diff --git a/core-it-suite/src/test/resources/mng-7568-inactive-profile-deactivation/pom.xml b/core-it-suite/src/test/resources/mng-7568-inactive-profile-deactivation/pom.xml
new file mode 100644
index 000000000..2d95a0323
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7568-inactive-profile-deactivation/pom.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.mng7568</groupId>
+  <artifactId>profile-selection</artifactId>
+  <version>1.0</version>
+
+  <profiles>
+    <profile>
+      <id>k-profile</id>
+    </profile>
+  </profiles>
+
+</project>
diff --git a/core-it-suite/src/test/resources/mng-7568-inactive-profile-deactivation/settings.xml b/core-it-suite/src/test/resources/mng-7568-inactive-profile-deactivation/settings.xml
new file mode 100644
index 000000000..4d8318bd4
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7568-inactive-profile-deactivation/settings.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0
+                      https://maven.apache.org/xsd/settings-1.1.0.xsd">
+  <profiles>
+    <profile>
+      <id>k-profile</id>
+    </profile>
+  </profiles>
+
+  <activeProfiles>
+    <activeProfile>k-profile</activeProfile>
+  </activeProfiles>
+</settings>
+