in maven-wrapper/src/main/java/org/apache/maven/wrapper/Installer.java [63:123]
public Path createDist(WrapperConfiguration configuration) throws Exception {
URI distributionUrl = configuration.getDistribution();
boolean alwaysDownload = configuration.isAlwaysDownload();
boolean alwaysUnpack = configuration.isAlwaysUnpack();
boolean verifyDistributionSha256Sum =
!configuration.getDistributionSha256Sum().isEmpty();
PathAssembler.LocalDistribution localDistribution = pathAssembler.getDistribution(configuration);
Path localZipFile = localDistribution.getZipFile();
if (alwaysDownload || alwaysUnpack || Files.notExists(localZipFile)) {
Logger.info("Installing Maven distribution "
+ localDistribution.getDistributionDir().toAbsolutePath());
}
boolean downloaded = false;
if (alwaysDownload || Files.notExists(localZipFile)) {
Logger.info("Downloading " + distributionUrl);
Path tmpZipFile = localZipFile.resolveSibling(localZipFile.getFileName() + ".part");
Files.deleteIfExists(tmpZipFile);
download.download(distributionUrl, tmpZipFile);
Files.move(tmpZipFile, localZipFile, StandardCopyOption.REPLACE_EXISTING);
downloaded = Files.exists(localZipFile);
}
Path distDir = localDistribution.getDistributionDir();
List<Path> dirs = listDirs(distDir);
if (downloaded || alwaysUnpack || dirs.isEmpty()) {
if (verifyDistributionSha256Sum) {
verifier.verify(
localZipFile,
"distributionSha256Sum",
Verifier.SHA_256_ALGORITHM,
configuration.getDistributionSha256Sum());
}
for (Path dir : dirs) {
Logger.info("Deleting directory " + dir.toAbsolutePath());
deleteDir(dir);
}
Logger.info("Unzipping " + localZipFile.toAbsolutePath() + " to " + distDir.toAbsolutePath());
unzip(localZipFile, distDir);
dirs = listDirs(distDir);
if (dirs.isEmpty()) {
throw new RuntimeException(String.format(
Locale.ROOT,
"Maven distribution '%s' does not contain any directory."
+ " Expected to find exactly 1 directory.",
distDir));
}
setExecutablePermissions(dirs.get(0));
}
if (dirs.size() != 1) {
throw new RuntimeException(String.format(
Locale.ROOT,
"Maven distribution '%s' contains too many directories." + " Expected to find exactly 1 directory.",
distDir));
}
return dirs.get(0);
}