示例#1
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;
          }
        });
  }