use of com.intellij.execution.process.OSProcessHandler in project moe-ide-integration by multi-os-engine.
the class MOERunProfileState method createProcessHandler.
@NotNull
private OSProcessHandler createProcessHandler() throws ExecutionException {
if (runConfiguration.configuration() == null) {
throw new ExecutionException("Invalid build configuration for " + runConfiguration.getClass().getName());
} else if (runConfiguration.architecture() == null) {
throw new ExecutionException("Invalid architecture for " + runConfiguration.getClass().getName());
}
final MOEGradleRunner gradleRunner = new MOEGradleRunner(runConfiguration);
final boolean isDebug = runConfiguration.getActionType().equals("Debug");
final GeneralCommandLine commandLine = gradleRunner.construct(isDebug, true);
final OSProcessHandler handler = new MOEOSProcessHandler(commandLine);
handler.setShouldDestroyProcessRecursively(true);
final MOETestResultParser parser = new MOETestResultParser(new MOETestListener(this));
final boolean isTest = runConfiguration.runJUnitTests();
handler.addProcessListener(new ProcessListener() {
@Override
public void startNotified(ProcessEvent event) {
}
@Override
public void processTerminated(ProcessEvent event) {
}
@Override
public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
}
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
String text = event.getText();
if (isTest) {
parser.addOutput(text);
}
if (text.contains("ApplicationVerificationFailed")) {
MOEToolWindow.getInstance(project).balloon(MessageType.ERROR, "Application installation failed. Please check log for details...");
MOEToolWindow.getInstance(project).log("Application installation failed. Please make sure you have correct bundle id in your Info.plist file.");
}
}
});
return handler;
}
use of com.intellij.execution.process.OSProcessHandler in project moe-ide-integration by multi-os-engine.
the class MOEGradleRunner method buildProject.
private void buildProject(MOEGradleInvocationResult result) {
final Stopwatch stopwatch = Stopwatch.createUnstarted();
stopwatch.start();
String errorMessage = null;
try {
LOG.debug("Start build process");
final org.moe.idea.compiler.MOEGradleRunner gradleRunner = new org.moe.idea.compiler.MOEGradleRunner(runConfig);
final boolean isDebug = runConfig.getActionType().equals("Debug");
boolean isMaven = ModuleUtils.isMOEMavenModule(runConfig.module());
final MOEToolWindow toolWindow = MOEToolWindow.getInstance(runConfig.getProject());
if (!isMaven) {
final GeneralCommandLine commandLine = gradleRunner.construct(isDebug, false);
final OSProcessHandler handler = new OSProcessHandler(commandLine);
handler.setShouldDestroyProcessRecursively(true);
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();
int returnCode = handler.getProcess().exitValue();
// Show on failure
if (returnCode != 0) {
toolWindow.balloon(MessageType.ERROR, "BUILD FAILED");
errorMessage = "Multi-OS Engine module build failed";
}
} else {
MOEMavenBuildTask mavenTask = new MOEMavenBuildTask(runConfig, "Building " + runConfig.moduleName(), true);
boolean res = mavenTask.runTask();
if (!res) {
toolWindow.balloon(MessageType.ERROR, "BUILD FAILED");
errorMessage = "Multi-OS Engine module build failed";
}
}
if (errorMessage == null) {
result.setBuildSuccessful(true);
} else {
result.setBuildSuccessful(false);
result.setErrorMessage(errorMessage);
}
} catch (Exception e) {
result.setBuildSuccessful(false);
result.setErrorMessage(String.format("Error while building %s .%n", e.getMessage()));
} finally {
stopwatch.stop();
}
}
use of com.intellij.execution.process.OSProcessHandler in project moe-ide-integration by multi-os-engine.
the class MOEGenerateActionsAndOutletsAction 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", "Actions and Outlets Generation 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, "Actions and Outlets Generation 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, "moeGenerateUIObjCInterfaces");
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:generateUIObjCInterfaces");
if (!task.runTask()) {
ModuleUtils.runInDispatchedThread(new Runnable() {
@Override
public void run() {
Messages.showErrorDialog("Unable run generation", "Actions and Outlets Generation Error");
}
});
}
}
}, null);
ModuleUtils.runInDispatchedThread(new Runnable() {
@Override
public void run() {
MOEMavenTask task = new MOEMavenTask(module, ACTION_TITLE, false);
task.setGoal("moe:generateUIObjCInterfaces");
if (!task.runTask()) {
Messages.showErrorDialog("Unable run generation", "Actions and Outlets Generation Error");
}
}
});
}
}
use of com.intellij.execution.process.OSProcessHandler in project intellij by bazelbuild.
the class BlazeIntellijPluginConfiguration method getState.
/**
* Plugin jar has been previously created via blaze build. This method: - copies jar to sandbox
* environment - cracks open jar and finds plugin.xml (with ID, etc., needed for JVM args) - sets
* up the SDK, etc. (use project SDK?) - sets up the JVM, and returns a JavaCommandLineState
*/
@Nullable
@Override
public RunProfileState getState(Executor executor, ExecutionEnvironment env) throws ExecutionException {
final Sdk ideaJdk = pluginSdk;
if (!IdeaJdkHelper.isIdeaJdk(ideaJdk)) {
throw new ExecutionException("Choose an IntelliJ Platform Plugin SDK");
}
String sandboxHome = IdeaJdkHelper.getSandboxHome(ideaJdk);
if (sandboxHome == null) {
throw new ExecutionException("No sandbox specified for IntelliJ Platform Plugin SDK");
}
try {
sandboxHome = new File(sandboxHome).getCanonicalPath();
} catch (IOException e) {
throw new ExecutionException("No sandbox specified for IntelliJ Platform Plugin SDK");
}
String buildNumber = IdeaJdkHelper.getBuildNumber(ideaJdk);
final BlazeIntellijPluginDeployer deployer = new BlazeIntellijPluginDeployer(sandboxHome, buildNumber, getTarget());
env.putUserData(BlazeIntellijPluginDeployer.USER_DATA_KEY, deployer);
// copy license from running instance of idea
IdeaJdkHelper.copyIDEALicense(sandboxHome);
return new JavaCommandLineState(env) {
@Override
protected JavaParameters createJavaParameters() throws ExecutionException {
List<String> pluginIds = deployer.deployNonBlocking();
final JavaParameters params = new JavaParameters();
ParametersList vm = params.getVMParametersList();
fillParameterList(vm, vmParameters);
fillParameterList(params.getProgramParametersList(), programParameters);
IntellijWithPluginClasspathHelper.addRequiredVmParams(params, ideaJdk);
vm.defineProperty(JetBrainsProtocolHandler.REQUIRED_PLUGINS_KEY, Joiner.on(',').join(pluginIds));
if (!vm.hasProperty(PlatformUtils.PLATFORM_PREFIX_KEY) && buildNumber != null) {
String prefix = IdeaJdkHelper.getPlatformPrefix(buildNumber);
if (prefix != null) {
vm.defineProperty(PlatformUtils.PLATFORM_PREFIX_KEY, prefix);
}
}
return params;
}
@Override
protected OSProcessHandler startProcess() throws ExecutionException {
deployer.blockUntilDeployComplete();
final OSProcessHandler handler = super.startProcess();
handler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
deployer.deleteDeployment();
}
});
return handler;
}
};
}
use of com.intellij.execution.process.OSProcessHandler in project intellij by bazelbuild.
the class AaptUtil method getAaptBadging.
/**
* Uses aapt to dump badging information for the given apk, and extracts information from the
* output matching the given pattern.
*/
@Nullable
private static MatchResult getAaptBadging(Project project, File apk, Pattern pattern) throws AaptUtilException {
if (!apk.exists()) {
throw new AaptUtilException("apk file does not exist: " + apk);
}
AndroidPlatform androidPlatform = SdkUtil.getAndroidPlatform(project);
if (androidPlatform == null) {
throw new AaptUtilException("Could not find Android platform sdk for project " + project.getName());
}
BuildToolInfo toolInfo = androidPlatform.getSdkData().getLatestBuildTool();
if (toolInfo == null) {
throw new AaptUtilException("Could not find Android sdk build-tools for project " + project.getName());
}
String aapt = toolInfo.getPath(PathId.AAPT);
GeneralCommandLine commandLine = new GeneralCommandLine(aapt, "dump", "badging", apk.getAbsolutePath());
OSProcessHandler handler;
try {
handler = new OSProcessHandler(commandLine);
} catch (ExecutionException e) {
throw new AaptUtilException("Could not execute aapt to extract apk information.", e);
}
// The wrapped stream is closed by the process handler.
BufferedReader reader = new BufferedReader(new InputStreamReader(handler.getProcess().getInputStream()));
try {
String line;
while ((line = reader.readLine()) != null) {
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
return matcher.toMatchResult();
}
}
} catch (IOException e) {
throw new AaptUtilException("Could not read aapt output.", e);
}
return null;
}
Aggregations