org.codehaus.plexus.archiver.tar.TarGZipUnArchiver Java Examples

The following examples show how to use org.codehaus.plexus.archiver.tar.TarGZipUnArchiver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamoDBLocal.java    From geowave with Apache License 2.0 6 votes vote down vote up
protected boolean install() throws IOException {
  HttpURLConnection.setFollowRedirects(true);
  final URL url = new URL(DYNDB_URL + DYNDB_TAR);

  final File downloadFile = new File(dynLocalDir, DYNDB_TAR);
  if (!downloadFile.exists()) {
    try (FileOutputStream fos = new FileOutputStream(downloadFile)) {
      IOUtils.copyLarge(url.openStream(), fos);
      fos.flush();
    }
  }

  final TarGZipUnArchiver unarchiver = new TarGZipUnArchiver();
  unarchiver.enableLogging(new ConsoleLogger(Logger.WARN, "DynamoDB Local Unarchive"));
  unarchiver.setSourceFile(downloadFile);
  unarchiver.setDestDirectory(dynLocalDir);
  unarchiver.extract();

  if (!downloadFile.delete()) {
    LOGGER.warn("cannot delete " + downloadFile.getAbsolutePath());
  }

  // Check the install
  if (!isInstalled()) {
    LOGGER.error("DynamoDB Local install failed");
    return false;
  }

  return true;
}
 
Example #2
Source File: ArchiveUtil.java    From elasticsearch-maven-plugin with Apache License 2.0 5 votes vote down vote up
public static void extractTarGz(File archiveFile, File targetDir) {
	TarGZipUnArchiver unArchiver = new TarGZipUnArchiver(archiveFile);
	unArchiver.setDestDirectory(targetDir);
	// We don't want logging, but this is necessary to avoid an NPE
	unArchiver.enableLogging(new ConsoleLogger(ConsoleLogger.LEVEL_DISABLED, "console"));
	unArchiver.extract();
}
 
Example #3
Source File: TarGzArchive.java    From dropwizard-experiment with MIT License 5 votes vote down vote up
/**
 * Unpack a .tar.gz archive and return the folder it was unpacked in.
 *
 * @param tarGz The archive
 * @return The unpacked folder
 */
public static File unpack(File tarGz) {
    File unpackDir = Files.createTempDir();
    unpackDir.deleteOnExit();

    TarGZipUnArchiver unArchiver = new TarGZipUnArchiver(tarGz);
    // Needed to avoid a null pointer...
    unArchiver.enableLogging(new ConsoleLogger(Logger.LEVEL_DISABLED, "console"));
    unArchiver.setDestDirectory(unpackDir);
    unArchiver.extract();

    return unpackDir;
}
 
Example #4
Source File: TarGzArchiveTest.java    From dropwizard-experiment with MIT License 5 votes vote down vote up
private List<File> unpack(File tgzFile) {
    TarGZipUnArchiver unarchiver = new TarGZipUnArchiver(tgzFile);
    unarchiver.enableLogging(new ConsoleLogger(Logger.LEVEL_DISABLED, "console"));
    unarchiver.setDestDirectory(unpackDir);
    unarchiver.extract();

    return ImmutableList.copyOf(unpackDir.listFiles());
}
 
Example #5
Source File: KuduLocal.java    From geowave with Apache License 2.0 4 votes vote down vote up
private boolean install() throws IOException, ArchiveException {
  LOGGER.info("Installing {}", KUDU_DEB_PACKAGE);

  LOGGER.debug("downloading kudu debian package");
  final File debPackageFile = new File(kuduLocalDir, KUDU_DEB_PACKAGE);
  if (!debPackageFile.exists()) {
    HttpURLConnection.setFollowRedirects(true);
    final URL url = new URL(KUDU_REPO_URL + KUDU_DEB_PACKAGE);
    try (FileOutputStream fos = new FileOutputStream(debPackageFile)) {
      IOUtils.copy(url.openStream(), fos);
      fos.flush();
    }
  }

  LOGGER.debug("extracting kudu debian package data contents");
  final File debDataTarGz = new File(kuduLocalDir, "data.tar.gz");
  if (!debDataTarGz.exists()) {
    try (FileInputStream fis = new FileInputStream(debPackageFile);
        ArchiveInputStream debInputStream =
            new ArchiveStreamFactory().createArchiveInputStream("ar", fis)) {
      ArchiveEntry entry = null;
      while ((entry = debInputStream.getNextEntry()) != null) {
        if (debDataTarGz.getName().equals(entry.getName())) {
          try (FileOutputStream fos = new FileOutputStream(debDataTarGz)) {
            IOUtils.copy(debInputStream, fos);
          }
          break;
        }
      }
    }
  }

  LOGGER.debug("extracting kudu data contents");
  final TarGZipUnArchiver unarchiver = new TarGZipUnArchiver();
  unarchiver.enableLogging(new ConsoleLogger(Logger.WARN, "Kudu Local Unarchive"));
  unarchiver.setSourceFile(debDataTarGz);
  unarchiver.setDestDirectory(kuduLocalDir);
  unarchiver.extract();

  for (final File f : new File[] {debPackageFile, debDataTarGz}) {
    if (!f.delete()) {
      LOGGER.warn("cannot delete {}", f.getAbsolutePath());
    }
  }

  LOGGER.debug("moving kudu master and tablet binaries to {}", kuduLocalDir);
  // move the master and tablet server binaries into the kudu local directory
  final Path kuduBin =
      Paths.get(kuduLocalDir.getAbsolutePath(), "usr", "lib", "kudu", "sbin-release");
  final File kuduMasterBinary = kuduBin.resolve(KUDU_MASTER).toFile();
  final File kuduTabletBinary = kuduBin.resolve(KUDU_TABLET).toFile();
  kuduMasterBinary.setExecutable(true);
  kuduTabletBinary.setExecutable(true);
  FileUtils.moveFileToDirectory(kuduMasterBinary, kuduLocalDir, false);
  FileUtils.moveFileToDirectory(kuduTabletBinary, kuduLocalDir, false);

  if (isInstalled()) {
    LOGGER.info("Kudu Local installation successful");
    return true;
  } else {
    LOGGER.error("Kudu Local installation failed");
    return false;
  }
}
 
Example #6
Source File: BigtableEmulator.java    From geowave with Apache License 2.0 4 votes vote down vote up
protected boolean install() throws IOException {
  final URL url = new URL(downloadUrl + "/" + fileName);

  final File downloadFile = new File(sdkDir.getParentFile(), fileName);
  if (!downloadFile.exists()) {
    try (FileOutputStream fos = new FileOutputStream(downloadFile)) {
      IOUtils.copyLarge(url.openStream(), fos);
      fos.flush();
    }
  }
  if (downloadFile.getName().endsWith(".zip")) {
    ZipUtils.unZipFile(downloadFile, sdkDir.getAbsolutePath());
  } else if (downloadFile.getName().endsWith(".tar.gz")) {
    final TarGZipUnArchiver unarchiver = new TarGZipUnArchiver();
    unarchiver.enableLogging(new ConsoleLogger(Logger.LEVEL_WARN, "Gcloud SDK Unarchive"));
    unarchiver.setSourceFile(downloadFile);
    unarchiver.setDestDirectory(sdkDir);
    unarchiver.extract();
  }
  if (!downloadFile.delete()) {
    LOGGER.warn("cannot delete " + downloadFile.getAbsolutePath());
  }
  // Check the install
  if (!isInstalled()) {
    LOGGER.error("Gcloud install failed");
    return false;
  }

  // Install the beta components
  final File gcloudExe = new File(sdkDir, GCLOUD_EXE_DIR + "/gcloud");

  final CommandLine cmdLine = new CommandLine(gcloudExe);
  cmdLine.addArgument("components");
  cmdLine.addArgument("install");
  cmdLine.addArgument("beta");
  cmdLine.addArgument("--quiet");
  final DefaultExecutor executor = new DefaultExecutor();
  final int exitValue = executor.execute(cmdLine);

  return (exitValue == 0);
}