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

hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-wrapper.git


The following commit(s) were added to refs/heads/master by this push:
     new b3e1720  [MWRAPPER-37] restore MVNW_REPOURL support for wrapper plugin
b3e1720 is described below

commit b3e172046d6bef40a5d112a8b86e18be6267b1f3
Author: HervĂ© Boutemy <[email protected]>
AuthorDate: Sun Dec 12 02:09:01 2021 +0100

    [MWRAPPER-37] restore MVNW_REPOURL support for wrapper plugin
---
 maven-wrapper-plugin/pom.xml                       |  1 +
 .../src/it/projects/type_script/invoker.properties | 19 +++++++++
 .../src/it/projects/type_script/verify.groovy      |  7 +++-
 .../src/it/projects/type_source/invoker.properties | 19 +++++++++
 .../src/it/projects/type_source/verify.groovy      |  6 +++
 .../apache/maven/plugins/wrapper/WrapperMojo.java  | 46 +++++++++++++++++++++-
 6 files changed, 96 insertions(+), 2 deletions(-)

diff --git a/maven-wrapper-plugin/pom.xml b/maven-wrapper-plugin/pom.xml
index 39d2802..d5b7686 100644
--- a/maven-wrapper-plugin/pom.xml
+++ b/maven-wrapper-plugin/pom.xml
@@ -108,6 +108,7 @@ under the License.
           <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-invoker-plugin</artifactId>
+            <version>3.2.2</version>
             <configuration>
               <goals>
                 
<goal>${project.groupId}:${project.artifactId}:${project.version}:wrapper</goal>
diff --git 
a/maven-wrapper-plugin/src/it/projects/type_script/invoker.properties 
b/maven-wrapper-plugin/src/it/projects/type_script/invoker.properties
new file mode 100644
index 0000000..68fdc5e
--- /dev/null
+++ b/maven-wrapper-plugin/src/it/projects/type_script/invoker.properties
@@ -0,0 +1,19 @@
+# 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.
+
+invoker.debug = true
+invoker.environmentVariables.MVNW_REPOURL = @localRepositoryUrl@
diff --git a/maven-wrapper-plugin/src/it/projects/type_script/verify.groovy 
b/maven-wrapper-plugin/src/it/projects/type_script/verify.groovy
index cc72df5..2b6d569 100644
--- a/maven-wrapper-plugin/src/it/projects/type_script/verify.groovy
+++ b/maven-wrapper-plugin/src/it/projects/type_script/verify.groovy
@@ -24,4 +24,9 @@ assert !(new File(basedir,'mvnwDebug').exists())
 assert !(new File(basedir,'mvnwDebug.cmd').exists())
 assert new File(basedir,'.mvn/wrapper/maven-wrapper.properties').exists()
 assert !new File(basedir,'.mvn/wrapper/maven-wrapper.jar').exists()
-assert new File(basedir, 'build.log').text.contains('[INFO] Unpacked script 
type wrapper distribution 
org.apache.maven.wrapper:maven-wrapper-distribution:zip:script:')
\ No newline at end of file
+
+log = new File(basedir, 'build.log').text
+assert log.contains('[INFO] Unpacked script type wrapper distribution 
org.apache.maven.wrapper:maven-wrapper-distribution:zip:script:')
+
+assert log.contains('[DEBUG] Using repo URL from MVNW_REPOURL environment 
variable.')
+assert log.contains('[DEBUG] Determined repo URL to use as 
@localRepositoryUrl@')
diff --git 
a/maven-wrapper-plugin/src/it/projects/type_source/invoker.properties 
b/maven-wrapper-plugin/src/it/projects/type_source/invoker.properties
new file mode 100644
index 0000000..68fdc5e
--- /dev/null
+++ b/maven-wrapper-plugin/src/it/projects/type_source/invoker.properties
@@ -0,0 +1,19 @@
+# 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.
+
+invoker.debug = true
+invoker.environmentVariables.MVNW_REPOURL = @localRepositoryUrl@
diff --git a/maven-wrapper-plugin/src/it/projects/type_source/verify.groovy 
b/maven-wrapper-plugin/src/it/projects/type_source/verify.groovy
index 8364162..b17326d 100644
--- a/maven-wrapper-plugin/src/it/projects/type_source/verify.groovy
+++ b/maven-wrapper-plugin/src/it/projects/type_source/verify.groovy
@@ -25,3 +25,9 @@ assert !(new File(basedir,'mvnwDebug.cmd').exists())
 assert new File(basedir,'.mvn/wrapper/maven-wrapper.properties').exists()
 assert new File(basedir,'.mvn/wrapper/MavenWrapperDownloader.java').exists()
 assert !(new File(basedir,'.mvn/wrapper/maven-wrapper.jar').exists())
+
+log = new File(basedir, 'build.log').text
+assert log.contains('[INFO] Unpacked source type wrapper distribution 
org.apache.maven.wrapper:maven-wrapper-distribution:zip:source:')
+
+assert log.contains('[DEBUG] Using repo URL from MVNW_REPOURL environment 
variable.')
+assert log.contains('[DEBUG] Determined repo URL to use as 
@localRepositoryUrl@')
diff --git 
a/maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java
 
b/maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java
index ae70a76..825bc37 100644
--- 
a/maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java
+++ 
b/maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java
@@ -45,6 +45,8 @@ import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.repository.RepositorySystem;
+import org.apache.maven.settings.Mirror;
+import org.apache.maven.settings.Settings;
 import org.codehaus.plexus.archiver.UnArchiver;
 import org.codehaus.plexus.components.io.fileselectors.FileInfo;
 import org.codehaus.plexus.components.io.fileselectors.FileSelector;
@@ -60,6 +62,10 @@ import static 
org.apache.maven.shared.utils.logging.MessageUtils.buffer;
 @Mojo( name = "wrapper", aggregator = true, requiresDirectInvocation = true )
 public class WrapperMojo extends AbstractMojo
 {
+    private static final String MVNW_REPOURL = "MVNW_REPOURL";
+
+    private static final String DEFAULT_REPOURL = 
"https://repo.maven.apache.org/maven2";;
+
     // CONFIGURATION PARAMETERS
     
     /**
@@ -96,6 +102,9 @@ public class WrapperMojo extends AbstractMojo
     @Parameter( defaultValue = "${session}", readonly = true, required = true )
     private MavenSession session;
     
+    @Parameter( defaultValue = "${settings}", readonly = true, required = true 
)
+    private Settings settings;
+
     // Waiting for 
org.codehaus.plexus.component.configurator.converters.basic.PathConverter
     @Parameter( defaultValue = "${project.basedir}", readonly = true, required 
= true )
     private File basedir;
@@ -212,7 +221,8 @@ public class WrapperMojo extends AbstractMojo
      */
     private void replaceProperties( String wrapperVersion, Path targetFolder ) 
throws IOException
     {
-        String repoUrl = "https://repo.maven.apache.org/maven2";;
+        String repoUrl = getRepoUrl();
+
         String distributionUrl =
             repoUrl + "/org/apache/maven/apache-maven/" + mavenVersion + 
"/apache-maven-" + mavenVersion + "-bin.zip";
         String wrapperUrl = repoUrl + 
"/org/apache/maven/wrapper/maven-wrapper/" + wrapperVersion
@@ -267,4 +277,38 @@ public class WrapperMojo extends AbstractMojo
         }
         return version;
     }
+
+    /**
+     * Determine the repository URL to download Wrapper and Maven from.
+     */
+    private String getRepoUrl()
+    {
+        // default
+        String repoUrl = DEFAULT_REPOURL;
+
+        // adapt to also support MVNW_REPOURL as supported by mvnw scripts 
from maven-wrapper
+        String mvnwRepoUrl = System.getenv( MVNW_REPOURL );
+        if ( mvnwRepoUrl != null && !mvnwRepoUrl.isEmpty() )
+        {
+            repoUrl = mvnwRepoUrl;
+            getLog().debug( "Using repo URL from " + MVNW_REPOURL + " 
environment variable." );
+        }
+        // otherwise mirror from settings
+        else if ( settings.getMirrors() != null && 
settings.getMirrors().size() > 0 )
+        {
+            for ( Mirror current : settings.getMirrors() )
+            {
+                if ( "*".equals( current.getMirrorOf() ) )
+                {
+                    repoUrl = current.getUrl();
+                    break;
+                }
+            }
+            getLog().debug( "Using repo URL from * mirror in settings file." );
+        }
+
+        getLog().debug( "Determined repo URL to use as " + repoUrl );
+
+        return repoUrl;
+    }
 }

Reply via email to