From 5e71ecd681d0d5ad28cbb6fe72b5c7ca01aec3cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sun, 7 Nov 2021 16:28:14 +0100 Subject: [PATCH] fix log messages and Java 8 code optimisation --- .../org/apache/maven/wrapper/Installer.java | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/maven-wrapper/src/main/java/org/apache/maven/wrapper/Installer.java b/maven-wrapper/src/main/java/org/apache/maven/wrapper/Installer.java index b5c287f..a869643 100644 --- a/maven-wrapper/src/main/java/org/apache/maven/wrapper/Installer.java +++ b/maven-wrapper/src/main/java/org/apache/maven/wrapper/Installer.java @@ -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 ) ) @@ -95,30 +97,27 @@ public Path createDist( WrapperConfiguration configuration ) if ( downloaded || alwaysUnpack || dirs.isEmpty() ) { - Files.walkFileTree( distDir.toAbsolutePath(), new SimpleFileVisitor() + 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() { - 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 ); @@ -128,7 +127,7 @@ 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 ) ); } @@ -136,7 +135,7 @@ public FileVisitResult visitFile( Path file, BasicFileAttributes attrs ) { throw new IllegalStateException( String.format( "Maven distribution '%s' contains too many directories. Expected to find exactly 1 directory.", - distributionUrl ) ); + distDir ) ); } return dirs.get( 0 ); } @@ -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 { @@ -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." ); } }