in appengine-plugins-core/src/main/java/com/google/cloud/tools/managedcloudsdk/install/SdkInstaller.java [78:156]
public Path install(
final ProgressListener progressListener, final ConsoleListener consoleListener)
throws IOException, InterruptedException, SdkInstallerException, CommandExecutionException,
CommandExitException {
FileResourceProvider fileResourceProvider =
fileResourceProviderFactory.newFileResourceProvider();
// Cleanup, remove old downloaded archive if exists
if (Files.isRegularFile(fileResourceProvider.getArchiveDestination())) {
logger.info("Removing stale archive: " + fileResourceProvider.getArchiveDestination());
Files.delete(fileResourceProvider.getArchiveDestination());
}
// Cleanup, remove old SDK directory if exists
if (Files.exists(fileResourceProvider.getArchiveExtractionDestination())) {
logger.info(
"Removing stale install: " + fileResourceProvider.getArchiveExtractionDestination());
MoreFiles.deleteRecursively(
fileResourceProvider.getArchiveExtractionDestination(),
RecursiveDeleteOption.ALLOW_INSECURE);
}
progressListener.start("Installing Cloud SDK", installerFactory != null ? 300 : 200);
// download and verify
Downloader downloader =
downloaderFactory.newDownloader(
fileResourceProvider.getArchiveSource(),
fileResourceProvider.getArchiveDestination(),
progressListener.newChild(100));
downloader.download();
if (!Files.isRegularFile(fileResourceProvider.getArchiveDestination())) {
throw new SdkInstallerException(
"Download succeeded but valid archive not found at "
+ fileResourceProvider.getArchiveDestination());
}
try {
// extract and verify
extractorFactory
.newExtractor(
fileResourceProvider.getArchiveDestination(),
fileResourceProvider.getArchiveExtractionDestination(),
progressListener.newChild(100))
.extract();
if (!Files.isDirectory(fileResourceProvider.getExtractedSdkHome())) {
throw new SdkInstallerException(
"Extraction succeeded but valid sdk home not found at "
+ fileResourceProvider.getExtractedSdkHome());
}
} catch (UnknownArchiveTypeException e) {
// fileResourceProviderFactory.newFileResourceProvider() creates a fileResourceProvider that
// returns either .tar.gz or .zip for getArchiveDestination().
throw new RuntimeException(e);
}
// install if necessary
if (installerFactory != null) {
installerFactory
.newInstaller(
fileResourceProvider.getExtractedSdkHome(),
progressListener.newChild(100),
consoleListener,
environmentVariables)
.install();
}
// verify final state
if (!Files.isRegularFile(fileResourceProvider.getExtractedGcloud())) {
throw new SdkInstallerException(
"Installation succeeded but gcloud executable not found at "
+ fileResourceProvider.getExtractedGcloud());
}
progressListener.done();
return fileResourceProvider.getExtractedSdkHome();
}