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 45f1d381e..11838b14b 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,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( MavenITmng5868NoDuplicateAttachedArtifacts.class ); suite.addTestSuite( MavenITmng5937MavenWrapper.class ); suite.addTestSuite( MavenITmng4660ResumeFromTest.class ); diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5338FileOptionToDirectory.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5338FileOptionToDirectory.java index c5da6f9d4..9051a4231 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5338FileOptionToDirectory.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5338FileOptionToDirectory.java @@ -51,6 +51,7 @@ public void setUp() protected void tearDown() throws Exception { + super.tearDown(); } 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 c2835f91d..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 @@ -45,7 +45,7 @@ public MavenITmng5669ReadPomsOnce() super( "[3.7.0,)" ); } - public void testit() + public void testWithoutBuildConsumer() throws Exception { // prepare JavaAgent @@ -61,11 +61,12 @@ public void testit() verifier.setAutoclean( false ); verifier.addCliOption( "-q" ); verifier.addCliOption( "-U" ); + 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:" ) ) { @@ -74,21 +75,75 @@ public void testit() } } 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 ) + { + 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 */ ); + } + + 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 ) + 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 } } @@ -96,4 +151,5 @@ public void testit() } assertEquals( uniqueBuildingSources.size(), 167 /* is 168 minus superpom */ ); } + } 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..b39ac5782 --- /dev/null +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6656BuildConsumer.java @@ -0,0 +1,91 @@ +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 org.apache.maven.shared.utils.io.FileUtils; + +import java.io.File; +import java.util.Arrays; + +/** + * With the build-consumer the pom.xml will be adjusted during the process. + *
    + *
  • CLI-friendly versions will be resolved
  • + *
  • parents can omit the version if the relative path points to the correct parent
  • + *
  • dependencies can omit the version if it is part of the reactor
  • + *
+ * + * During install the pom will be cleaned up + *
    + *
  • the modules will be removed
  • + *
  • the relativePath will be removed
  • + *
+ * + * MNG-6656. + * + */ +public class MavenITmng6656BuildConsumer + extends AbstractMavenIntegrationTestCase +{ + + public MavenITmng6656BuildConsumer() + { + super( "[3.7.0,)" ); + } + + /** + * 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 + { + 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(); + + String content; + 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( testDir, "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") ); + verifier.assertArtifactContents( "org.sonatype.mavenbook.multi", "simple-weather", "0.9-MNG6656-SNAPSHOT", "pom", content ); + + 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 new file mode 100644 index 000000000..53a7d3d5b --- /dev/null +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/parent.pom @@ -0,0 +1,28 @@ + + 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..737120707 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/expected/simple-webapp.pom @@ -0,0 +1,47 @@ + + 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/pom.xml b/core-it-suite/src/test/resources/mng-6656-buildconsumer/pom.xml new file mode 100644 index 000000000..145552348 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/pom.xml @@ -0,0 +1,36 @@ + + + + + + 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..f16212109 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/pom.xml @@ -0,0 +1,50 @@ + + + + + + 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 + + + + + + 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..08baf8e76 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-weather/pom.xml @@ -0,0 +1,35 @@ + + + + + + 4.0.0 + + org.sonatype.mavenbook.multi + simple-parent + + simple-weather + jar + + Multi Chapter Simple Weather API + + 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..9e9c0874c --- /dev/null +++ b/core-it-suite/src/test/resources/mng-6656-buildconsumer/simple-parent/simple-webapp/pom.xml @@ -0,0 +1,51 @@ + + + + + + 4.0.0 + + org.sonatype.mavenbook.multi + simple-parent + + + simple-webapp + Multi Chapter Simple Web Application Project + + + org.sonatype.mavenbook.multi + simple-weather + + + + simple-webapp + + + + org.apache.maven.plugins + maven-war-plugin + 2.6 + + + + +