[MWRAPPER-43] Make jar download quiet by default
Signed-off-by: Jorge Solórzano <jorsol@gmail.com>
diff --git a/maven-wrapper-distribution/src/resources/mvn/wrapper/MavenWrapperDownloader.java b/maven-wrapper-distribution/src/resources/mvn/wrapper/MavenWrapperDownloader.java
index 8bc2bc3..b7612e5 100644
--- a/maven-wrapper-distribution/src/resources/mvn/wrapper/MavenWrapperDownloader.java
+++ b/maven-wrapper-distribution/src/resources/mvn/wrapper/MavenWrapperDownloader.java
@@ -26,6 +26,8 @@
{
private static final String WRAPPER_VERSION = "@project.version@";
+ private static final boolean VERBOSE = Boolean.parseBoolean( System.getenv( "MVNW_VERBOSE" ) );
+
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
@@ -51,9 +53,9 @@
public static void main( String args[] )
{
- System.out.println( "- Downloader started" );
+ log( " - Downloader started" );
File baseDirectory = new File( args[0] );
- System.out.println( "- Using base directory: " + baseDirectory.getAbsolutePath() );
+ log( " - Using base directory: " + baseDirectory.getAbsolutePath() );
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
@@ -71,7 +73,7 @@
}
catch ( IOException e )
{
- System.out.println( "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'" );
+ System.err.println( " - ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'" );
}
finally
{
@@ -88,27 +90,27 @@
}
}
}
- System.out.println( "- Downloading from: " + url );
+ log( " - Downloading from: " + url );
File outputFile = new File( baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH );
if ( !outputFile.getParentFile().exists() )
{
if ( !outputFile.getParentFile().mkdirs() )
{
- System.out.println( "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath()
+ System.err.println( "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath()
+ "'" );
}
}
- System.out.println( "- Downloading to: " + outputFile.getAbsolutePath() );
+ log( " - Downloading to: " + outputFile.getAbsolutePath() );
try
{
downloadFileFromURL( url, outputFile );
- System.out.println( "Done" );
+ log( "Done" );
System.exit( 0 );
}
catch ( Throwable e )
{
- System.out.println( "- Error downloading" );
+ System.err.println( "- Error downloading" );
e.printStackTrace();
System.exit( 1 );
}
@@ -139,4 +141,12 @@
rbc.close();
}
+ private static void log( String msg )
+ {
+ if ( VERBOSE )
+ {
+ System.out.println( msg );
+ }
+ }
+
}
diff --git a/maven-wrapper-distribution/src/resources/mvnw b/maven-wrapper-distribution/src/resources/mvnw
index 1a0654d..b2dbf0e 100755
--- a/maven-wrapper-distribution/src/resources/mvnw
+++ b/maven-wrapper-distribution/src/resources/mvnw
@@ -233,22 +233,26 @@
fi
if command -v wget > /dev/null; then
+ QUIET="--quiet"
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
+ QUIET=""
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
- wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
+ wget $QUIET "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
else
- wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
+ wget $QUIET --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
fi
elif command -v curl > /dev/null; then
+ QUIET="--silent"
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
+ QUIET=""
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
- curl -o "$wrapperJarPath" "$jarUrl" -f
+ curl $QUIET -o "$wrapperJarPath" "$jarUrl" -f
else
- curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
+ curl $QUIET --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
fi
else