Skip to content

Commit b0c5a76

Browse files
jorsolhboutemy
authored andcommitted
[MWRAPPER-43] Make jar download quiet by default
Signed-off-by: Jorge Solórzano <jorsol@gmail.com>
1 parent 0cc43ce commit b0c5a76

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

maven-wrapper-distribution/src/resources/mvn/wrapper/MavenWrapperDownloader.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class MavenWrapperDownloader
2626
{
2727
private static final String WRAPPER_VERSION = "@project.version@";
2828

29+
private static final boolean VERBOSE = Boolean.parseBoolean( System.getenv( "MVNW_VERBOSE" ) );
30+
2931
/**
3032
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
3133
*/
@@ -51,9 +53,9 @@ public class MavenWrapperDownloader
5153

5254
public static void main( String args[] )
5355
{
54-
System.out.println( "- Downloader started" );
56+
log( " - Downloader started" );
5557
File baseDirectory = new File( args[0] );
56-
System.out.println( "- Using base directory: " + baseDirectory.getAbsolutePath() );
58+
log( " - Using base directory: " + baseDirectory.getAbsolutePath() );
5759

5860
// If the maven-wrapper.properties exists, read it and check if it contains a custom
5961
// wrapperUrl parameter.
@@ -71,7 +73,7 @@ public static void main( String args[] )
7173
}
7274
catch ( IOException e )
7375
{
74-
System.out.println( "- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'" );
76+
System.err.println( " - ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'" );
7577
}
7678
finally
7779
{
@@ -88,27 +90,27 @@ public static void main( String args[] )
8890
}
8991
}
9092
}
91-
System.out.println( "- Downloading from: " + url );
93+
log( " - Downloading from: " + url );
9294

9395
File outputFile = new File( baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH );
9496
if ( !outputFile.getParentFile().exists() )
9597
{
9698
if ( !outputFile.getParentFile().mkdirs() )
9799
{
98-
System.out.println( "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath()
100+
System.err.println( "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath()
99101
+ "'" );
100102
}
101103
}
102-
System.out.println( "- Downloading to: " + outputFile.getAbsolutePath() );
104+
log( " - Downloading to: " + outputFile.getAbsolutePath() );
103105
try
104106
{
105107
downloadFileFromURL( url, outputFile );
106-
System.out.println( "Done" );
108+
log( "Done" );
107109
System.exit( 0 );
108110
}
109111
catch ( Throwable e )
110112
{
111-
System.out.println( "- Error downloading" );
113+
System.err.println( "- Error downloading" );
112114
e.printStackTrace();
113115
System.exit( 1 );
114116
}
@@ -139,4 +141,12 @@ protected PasswordAuthentication getPasswordAuthentication()
139141
rbc.close();
140142
}
141143

144+
private static void log( String msg )
145+
{
146+
if ( VERBOSE )
147+
{
148+
System.out.println( msg );
149+
}
150+
}
151+
142152
}

maven-wrapper-distribution/src/resources/mvnw

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,26 @@ else
233233
fi
234234

235235
if command -v wget > /dev/null; then
236+
QUIET="--quiet"
236237
if [ "$MVNW_VERBOSE" = true ]; then
237238
echo "Found wget ... using wget"
239+
QUIET=""
238240
fi
239241
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
240-
wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
242+
wget $QUIET "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
241243
else
242-
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
244+
wget $QUIET --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
243245
fi
244246
elif command -v curl > /dev/null; then
247+
QUIET="--silent"
245248
if [ "$MVNW_VERBOSE" = true ]; then
246249
echo "Found curl ... using curl"
250+
QUIET=""
247251
fi
248252
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
249-
curl -o "$wrapperJarPath" "$jarUrl" -f
253+
curl $QUIET -o "$wrapperJarPath" "$jarUrl" -f
250254
else
251-
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
255+
curl $QUIET --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
252256
fi
253257

254258
else

0 commit comments

Comments
 (0)