Search in sources :

Example 1 with ProjectBuildException

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;
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ProjectBuildException

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();
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler)

Example 3 with ProjectBuildException

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);
    }
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) JpsModule(org.jetbrains.jps.model.module.JpsModule) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsProject(org.jetbrains.jps.model.JpsProject) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) ElixirCompilerOptions(org.elixir_lang.jps.model.ElixirCompilerOptions) File(java.io.File) URL(java.net.URL)

Example 4 with ProjectBuildException

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());
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) BuildOutputParser(com.android.tools.idea.gradle.output.parser.BuildOutputParser) PrintStream(java.io.PrintStream) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) Message(com.android.ide.common.blame.Message) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) BuildMessage(org.jetbrains.jps.incremental.messages.BuildMessage) PatternAwareOutputParser(com.android.ide.common.blame.parser.PatternAwareOutputParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 5 with ProjectBuildException

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();
    }
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) BuildLauncher(org.gradle.tooling.BuildLauncher) ProjectConnection(org.gradle.tooling.ProjectConnection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) BuildException(org.gradle.tooling.BuildException) IOException(java.io.IOException) BuildMode(com.android.tools.idea.gradle.util.BuildMode) File(java.io.File) GradleConnector(org.gradle.tooling.GradleConnector) DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector)

Aggregations

ProjectBuildException (org.jetbrains.jps.incremental.ProjectBuildException)14 File (java.io.File)8 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)7 IOException (java.io.IOException)5 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)5 BaseOSProcessHandler (com.intellij.execution.process.BaseOSProcessHandler)3 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)3 NotNull (org.jetbrains.annotations.NotNull)3 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 URL (java.net.URL)2 JpsProject (org.jetbrains.jps.model.JpsProject)2 Message (com.android.ide.common.blame.Message)1 PatternAwareOutputParser (com.android.ide.common.blame.parser.PatternAwareOutputParser)1 BuildOutputParser (com.android.tools.idea.gradle.output.parser.BuildOutputParser)1 BuildMode (com.android.tools.idea.gradle.util.BuildMode)1 ExecutionException (com.intellij.execution.ExecutionException)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 FlexResourceBuildTarget (com.intellij.flex.build.FlexResourceBuildTarget)1 JpsFlexBuildConfiguration (com.intellij.flex.model.bc.JpsFlexBuildConfiguration)1