com.google.cloud.tools.appengine.operations.cloudsdk.process.ProcessHandler Java Examples
The following examples show how to use
com.google.cloud.tools.appengine.operations.cloudsdk.process.ProcessHandler.
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: DevAppServerStartTask.java From app-gradle-plugin with Apache License 2.0 | 6 votes |
/** Task entrypoint : start the dev appserver (non-blocking). */ @TaskAction public void startAction() throws AppEngineException, IOException { // Add a listener to write to a file for non-blocking starts, this really only works // when the gradle daemon is running (which is default for newer versions of gradle) File logFile = new File(devAppServerLoggingDir, "dev_appserver.out"); FileOutputLineListener logFileWriter = new FileOutputLineListener(logFile); Logger taskLogger = getLogger(); ProcessHandler processHandler = LegacyProcessHandler.builder() .addStdOutLineListener(taskLogger::lifecycle) .addStdOutLineListener(logFileWriter) .addStdErrLineListener(taskLogger::lifecycle) .addStdErrLineListener(logFileWriter) .setExitListener(new NonZeroExceptionExitListener()) .buildDevAppServerAsync(runConfig.getStartSuccessTimeout()); devServers.newDevAppServer(processHandler).run(runConfig.toRunConfiguration()); getLogger().lifecycle("Dev App Server output written to : " + logFile.getAbsolutePath()); }
Example #2
Source File: DeployAllTaskTest.java From app-gradle-plugin with Apache License 2.0 | 6 votes |
/** Setup DeployAllTaskTest. */ @Before public void setup() throws IOException { Project tempProject = ProjectBuilder.builder().build(); deployExtension = new DeployExtension(tempProject); deployExtension.setDeployTargetResolver(deployTargetResolver); deployCapture = ArgumentCaptor.forClass(DeployConfiguration.class); stageDir = tempFolder.newFolder("staging"); deployAllTask = tempProject.getTasks().create("tempDeployAllTask", DeployAllTask.class); deployAllTask.setDeployExtension(deployExtension); deployAllTask.setGcloud(gcloud); deployAllTask.setStageDirectory(stageDir); when(gcloud.newDeployment(Mockito.any(ProcessHandler.class))).thenReturn(deploy); }
Example #3
Source File: CloudSdkAppEngineFactory.java From app-maven-plugin with Apache License 2.0 | 6 votes |
private ProcessHandler newDevAppServerAsyncHandler(int timeout) { Path logDir = Paths.get(mojo.getMavenProject().getBuild().getDirectory()).resolve("dev-appserver-out"); if (!Files.exists(logDir)) { try { logDir = Files.createDirectories(logDir); } catch (IOException e) { throw new RuntimeException("Failed to create dev-appserver logging directory."); } } File logFile = logDir.resolve("dev_appserver.out").toFile(); FileOutputLineListener fileListener = new FileOutputLineListener(logFile); mojo.getLog().info("Dev App Server output written to : " + logFile); ProcessOutputLineListener lineListener = new DefaultProcessOutputLineListener(mojo.getLog()); return LegacyProcessHandler.builder() .addStdOutLineListener(lineListener) .addStdOutLineListener(fileListener) .addStdErrLineListener(lineListener) .addStdErrLineListener(fileListener) .setExitListener(new NonZeroExceptionExitListener()) .buildDevAppServerAsync(timeout); }
Example #4
Source File: LocalAppEngineServerBehaviour.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
private void initializeDevServer(MessageConsoleStream stdout, MessageConsoleStream stderr, Path javaHomePath) throws CloudSdkNotFoundException { MessageConsoleWriterListener stdoutListener = new MessageConsoleWriterListener(stdout); MessageConsoleWriterListener stderrListener = new MessageConsoleWriterListener(stderr); // dev_appserver output goes to stderr cloudSdk = new CloudSdk.Builder() .javaHome(javaHomePath) .build(); ProcessHandler processHandler = LegacyProcessHandler.builder() .addStdOutLineListener(stdoutListener).addStdErrLineListener(stderrListener) .addStdErrLineListener(serverOutputListener) .setStartListener(localAppEngineStartListener) .setExitListener(localAppEngineExitListener) .async(true) .build(); DevServers localRun = DevServers.builder(cloudSdk).build(); devServer = localRun.newDevAppServer(processHandler); moduleToUrlMap.clear(); }
Example #5
Source File: CloudSdkProcessWrapper.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** * Sets up a {@link CloudSdk} to be used for App Engine standard staging. * * @param javaHome JDK/JRE to 1) run {@code com.google.appengine.tools.admin.AppCfg} from * {@code appengine-tools-api.jar}; and 2) compile JSPs during staging */ public AppEngineWebXmlProjectStaging getAppEngineStandardStaging(Path javaHome, MessageConsoleStream stdoutOutputStream, MessageConsoleStream stderrOutputStream) throws CloudSdkNotFoundException { Preconditions.checkState(!initialized, "process wrapper already set up"); initialized = true; CloudSdk cloudSdk = javaHome == null ? new CloudSdk.Builder().build() : new CloudSdk.Builder().javaHome(javaHome).build(); ProcessHandler processHandler = LegacyProcessHandler.builder() .setStartListener(this::storeProcessObject) .setExitListener(this::recordProcessExitCode) .addStdOutLineListener(new MessageConsoleWriterListener(stdoutOutputStream)) .addStdErrLineListener(new MessageConsoleWriterListener(stderrOutputStream)) .build(); return AppCfg.builder(cloudSdk).build().newStaging(processHandler); }
Example #6
Source File: GcloudRunnerTest.java From appengine-plugins-core with Apache License 2.0 | 6 votes |
@Test public void testGcloudCommandEnvironment() { GcloudRunner gcloudRunner = new GcloudRunner( sdk, "intellij", // metrics env "99", // metrics env version mock(Path.class), // credential file null, // irrelevant to test "irrelevant-to-test", // output format "always", // show structured logs mock(ProcessBuilderFactory.class), mock(ProcessHandler.class)); Map<String, String> env = gcloudRunner.getGcloudCommandEnvironment(); assertEquals("0", env.get("CLOUDSDK_APP_USE_GSUTIL")); assertEquals("always", env.get("CLOUDSDK_CORE_SHOW_STRUCTURED_LOGS")); assertEquals("intellij", env.get("CLOUDSDK_METRICS_ENVIRONMENT")); assertEquals("99", env.get("CLOUDSDK_METRICS_ENVIRONMENT_VERSION")); assertEquals("1", env.get("CLOUDSDK_CORE_DISABLE_PROMPTS")); }
Example #7
Source File: GcloudRunner.java From appengine-plugins-core with Apache License 2.0 | 6 votes |
GcloudRunner newRunner( CloudSdk sdk, @Nullable String metricsEnvironment, @Nullable String metricsEnvironmentVersion, @Nullable Path credentialFile, @Nullable List<Path> flagsFiles, @Nullable String outputFormat, @Nullable String showStructuredLogs, ProcessHandler processHandler) { return new GcloudRunner( sdk, metricsEnvironment, metricsEnvironmentVersion, credentialFile, flagsFiles, outputFormat, showStructuredLogs, processBuilderFactory, processHandler); }
Example #8
Source File: GcloudRunner.java From appengine-plugins-core with Apache License 2.0 | 6 votes |
GcloudRunner( CloudSdk sdk, @Nullable String metricsEnvironment, @Nullable String metricsEnvironmentVersion, @Nullable Path credentialFile, @Nullable List<Path> flagsFiles, @Nullable String outputFormat, @Nullable String showStructuredLogs, ProcessBuilderFactory processBuilderFactory, ProcessHandler processHandler) { this.sdk = sdk; this.metricsEnvironment = metricsEnvironment; this.metricsEnvironmentVersion = metricsEnvironmentVersion; this.credentialFile = credentialFile; this.flagsFiles = flagsFiles; this.outputFormat = outputFormat; this.showStructuredLogs = showStructuredLogs; this.processBuilderFactory = processBuilderFactory; this.processHandler = processHandler; }
Example #9
Source File: CloudSdkOperations.java From app-gradle-plugin with Apache License 2.0 | 5 votes |
/** Create a return a new default configured process handler. */ public static ProcessHandler getDefaultHandler(Logger logger) { return LegacyProcessHandler.builder() .addStdErrLineListener(logger::lifecycle) .addStdOutLineListener(logger::lifecycle) .setExitListener(new NonZeroExceptionExitListener()) .build(); }
Example #10
Source File: CloudSdkAppEngineFactory.java From app-maven-plugin with Apache License 2.0 | 5 votes |
private ProcessHandler newDefaultProcessHandler() { ProcessOutputLineListener lineListener = new DefaultProcessOutputLineListener(mojo.getLog()); return LegacyProcessHandler.builder() .addStdOutLineListener(lineListener) .addStdErrLineListener(lineListener) .setExitListener(new NonZeroExceptionExitListener()) .build(); }
Example #11
Source File: CloudSdkStagingHelperTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
private AppEngineWebXmlProjectStaging setUpAppEngineStaging() throws CloudSdkNotFoundException, CoreException { createFile("WebContent/WEB-INF/appengine-web.xml", APPENGINE_WEB_XML); createFile("WebContent/WEB-INF/web.xml", WEB_XML); createFile("WebContent/META-INF/MANIFEST.MF", ""); CloudSdk cloudSdk = new CloudSdk.Builder().build(); AppCfg appCfg = AppCfg.builder(cloudSdk).build(); ProcessHandler processHandler = LegacyProcessHandler.builder().async(false).build(); return appCfg.newStaging(processHandler); }
Example #12
Source File: CloudSdkProcessWrapper.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
/** * Sets up a {@link CloudSdk} to be used for App Engine deploy. */ public Deployment getAppEngineDeployment(Path credentialFile, MessageConsoleStream normalOutputStream) throws CloudSdkNotFoundException { Preconditions.checkNotNull(credentialFile, "credential required for deploying"); Preconditions.checkArgument(Files.exists(credentialFile), "non-existing credential file"); Preconditions.checkState(!initialized, "process wrapper already set up"); initialized = true; CloudSdk cloudSdk = new CloudSdk.Builder().build(); Gcloud gcloud = Gcloud.builder(cloudSdk) .setCredentialFile(credentialFile.toFile().toPath()) .setMetricsEnvironment(CloudToolsInfo.METRICS_NAME, CloudToolsInfo.getToolsVersion()) .setShowStructuredLogs("always") // turns on gcloud structured log .setOutputFormat("json") // Deploy result will be in JSON. .build(); // Gcloud sends structured deploy result (in JSON format) to stdout, so prepare to capture that. stdOutCaptor = StringBuilderProcessOutputLineListener.newListenerWithNewlines(); // Gcloud sends structured gcloud logs (in JSON format) to stderr, so prepare to capture them. gcloudErrorMessageCollector = new GcloudStructuredLogErrorMessageCollector(); ProcessHandler processHandler = LegacyProcessHandler.builder() .setStartListener(this::storeProcessObject) .setExitListener(this::recordProcessExitCode) // Gcloud sends normal operation output to stderr. .addStdErrLineListener(new MessageConsoleWriterListener(normalOutputStream)) .addStdErrLineListener(gcloudErrorMessageCollector) .addStdOutLineListener(stdOutCaptor) .build(); return gcloud.newDeployment(processHandler); }
Example #13
Source File: Gcloud.java From appengine-plugins-core with Apache License 2.0 | 5 votes |
@VisibleForTesting GcloudRunner getRunner(ProcessHandler processHandler) { return gcloudRunnerFactory.newRunner( sdk, metricsEnvironment, metricsEnvironmentVersion, credentialFile, flagsFiles, // this is the only consumer of flagsFiles outputFormat, showStructuredLogs, processHandler); }
Example #14
Source File: Gcloud.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
public GenRepoInfoFile newGenRepoInfo(ProcessHandler processHandler) { return new GenRepoInfoFile(getRunner(processHandler)); }
Example #15
Source File: DevServers.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
public DevServer newDevAppServer(ProcessHandler processHandler) { return new DevServer(sdk, getRunner(processHandler)); }
Example #16
Source File: DevServers.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
@VisibleForTesting DevAppServerRunner getRunner(ProcessHandler processHandler) { return devAppServerRunnerFactory.newRunner(sdk, processHandler); }
Example #17
Source File: Gcloud.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
public Auth newAuth(ProcessHandler processHandler) { return new Auth(getRunner(processHandler)); }
Example #18
Source File: Gcloud.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
public Versions newVersions(ProcessHandler processHandler) { return new Versions(getRunner(processHandler)); }
Example #19
Source File: Gcloud.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
public Deployment newDeployment(ProcessHandler processHandler) { return new Deployment(getRunner(processHandler)); }
Example #20
Source File: AppCfg.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
@VisibleForTesting AppCfgRunner getRunner(ProcessHandler processHandler) { return appCfgRunnerFactory.newRunner(sdk, processHandler); }
Example #21
Source File: AppCfg.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
public AppEngineWebXmlProjectStaging newStaging(ProcessHandler processHandler) { return new AppEngineWebXmlProjectStaging(getRunner(processHandler)); }
Example #22
Source File: DevAppServerRunner.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
DevAppServerRunner newRunner(CloudSdk sdk, ProcessHandler processHandler) { return new DevAppServerRunner(sdk, processBuilderFactory, processHandler); }
Example #23
Source File: DevAppServerRunner.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
DevAppServerRunner( CloudSdk sdk, ProcessBuilderFactory processBuilderFactory, ProcessHandler processHandler) { this.sdk = sdk; this.processBuilderFactory = processBuilderFactory; this.processHandler = processHandler; }
Example #24
Source File: AppCfgRunner.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
AppCfgRunner newRunner(CloudSdk sdk, ProcessHandler processHandler) { return new AppCfgRunner(sdk, processBuilderFactory, processHandler); }
Example #25
Source File: AppCfgRunner.java From appengine-plugins-core with Apache License 2.0 | 4 votes |
AppCfgRunner( CloudSdk sdk, ProcessBuilderFactory processBuilderFactory, ProcessHandler processHandler) { this.sdk = sdk; this.processBuilderFactory = processBuilderFactory; this.processHandler = processHandler; }