[5937] Maven-Wrapper for unified project environments

This commit is contained in:
rfscholte 2020-05-22 22:33:01 +02:00
parent b60b15d8e7
commit 0ac723e2a6
9 changed files with 301 additions and 4 deletions

View File

@ -58,6 +58,12 @@ under the License.
ITs that don't require to fork Maven can also be run from the IDE using the Maven projects from the workspace if the
Maven dependencies are added to the test class path.
To test with the maven wrapper, you should add the wrapperDistroDir too.
mvn clean test -Prun-its -Dmaven.repo.local=<path-to-local-repo> -DmavenDistro=<path-to-bin-archive> -DwrapperDistroDir=<path-to-wrapper-distro-directory> -DmavenWrapper=<path-to-wrapper-jar>
Tests can pick up the maven.wrapper.distrodir system property to unpack it into their testDir to verify the wrapper.
If you're behind a proxy, use the system properties proxy.host, proxy.port, proxy.user, proxy.pass and
proxy.nonProxyHosts to specify the required proxy setup for the ITs. Alternatively, set the system property
maven.it.central to a URL of a local repository manager (anonymous authentication only) that proxies the
@ -141,6 +147,17 @@ under the License.
<artifactId>guava</artifactId>
<version>16.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
<version>0.3.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
@ -176,6 +193,14 @@ under the License.
<name>maven.it.global-settings.dir</name>
<value>${project.build.testOutputDirectory}</value>
</property>
<property>
<name>maven.wrapper.distrodir</name>
<value>${wrapperDistroDir}</value>
</property>
<property>
<name>maven.distro</name>
<value>${mavenDistro}</value>
</property>
</systemProperties>
</configuration>
</plugin>
@ -452,6 +477,36 @@ under the License.
</plugins>
</build>
</profile>
<profile>
<id>maven-wrapper</id>
<activation>
<property>
<name>mavenWrapper</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<!-- install, so it can be called via a URL -->
<execution>
<id>prepare-wrapper</id>
<phase>process-test-resources</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${mavenWrapper}</file>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>emma</id>
<properties>

View File

@ -86,7 +86,7 @@ public class IntegrationTestSuite
suite.addTestSuite( MavenITBootstrapTest.class );
/*
* Add tests in reverse alpha order by number below. This makes testing new
* Add tests in reverse order of implementation. This makes testing new
* ITs quicker and since it counts down to zero, it's easier to judge how close
* the tests are to finishing. Newer tests are also more likely to fail, so this is
* a fail fast technique as well.
@ -107,6 +107,7 @@ public class IntegrationTestSuite
// -------------------------------------------------------------------------------------------------------------
// suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
suite.addTestSuite( MavenITmng5937MavenWrapper.class );
suite.addTestSuite( MavenITmng4660ResumeFromTest.class );
suite.addTestSuite( MavenITmng4660OutdatedPackagedArtifact.class );
suite.addTestSuite( MavenITmng6759TransitiveDependencyRepositoriesTest.class );

View File

@ -0,0 +1,148 @@
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 java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import org.codehaus.plexus.archiver.zip.ZipUnArchiver;
import org.codehaus.plexus.logging.console.ConsoleLogger;
/**
* This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-5937">MNG-5937</a>.
*
*/
public class MavenITmng5937MavenWrapper
extends AbstractMavenIntegrationTestCase
{
private final Path wrapperDistro;
private final Map<String,String> envVars;
private final Path baseDir = Paths.get( "target/test-classes/mng-5937-wrapper" );
private ZipUnArchiver zipUnArchiver = new ZipUnArchiver();
public MavenITmng5937MavenWrapper() throws Exception
{
super( "[3.7.0,)" );
String mavenDist = System.getProperty( "maven.distro" );
if ( mavenDist == null )
{
throw new IllegalStateException( "Missing maven.distro to test maven-wrapper" );
}
Verifier distInstaller = newVerifier( baseDir.toAbsolutePath().toFile().toString() );
distInstaller.setSystemProperty( "file", mavenDist );
distInstaller.setSystemProperty( "groupId", "org.apache.maven" );
distInstaller.setSystemProperty( "artifactId", "apache-maven" );
distInstaller.setSystemProperty( "version", getMavenVersion().toString() );
distInstaller.setSystemProperty( "classifier", "bin" );
distInstaller.setSystemProperty( "packaging", "zip" );
distInstaller.executeGoal( "org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file" );
String distroValue = System.getProperty( "maven.wrapper.distrodir" );
if ( distroValue == null )
{
throw new IllegalStateException( "Missing maven.wrapper.distrodir to test maven-wrapper" );
}
wrapperDistro = Paths.get( distroValue );
String localRepo = System.getProperty("maven.repo.local");
envVars = new HashMap<>( 4 );
envVars.put( "MVNW_REPOURL", Paths.get( localRepo ).toUri().toURL().toString() );
envVars.put( "MVNW_VERBOSE", "true" );
String javaHome = System.getenv( "JAVA_HOME" );
if ( javaHome != null )
{
// source needs to call the javac executable.
// if JAVA_HOME is not set, ForkedLauncher sets it to java.home, which is the JRE home
envVars.put( "JAVA_HOME", javaHome );
}
}
public void testitMNG5937Bin()
throws Exception
{
final File testDir = baseDir.resolve( "bin" ).toFile();
unpack( testDir.toPath(), "bin" );
envVars.put( "MAVEN_BASEDIR", testDir.getAbsolutePath() );
Verifier verifier = newVerifier( testDir.getAbsolutePath() );
verifier.setAutoclean( false );
verifier.setDebug( true );
verifier.executeGoal( "validate", envVars );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
}
public void testitMNG5937Script()
throws Exception
{
final File testDir = baseDir.resolve( "script" ).toFile();
unpack( testDir.toPath(), "script" );
envVars.put( "MAVEN_BASEDIR", testDir.getAbsolutePath() );
Verifier verifier = newVerifier( testDir.getAbsolutePath() );
verifier.setAutoclean( false );
verifier.setDebug( true );
verifier.executeGoal( "validate", envVars );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
}
public void testitMNG5937Source()
throws Exception
{
final File testDir = baseDir.resolve( "source" ).toFile();
unpack( testDir.toPath(), "source" );
envVars.put( "MAVEN_BASEDIR", testDir.getAbsolutePath() );
Verifier verifier = newVerifier( testDir.getAbsolutePath() );
verifier.setAutoclean( false );
verifier.setDebug( true );
verifier.executeGoal( "validate", envVars );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
}
private void unpack( Path target, String classifier ) throws IOException
{
Path distro = wrapperDistro.resolve( "apache-maven-wrapper-" + getMavenVersion() + '-' + classifier + ".zip" );
zipUnArchiver.setSourceFile( distro.toFile() );
zipUnArchiver.setDestDirectory( target.toFile() );
zipUnArchiver.enableLogging( new ConsoleLogger() );
zipUnArchiver.extract();
}
}

View File

@ -0,0 +1,31 @@
<?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>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng5936</groupId>
<artifactId>test</artifactId>
<version>1</version>
<name>Maven Integration Test :: MNG-5979</name>
</project>

View File

@ -0,0 +1,31 @@
<?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>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng5936</groupId>
<artifactId>test</artifactId>
<version>1</version>
<name>Maven Integration Test :: MNG-5979</name>
</project>

View File

@ -0,0 +1,31 @@
<?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>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng5936</groupId>
<artifactId>test</artifactId>
<version>1</version>
<name>Maven Integration Test :: MNG-5979</name>
</project>

View File

@ -130,7 +130,7 @@ public abstract class AbstractMavenIntegrationTestCase
*
* @return The Maven version or <code>null</code> if unknown.
*/
private ArtifactVersion getMavenVersion()
protected final ArtifactVersion getMavenVersion()
{
if ( mavenVersion == null )
{

View File

@ -81,7 +81,7 @@ under the License.
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-verifier</artifactId>
<version>1.7.1</version>
<version>1.7.2</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -19,7 +19,7 @@
@REM How JvZ runs the ITs from a clean slate if it would be on Windows
mvn clean install -Prun-its,embedded -Dmaven.repo.local=%cd%\repo
mvn clean install -U -Prun-its,embedded -Dmaven.repo.local=%cd%\repo
@REM If behind a proxy try this..