use of com.intellij.execution.process.ProcessEvent in project ballerina by ballerina-lang.
the class BallerinaApplicationRunningState method startProcess.
@NotNull
@Override
protected ProcessHandler startProcess() throws ExecutionException {
ProcessHandler processHandler = super.startProcess();
processHandler.addProcessListener(new ProcessAdapter() {
@Override
public void startNotified(ProcessEvent event) {
if (myHistoryProcessHandler != null) {
myHistoryProcessHandler.apply(processHandler);
}
}
});
return processHandler;
}
use of com.intellij.execution.process.ProcessEvent in project azure-tools-for-java by Microsoft.
the class SpringCloudDeploymentConfigurationState method execute.
@Override
@Nullable
public ExecutionResult execute(Executor executor, @NotNull ProgramRunner<?> runner) throws ExecutionException {
final RunProcessHandler processHandler = new RunProcessHandler();
processHandler.addDefaultListener();
processHandler.startNotify();
processHandler.setProcessTerminatedHandler(RunProcessHandler.DO_NOTHING);
final ConsoleMessager messager = new ConsoleMessager(processHandler);
final ConsoleView consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(this.project).getConsole();
consoleView.attachToProcess(processHandler);
final Disposable subscribe = Mono.fromCallable(() -> this.execute(messager)).doOnTerminate(processHandler::notifyComplete).subscribeOn(Schedulers.boundedElastic()).subscribe((res) -> messager.success("Deploy succeed!"), messager::error);
processHandler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(@NotNull ProcessEvent event) {
subscribe.dispose();
}
});
return new DefaultExecutionResult(consoleView, processHandler);
}
use of com.intellij.execution.process.ProcessEvent in project azure-tools-for-java by Microsoft.
the class RunProcessHandler method addDefaultListener.
public void addDefaultListener() {
ProcessListener defaultListener = new ProcessListener() {
@Override
public void startNotified(ProcessEvent processEvent) {
}
@Override
public void processTerminated(ProcessEvent processEvent) {
}
@Override
public void processWillTerminate(ProcessEvent processEvent, boolean b) {
notifyProcessTerminated(0);
}
@Override
public void onTextAvailable(ProcessEvent processEvent, Key key) {
}
};
addProcessListener(defaultListener);
}
use of com.intellij.execution.process.ProcessEvent in project azure-tools-for-java by Microsoft.
the class DockerHostRunState method executeSteps.
@Override
public String executeSteps(@NotNull RunProcessHandler processHandler, @NotNull Operation operation) throws Exception {
final String[] runningContainerId = { null };
processHandler.addProcessListener(new ProcessListener() {
@Override
public void startNotified(ProcessEvent processEvent) {
}
@Override
public void processTerminated(ProcessEvent processEvent) {
}
@Override
public void processWillTerminate(ProcessEvent processEvent, boolean b) {
try {
DockerClient docker = DockerUtil.getDockerClient(dataModel.getDockerHost(), dataModel.isTlsEnabled(), dataModel.getDockerCertPath());
DockerUtil.stopContainer(docker, runningContainerId[0]);
} catch (Exception e) {
// ignore
}
}
@Override
public void onTextAvailable(ProcessEvent processEvent, Key key) {
}
});
processHandler.setText("Starting job ... ");
String basePath = project.getBasePath();
if (basePath == null) {
processHandler.println("Project base path is null.", ProcessOutputTypes.STDERR);
throw new FileNotFoundException("Project base path is null.");
}
// locate artifact to specified location
String targetFilePath = dataModel.getTargetPath();
processHandler.setText(String.format("Locating artifact ... [%s]", targetFilePath));
// validate dockerfile
Path targetDockerfile = Paths.get(dataModel.getDockerFilePath());
processHandler.setText(String.format("Validating dockerfile ... [%s]", targetDockerfile));
if (!targetDockerfile.toFile().exists()) {
throw new FileNotFoundException("Dockerfile not found.");
}
// replace placeholder if exists
String content = new String(Files.readAllBytes(targetDockerfile));
content = content.replaceAll(Constant.DOCKERFILE_ARTIFACT_PLACEHOLDER, Paths.get(basePath).toUri().relativize(Paths.get(targetFilePath).toUri()).getPath());
Files.write(targetDockerfile, content.getBytes());
// build image
String imageNameWithTag = String.format("%s:%s", dataModel.getImageName(), dataModel.getTagName());
processHandler.setText(String.format("Building image ... [%s]", imageNameWithTag));
DockerClient docker = DockerUtil.getDockerClient(dataModel.getDockerHost(), dataModel.isTlsEnabled(), dataModel.getDockerCertPath());
DockerUtil.ping(docker);
DockerUtil.buildImage(docker, imageNameWithTag, targetDockerfile.getParent(), targetDockerfile.getFileName().toString(), new DockerProgressHandler(processHandler));
// docker run
String containerServerPort = getPortFromDockerfile(content);
if (StringUtils.isBlank(containerServerPort)) {
if (StringUtils.endsWith(targetFilePath, MavenConstants.TYPE_WAR)) {
containerServerPort = "80";
} else {
containerServerPort = "8080";
}
}
String containerId = DockerUtil.createContainer(docker, String.format("%s:%s", dataModel.getImageName(), dataModel.getTagName()), containerServerPort);
runningContainerId[0] = containerId;
Container container = DockerUtil.runContainer(docker, containerId);
// props
String hostname = new URI(dataModel.getDockerHost()).getHost();
String publicPort = null;
ImmutableList<Container.PortMapping> ports = container.ports();
if (ports != null) {
for (Container.PortMapping portMapping : ports) {
if (StringUtils.equals(containerServerPort, String.valueOf(portMapping.privatePort()))) {
publicPort = String.valueOf(portMapping.publicPort());
}
}
}
processHandler.setText(String.format(Constant.MESSAGE_CONTAINER_STARTED, (hostname != null ? hostname : "localhost") + (publicPort != null ? ":" + publicPort : "")));
return null;
}
use of com.intellij.execution.process.ProcessEvent in project moe-ide-integration by multi-os-engine.
the class MOERefreshXcodeProject method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final Module module = (Module) dataContext.getData(LangDataKeys.MODULE.getName());
if (module == null) {
Messages.showErrorDialog("Failed to locate module", "Injecting/Refreshing Xcode Settings Error");
return;
}
boolean isMaven = ModuleUtils.isMOEMavenModule(module);
if (!isMaven) {
ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
if (progress == null) {
progress = new EmptyProgressIndicator();
}
progress.pushState();
try {
progress.setText(ACTION_PROGRESS_LABEL);
runInternal();
} catch (final Throwable t) {
t.printStackTrace(System.err);
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
String message = t.getMessage();
if (message == null || message.length() == 0) {
message = "Unknown error";
}
Messages.showErrorDialog(message, "Injecting/Refreshing Xcode Settings Error");
final MOEToolWindow toolWindow = MOEToolWindow.getInstance(module.getProject());
toolWindow.show();
}
});
} finally {
progress.popState();
}
}
private void runInternal() throws IOException, ExecutionException {
final GeneralCommandLine commandLine = MOEGradleRunner.construct(module, "moeUpdateXcodeSettings");
final OSProcessHandler handler = new OSProcessHandler(commandLine);
handler.setShouldDestroyProcessRecursively(true);
// Configure output
final MOEToolWindow toolWindow = MOEToolWindow.getInstance(module.getProject());
toolWindow.clear();
handler.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
if (ProcessOutputTypes.STDERR.equals(outputType)) {
toolWindow.error(event.getText());
} else if (ProcessOutputTypes.STDOUT.equals(outputType)) {
toolWindow.log(event.getText());
}
}
});
handler.startNotify();
// Start and wait
handler.waitFor();
final int exitValue = handler.getProcess().exitValue();
if (exitValue != 0) {
throw new IOException(ACTION_TITLE + " finished with non-zero exit value (" + exitValue + ")");
}
}
}, ACTION_TITLE, true, module.getProject());
} else {
CompilerTask compilerTask = new CompilerTask(module.getProject(), "", false, true, true, true);
compilerTask.start(new Runnable() {
@Override
public void run() {
MOEMavenTask task = new MOEMavenTask(module, ACTION_TITLE, false);
task.setGoal("moe:updateXcodeSettings");
if (!task.runTask()) {
ModuleUtils.runInDispatchedThread(new Runnable() {
@Override
public void run() {
Messages.showErrorDialog("Unable to refresh Xcode project", "Injecting/Refreshing Xcode Settings Error");
}
});
}
}
}, null);
ModuleUtils.runInDispatchedThread(new Runnable() {
@Override
public void run() {
MOEMavenTask task = new MOEMavenTask(module, ACTION_TITLE, false);
task.setGoal("moe:updateXcodeSettings");
if (!task.runTask()) {
Messages.showErrorDialog("Unable to refresh Xcode project", "Injecting/Refreshing Xcode Settings Error");
}
}
});
}
}
Aggregations