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

sjaranowski pushed a commit to branch fix-mng-5669
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git

commit b0518c88f0a419e1d10606f32a1923507e08801c
Author: Slawomir Jaranowski <s.jaranow...@gmail.com>
AuthorDate: Thu Jan 12 19:22:48 2023 +0100

    Fix MavenITmng5669ReadPomsOnce
    
    In test, we check if pom files are read only once.
    
    When we update plugin or dependencies in test,
    number of read items can change again.
    
    So should be good enough to check if duplicate items exist in log file.
---
 .../maven/it/MavenITmng5669ReadPomsOnce.java       | 124 +++++++++------------
 .../src/test/resources-filtered/bootstrap.txt      |   2 +
 2 files changed, 54 insertions(+), 72 deletions(-)

diff --git 
a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5669ReadPomsOnce.java
 
b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5669ReadPomsOnce.java
index 67445d15c..c07f1b0c1 100644
--- 
a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5669ReadPomsOnce.java
+++ 
b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5669ReadPomsOnce.java
@@ -19,17 +19,16 @@ package org.apache.maven.it;
  * under the License.
  */
 
-import org.apache.maven.shared.verifier.util.ResourceExtractor;
-import org.apache.maven.shared.verifier.Verifier;
-
 import java.io.File;
-import java.util.Arrays;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
+import java.util.Objects;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
+import org.apache.maven.shared.verifier.Verifier;
+import org.apache.maven.shared.verifier.util.ResourceExtractor;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -43,8 +42,6 @@ public class MavenITmng5669ReadPomsOnce
     extends AbstractMavenIntegrationTestCase
 {
 
-    private static final int LOG_SIZE = 233;
-
     public MavenITmng5669ReadPomsOnce()
     {
         super( "[4.0.0-alpha-1,)" );
@@ -63,45 +60,28 @@ public class MavenITmng5669ReadPomsOnce
         verifier.filterFile( ".mvn/jvm.config", ".mvn/jvm.config", null, 
filterProperties );
 
         verifier.setForkJvm( true ); // pick up agent
-        verifier.setMavenDebug( false );
         verifier.setAutoclean( false );
-        verifier.addCliOption( "-q" );
-        verifier.addCliOption( "-U" );
-        verifier.addCliOption( "-Dmaven.experimental.buildconsumer=false" );
+        verifier.addCliArgument( "-q" );
+        verifier.addCliArgument( "-U" );
+        verifier.addCliArgument( "-Dmaven.experimental.buildconsumer=false" );
         verifier.addCliArgument( "verify");
         verifier.execute();
 
         List<String> logTxt = verifier.loadLines( "log.txt", "utf-8" );
-        for ( String line : logTxt )
-        {
-            if ( line.startsWith( "Picked up JAVA_TOOL_OPTIONS:" ) )
-            {
-                logTxt.remove( line );
-                break;
-            }
-        }
-        assertEquals( logTxt.toString(), LOG_SIZE, logTxt.size() );
 
-        // analyze lines. It is a Hashmap, so we can't rely on the order
-        Set<String> uniqueBuildingSources = new HashSet<>( LOG_SIZE );
-        final String buildSourceKey = 
"org.apache.maven.model.building.source=";
-        final int keyLength = buildSourceKey.length();
-        for ( String line : logTxt )
-        {
-            int start = line.indexOf( buildSourceKey );
-            if ( start < 0 )
-            {
-                continue;
-            }
-
-            int end = line.indexOf( ", ", start );
-            if ( end < 0 )
-            {
-                end = line.length() - 1; // is the }
-            }
-            uniqueBuildingSources.add( line.substring( start + keyLength, end 
) );
-        }
-        assertEquals( uniqueBuildingSources.size(), LOG_SIZE - 1 /* minus 
superpom */ );
+        // count source items
+        Map<String, Long> sourceMap = logTxt.stream()
+                .map(this::getSourceFromLogLine)
+                .filter(Objects::nonNull)
+                .collect(Collectors.groupingBy(Function.identity(), 
Collectors.counting()));
+
+        // find duplicates
+        List<String> duplicates = sourceMap.entrySet().stream()
+                .filter(entry -> entry.getValue() > 1)
+                .map(Map.Entry::getKey)
+                .collect(Collectors.toList());
+
+        assertTrue("Duplicate items: " + String.join(System.lineSeparator(), 
duplicates), duplicates.isEmpty());
     }
 
     @Test
@@ -118,46 +98,46 @@ public class MavenITmng5669ReadPomsOnce
 
         verifier.setLogFileName( "log-bc.txt" );
         verifier.setForkJvm( true ); // pick up agent
-        verifier.setMavenDebug( false );
         verifier.setAutoclean( false );
-        verifier.addCliOption( "-q" );
-        verifier.addCliOption( "-U" );
-        verifier.addCliOption( "-Dmaven.experimental.buildconsumer=true" );
+        verifier.addCliArgument( "-q" );
+        verifier.addCliArgument( "-U" );
+        verifier.addCliArgument( "-Dmaven.experimental.buildconsumer=true" );
         verifier.addCliArgument( "verify" );
         verifier.execute();
 
         List<String> logTxt = verifier.loadLines( "log-bc.txt", "utf-8" );
-        for ( String line : logTxt )
-        {
-            if ( line.startsWith( "Picked up JAVA_TOOL_OPTIONS:" ) )
-            {
-                logTxt.remove( line );
-                break;
-            }
-        }
-        assertEquals( logTxt.toString(), LOG_SIZE + 4 /* reactor poms are read 
twice: file + raw (=XMLFilters) */,
-                      logTxt.size() );
 
-        // analyze lines. It is a Hashmap, so we can't rely on the order
-        Set<String> uniqueBuildingSources = new HashSet<>( LOG_SIZE );
+        // count source items
+        Map<String, Long> sourceMap = logTxt.stream()
+                .map(this::getSourceFromLogLine)
+                .filter(Objects::nonNull)
+                .collect(Collectors.groupingBy(Function.identity(), 
Collectors.counting()));
+
+        // find duplicates
+        List<String> duplicates = sourceMap.entrySet().stream()
+                .filter(entry -> entry.getValue() > 1)
+                .map(Map.Entry::getKey)
+                .collect(Collectors.toList());
+
+        assertTrue("Duplicate items: " + String.join(System.lineSeparator(), 
duplicates), duplicates.isEmpty());
+    }
+
+    private String getSourceFromLogLine(String line) {
+
         final String buildSourceKey = 
"org.apache.maven.model.building.source=";
         final int keyLength = buildSourceKey.length();
-        for ( String line : logTxt )
+        int start = line.indexOf( buildSourceKey );
+        if ( start < 0 )
         {
-            int start = line.indexOf( buildSourceKey );
-            if ( start < 0 )
-            {
-                continue;
-            }
-
-            int end = line.indexOf( ", ", start );
-            if ( end < 0 )
-            {
-                end = line.length() - 1; // is the }
-            }
-            uniqueBuildingSources.add( line.substring( start + keyLength, end 
) );
+            return null;
+        }
+
+        int end = line.indexOf( ", ", start );
+        if ( end < 0 )
+        {
+            end = line.length() - 1; // is the }
         }
-        assertEquals( uniqueBuildingSources.size(), LOG_SIZE - 1 /* minus 
superpom */ );
-    }
 
+        return line.substring( start + keyLength, end );
+    }
 }
diff --git a/core-it-suite/src/test/resources-filtered/bootstrap.txt 
b/core-it-suite/src/test/resources-filtered/bootstrap.txt
index d9ccd06b7..eb06b65e9 100644
--- a/core-it-suite/src/test/resources-filtered/bootstrap.txt
+++ b/core-it-suite/src/test/resources-filtered/bootstrap.txt
@@ -79,6 +79,7 @@ org.apache.maven.plugins:maven-dependency-plugin:3.3.0
 org.apache.maven.plugins:maven-deploy-plugin:${stubPluginVersion}
 org.apache.maven.plugins:maven-deploy-plugin:2.7
 org.apache.maven.plugins:maven-deploy-plugin:3.0.0
+org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M2
 org.apache.maven.plugins:maven-ear-plugin:${stubPluginVersion}
 org.apache.maven.plugins:maven-ear-plugin:3.2.0
 org.apache.maven.plugins:maven-ejb-plugin:${stubPluginVersion}
@@ -86,6 +87,7 @@ org.apache.maven.plugins:maven-ejb-plugin:3.1.0
 org.apache.maven.plugins:maven-install-plugin:${stubPluginVersion}
 org.apache.maven.plugins:maven-install-plugin:3.0.1
 org.apache.maven.plugins:maven-jar-plugin:${stubPluginVersion}
+org.apache.maven.plugins:maven-jar-plugin:3.2.0
 org.apache.maven.plugins:maven-jar-plugin:3.3.0
 org.apache.maven.plugins:maven-javadoc-plugin:${stubPluginVersion}
 org.apache.maven.plugins:maven-plugin-plugin:${stubPluginVersion}

Reply via email to