From dc29b09aa2062b3b0c9d69a866cb894ed3afcc81 Mon Sep 17 00:00:00 2001 From: rfscholte Date: Mon, 25 Nov 2019 08:29:27 +0100 Subject: [PATCH 1/9] [MNG-6656] Support build/consumer process --- .../apache/maven/it/IntegrationTestSuite.java | 3 +- .../maven/it/MavenITmng6656BuildConsumer.java | 68 +++++++++++++++++++ .../resources/mng-6656-buildconsumer/pom.xml | 34 ++++++++++ .../simple-parent/pom.xml | 62 +++++++++++++++++ .../simple-parent/simple-weather/pom.xml | 63 +++++++++++++++++ .../simple-parent/simple-webapp/pom.xml | 55 +++++++++++++++ 6 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java create mode 100644 core-it-suite/src/test/resources/mng-6656-buildconsumer/pom.xml create mode 100644 core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/pom.xml create mode 100644 core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-weather/pom.xml create mode 100644 core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-webapp/pom.xml 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 6d61985a2..b9c2e7122 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,7 +106,8 @@ public static Test suite() // Tests that don't run stable and need to be fixed // ------------------------------------------------------------------------------------------------------------- // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137 - + + suite.addTestSuite( MavenITmng6656BuildConsumer.class ); suite.addTestSuite( MavenITmng6759TransitiveDependencyRepositoriesTest.class ); suite.addTestSuite( MavenITmng6720FailFastTest.class ); suite.addTestSuite( MavenITmng6506PackageAnnotationTest.class ); diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java new file mode 100644 index 000000000..08ded29ac --- /dev/null +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java @@ -0,0 +1,68 @@ +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 java.io.File; +import java.util.Arrays; + +/** + * With the build-consumer the pom.xml will be adjusted during the process. + * + * + * During install the pom will be cleaned up + * + * + * MNG-6656. + * + */ +public class MavenITmng6656BuildConsumer + extends AbstractMavenIntegrationTestCase +{ + + public MavenITmng6656BuildConsumer() + { + super( "[3.7.0,)" ); + } + + public void testValidOmittedVersions() + throws Exception + { + File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6656-buildconsumer" ); + + Verifier verifier = newVerifier( testDir.getAbsolutePath(), false ); + verifier.setMavenDebug( false ); + verifier.setAutoclean( false ); + verifier.addCliOption( "-Dchangelist=JIRA101" ); + + // install is useless in this IT suite as it doesn't write the pomfile to the local repo + verifier.executeGoals( Arrays.asList( "validate" ) ); + + verifier.verifyErrorFreeLog(); + } +} diff --git a/core-it-suite/src/test/resources/mng-6656-buildconsumer/pom.xml b/core-it-suite/src/test/resources/mng-6656-buildconsumer/pom.xml new file mode 100644 index 000000000..f41ed6a87 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/pom.xml @@ -0,0 +1,34 @@ + + + + + + 4.0.0 + org.sonatype.mavenbook.multi + parent + 0.9-${changelist}-SNAPSHOT + pom + Multi Chapter Parent Project + + simple-parent + + diff --git a/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/pom.xml b/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/pom.xml new file mode 100644 index 000000000..d31620ae1 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/pom.xml @@ -0,0 +1,62 @@ + + + + + + 4.0.0 + + org.sonatype.mavenbook.multi + parent + + simple-parent + pom + Multi Chapter Simple Parent Project + + + simple-weather + simple-webapp + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + + junit + junit + 4.12 + test + + + diff --git a/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-weather/pom.xml b/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-weather/pom.xml new file mode 100644 index 000000000..165a245b2 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-weather/pom.xml @@ -0,0 +1,63 @@ + + + + + + 4.0.0 + + org.sonatype.mavenbook.multi + simple-parent + + simple-weather + jar + + Multi Chapter Simple Weather API + + + + log4j + log4j + 1.2.14 + + + dom4j + dom4j + 1.6.1 + + + jaxen + jaxen + 1.1.1 + + + velocity + velocity + 1.5 + + + org.apache.commons + commons-io + 1.3.2 + test + + + diff --git a/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-webapp/pom.xml b/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-webapp/pom.xml new file mode 100644 index 000000000..b3be6ede4 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-webapp/pom.xml @@ -0,0 +1,55 @@ + + + + + + 4.0.0 + + org.sonatype.mavenbook.multi + simple-parent + + + simple-webapp + war + Multi Chapter Simple Web Application Project + + + org.apache.geronimo.specs + geronimo-servlet_2.4_spec + 1.1.1 + + + org.sonatype.mavenbook.multi + simple-weather + + + + simple-webapp + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.9 + + + + From 662241aa3599bdd52e8a4e8a1bca34fc47fa79ff Mon Sep 17 00:00:00 2001 From: rfscholte Date: Wed, 26 Feb 2020 00:15:42 +0100 Subject: [PATCH 2/9] Pom will be read again for build/consumer --- .../maven/it/MavenITmng5669ReadPomsOnce.java | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) 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 26944d249..7bfccb9a7 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 @@ -45,7 +45,7 @@ public MavenITmng5669ReadPomsOnce() super( "[3.7.0,)" ); } - public void test() + public void testWithoutBuildConsumer() throws Exception { // prepare JavaAgent @@ -61,6 +61,7 @@ public void test() verifier.setAutoclean( false ); verifier.addCliOption( "-q" ); verifier.addCliOption( "-U" ); + verifier.addCliOption( "-Dmaven.experimental.buildconsumer=false" ); verifier.executeGoals( Arrays.asList( "verify" ) ); verifier.resetStreams(); @@ -96,4 +97,58 @@ public void test() } assertEquals( uniqueBuildingSources.size(), 167 /* is 168 minus superpom */ ); } + + public void testWithBuildConsumer() + throws Exception + { + // prepare JavaAgent + File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5669-read-poms-once" ); + Verifier verifier = newVerifier( testDir.getAbsolutePath(), false ); + Map filterProperties = + Collections.singletonMap( "${javaAgentJar}", + verifier.getArtifactPath( "mng-coreit", "javaagent", "1.0-SNAPSHOT", "jar" ) ); + 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=true" ); + verifier.executeGoals( Arrays.asList( "verify" ) ); + verifier.resetStreams(); + + List 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(), 168 + 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 uniqueBuildingSources = new HashSet<>( 168 ); + 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(), 167 /* is 168 minus superpom */ ); + } + } From a2dcebb8615dc0f98a64e0660931b62eafbc17f0 Mon Sep 17 00:00:00 2001 From: rfscholte Date: Mon, 6 Apr 2020 20:16:32 +0200 Subject: [PATCH 3/9] [MNG-6656] Verify installed poms --- .../maven/it/MavenITmng6656BuildConsumer.java | 33 ++++++++++++- .../expected/parent.pom | 26 +++++++++++ .../expected/simple-parent.pom | 42 +++++++++++++++++ .../expected/simple-weather.pom | 30 ++++++++++++ .../expected/simple-webapp.pom | 46 +++++++++++++++++++ .../simple-parent/pom.xml | 12 ----- .../simple-parent/simple-weather/pom.xml | 28 ----------- .../simple-parent/simple-webapp/pom.xml | 22 ++++----- 8 files changed, 184 insertions(+), 55 deletions(-) create mode 100644 core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/parent.pom create mode 100644 core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-parent.pom create mode 100644 core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-weather.pom create mode 100644 core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-webapp.pom diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java index 08ded29ac..13306c173 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java @@ -20,6 +20,7 @@ */ import org.apache.maven.it.util.ResourceExtractor; +import org.apache.maven.shared.utils.io.FileUtils; import java.io.File; import java.util.Arrays; @@ -60,9 +61,37 @@ public void testValidOmittedVersions() verifier.setAutoclean( false ); verifier.addCliOption( "-Dchangelist=JIRA101" ); - // install is useless in this IT suite as it doesn't write the pomfile to the local repo verifier.executeGoals( Arrays.asList( "validate" ) ); - verifier.verifyErrorFreeLog(); } + + public void testPublishedPoms() + throws Exception + { + File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6656-buildconsumer" ); + + Verifier verifier = newVerifier( testDir.getAbsolutePath(), false ); + verifier.setMavenDebug( false ); + verifier.setAutoclean( false ); + verifier.addCliOption( "-Dchangelist=MNG6656" ); + + verifier.executeGoals( Arrays.asList( "install" ) ); + verifier.verifyErrorFreeLog(); + + // use original resource files to ensure correct EOLs + File resourcesDir = new File( "src/test/resources/mng-6656-buildconsumer" ); + String content; + content = FileUtils.fileRead( new File( resourcesDir, "expected/parent.pom") ); + verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "parent", "0.9-MNG6656-SNAPSHOT", "pom", content ); + + content = FileUtils.fileRead( new File( resourcesDir, "expected/simple-parent.pom") ); + verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "simple-parent", "0.9-MNG6656-SNAPSHOT", "pom", content ); + + content = FileUtils.fileRead( new File( resourcesDir, "expected/simple-weather.pom") ); + verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "simple-weather", "0.9-MNG6656-SNAPSHOT", "pom", content ); + + content = FileUtils.fileRead( new File( resourcesDir, "expected/simple-webapp.pom") ); + verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "simple-webapp", "0.9-MNG6656-SNAPSHOT", "pom", content ); + } + } diff --git a/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/parent.pom b/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/parent.pom new file mode 100644 index 000000000..5d81426cb --- /dev/null +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/parent.pom @@ -0,0 +1,26 @@ + + 4.0.0 + org.sonatype.mavenbook.multi + parent + 0.9-MNG6656-SNAPSHOT + pom + Multi Chapter Parent Project + + \ No newline at end of file diff --git a/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-parent.pom b/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-parent.pom new file mode 100644 index 000000000..ecef8df8b --- /dev/null +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-parent.pom @@ -0,0 +1,42 @@ + + 4.0.0 + + org.sonatype.mavenbook.multi + parent + 0.9-MNG6656-SNAPSHOT + + simple-parent + pom + Multi Chapter Simple Parent Project + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + + \ No newline at end of file diff --git a/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-weather.pom b/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-weather.pom new file mode 100644 index 000000000..10570e395 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-weather.pom @@ -0,0 +1,30 @@ + + 4.0.0 + + org.sonatype.mavenbook.multi + simple-parent + 0.9-MNG6656-SNAPSHOT + + simple-weather + jar + + Multi Chapter Simple Weather API + + \ No newline at end of file diff --git a/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-webapp.pom b/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-webapp.pom new file mode 100644 index 000000000..05287702c --- /dev/null +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-webapp.pom @@ -0,0 +1,46 @@ + + 4.0.0 + + org.sonatype.mavenbook.multi + simple-parent + 0.9-MNG6656-SNAPSHOT + + + simple-webapp + Multi Chapter Simple Web Application Project + + + org.sonatype.mavenbook.multi + simple-weather + 0.9-MNG6656-SNAPSHOT + + + simple-webapp + + + + org.apache.maven.plugins + maven-war-plugin + 2.6 + + + + + \ No newline at end of file diff --git a/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/pom.xml b/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/pom.xml index d31620ae1..f16212109 100644 --- a/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/pom.xml +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/pom.xml @@ -42,21 +42,9 @@ under the License. org.apache.maven.plugins maven-compiler-plugin - - 1.8 - 1.8 - - - - junit - junit - 4.12 - test - - diff --git a/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-weather/pom.xml b/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-weather/pom.xml index 165a245b2..08baf8e76 100644 --- a/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-weather/pom.xml +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-weather/pom.xml @@ -32,32 +32,4 @@ under the License. Multi Chapter Simple Weather API - - - log4j - log4j - 1.2.14 - - - dom4j - dom4j - 1.6.1 - - - jaxen - jaxen - 1.1.1 - - - velocity - velocity - 1.5 - - - org.apache.commons - commons-io - 1.3.2 - test - - diff --git a/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-webapp/pom.xml b/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-webapp/pom.xml index b3be6ede4..9e9c0874c 100644 --- a/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-webapp/pom.xml +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-webapp/pom.xml @@ -29,14 +29,8 @@ under the License. simple-webapp - war Multi Chapter Simple Web Application Project - - org.apache.geronimo.specs - geronimo-servlet_2.4_spec - 1.1.1 - org.sonatype.mavenbook.multi simple-weather @@ -44,12 +38,14 @@ under the License. simple-webapp - - - org.mortbay.jetty - maven-jetty-plugin - 6.1.9 - - + + + + org.apache.maven.plugins + maven-war-plugin + 2.6 + + + From f22cbbfaa62e3672d197ec4d8ff91cb1291c7277 Mon Sep 17 00:00:00 2001 From: rfscholte Date: Tue, 5 May 2020 14:10:41 +0200 Subject: [PATCH 4/9] [MNG-6656] Adjust expected output --- .../mng-6656-buildconsumer/expected/simple-webapp.pom | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-webapp.pom b/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-webapp.pom index 05287702c..737120707 100644 --- a/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-webapp.pom +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-webapp.pom @@ -29,7 +29,8 @@ under the License. org.sonatype.mavenbook.multi simple-weather - 0.9-MNG6656-SNAPSHOT + 0.9-MNG6656-SNAPSHOT + simple-webapp From a58551c9ee52cbece71b4aea804cd26a5d5659c9 Mon Sep 17 00:00:00 2001 From: rfscholte Date: Tue, 5 May 2020 16:19:58 +0200 Subject: [PATCH 5/9] [MNG-6656] Verify EOL after git checkout --- .../apache/maven/it/MavenITmng6656BuildConsumer.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java index 13306c173..b534aa8fe 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java @@ -78,19 +78,17 @@ public void testPublishedPoms() verifier.executeGoals( Arrays.asList( "install" ) ); verifier.verifyErrorFreeLog(); - // use original resource files to ensure correct EOLs - File resourcesDir = new File( "src/test/resources/mng-6656-buildconsumer" ); String content; - content = FileUtils.fileRead( new File( resourcesDir, "expected/parent.pom") ); + content = FileUtils.fileRead( new File( testDir, "expected/parent.pom") ); verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "parent", "0.9-MNG6656-SNAPSHOT", "pom", content ); - content = FileUtils.fileRead( new File( resourcesDir, "expected/simple-parent.pom") ); + content = FileUtils.fileRead( new File( testDir, "expected/simple-parent.pom") ); verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "simple-parent", "0.9-MNG6656-SNAPSHOT", "pom", content ); - content = FileUtils.fileRead( new File( resourcesDir, "expected/simple-weather.pom") ); + content = FileUtils.fileRead( new File( testDir, "expected/simple-weather.pom") ); verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "simple-weather", "0.9-MNG6656-SNAPSHOT", "pom", content ); - content = FileUtils.fileRead( new File( resourcesDir, "expected/simple-webapp.pom") ); + content = FileUtils.fileRead( new File( testDir, "expected/simple-webapp.pom") ); verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "simple-webapp", "0.9-MNG6656-SNAPSHOT", "pom", content ); } From 314503b14ed53f865e4b61904493582993670d19 Mon Sep 17 00:00:00 2001 From: rfscholte Date: Tue, 5 May 2020 18:37:35 +0200 Subject: [PATCH 6/9] Revert "[MNG-6656] Verify EOL after git checkout" This reverts commit a58551c9ee52cbece71b4aea804cd26a5d5659c9. adjust EOL of pom --- .../apache/maven/it/MavenITmng6656BuildConsumer.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java index b534aa8fe..13306c173 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java @@ -78,17 +78,19 @@ public void testPublishedPoms() verifier.executeGoals( Arrays.asList( "install" ) ); verifier.verifyErrorFreeLog(); + // use original resource files to ensure correct EOLs + File resourcesDir = new File( "src/test/resources/mng-6656-buildconsumer" ); String content; - content = FileUtils.fileRead( new File( testDir, "expected/parent.pom") ); + content = FileUtils.fileRead( new File( resourcesDir, "expected/parent.pom") ); verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "parent", "0.9-MNG6656-SNAPSHOT", "pom", content ); - content = FileUtils.fileRead( new File( testDir, "expected/simple-parent.pom") ); + content = FileUtils.fileRead( new File( resourcesDir, "expected/simple-parent.pom") ); verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "simple-parent", "0.9-MNG6656-SNAPSHOT", "pom", content ); - content = FileUtils.fileRead( new File( testDir, "expected/simple-weather.pom") ); + content = FileUtils.fileRead( new File( resourcesDir, "expected/simple-weather.pom") ); verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "simple-weather", "0.9-MNG6656-SNAPSHOT", "pom", content ); - content = FileUtils.fileRead( new File( testDir, "expected/simple-webapp.pom") ); + content = FileUtils.fileRead( new File( resourcesDir, "expected/simple-webapp.pom") ); verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "simple-webapp", "0.9-MNG6656-SNAPSHOT", "pom", content ); } From 40463ebc4ecfde9a54e2ba46558af72f2cc89fd0 Mon Sep 17 00:00:00 2001 From: rfscholte Date: Sat, 6 Jun 2020 11:43:40 +0200 Subject: [PATCH 7/9] Improve scripts --- run-its.bat | 4 ++-- run-its.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/run-its.bat b/run-its.bat index ce055c192..d091dd8ff 100644 --- a/run-its.bat +++ b/run-its.bat @@ -23,8 +23,8 @@ if "%MAVENCODEBASE%" == "" ( @ECHO ON ) else ( @ECHO ON - mvn verify -Plocal-it -f "%MAVENCODEBASE%" - mvn clean install -Prun-its,embdedded -Dmaven.repo.local="%cd%\repo" -DmavenDistro="%MAVENCODEBASE%\apache-maven\target\apache-maven-bin.zip" -DwrapperDistroDir="%MAVENCODEBASE%\apache-maven\target" -DmavenWrapper="%MAVENCODEBASE%\maven-wrapper\target\maven-wrapper.jar" + mvn verify -DdistributionFileName=${project.artifactId} -f "%MAVENCODEBASE%" + mvn clean install -Prun-its,embedded -Dmaven.repo.local="%cd%\repo" -DmavenDistro="%MAVENCODEBASE%\apache-maven\target\apache-maven-bin.zip" -DwrapperDistroDir="%MAVENCODEBASE%\apache-maven\target" -DmavenWrapper="%MAVENCODEBASE%\maven-wrapper\target\maven-wrapper.jar" ) @REM If behind a proxy try this.. diff --git a/run-its.sh b/run-its.sh index 050a61737..6c758110e 100755 --- a/run-its.sh +++ b/run-its.sh @@ -24,8 +24,8 @@ if [ -z "$MAVENCODEBASE" ] ; then echo Please export MAVENCODEBASE else - mvn verify -P local-it -f "$MAVENCODEBASE" - mvn clean test -Prun-its,embdedded -Dmaven.repo.local=`pwd`/repo -DmavenDistro="$MAVENCODEBASE\apache-maven\target\apache-maven-bin.zip" -DwrapperDistroDir="$MAVENCODEBASE\apache-maven\target" -DmavenWrapper="$MAVENCODEBASE\maven-wrapper\target\maven-wrapper.jar" + mvn verify -DdistributionFileName=${project.artifactId} -f "$MAVENCODEBASE" + mvn clean install -Prun-its,embedded -Dmaven.repo.local=`pwd`/repo -DmavenDistro="$MAVENCODEBASE\apache-maven\target\apache-maven-bin.zip" -DwrapperDistroDir="$MAVENCODEBASE\apache-maven\target" -DmavenWrapper="$MAVENCODEBASE\maven-wrapper\target\maven-wrapper.jar" fi From f772c920e9f1a667275797e706c54a0aa9d14aa3 Mon Sep 17 00:00:00 2001 From: rfscholte Date: Sun, 14 Jun 2020 19:51:13 +0200 Subject: [PATCH 8/9] Fix checkstyle reported errors --- .../maven/it/MavenITmng5669ReadPomsOnce.java | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 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 7bfccb9a7..666b64747 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 @@ -64,9 +64,9 @@ public void testWithoutBuildConsumer() verifier.addCliOption( "-Dmaven.experimental.buildconsumer=false" ); verifier.executeGoals( Arrays.asList( "verify" ) ); verifier.resetStreams(); - + List logTxt = verifier.loadLines( "log.txt", "utf-8" ); - for ( String line : logTxt ) + for ( String line : logTxt ) { if ( line.startsWith( "Picked up JAVA_TOOL_OPTIONS:" ) ) { @@ -75,21 +75,21 @@ public void testWithoutBuildConsumer() } } assertEquals( logTxt.toString(), 168, logTxt.size() ); - + // analyze lines. It is a Hashmap, so we can't rely on the order Set uniqueBuildingSources = new HashSet<>( 168 ); final String buildSourceKey = "org.apache.maven.model.building.source="; final int keyLength = buildSourceKey.length(); - for( String line : logTxt ) + for ( String line : logTxt ) { int start = line.indexOf( buildSourceKey ); if ( start < 0 ) { continue; } - - int end = line.indexOf(", ", start); - if ( end < 0) + + int end = line.indexOf( ", ", start ); + if ( end < 0 ) { end = line.length() - 1; // is the } } @@ -97,9 +97,9 @@ public void testWithoutBuildConsumer() } assertEquals( uniqueBuildingSources.size(), 167 /* is 168 minus superpom */ ); } - + public void testWithBuildConsumer() - throws Exception + throws Exception { // prepare JavaAgent File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5669-read-poms-once" ); @@ -117,9 +117,9 @@ public void testWithBuildConsumer() verifier.addCliOption( "-Dmaven.experimental.buildconsumer=true" ); verifier.executeGoals( Arrays.asList( "verify" ) ); verifier.resetStreams(); - + List logTxt = verifier.loadLines( "log.txt", "utf-8" ); - for ( String line : logTxt ) + for ( String line : logTxt ) { if ( line.startsWith( "Picked up JAVA_TOOL_OPTIONS:" ) ) { @@ -127,22 +127,23 @@ public void testWithBuildConsumer() break; } } - assertEquals( logTxt.toString(), 168 + 4 /* reactor poms are read twice: file + raw (=XMLFilters) */, logTxt.size() ); - + assertEquals( logTxt.toString(), 168 + 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 uniqueBuildingSources = new HashSet<>( 168 ); final String buildSourceKey = "org.apache.maven.model.building.source="; final int keyLength = buildSourceKey.length(); - for( String line : logTxt ) + for ( String line : logTxt ) { int start = line.indexOf( buildSourceKey ); if ( start < 0 ) { continue; } - - int end = line.indexOf(", ", start); - if ( end < 0) + + int end = line.indexOf( ", ", start ); + if ( end < 0 ) { end = line.length() - 1; // is the } } @@ -150,5 +151,5 @@ public void testWithBuildConsumer() } assertEquals( uniqueBuildingSources.size(), 167 /* is 168 minus superpom */ ); } - + } From 168d410ebe0814057332d1fded32b6a7bc6538f5 Mon Sep 17 00:00:00 2001 From: rfscholte Date: Fri, 19 Jun 2020 12:57:54 +0200 Subject: [PATCH 9/9] [MNG-6656] Improve test --- .../maven/it/MavenITmng6656BuildConsumer.java | 34 ++++++++----------- .../expected/parent.pom | 2 ++ .../resources/mng-6656-buildconsumer/pom.xml | 2 ++ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java index 13306c173..b39ac5782 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java @@ -51,20 +51,16 @@ public MavenITmng6656BuildConsumer() super( "[3.7.0,)" ); } - public void testValidOmittedVersions() - throws Exception - { - File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6656-buildconsumer" ); - - Verifier verifier = newVerifier( testDir.getAbsolutePath(), false ); - verifier.setMavenDebug( false ); - verifier.setAutoclean( false ); - verifier.addCliOption( "-Dchangelist=JIRA101" ); - - verifier.executeGoals( Arrays.asList( "validate" ) ); - verifier.verifyErrorFreeLog(); - } - + /** + * Verifies: + *
    + *
  • preserve license
  • + *
  • consistent line separators
  • + *
  • resolved project versions (at least 2 levels deep) in parent and dependencies
  • + *
  • removal of modules in aggregators
  • + *
+ * @throws Exception + */ public void testPublishedPoms() throws Exception { @@ -78,19 +74,17 @@ public void testPublishedPoms() verifier.executeGoals( Arrays.asList( "install" ) ); verifier.verifyErrorFreeLog(); - // use original resource files to ensure correct EOLs - File resourcesDir = new File( "src/test/resources/mng-6656-buildconsumer" ); String content; - content = FileUtils.fileRead( new File( resourcesDir, "expected/parent.pom") ); + content = FileUtils.fileRead( new File( testDir, "expected/parent.pom") ); verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "parent", "0.9-MNG6656-SNAPSHOT", "pom", content ); - content = FileUtils.fileRead( new File( resourcesDir, "expected/simple-parent.pom") ); + content = FileUtils.fileRead( new File( testDir, "expected/simple-parent.pom") ); verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "simple-parent", "0.9-MNG6656-SNAPSHOT", "pom", content ); - content = FileUtils.fileRead( new File( resourcesDir, "expected/simple-weather.pom") ); + content = FileUtils.fileRead( new File( testDir, "expected/simple-weather.pom") ); verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "simple-weather", "0.9-MNG6656-SNAPSHOT", "pom", content ); - content = FileUtils.fileRead( new File( resourcesDir, "expected/simple-webapp.pom") ); + content = FileUtils.fileRead( new File( testDir, "expected/simple-webapp.pom") ); verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "simple-webapp", "0.9-MNG6656-SNAPSHOT", "pom", content ); } diff --git a/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/parent.pom b/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/parent.pom index 5d81426cb..53a7d3d5b 100644 --- a/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/parent.pom +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/parent.pom @@ -22,5 +22,7 @@ under the License. 0.9-MNG6656-SNAPSHOT pom Multi Chapter Parent Project + + \ No newline at end of file diff --git a/core-it-suite/src/test/resources/mng-6656-buildconsumer/pom.xml b/core-it-suite/src/test/resources/mng-6656-buildconsumer/pom.xml index f41ed6a87..145552348 100644 --- a/core-it-suite/src/test/resources/mng-6656-buildconsumer/pom.xml +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/pom.xml @@ -28,6 +28,8 @@ under the License. 0.9-${changelist}-SNAPSHOT pom Multi Chapter Parent Project + + simple-parent