Skip to content

Commit b746e6a

Browse files
authored
[mvn] Update maven wrapper to 3.1.1 (#2622)
[mvn] Update maven wrapper
1 parent 59e27a0 commit b746e6a

File tree

4 files changed

+124
-134
lines changed

4 files changed

+124
-134
lines changed

.mvn/wrapper/MavenWrapperDownloader.java

+83-63
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,24 @@
1717
* under the License.
1818
*/
1919

20-
import java.net.*;
21-
import java.io.*;
22-
import java.nio.channels.*;
20+
import java.io.IOException;
21+
import java.io.InputStream;
22+
import java.net.Authenticator;
23+
import java.net.PasswordAuthentication;
24+
import java.net.URL;
25+
import java.nio.file.Files;
26+
import java.nio.file.LinkOption;
27+
import java.nio.file.Path;
28+
import java.nio.file.Paths;
29+
import java.nio.file.StandardCopyOption;
30+
import java.nio.file.StandardOpenOption;
2331
import java.util.Properties;
2432

25-
public class MavenWrapperDownloader
33+
public final class MavenWrapperDownloader
2634
{
27-
private static final String WRAPPER_VERSION = "3.1.0";
35+
private static final String WRAPPER_VERSION = "3.1.1";
36+
37+
private static final boolean VERBOSE = Boolean.parseBoolean( System.getenv( "MVNW_VERBOSE" ) );
2838

2939
/**
3040
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
@@ -49,78 +59,53 @@ public class MavenWrapperDownloader
4959
*/
5060
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
5161

52-
public static void main( String args[] )
62+
public static void main( String[] args )
5363
{
54-
System.out.println( "- Downloader started" );
55-
File baseDirectory = new File( args[0] );
56-
System.out.println( "- Using base directory: " + baseDirectory.getAbsolutePath() );
57-
58-
// If the maven-wrapper.properties exists, read it and check if it contains a custom
59-
// wrapperUrl parameter.
60-
File mavenWrapperPropertyFile = new File( baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH );
61-
String url = DEFAULT_DOWNLOAD_URL;
62-
if ( mavenWrapperPropertyFile.exists() )
64+
if ( args.length == 0 )
6365
{
64-
FileInputStream mavenWrapperPropertyFileInputStream = null;
65-
try
66-
{
67-
mavenWrapperPropertyFileInputStream = new FileInputStream( mavenWrapperPropertyFile );
68-
Properties mavenWrapperProperties = new Properties();
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-
{
82-
mavenWrapperPropertyFileInputStream.close();
83-
}
84-
}
85-
catch ( IOException e )
86-
{
87-
// Ignore ...
88-
}
89-
}
66+
System.err.println( " - ERROR projectBasedir parameter missing" );
67+
System.exit( 1 );
9068
}
91-
System.out.println( "- Downloading from: " + url );
9269

93-
File outputFile = new File( baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH );
94-
if ( !outputFile.getParentFile().exists() )
70+
log( " - Downloader started" );
71+
final String dir = args[0].replace( "..", "" ); // Sanitize path
72+
final Path projectBasedir = Paths.get( dir ).toAbsolutePath().normalize();
73+
if ( !Files.isDirectory( projectBasedir, LinkOption.NOFOLLOW_LINKS ) )
9574
{
96-
if ( !outputFile.getParentFile().mkdirs() )
97-
{
98-
System.out.println( "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath()
99-
+ "'" );
100-
}
75+
System.err.println( " - ERROR projectBasedir not exists: " + projectBasedir );
76+
System.exit( 1 );
10177
}
102-
System.out.println( "- Downloading to: " + outputFile.getAbsolutePath() );
78+
79+
log( " - Using base directory: " + projectBasedir );
80+
81+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
82+
// wrapperUrl parameter.
83+
Path mavenWrapperPropertyFile = projectBasedir.resolve( MAVEN_WRAPPER_PROPERTIES_PATH );
84+
String url = readWrapperUrl( mavenWrapperPropertyFile );
85+
10386
try
10487
{
88+
Path outputFile = projectBasedir.resolve( MAVEN_WRAPPER_JAR_PATH );
89+
createDirectories( outputFile.getParent() );
10590
downloadFileFromURL( url, outputFile );
106-
System.out.println( "Done" );
91+
log( "Done" );
10792
System.exit( 0 );
10893
}
109-
catch ( Throwable e )
94+
catch ( IOException e )
11095
{
111-
System.out.println( "- Error downloading" );
96+
System.err.println( "- Error downloading" );
11297
e.printStackTrace();
11398
System.exit( 1 );
11499
}
115100
}
116101

117-
private static void downloadFileFromURL( String urlString, File destination )
118-
throws Exception
102+
private static void downloadFileFromURL( String urlString, Path destination ) throws IOException
119103
{
104+
log( " - Downloading to: " + destination );
120105
if ( System.getenv( "MVNW_USERNAME" ) != null && System.getenv( "MVNW_PASSWORD" ) != null )
121106
{
122-
String username = System.getenv( "MVNW_USERNAME" );
123-
char[] password = System.getenv( "MVNW_PASSWORD" ).toCharArray();
107+
final String username = System.getenv( "MVNW_USERNAME" );
108+
final char[] password = System.getenv( "MVNW_PASSWORD" ).toCharArray();
124109
Authenticator.setDefault( new Authenticator()
125110
{
126111
@Override
@@ -131,12 +116,47 @@ protected PasswordAuthentication getPasswordAuthentication()
131116
} );
132117
}
133118
URL website = new URL( urlString );
134-
ReadableByteChannel rbc;
135-
rbc = Channels.newChannel( website.openStream() );
136-
FileOutputStream fos = new FileOutputStream( destination );
137-
fos.getChannel().transferFrom( rbc, 0, Long.MAX_VALUE );
138-
fos.close();
139-
rbc.close();
119+
try ( InputStream inStream = website.openStream() ) {
120+
Files.copy( inStream, destination, StandardCopyOption.REPLACE_EXISTING );
121+
}
122+
log( " - Downloader complete" );
123+
}
124+
125+
private static void createDirectories(Path outputPath) throws IOException
126+
{
127+
if ( !Files.isDirectory( outputPath, LinkOption.NOFOLLOW_LINKS ) ) {
128+
Path createDirectories = Files.createDirectories( outputPath );
129+
log( " - Directories created: " + createDirectories );
130+
}
131+
}
132+
133+
private static String readWrapperUrl( Path mavenWrapperPropertyFile )
134+
{
135+
String url = DEFAULT_DOWNLOAD_URL;
136+
if ( Files.exists( mavenWrapperPropertyFile, LinkOption.NOFOLLOW_LINKS ) )
137+
{
138+
log( " - Reading property file: " + mavenWrapperPropertyFile );
139+
try ( InputStream in = Files.newInputStream( mavenWrapperPropertyFile, StandardOpenOption.READ ) )
140+
{
141+
Properties mavenWrapperProperties = new Properties();
142+
mavenWrapperProperties.load( in );
143+
url = mavenWrapperProperties.getProperty( PROPERTY_NAME_WRAPPER_URL, DEFAULT_DOWNLOAD_URL );
144+
}
145+
catch ( IOException e )
146+
{
147+
System.err.println( " - ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'" );
148+
}
149+
}
150+
log( " - Downloading from: " + url );
151+
return url;
152+
}
153+
154+
private static void log( String msg )
155+
{
156+
if ( VERBOSE )
157+
{
158+
System.out.println( msg );
159+
}
140160
}
141161

142162
}

.mvn/wrapper/maven-wrapper.properties

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
# to you under the Apache License, Version 2.0 (the
66
# "License"); you may not use this file except in compliance
77
# with the License. You may obtain a copy of the License at
8-
#
9-
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
1111
# Unless required by applicable law or agreed to in writing,
1212
# software distributed under the License is distributed on an
1313
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip
18-
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
18+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar

0 commit comments

Comments
 (0)