Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
fix log messages and Java 8 code optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Nov 7, 2021
1 parent d17f051 commit 5e71ecd
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions maven-wrapper/src/main/java/org/apache/maven/wrapper/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ public Path createDist( WrapperConfiguration configuration )
{
distributionUrl = configuration.getDistribution();
}
Logger.info( "Downloading Maven binary from " + distributionUrl );

boolean alwaysDownload = configuration.isAlwaysDownload();
boolean alwaysUnpack = configuration.isAlwaysUnpack();

PathAssembler.LocalDistribution localDistribution = pathAssembler.getDistribution( configuration );

Logger.info( "Installing Maven distribution " + localDistribution.getDistributionDir().getFileName() );

Path localZipFile = localDistribution.getZipFile();
boolean downloaded = false;
if ( alwaysDownload || !Files.exists( localZipFile ) )
Expand All @@ -95,30 +97,27 @@ public Path createDist( WrapperConfiguration configuration )

if ( downloaded || alwaysUnpack || dirs.isEmpty() )
{
Files.walkFileTree( distDir.toAbsolutePath(), new SimpleFileVisitor<Path>()
for ( Path distSubDir : dirs )
{
@Override
public FileVisitResult postVisitDirectory( Path dir, IOException exc )
throws IOException
Logger.info( "Deleting directory " + distSubDir.toAbsolutePath() );
Files.walkFileTree( distSubDir.toAbsolutePath(), new SimpleFileVisitor<Path>()
{
if ( dir.getParent().equals( distDir ) )
@Override
public FileVisitResult postVisitDirectory( Path dir, IOException exc )
throws IOException
{
Logger.info( "Deleting directory " + distDir.toAbsolutePath() );
Files.delete( dir );
return FileVisitResult.CONTINUE;
}
return FileVisitResult.CONTINUE;
}

public FileVisitResult visitFile( Path file, BasicFileAttributes attrs )
throws IOException
{
if ( !file.getParent().equals( distDir ) )

public FileVisitResult visitFile( Path file, BasicFileAttributes attrs )
throws IOException
{
Files.delete( file );
}
return FileVisitResult.CONTINUE;
};
} );
return FileVisitResult.CONTINUE;
};
} );
}

Logger.info( "Unzipping " + localZipFile.toAbsolutePath() + " to " + distDir.toAbsolutePath() );
unzip( localZipFile, distDir );
Expand All @@ -128,15 +127,15 @@ public FileVisitResult visitFile( Path file, BasicFileAttributes attrs )
{
throw new RuntimeException( String.format(
"Maven distribution '%s' does not contain any directories. Expected to find exactly 1 directory.",
distributionUrl ) );
distDir ) );
}
setExecutablePermissions( dirs.get( 0 ) );
}
if ( dirs.size() != 1 )
{
throw new IllegalStateException( String.format(
"Maven distribution '%s' contains too many directories. Expected to find exactly 1 directory.",
distributionUrl ) );
distDir ) );
}
return dirs.get( 0 );
}
Expand All @@ -157,15 +156,15 @@ private void setExecutablePermissions( Path mavenHome )
{
return;
}
Path mavenCommand = mavenHome.resolve( "bin/mvn" );
Path binMvnScript = mavenHome.resolve( "bin/mvn" );
String errorMessage = null;
try
{
ProcessBuilder pb = new ProcessBuilder( "chmod", "755", mavenCommand.toString() );
ProcessBuilder pb = new ProcessBuilder( "chmod", "755", binMvnScript.toString() );
Process p = pb.start();
if ( p.waitFor() == 0 )
{
Logger.info( "Set executable permissions for: " + mavenCommand.toString() );
Logger.info( "Set executable permissions for " + binMvnScript.toString() );
}
else
{
Expand All @@ -188,8 +187,8 @@ private void setExecutablePermissions( Path mavenHome )
}
if ( errorMessage != null )
{
Logger.warn( "Could not set executable permissions for: " + mavenCommand );
Logger.warn( "Please do this manually if you want to use maven." );
Logger.warn( "Could not set executable permissions for " + binMvnScript );
Logger.warn( "Please do this manually if you want to use Maven." );
}
}

Expand Down

0 comments on commit 5e71ecd

Please sign in to comment.