You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2023/01/13 08:01:29 UTC
[maven-integration-testing] branch master updated: Fix MavenITmng5669ReadPomsOnce
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git
The following commit(s) were added to refs/heads/master by this push:
new af1de3bd5 Fix MavenITmng5669ReadPomsOnce
af1de3bd5 is described below
commit af1de3bd5a8d6834c7e730fa53937b18b6037ee8
Author: Slawomir Jaranowski <s....@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 +++++++++------------
1 file changed, 52 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 );
+ }
}