com.google.cloud.tools.managedcloudsdk.ConsoleListener Java Examples
The following examples show how to use
com.google.cloud.tools.managedcloudsdk.ConsoleListener.
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: CloudSdkUpdateJobTest.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@Test public void testRun_sdkInstalled_updateFailed() throws ManagedSdkVerificationException, ManagedSdkVersionMismatchException, InterruptedException, CommandExitException, CommandExecutionException { when(managedCloudSdk.isInstalled()).thenReturn(true); when(managedCloudSdk.isUpToDate()).thenReturn(false); when(managedCloudSdk.newUpdater()).thenReturn(sdkUpdater); CommandExecutionException exception = new CommandExecutionException(new RuntimeException()); doThrow(exception).when(sdkUpdater) .update(any(ProgressListener.class), any(ConsoleListener.class)); CloudSdkUpdateJob job = newCloudSdkUpdateJob(); job.schedule(); job.join(); assertEquals(IStatus.ERROR, job.getResult().getSeverity()); assertEquals(exception, job.getResult().getException()); verify(managedCloudSdk).isInstalled(); verify(managedCloudSdk).isUpToDate(); verify(managedCloudSdk).newUpdater(); verify(sdkUpdater).update(any(ProgressListener.class), any(ConsoleListener.class)); verify(managedCloudSdk).getSdkHome(); // used to obtain old version verifyNoMoreInteractions(managedCloudSdk); }
Example #2
Source File: CloudSdkUpdateJobTest.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@Test public void testRun_sdkInstalled_updateSuccess() throws ManagedSdkVerificationException, ManagedSdkVersionMismatchException, InterruptedException, CommandExecutionException, CommandExitException { when(managedCloudSdk.isInstalled()).thenReturn(true); when(managedCloudSdk.isUpToDate()).thenReturn(false); when(managedCloudSdk.newUpdater()).thenReturn(sdkUpdater); CloudSdkUpdateJob job = newCloudSdkUpdateJob(); job.schedule(); job.join(); assertTrue(job.getResult().isOK()); verify(managedCloudSdk).isInstalled(); verify(managedCloudSdk).isUpToDate(); verify(managedCloudSdk).newUpdater(); verify(sdkUpdater).update(any(ProgressListener.class), any(ConsoleListener.class)); verify(managedCloudSdk, times(2)).getSdkHome(); // used to log old and new versions verifyNoMoreInteractions(managedCloudSdk); }
Example #3
Source File: CommandRunner.java From appengine-plugins-core with Apache License 2.0 | 6 votes |
/** Run the command and wait for completion. */ public void run( List<String> command, @Nullable Path workingDirectory, @Nullable Map<String, String> environment, ConsoleListener consoleListener) throws InterruptedException, CommandExitException, CommandExecutionException { ProcessExecutor processExecutor = processExecutorSupplier.get(); try { int exitCode = processExecutor.run( command, workingDirectory, environment, streamHandlerFactory.newHandler(consoleListener), streamHandlerFactory.newHandler(consoleListener)); if (exitCode != 0) { throw new CommandExitException(exitCode); } } catch (IOException ex) { throw new CommandExecutionException(ex); } }
Example #4
Source File: SdkComponentInstaller.java From appengine-plugins-core with Apache License 2.0 | 6 votes |
/** * Install a component. * * @param component component to install * @param progressListener listener to action progress feedback * @param consoleListener listener to process console feedback */ public void installComponent( SdkComponent component, ProgressListener progressListener, ConsoleListener consoleListener) throws InterruptedException, CommandExitException, CommandExecutionException { progressListener.start("Installing " + component.toString(), ProgressListener.UNKNOWN); Map<String, String> environment = null; if (pythonCopier != null) { environment = pythonCopier.copyPython(); } Path workingDirectory = gcloudPath.getRoot(); List<String> command = Arrays.asList( gcloudPath.toString(), "components", "install", component.toString(), "--quiet"); commandRunner.run(command, workingDirectory, environment, consoleListener); progressListener.done(); }
Example #5
Source File: CloudSdkInstallJobTest.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@Test public void testRun_notInstalled() throws ManagedSdkVerificationException, ManagedSdkVersionMismatchException, InterruptedException, IOException, SdkInstallerException, CommandExecutionException, CommandExitException { when(managedCloudSdk.isInstalled()).thenReturn(false); when(managedCloudSdk.hasComponent(any(SdkComponent.class))).thenReturn(false); CloudSdkInstallJob job = newCloudSdkInstallJob(); job.schedule(); job.join(); assertTrue(job.getResult().isOK()); verify(managedCloudSdk).newInstaller(); verify(managedCloudSdk).newComponentInstaller(); verify(sdkInstaller).install(any(ProgressListener.class), any(ConsoleListener.class)); verify(componentInstaller) .installComponent( any(SdkComponent.class), any(ProgressListener.class), any(ConsoleListener.class)); }
Example #6
Source File: CloudSdkInstallJobTest.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@Test public void testFailureSeverity() throws ManagedSdkVerificationException, ManagedSdkVersionMismatchException, InterruptedException, IOException, SdkInstallerException, CommandExecutionException, CommandExitException { when(managedCloudSdk.isInstalled()).thenReturn(false); when(managedCloudSdk.hasComponent(any(SdkComponent.class))).thenReturn(false); SdkInstallerException installerException = new SdkInstallerException("unsupported"); when(managedCloudSdk.newInstaller()).thenReturn(sdkInstaller); when(sdkInstaller.install(any(ProgressWrapper.class), any(ConsoleListener.class))) .thenThrow(installerException); CloudSdkInstallJob job = newCloudSdkInstallJob(); job.schedule(); job.join(); IStatus result = job.getResult(); assertEquals(IStatus.WARNING, result.getSeverity()); assertEquals("Failed to install the Google Cloud SDK.", result.getMessage()); assertEquals(installerException, result.getException()); }
Example #7
Source File: CloudSdkInstallJobTest.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@Test public void testRun_sdkInstalled_componentNotInstalled() throws ManagedSdkVerificationException, ManagedSdkVersionMismatchException, InterruptedException, CommandExecutionException, CommandExitException { when(managedCloudSdk.isInstalled()).thenReturn(true); when(managedCloudSdk.hasComponent(any(SdkComponent.class))).thenReturn(false); CloudSdkInstallJob job = newCloudSdkInstallJob(); job.schedule(); job.join(); assertTrue(job.getResult().isOK()); verify(managedCloudSdk, never()).newInstaller(); verify(managedCloudSdk).newComponentInstaller(); verify(componentInstaller) .installComponent( any(SdkComponent.class), any(ProgressListener.class), any(ConsoleListener.class)); }
Example #8
Source File: DownloadCloudSdkTask.java From app-gradle-plugin with Apache License 2.0 | 5 votes |
/** Task entrypoint : Download/update Cloud SDK. */ @TaskAction public void downloadCloudSdkAction() throws ManagedSdkVerificationException, ManagedSdkVersionMismatchException, InterruptedException, CommandExecutionException, SdkInstallerException, CommandExitException, IOException { // managedCloudSdk is set by AppEngineCorePluginConfiguration if the cloud SDK home is empty if (managedCloudSdk == null) { throw new GradleException("Cloud SDK home path must not be configured to run this task."); } ProgressListener progressListener = new NoOpProgressListener(); ConsoleListener consoleListener = new DownloadCloudSdkTaskConsoleListener(getProject()); // Install sdk if not installed if (!managedCloudSdk.isInstalled()) { SdkInstaller installer = managedCloudSdk.newInstaller(); installer.install(progressListener, consoleListener); } // install components if (components != null) { for (SdkComponent component : components) { if (!managedCloudSdk.hasComponent(component)) { managedCloudSdk .newComponentInstaller() .installComponent(component, progressListener, consoleListener); } } } // If version is set to LATEST, update Cloud SDK if (!managedCloudSdk.isUpToDate()) { SdkUpdater updater = managedCloudSdk.newUpdater(); updater.update(progressListener, consoleListener); } }
Example #9
Source File: InstallerFactory.java From appengine-plugins-core with Apache License 2.0 | 5 votes |
/** * Returns a new {@link Installer} instance. * * @param installedSdkRoot path to the Cloud SDK directory * @param progressListener listener on installer script output * @return a {@link Installer} instance. */ Installer newInstaller( Path installedSdkRoot, ProgressListener progressListener, ConsoleListener consoleListener) { return new Installer( installedSdkRoot, getInstallScriptProvider(), usageReporting, progressListener, consoleListener, CommandRunner.newRunner()); }
Example #10
Source File: Installer.java From appengine-plugins-core with Apache License 2.0 | 5 votes |
/** Instantiated by {@link InstallerFactory}. */ Installer( Path installedSdkRoot, InstallScriptProvider installScriptProvider, boolean usageReporting, ProgressListener progressListener, ConsoleListener consoleListener, CommandRunner commandRunner) { this.installedSdkRoot = installedSdkRoot; this.installScriptProvider = installScriptProvider; this.usageReporting = usageReporting; this.progressListener = progressListener; this.consoleListener = consoleListener; this.commandRunner = commandRunner; }
Example #11
Source File: SdkUpdater.java From appengine-plugins-core with Apache License 2.0 | 5 votes |
/** * Update the Cloud SDK. * * @param progressListener listener to action progress feedback * @param consoleListener listener to process console feedback */ public void update(ProgressListener progressListener, ConsoleListener consoleListener) throws InterruptedException, CommandExitException, CommandExecutionException { progressListener.start("Updating Cloud SDK", ProgressListener.UNKNOWN); Map<String, String> environment = null; if (pythonCopier != null) { environment = pythonCopier.copyPython(); } Path workingDirectory = gcloudPath.getRoot(); List<String> command = Arrays.asList(gcloudPath.toString(), "components", "update", "--quiet"); commandRunner.run(command, workingDirectory, environment, consoleListener); progressListener.done(); }
Example #12
Source File: SdkComponentInstallerTest.java From appengine-plugins-core with Apache License 2.0 | 5 votes |
@Test public void testInstallComponent_workingDirectorySet() throws InterruptedException, CommandExitException, CommandExecutionException { SdkComponentInstaller testInstaller = new SdkComponentInstaller(fakeGcloudPath, mockCommandRunner, null); testInstaller.installComponent(testComponent, mockProgressListener, mockConsoleListener); Mockito.verify(mockCommandRunner) .run( Mockito.anyList(), Mockito.eq(fakeGcloudPath.getRoot()), Mockito.<Map<String, String>>any(), Mockito.any(ConsoleListener.class)); }
Example #13
Source File: SdkUpdaterTest.java From appengine-plugins-core with Apache License 2.0 | 5 votes |
@Test public void testInstallComponent_workingDirectorySet() throws InterruptedException, CommandExitException, CommandExecutionException { SdkUpdater testUpdater = new SdkUpdater(fakeGcloudPath, mockCommandRunner, null); testUpdater.update(mockProgressListener, mockConsoleListener); Mockito.verify(mockCommandRunner) .run( Mockito.anyList(), Mockito.eq(fakeGcloudPath.getRoot()), Mockito.<Map<String, String>>any(), Mockito.any(ConsoleListener.class)); }
Example #14
Source File: CloudSdkDownloader.java From app-maven-plugin with Apache License 2.0 | 4 votes |
/** * Downloads/installs/updates the Cloud SDK. * * @return The cloud SDK installation directory */ public Path downloadIfNecessary( String version, Log log, List<SdkComponent> components, boolean offline) { ManagedCloudSdk managedCloudSdk = managedCloudSdkFactory.apply(version); if (offline) { // in offline mode, don't download anything return managedCloudSdk.getSdkHome(); } try { ProgressListener progressListener = new NoOpProgressListener(); ConsoleListener consoleListener = new CloudSdkDownloaderConsoleListener(log); if (!managedCloudSdk.isInstalled()) { managedCloudSdk.newInstaller().install(progressListener, consoleListener); } // install requested components if (components != null) { for (SdkComponent component : components) { if (!managedCloudSdk.hasComponent(component)) { managedCloudSdk .newComponentInstaller() .installComponent(component, progressListener, consoleListener); } } } if (!managedCloudSdk.isUpToDate()) { managedCloudSdk.newUpdater().update(progressListener, consoleListener); } return managedCloudSdk.getSdkHome(); } catch (IOException | SdkInstallerException | ManagedSdkVersionMismatchException | InterruptedException | CommandExecutionException | CommandExitException | ManagedSdkVerificationException ex) { throw new RuntimeException(ex); } }
Example #15
Source File: AsyncStreamHandlerFactory.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
ConsoleListenerForwardingByteHandler(ConsoleListener consoleListener) { this.consoleListener = consoleListener; }
Example #16
Source File: SdkInstaller.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
/** Download and install a new Cloud SDK. */ 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) .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(); }
Example #17
Source File: AsyncStreamHandlerFactory.java From appengine-plugins-core with Apache License 2.0 | 2 votes |
/** * Create a new AsyncStreamHandler using the {@link ConsoleListenerForwardingByteHandler} * implementation. */ AsyncStreamHandler newHandler(ConsoleListener consoleListener) { return new AsyncByteConsumer(new ConsoleListenerForwardingByteHandler(consoleListener)); }