Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void setUp()
protected void tearDown()
throws Exception
{

super.tearDown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public MavenITmng5669ReadPomsOnce()
super( "[3.7.0,)" );
}

public void testit()
public void testWithoutBuildConsumer()
throws Exception
{
// prepare JavaAgent
Expand All @@ -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<String> logTxt = verifier.loadLines( "log.txt", "utf-8" );
for ( String line : logTxt )
for ( String line : logTxt )
{
if ( line.startsWith( "Picked up JAVA_TOOL_OPTIONS:" ) )
{
Expand All @@ -74,26 +75,81 @@ public void testit()
}
}
assertEquals( logTxt.toString(), 168, logTxt.size() );


// analyze lines. It is a Hashmap, so we can't rely on the order
Set<String> 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<String, String> 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<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(), 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<String> 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 }
}
uniqueBuildingSources.add( line.substring( start + keyLength, end ) );
}
assertEquals( uniqueBuildingSources.size(), 167 /* is 168 minus superpom */ );
}

}
Original file line number Diff line number Diff line change
@@ -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.
* <ul>
* <li>CLI-friendly versions will be resolved</li>
* <li>parents can omit the version if the relative path points to the correct parent</li>
* <li>dependencies can omit the version if it is part of the reactor</li>
* </ul>
*
* During install the pom will be cleaned up
* <ul>
* <li>the modules will be removed</li>
* <li>the relativePath will be removed</li>
* </ul>
*
* <a href="https://issues.apache.org/jira/browse/MNG-6656">MNG-6656</a>.
*
*/
public class MavenITmng6656BuildConsumer
extends AbstractMavenIntegrationTestCase
{

public MavenITmng6656BuildConsumer()
{
super( "[3.7.0,)" );
}

/**
* Verifies:
* <ul>
* <li>preserve license</li>
* <li>consistent line separators</li>
* <li>resolved project versions (at least 2 levels deep) in parent and dependencies</li>
* <li>removal of modules in aggregators</li>
* </ul>
* @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 );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>parent</artifactId>
<version>0.9-MNG6656-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Multi Chapter Parent Project</name>

<!-- Optimized from https://github.com/sonatype/maven-example-en/tree/master/examples/ch-multi -->

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>parent</artifactId>
<version>0.9-MNG6656-SNAPSHOT</version>
</parent>
<artifactId>simple-parent</artifactId>
<packaging>pom</packaging>
<name>Multi Chapter Simple Parent Project</name>



<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<version>0.9-MNG6656-SNAPSHOT</version>
</parent>
<artifactId>simple-weather</artifactId>
<packaging>jar</packaging>

<name>Multi Chapter Simple Weather API</name>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<version>0.9-MNG6656-SNAPSHOT</version>
</parent>

<artifactId>simple-webapp</artifactId>
<name>Multi Chapter Simple Web Application Project</name>
<dependencies>
<dependency>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-weather</artifactId>
<version>0.9-MNG6656-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>simple-webapp</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Loading