You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2020/05/02 11:16:46 UTC

[maven-integration-testing] branch MNG-5937 created (now fd5219d)

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a change to branch MNG-5937
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git.


      at fd5219d  [5937] Maven-Wrapper for unified project environments

This branch includes the following new commits:

     new fd5219d  [5937] Maven-Wrapper for unified project environments

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-integration-testing] 01/01: [5937] Maven-Wrapper for unified project environments

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-5937
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git

commit fd5219d1f8d94651bba9b9e221ea61a99eca92a7
Author: rfscholte <rf...@apache.org>
AuthorDate: Sat May 2 13:16:34 2020 +0200

    [5937] Maven-Wrapper for unified project environments
---
 core-it-suite/pom.xml                              |  57 ++++++++
 .../org/apache/maven/it/IntegrationTestSuite.java  |   3 +-
 .../maven/it/MavenITmng5937MavenWrapper.java       | 149 +++++++++++++++++++++
 .../test/resources/mng-5937-wrapper/bin/pom.xml    |  31 +++++
 .../test/resources/mng-5937-wrapper/script/pom.xml |  31 +++++
 .../test/resources/mng-5937-wrapper/source/pom.xml |  31 +++++
 .../maven/it/AbstractMavenIntegrationTestCase.java |   2 +-
 run-its.bat                                        |   2 +-
 8 files changed, 303 insertions(+), 3 deletions(-)

diff --git a/core-it-suite/pom.xml b/core-it-suite/pom.xml
index 774602f..2cf10ae 100644
--- a/core-it-suite/pom.xml
+++ b/core-it-suite/pom.xml
@@ -57,6 +57,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 -DwrapperDistroDir=<path-to-wrapper-distro-directory>
+	
+  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
@@ -176,6 +182,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>
@@ -453,6 +467,49 @@ under the License.
       </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>
+              <execution>
+                <id>prepare-maven-distro</id>
+                <phase>process-test-resources</phase>
+                <goals>
+                  <goal>install-file</goal>
+                </goals>
+                <configuration>
+                  <file>${mavenDistro}</file>
+                  <pomFile>${mavenDistro}/../../pom.xml</pomFile>
+                  <classifier>bin</classifier>
+                  <packaging>zip</packaging>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+    <profile>
       <id>emma</id>
       <properties>
         <preparedMavenHome>${project.build.directory}/distro</preparedMavenHome>
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 3f0cbc8..01fdb89 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
@@ -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 );
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5937MavenWrapper.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5937MavenWrapper.java
new file mode 100644
index 0000000..951d35b
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5937MavenWrapper.java
@@ -0,0 +1,149 @@
+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.net.MalformedURLException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+/**
+ * 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;
+
+    public MavenITmng5937MavenWrapper() throws MalformedURLException
+    {
+        super( "[3.7.0,)" );
+        
+        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<>( 2 );
+        envVars.put( "MVNW_REPOURL", Paths.get( localRepo ).toUri().toURL().toString() );
+        envVars.put( "MAVEN_BATCH_ECHO", "on" );
+        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 = Paths.get( "target/test-classes/mng-5937-wrapper/bin" ).toFile();
+        
+        unpack( testDir.toPath(), "bin" );
+        
+        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 = Paths.get( "target/test-classes/mng-5937-wrapper/script" ).toFile();
+        
+        unpack( testDir.toPath(), "script" );
+        
+        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 = Paths.get( "target/test-classes/mng-5937-wrapper/source" ).toFile();
+        
+        unpack( testDir.toPath(), "source" );
+        
+        Verifier verifier = newVerifier( testDir.getAbsolutePath() );
+        verifier.setAutoclean( false );
+        verifier.setDebug( true );
+        verifier.executeGoal( "validate", envVars );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+    }
+
+    private static Path newPath( Path destinationDir, ZipEntry zipEntry )
+        throws IOException
+    {
+        Path destFile = destinationDir.resolve( zipEntry.getName() );
+
+        if ( !destFile.startsWith( destinationDir ) )
+        {
+            throw new IOException( "Entry is outside of the target dir: " + zipEntry.getName() );
+        }
+
+        return destFile;
+    }
+    
+    private void unpack( Path target, String classifier ) throws IOException
+    {
+        Path distro = wrapperDistro.resolve( "apache-maven-wrapper-" + getMavenVersion() + '-' + classifier + ".zip" );
+        
+        try ( ZipInputStream zis = new ZipInputStream( Files.newInputStream( distro ) ) )
+        {
+            ZipEntry zipEntry = zis.getNextEntry();
+            while ( zipEntry != null )
+            {
+                Path newFile = newPath( target, zipEntry );
+                if ( !zipEntry.isDirectory() )
+                {
+                    Files.createDirectories( newFile.getParent() );
+
+                    Files.copy( zis, newFile.toAbsolutePath(), StandardCopyOption.REPLACE_EXISTING );
+                }
+
+                zipEntry = zis.getNextEntry();
+            }
+        }
+    }
+}
diff --git a/core-it-suite/src/test/resources/mng-5937-wrapper/bin/pom.xml b/core-it-suite/src/test/resources/mng-5937-wrapper/bin/pom.xml
new file mode 100644
index 0000000..5ceadeb
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5937-wrapper/bin/pom.xml
@@ -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>
diff --git a/core-it-suite/src/test/resources/mng-5937-wrapper/script/pom.xml b/core-it-suite/src/test/resources/mng-5937-wrapper/script/pom.xml
new file mode 100644
index 0000000..5ceadeb
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5937-wrapper/script/pom.xml
@@ -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>
diff --git a/core-it-suite/src/test/resources/mng-5937-wrapper/source/pom.xml b/core-it-suite/src/test/resources/mng-5937-wrapper/source/pom.xml
new file mode 100644
index 0000000..5ceadeb
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5937-wrapper/source/pom.xml
@@ -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>
diff --git a/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java b/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java
index 7e3c42a..9e0edc4 100644
--- a/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java
+++ b/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java
@@ -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 )
         {
diff --git a/run-its.bat b/run-its.bat
index 7fbbbb3..0045694 100644
--- a/run-its.bat
+++ b/run-its.bat
@@ -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..