use of org.moe.idea.ui.MOEToolWindow in project moe-ide-integration by multi-os-engine.
the class GeneratorRunner method run.
private void run() {
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(progress);
} 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";
}
String title = test ? "Test Binding Error" : "Generate Binding Error";
Messages.showErrorDialog(message, title);
}
});
} finally {
progress.popState();
}
}
private void runInternal(final ProgressIndicator progress) throws ProjectException, IOException {
String s = null;
final MOEToolWindow toolWindow = MOEToolWindow.getInstance(module.getProject());
toolWindow.clear();
progress.setFraction(0.1);
final StringBuilder errorBuilder = new StringBuilder();
String modulePath = ModuleUtils.getModulePath(module);
File moduleFile = new File(modulePath);
progress.setFraction(0.2);
GradleExec exec = new GradleExec(moduleFile);
exec.getArguments().add("moeNatJGen");
exec.getArguments().add("-Draw-binding-output");
exec.getArguments().add("-Dmoe.binding.conf=" + coonfigurationFile.getPath());
if (test) {
exec.getArguments().add("-Dmoe.natjgen.testrun=true");
}
if (keep) {
exec.getArguments().add("-Dmoe.keep.natjgen");
}
ExecRunner runner = exec.getRunner();
runner.getBuilder().directory(moduleFile);
runner.setListener(new ExecRunnerBase.ExecRunnerListener() {
@Override
public void stdout(String line) {
toolWindow.printNormalMessage(line + "\n");
}
@Override
public void stderr(String line) {
toolWindow.printErrorMessage(line + "\n");
errorBuilder.append(line);
errorBuilder.append("\n");
}
});
runner.run(new IKillListener() {
@Override
public boolean needsKill() {
return progress.isCanceled();
}
});
progress.setFraction(0.9);
module.getProject().getBaseDir().getFileSystem().refresh(true);
progress.setFraction(1.0);
final String errorMessage = errorBuilder.toString();
if (errorMessage == null || errorMessage.isEmpty()) {
String format = test ? "Test successful" : "Generate successful";
toolWindow.balloon(MessageType.INFO, format);
} else {
String format = test ? "Test Error" : "Generate Error";
toolWindow.balloon(MessageType.INFO, format);
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
String title = test ? "Test Binding Error" : "Generate Binding Error";
Messages.showErrorDialog(errorMessage, title);
}
});
}
}
}, ACTION_TITLE, true, module.getProject());
}
use of org.moe.idea.ui.MOEToolWindow in project moe-ide-integration by multi-os-engine.
the class MOEGradleTaskProvider method executeTask.
@Override
public boolean executeTask(DataContext context, final RunConfiguration configuration, final ExecutionEnvironment env, MOEGradleTask task) {
final AtomicBoolean success = new AtomicBoolean();
final AtomicReference<String> errorMsgRef = new AtomicReference<String>();
try {
final Semaphore doneSemaphore = new Semaphore();
doneSemaphore.down();
final MOERunConfiguration runConfig = (MOERunConfiguration) configuration;
isOpenDialog = runConfig.getOpenDeploymentTargetDialog();
final MOEGradleRunner gradleRunner = new MOEGradleRunner(env.getProject(), "Building MOE application", runConfig);
final MOEAfterGradleInvocationTask afterTask = new MOEAfterGradleInvocationTask() {
@Override
public void execute(@NotNull MOEGradleInvocationResult result) {
LOG.debug("MOE application gradle build ended");
success.set(result.isBuildSuccessful());
errorMsgRef.set(result.getErrorMessage());
gradleRunner.removeAfterTask(this);
doneSemaphore.up();
}
};
gradleRunner.addAfterTask(afterTask);
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
if (ApplicationManager.getApplication().isDispatchThread()) {
showDialog(runConfig);
gradleRunner.queue();
} else {
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
showDialog(runConfig);
gradleRunner.queue();
}
});
}
}
});
doneSemaphore.waitFor();
} catch (Exception e) {
Log.debug("Unable execute task", e);
return false;
}
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
String errorMessage = errorMsgRef.get();
if (errorMessage != null) {
MOEToolWindow toolWindow = MOEToolWindow.getInstance(env.getProject());
toolWindow.printErrorMessage(errorMessage);
}
}
});
return success.get();
}
Aggregations