use of org.jetbrains.jps.incremental.ProjectBuildException in project intellij-elixir by KronicDeth.
the class ElixirTargetBuilderUtil method getSdk.
@NotNull
public static JpsSdk<JpsDummyElement> getSdk(@NotNull CompileContext context, @NotNull JpsModule module) throws ProjectBuildException {
JpsSdk<JpsDummyElement> sdk = module.getSdk(JpsElixirSdkType.INSTANCE);
if (sdk == null) {
String errorMessage = "No SDK for module " + module.getName();
context.processMessage(new CompilerMessage(ElixirBuilder.BUILDER_NAME, BuildMessage.Kind.ERROR, errorMessage));
throw new ProjectBuildException(errorMessage);
}
return sdk;
}
use of org.jetbrains.jps.incremental.ProjectBuildException in project intellij-elixir by KronicDeth.
the class MixBuilder method runMix.
private static void runMix(@NotNull String elixirPath, @NotNull String mixPath, @Nullable String contentRootPath, boolean addDebugInfo, @NotNull CompileContext context) throws ProjectBuildException {
GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.withWorkDirectory(contentRootPath);
commandLine.setExePath(elixirPath);
commandLine.addParameter(mixPath);
commandLine.addParameter("compile");
if (!addDebugInfo) {
commandLine.addParameter("--no-debug-info");
}
Process process;
try {
process = commandLine.createProcess();
} catch (ExecutionException e) {
throw new ProjectBuildException("Failed to run mix.", e);
}
BaseOSProcessHandler handler = new BaseOSProcessHandler(process, commandLine.getCommandLineString(), Charset.defaultCharset());
ProcessAdapter adapter = new ElixirCompilerProcessAdapter(context, NAME, commandLine.getWorkDirectory().getPath());
handler.addProcessListener(adapter);
handler.startNotify();
handler.waitFor();
}
use of org.jetbrains.jps.incremental.ProjectBuildException in project intellij-elixir by KronicDeth.
the class MixBuilder method build.
@Override
public void build(@NotNull ElixirTarget target, @NotNull DirtyFilesHolder<ElixirSourceRootDescriptor, ElixirTarget> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull CompileContext context) throws ProjectBuildException, IOException {
if (!holder.hasDirtyFiles() && !holder.hasRemovedFiles())
return;
JpsModule module = target.getModule();
JpsProject project = module.getProject();
ElixirCompilerOptions compilerOptions = JpsElixirCompilerOptionsExtension.getOrCreateExtension(project).getOptions();
if (!compilerOptions.myUseMixCompiler)
return;
String mixPath = getMixExecutablePath(project);
if (mixPath == null) {
String errorMessage = "Mix path is not set.";
context.processMessage(new CompilerMessage(NAME, BuildMessage.Kind.ERROR, errorMessage));
throw new ProjectBuildException(errorMessage);
}
JpsSdk<JpsDummyElement> sdk = ElixirTargetBuilderUtil.getSdk(context, module);
String elixirPath = JpsElixirSdkType.getScriptInterpreterExecutable(sdk.getHomePath()).getAbsolutePath();
for (String contentRootUrl : module.getContentRootsList().getUrls()) {
String contentRootPath = new URL(contentRootUrl).getPath();
File contentRootDir = new File(contentRootPath);
File mixConfigFile = new File(contentRootDir, MIX_CONFIG_FILE_NAME);
if (!mixConfigFile.exists())
continue;
runMix(elixirPath, mixPath, contentRootPath, compilerOptions.myAttachDebugInfoEnabled, context);
}
}
use of org.jetbrains.jps.incremental.ProjectBuildException in project android by JetBrains.
the class AndroidGradleTargetBuilder method handleBuildException.
/**
* Something went wrong while invoking Gradle. Since we cannot distinguish an execution error from compilation errors easily, we first try
* to show, in the "Problems" view, compilation errors by parsing the error output. If no errors are found, we show the stack trace in the
* "Problems" view. The idea is that we need to somehow inform the user that something went wrong.
*/
private static void handleBuildException(BuildException e, CompileContext context, String stdErr) throws ProjectBuildException {
Iterable<PatternAwareOutputParser> parsers = JpsServiceManager.getInstance().getExtensions(PatternAwareOutputParser.class);
Collection<Message> compilerMessages = new BuildOutputParser(parsers).parseGradleOutput(stdErr);
if (!compilerMessages.isEmpty()) {
boolean hasError = false;
for (Message message : compilerMessages) {
if (message.getKind() == Message.Kind.ERROR) {
hasError = true;
}
for (CompilerMessage compilerMessage : AndroidGradleJps.createCompilerMessages(message)) {
context.processMessage(compilerMessage);
}
}
if (hasError) {
return;
}
}
// There are no error messages to present. Show some feedback indicating that something went wrong.
if (!stdErr.isEmpty()) {
// Show the contents of stderr as a compiler error.
context.processMessage(createCompilerErrorMessage(stdErr));
} else {
// Since we have nothing else to show, just print the stack trace of the caught exception.
ByteArrayOutputStream out = new ByteArrayOutputStream(BUFFER_SIZE);
try {
//noinspection IOResourceOpenedButNotSafelyClosed
e.printStackTrace(new PrintStream(out));
String message = "Internal error:" + SystemProperties.getLineSeparator() + out.toString();
context.processMessage(createCompilerErrorMessage(message));
} finally {
try {
Closeables.close(out, true);
} catch (IOException e1) {
LOG.debug(e1);
}
}
}
throw new ProjectBuildException(e.getMessage());
}
use of org.jetbrains.jps.incremental.ProjectBuildException in project android by JetBrains.
the class AndroidGradleTargetBuilder method doBuild.
private static void doBuild(@NotNull CompileContext context, @NotNull List<String> buildTasks, @NotNull BuilderExecutionSettings executionSettings, @Nullable String androidHome) throws ProjectBuildException {
GradleConnector connector = getGradleConnector(executionSettings);
ProjectConnection connection = connector.connect();
ByteArrayOutputStream stdout = new ByteArrayOutputStream(BUFFER_SIZE);
ByteArrayOutputStream stderr = new ByteArrayOutputStream(BUFFER_SIZE);
try {
BuildLauncher launcher = connection.newBuild();
launcher.forTasks(toStringArray(buildTasks));
List<String> jvmArgs = Lists.newArrayList();
BuildMode buildMode = executionSettings.getBuildMode();
if (BuildMode.ASSEMBLE_TRANSLATE == buildMode) {
String arg = AndroidGradleSettings.createJvmArg(GradleBuilds.ENABLE_TRANSLATION_JVM_ARG, true);
jvmArgs.add(arg);
}
if (androidHome != null && !androidHome.isEmpty()) {
String androidSdkArg = AndroidGradleSettings.createAndroidHomeJvmArg(androidHome);
jvmArgs.add(androidSdkArg);
}
jvmArgs.addAll(executionSettings.getJvmOptions());
LOG.info("Build JVM args: " + jvmArgs);
if (!jvmArgs.isEmpty()) {
launcher.setJvmArguments(toStringArray(jvmArgs));
}
List<String> commandLineArgs = Lists.newArrayList();
commandLineArgs.addAll(executionSettings.getCommandLineOptions());
commandLineArgs.add(AndroidGradleSettings.createProjectProperty(AndroidProject.PROPERTY_INVOKED_FROM_IDE, true));
if (executionSettings.isParallelBuild() && !commandLineArgs.contains(PARALLEL_BUILD_OPTION)) {
commandLineArgs.add(PARALLEL_BUILD_OPTION);
}
if (executionSettings.isOfflineBuild() && !commandLineArgs.contains(OFFLINE_MODE_OPTION)) {
commandLineArgs.add(OFFLINE_MODE_OPTION);
}
if (executionSettings.isConfigureOnDemand() && !commandLineArgs.contains(CONFIGURE_ON_DEMAND_OPTION)) {
commandLineArgs.add(CONFIGURE_ON_DEMAND_OPTION);
}
LOG.info("Build command line args: " + commandLineArgs);
if (!commandLineArgs.isEmpty()) {
launcher.withArguments(toStringArray(commandLineArgs));
}
File javaHomeDir = executionSettings.getJavaHomeDir();
if (javaHomeDir != null) {
launcher.setJavaHome(javaHomeDir);
}
launcher.setStandardOutput(stdout);
launcher.setStandardError(stderr);
launcher.run();
} catch (BuildException e) {
handleBuildException(e, context, stderr.toString());
} finally {
String outText = stdout.toString();
context.processMessage(new ProgressMessage(outText, 1.0f));
try {
Closeables.close(stdout, true);
Closeables.close(stderr, true);
} catch (IOException e) {
LOG.debug(e);
}
connection.close();
}
}
Aggregations