Skip to content

Commit 38a9788

Browse files
committed
[mvn] Update maven wrapper
1 parent 38ba368 commit 38a9788

File tree

3 files changed

+22
-86
lines changed

3 files changed

+22
-86
lines changed

.mvn/extensions.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright 2013-2022 the original author or authors.
4+
Copyright 2013-2023 the original author or authors.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.

.mvn/settings.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright 2013-2022 the original author or authors.
4+
Copyright 2013-2023 the original author or authors.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.

.mvn/wrapper/MavenWrapperDownloader.java

+20-84
Original file line numberDiff line numberDiff line change
@@ -23,85 +23,50 @@
2323
import java.net.PasswordAuthentication;
2424
import java.net.URL;
2525
import java.nio.file.Files;
26-
import java.nio.file.LinkOption;
2726
import java.nio.file.Path;
2827
import java.nio.file.Paths;
2928
import java.nio.file.StandardCopyOption;
30-
import java.nio.file.StandardOpenOption;
31-
import java.util.Properties;
3229

3330
public final class MavenWrapperDownloader
3431
{
35-
private static final String WRAPPER_VERSION = "3.1.1";
32+
private static final String WRAPPER_VERSION = "3.2.0";
3633

3734
private static final boolean VERBOSE = Boolean.parseBoolean( System.getenv( "MVNW_VERBOSE" ) );
3835

39-
/**
40-
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
41-
*/
42-
private static final String DEFAULT_DOWNLOAD_URL =
43-
"https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/" + WRAPPER_VERSION
44-
+ "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
45-
46-
/**
47-
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to use instead of the
48-
* default one.
49-
*/
50-
private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties";
51-
52-
/**
53-
* Path where the maven-wrapper.jar will be saved to.
54-
*/
55-
private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar";
56-
57-
/**
58-
* Name of the property which should be used to override the default download url for the wrapper.
59-
*/
60-
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
61-
6236
public static void main( String[] args )
6337
{
64-
if ( args.length == 0 )
65-
{
66-
System.err.println( " - ERROR projectBasedir parameter missing" );
67-
System.exit( 1 );
68-
}
38+
log( "Apache Maven Wrapper Downloader " + WRAPPER_VERSION );
6939

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 ) )
40+
if ( args.length != 2 )
7441
{
75-
System.err.println( " - ERROR projectBasedir not exists: " + projectBasedir );
42+
System.err.println( " - ERROR wrapperUrl or wrapperJarPath parameter missing" );
7643
System.exit( 1 );
7744
}
7845

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-
8646
try
8747
{
88-
Path outputFile = projectBasedir.resolve( MAVEN_WRAPPER_JAR_PATH );
89-
createDirectories( outputFile.getParent() );
90-
downloadFileFromURL( url, outputFile );
48+
log( " - Downloader started" );
49+
final URL wrapperUrl = new URL( args[0] );
50+
final String jarPath = args[1].replace( "..", "" ); // Sanitize path
51+
final Path wrapperJarPath = Paths.get( jarPath ).toAbsolutePath().normalize();
52+
downloadFileFromURL( wrapperUrl, wrapperJarPath );
9153
log( "Done" );
92-
System.exit( 0 );
9354
}
9455
catch ( IOException e )
9556
{
96-
System.err.println( "- Error downloading" );
97-
e.printStackTrace();
57+
System.err.println( "- Error downloading: " + e.getMessage() );
58+
if ( VERBOSE )
59+
{
60+
e.printStackTrace();
61+
}
9862
System.exit( 1 );
9963
}
10064
}
10165

102-
private static void downloadFileFromURL( String urlString, Path destination ) throws IOException
66+
private static void downloadFileFromURL( URL wrapperUrl, Path wrapperJarPath )
67+
throws IOException
10368
{
104-
log( " - Downloading to: " + destination );
69+
log( " - Downloading to: " + wrapperJarPath );
10570
if ( System.getenv( "MVNW_USERNAME" ) != null && System.getenv( "MVNW_PASSWORD" ) != null )
10671
{
10772
final String username = System.getenv( "MVNW_USERNAME" );
@@ -115,40 +80,11 @@ protected PasswordAuthentication getPasswordAuthentication()
11580
}
11681
} );
11782
}
118-
URL website = new URL( urlString );
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 ) )
83+
try ( InputStream inStream = wrapperUrl.openStream() )
13784
{
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-
}
85+
Files.copy( inStream, wrapperJarPath, StandardCopyOption.REPLACE_EXISTING );
14986
}
150-
log( " - Downloading from: " + url );
151-
return url;
87+
log( " - Downloader complete" );
15288
}
15389

15490
private static void log( String msg )

0 commit comments

Comments
 (0)