Skip to content

Commit 471e8a8

Browse files
hazendazscordio
authored andcommitted
Switch to the official Maven Wrapper by Apache (#2452)
Performed by running: ``` ./mvnw -N org.apache.maven.plugins:maven-wrapper-plugin:wrapper -Dtype=source -Dmaven=3.8.4 ```
1 parent cf836b8 commit 471e8a8

4 files changed

Lines changed: 135 additions & 82 deletions

File tree

.mvn/wrapper/MavenWrapperDownloader.java

Lines changed: 88 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,140 @@
11
/*
2-
* Copyright 2007-present the original author or authors.
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
39
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
711
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
1518
*/
19+
1620
import java.net.*;
1721
import java.io.*;
1822
import java.nio.channels.*;
1923
import java.util.Properties;
2024

21-
public class MavenWrapperDownloader {
25+
public class MavenWrapperDownloader
26+
{
27+
private static final String WRAPPER_VERSION = "3.1.0";
2228

23-
private static final String WRAPPER_VERSION = "0.5.6";
2429
/**
2530
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
2631
*/
27-
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28-
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
32+
private static final String DEFAULT_DOWNLOAD_URL =
33+
"https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/" + WRAPPER_VERSION
34+
+ "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
2935

3036
/**
31-
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32-
* use instead of the default one.
37+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to use instead of the
38+
* default one.
3339
*/
34-
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35-
".mvn/wrapper/maven-wrapper.properties";
40+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties";
3641

3742
/**
3843
* Path where the maven-wrapper.jar will be saved to.
3944
*/
40-
private static final String MAVEN_WRAPPER_JAR_PATH =
41-
".mvn/wrapper/maven-wrapper.jar";
45+
private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar";
4246

4347
/**
4448
* Name of the property which should be used to override the default download url for the wrapper.
4549
*/
4650
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
4751

48-
public static void main(String args[]) {
49-
System.out.println("- Downloader started");
50-
File baseDirectory = new File(args[0]);
51-
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52+
public static void main( String args[] )
53+
{
54+
System.out.println( "- Downloader started" );
55+
File baseDirectory = new File( args[0] );
56+
System.out.println( "- Using base directory: " + baseDirectory.getAbsolutePath() );
5257

5358
// If the maven-wrapper.properties exists, read it and check if it contains a custom
5459
// wrapperUrl parameter.
55-
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
60+
File mavenWrapperPropertyFile = new File( baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH );
5661
String url = DEFAULT_DOWNLOAD_URL;
57-
if(mavenWrapperPropertyFile.exists()) {
62+
if ( mavenWrapperPropertyFile.exists() )
63+
{
5864
FileInputStream mavenWrapperPropertyFileInputStream = null;
59-
try {
60-
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
65+
try
66+
{
67+
mavenWrapperPropertyFileInputStream = new FileInputStream( mavenWrapperPropertyFile );
6168
Properties mavenWrapperProperties = new Properties();
62-
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63-
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64-
} catch (IOException e) {
65-
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66-
} finally {
67-
try {
68-
if(mavenWrapperPropertyFileInputStream != null) {
69+
mavenWrapperProperties.load( mavenWrapperPropertyFileInputStream );
70+
url = mavenWrapperProperties.getProperty( PROPERTY_NAME_WRAPPER_URL, url );
71+
}
72+
catch ( IOException e )
73+
{
74+
System.out.println( "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'" );
75+
}
76+
finally
77+
{
78+
try
79+
{
80+
if ( mavenWrapperPropertyFileInputStream != null )
81+
{
6982
mavenWrapperPropertyFileInputStream.close();
7083
}
71-
} catch (IOException e) {
84+
}
85+
catch ( IOException e )
86+
{
7287
// Ignore ...
7388
}
7489
}
7590
}
76-
System.out.println("- Downloading from: " + url);
91+
System.out.println( "- Downloading from: " + url );
7792

78-
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79-
if(!outputFile.getParentFile().exists()) {
80-
if(!outputFile.getParentFile().mkdirs()) {
81-
System.out.println(
82-
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
93+
File outputFile = new File( baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH );
94+
if ( !outputFile.getParentFile().exists() )
95+
{
96+
if ( !outputFile.getParentFile().mkdirs() )
97+
{
98+
System.out.println( "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath()
99+
+ "'" );
83100
}
84101
}
85-
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86-
try {
87-
downloadFileFromURL(url, outputFile);
88-
System.out.println("Done");
89-
System.exit(0);
90-
} catch (Throwable e) {
91-
System.out.println("- Error downloading");
102+
System.out.println( "- Downloading to: " + outputFile.getAbsolutePath() );
103+
try
104+
{
105+
downloadFileFromURL( url, outputFile );
106+
System.out.println( "Done" );
107+
System.exit( 0 );
108+
}
109+
catch ( Throwable e )
110+
{
111+
System.out.println( "- Error downloading" );
92112
e.printStackTrace();
93-
System.exit(1);
113+
System.exit( 1 );
94114
}
95115
}
96116

97-
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98-
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99-
String username = System.getenv("MVNW_USERNAME");
100-
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101-
Authenticator.setDefault(new Authenticator() {
117+
private static void downloadFileFromURL( String urlString, File destination )
118+
throws Exception
119+
{
120+
if ( System.getenv( "MVNW_USERNAME" ) != null && System.getenv( "MVNW_PASSWORD" ) != null )
121+
{
122+
String username = System.getenv( "MVNW_USERNAME" );
123+
char[] password = System.getenv( "MVNW_PASSWORD" ).toCharArray();
124+
Authenticator.setDefault( new Authenticator()
125+
{
102126
@Override
103-
protected PasswordAuthentication getPasswordAuthentication() {
104-
return new PasswordAuthentication(username, password);
127+
protected PasswordAuthentication getPasswordAuthentication()
128+
{
129+
return new PasswordAuthentication( username, password );
105130
}
106-
});
131+
} );
107132
}
108-
URL website = new URL(urlString);
133+
URL website = new URL( urlString );
109134
ReadableByteChannel rbc;
110-
rbc = Channels.newChannel(website.openStream());
111-
FileOutputStream fos = new FileOutputStream(destination);
112-
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
135+
rbc = Channels.newChannel( website.openStream() );
136+
FileOutputStream fos = new FileOutputStream( destination );
137+
fos.getChannel().transferFrom( rbc, 0, Long.MAX_VALUE );
113138
fos.close();
114139
rbc.close();
115140
}
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
117
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip
2-
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
18+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar

mvnw

Lines changed: 12 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mvnw.cmd

Lines changed: 18 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)