use of com.google.cloud.tools.intellij.appengine.cloud.executor.AppEngineStandardRunTask in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudSdkStartupPolicy method createStartupScriptHelper.
@Nullable
@Override
public ScriptHelper createStartupScriptHelper(final ProgramRunner programRunner) {
return new ScriptHelper() {
@Nullable
@Override
public ExecutableObject getDefaultScript(final CommonModel commonModel) {
return new ExecutableObject() {
@Override
public String getDisplayString() {
return GctBundle.getString("appengine.run.startupscript.name");
}
@Override
public OSProcessHandler createProcessHandler(String workingDirectory, Map<String, String> configuredEnvironment) throws ExecutionException {
try {
CloudSdkServiceManager.getInstance().blockUntilSdkReady(commonModel.getProject(), GctBundle.getString("appengine.run.startupscript"), new CloudSdkStatusHandler() {
@Override
public void log(String s) {
logger.info("Cloud SDK precondition check reported: " + s);
}
@Override
public void onError(String s) {
logger.warn("Cloud SDK precondition check reported error: " + s);
}
@Override
public void onUserCancel() {
}
@Override
public String getErrorMessage(SdkStatus sdkStatus) {
switch(sdkStatus) {
case INVALID:
case NOT_AVAILABLE:
return GctBundle.message("appengine.run.server.sdk.misconfigured.message");
default:
return "";
}
}
});
} catch (InterruptedException e) {
// should not happen, but would be an error.
throw new ExecutionException(GctBundle.message("appengine.run.server.sdk.misconfigured.message"));
}
// wait complete, check the final status here manually.
SdkStatus sdkStatus = CloudSdkService.getInstance().getStatus();
switch(sdkStatus) {
case INVALID:
case NOT_AVAILABLE:
throw new ExecutionException(GctBundle.message("appengine.run.server.sdk.misconfigured.message"));
case INSTALLING:
// cannot continue still installing.
throw new ExecutionException(GctBundle.message("appengine.run.server.sdk.installing.message"));
case READY:
// continue to start local dev server process.
break;
}
Sdk javaSdk = ProjectRootManager.getInstance(commonModel.getProject()).getProjectSdk();
if (javaSdk == null || javaSdk.getHomePath() == null) {
throw new ExecutionException(GctBundle.message("appengine.run.server.nosdk"));
}
AppEngineServerModel runConfiguration;
try {
// Getting the clone so the debug flags aren't added
// to the persisted settings.
runConfiguration = (AppEngineServerModel) commonModel.getServerModel().clone();
} catch (CloneNotSupportedException ee) {
throw new ExecutionException(ee);
}
Map<String, String> environment = Maps.newHashMap(configuredEnvironment);
// IntelliJ appends the JVM flags to the environment
// variables, keyed by an empty
// string; so we need extract them here.
String jvmFlags = environment.get(JVM_FLAGS_ENVIRONMENT_KEY);
if (jvmFlags != null) {
runConfiguration.appendJvmFlags(Arrays.asList(jvmFlags.trim().split(" ")));
}
// We don't want to pass the jvm flags to the dev server environment
environment.remove(JVM_FLAGS_ENVIRONMENT_KEY);
runConfiguration.setEnvironment(environment);
AppEngineStandardRunTask runTask = new AppEngineStandardRunTask(runConfiguration, javaSdk, programRunner.getRunnerId());
AppEngineExecutor executor = new AppEngineExecutor(runTask);
executor.run();
Process devappserverProcess = executor.getProcess();
startupProcessHandler = new OSProcessHandler(devappserverProcess, GctBundle.getString("appengine.run.startupscript"));
return startupProcessHandler;
}
};
}
};
}
Aggregations