Пример #1
0
 public File createDist(
     URI distributionUrl, String distBase, String distPath, String zipBase, String zipPath)
     throws Exception {
   File gradleHome = pathAssembler.gradleHome(distBase, distPath, distributionUrl);
   if (!alwaysDownload && !alwaysUnpack && gradleHome.isDirectory()) {
     return gradleHome;
   }
   File localZipFile = pathAssembler.distZip(zipBase, zipPath, distributionUrl);
   if (alwaysDownload || !localZipFile.exists()) {
     File tmpZipFile = new File(localZipFile.getParentFile(), localZipFile.getName() + ".part");
     tmpZipFile.delete();
     System.out.println("Downloading " + distributionUrl);
     download.download(distributionUrl, tmpZipFile);
     tmpZipFile.renameTo(localZipFile);
   }
   if (gradleHome.isDirectory()) {
     System.out.println("Deleting directory " + gradleHome.getAbsolutePath());
     deleteDir(gradleHome);
   }
   File distDest = gradleHome.getParentFile();
   System.out.println(
       "Unzipping " + localZipFile.getAbsolutePath() + " to " + distDest.getAbsolutePath());
   unzip(localZipFile, distDest);
   if (!gradleHome.isDirectory()) {
     throw new RuntimeException(
         String.format(
             "Gradle distribution '%s' does not contain expected directory '%s'.",
             distributionUrl, gradleHome.getName()));
   }
   setExecutablePermissions(gradleHome);
   return gradleHome;
 }
Пример #2
0
  public File createDist(WrapperConfiguration configuration) throws Exception {
    final URI distributionUrl = configuration.getDistribution();

    final PathAssembler.LocalDistribution localDistribution =
        pathAssembler.getDistribution(configuration);
    final File distDir = localDistribution.getDistributionDir();
    final File localZipFile = localDistribution.getZipFile();

    return exclusiveFileAccessManager.access(
        localZipFile,
        new Callable<File>() {
          public File call() throws Exception {
            final File markerFile =
                new File(localZipFile.getParentFile(), localZipFile.getName() + ".ok");
            if (distDir.isDirectory() && markerFile.isFile()) {
              return getDistributionRoot(distDir, distDir.getAbsolutePath());
            }

            boolean needsDownload = !localZipFile.isFile();

            if (needsDownload) {
              File tmpZipFile =
                  new File(localZipFile.getParentFile(), localZipFile.getName() + ".part");
              tmpZipFile.delete();
              System.out.println("Downloading " + distributionUrl);
              download.download(distributionUrl, tmpZipFile);
              tmpZipFile.renameTo(localZipFile);
            }

            List<File> topLevelDirs = listDirs(distDir);
            for (File dir : topLevelDirs) {
              System.out.println("Deleting directory " + dir.getAbsolutePath());
              deleteDir(dir);
            }
            System.out.println(
                "Unzipping " + localZipFile.getAbsolutePath() + " to " + distDir.getAbsolutePath());
            unzip(localZipFile, distDir);

            File root = getDistributionRoot(distDir, distributionUrl.toString());
            setExecutablePermissions(root);
            markerFile.createNewFile();

            return root;
          }
        });
  }