Search in sources :

Example 21 with CompilerMessage

use of org.jetbrains.jps.incremental.messages.CompilerMessage 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 22 with CompilerMessage

use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-plugins by JetBrains.

the class FlexBuilderUtils method copyAndFixCustomAirDescriptor.

private static void copyAndFixCustomAirDescriptor(final CompileContext context, final BuildOutputConsumer outputConsumer, final JpsFlexBuildConfiguration bc, final JpsAirPackagingOptions packagingOptions) {
    final String customDescriptorPath = packagingOptions.getCustomDescriptorPath();
    final File descriptorTemplateFile = new File(customDescriptorPath);
    if (!descriptorTemplateFile.isFile()) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("air.descriptor.not.found", customDescriptorPath)));
        return;
    }
    final String outputFilePath = bc.getActualOutputFilePath();
    final String outputFolderPath = PathUtilRt.getParentPath(outputFilePath);
    final File outputFolder = new File(outputFolderPath);
    if (!outputFolder.isDirectory()) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("output.folder.does.not.exist", outputFolder.getPath())));
        return;
    }
    final String content;
    try {
        content = fixInitialContent(descriptorTemplateFile, PathUtilRt.getFileName(outputFilePath));
    } catch (IOException e) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("failed.to.open.air.descriptor", descriptorTemplateFile.getPath(), e.getMessage())));
        return;
    } catch (JDOMException e) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("incorrect.air.descriptor.content", descriptorTemplateFile.getPath(), e.getMessage())));
        return;
    }
    try {
        final String descriptorFileName = bc.isTempBCForCompilation() ? FlexCommonUtils.getGeneratedAirDescriptorName(bc, packagingOptions) : descriptorTemplateFile.getName();
        final File outputFile = new File(outputFolder, descriptorFileName);
        FileUtil.writeToFile(outputFile, content.getBytes("UTF-8"));
        outputConsumer.registerOutputFile(outputFile, Collections.singletonList(descriptorTemplateFile.getPath()));
    } catch (IOException e) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("failed.to.copy.air.descriptor", e.getMessage())));
    }
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 23 with CompilerMessage

use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-plugins by JetBrains.

the class FlexBuilderUtils method generateAirDescriptor.

private static void generateAirDescriptor(final CompileContext context, final BuildOutputConsumer outputConsumer, final Collection<String> dirtyFilePaths, final JpsFlexBuildConfiguration bc, final String descriptorFileName, final boolean android, final boolean ios) {
    final JpsSdk<?> sdk = bc.getSdk();
    assert sdk != null;
    final String outputFilePath = bc.getActualOutputFilePath();
    final String outputFolderPath = PathUtilRt.getParentPath(outputFilePath);
    final File outputFolder = new File(outputFolderPath);
    if (!outputFolder.isDirectory()) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("output.folder.does.not.exist", outputFolder.getPath())));
        return;
    }
    final String airVersion = FlexCommonUtils.getAirVersion(sdk.getHomePath(), sdk.getVersionString());
    if (airVersion == null) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("failed.to.get.air.sdk.version.use.custom.descriptor")));
        return;
    }
    final String appId = FlexCommonUtils.fixApplicationId(bc.getMainClass());
    final String appName = StringUtil.getShortName(bc.getMainClass());
    final String swfName = PathUtilRt.getFileName(outputFilePath);
    final String[] extensions = getAirExtensionIDs(bc);
    try {
        final AirDescriptorOptions descriptorOptions = new AirDescriptorOptions(airVersion, appId, appName, swfName, extensions, android, ios);
        final String descriptorText = descriptorOptions.getAirDescriptorText();
        final File outputFile = new File(outputFolder, descriptorFileName);
        FileUtil.writeToFile(outputFile, descriptorText);
        outputConsumer.registerOutputFile(outputFile, dirtyFilePaths);
    } catch (IOException e) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("failed.to.generate.air.descriptor", e.getMessage())));
    }
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) AirDescriptorOptions(com.intellij.flex.build.AirDescriptorOptions) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 24 with CompilerMessage

use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-plugins by JetBrains.

the class JpsBuiltInFlexCompilerHandler method startCompilerProcess.

private void startCompilerProcess(final JpsSdk<?> sdk, final int port, final CompileContext context, final String compilerName) throws IOException {
    final StringBuilder classpath = new StringBuilder();
    classpath.append(FlexCommonUtils.getPathToBundledJar("idea-flex-compiler-fix.jar"));
    classpath.append(File.pathSeparatorChar);
    classpath.append(FlexCommonUtils.getPathToBundledJar("flex-compiler.jar"));
    if (sdk.getSdkType() == JpsFlexSdkType.INSTANCE) {
        classpath.append(File.pathSeparator).append(FileUtil.toSystemDependentName(sdk.getHomePath() + "/lib/flex-compiler-oem.jar"));
    }
    final List<String> commandLine = FlexCommonUtils.getCommandLineForSdkTool(myProject, sdk, classpath.toString(), "com.intellij.flex.compiler.FlexCompiler");
    commandLine.add(String.valueOf(port));
    final ProcessBuilder processBuilder = new ProcessBuilder(commandLine);
    processBuilder.redirectErrorStream(true);
    processBuilder.directory(new File(FlexCommonUtils.getFlexCompilerWorkDirPath(myProject)));
    final String plainCommand = StringUtil.join(processBuilder.command(), s -> s.contains(" ") ? "\"" + s + "\"" : s, " ");
    context.processMessage(new CompilerMessage(compilerName, BuildMessage.Kind.INFO, "Starting Flex compiler:\n" + plainCommand));
    final Process process = processBuilder.start();
    readInputStreamUntilConnected(process, context, compilerName);
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage)

Example 25 with CompilerMessage

use of org.jetbrains.jps.incremental.messages.CompilerMessage in project android by JetBrains.

the class AndroidDexBuilder method runDex.

public static boolean runDex(@NotNull AndroidPlatform platform, @NotNull String outFilePath, @NotNull String[] compileTargets, @NotNull CompileContext context, @NotNull JpsProject project, @NotNull BuildOutputConsumer outputConsumer, @NotNull String builderName, @NotNull String srcTargetName, @Nullable JpsModule module) throws IOException {
    BuildToolInfo buildToolInfo = platform.getTarget().getBuildToolInfo();
    if (buildToolInfo == null) {
        return false;
    }
    final String dxJarPath = FileUtil.toSystemDependentName(buildToolInfo.getPath(BuildToolInfo.PathId.DX_JAR));
    final AndroidBuildTestingManager testingManager = AndroidBuildTestingManager.getTestingManager();
    final File dxJar = new File(dxJarPath);
    if (testingManager == null && !dxJar.isFile()) {
        context.processMessage(new CompilerMessage(builderName, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.find.file", dxJarPath)));
        return false;
    }
    boolean multiDex = false;
    if (module != null) {
        JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
        if (extension != null && extension.isMultiDexEnabled()) {
            outFilePath = new File(outFilePath).getParent();
            multiDex = true;
        }
    }
    final List<String> programParamList = new ArrayList<String>();
    programParamList.add(dxJarPath);
    programParamList.add(outFilePath);
    final JpsAndroidDexCompilerConfiguration configuration = JpsAndroidExtensionService.getInstance().getDexCompilerConfiguration(project);
    final List<String> vmOptions;
    if (configuration != null) {
        vmOptions = new ArrayList<String>();
        vmOptions.addAll(ParametersListUtil.parse(configuration.getVmOptions()));
        if (!AndroidCommonUtils.hasXmxParam(vmOptions)) {
            vmOptions.add("-Xmx" + configuration.getMaxHeapSize() + "M");
        }
        programParamList.addAll(Arrays.asList("--optimize", Boolean.toString(configuration.isOptimize())));
        if (configuration.isForceJumbo()) {
            programParamList.addAll(Arrays.asList("--forceJumbo", Boolean.TRUE.toString()));
        }
        if (configuration.isCoreLibrary()) {
            programParamList.add("--coreLibrary");
        }
    } else {
        vmOptions = Collections.singletonList("-Xmx1024M");
    }
    if (multiDex) {
        JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
        if (extension != null) {
            programParamList.add("--multi-dex");
            if (!StringUtil.isEmpty(extension.getMainDexList())) {
                programParamList.add("--main-dex-list");
                programParamList.add(extension.getMainDexList());
            }
            if (extension.isMinimalMainDex()) {
                programParamList.add("--minimal-main-dex");
            }
        }
    }
    programParamList.addAll(Arrays.asList(compileTargets));
    programParamList.add("--exclude");
    final List<String> classPath = new ArrayList<String>();
    classPath.add(ClasspathBootstrap.getResourcePath(AndroidDxRunner.class));
    classPath.add(ClasspathBootstrap.getResourcePath(FileUtilRt.class));
    final File outFile = new File(outFilePath);
    if (outFile.exists() && !outFile.isDirectory() && !outFile.delete()) {
        context.processMessage(new CompilerMessage(builderName, BuildMessage.Kind.WARNING, AndroidJpsBundle.message("android.jps.cannot.delete.file", outFilePath)));
    }
    final String javaExecutable = getJavaExecutable(platform, context, builderName);
    if (javaExecutable == null) {
        return false;
    }
    final List<String> commandLine = ExternalProcessUtil.buildJavaCommandLine(javaExecutable, AndroidDxRunner.class.getName(), Collections.<String>emptyList(), classPath, vmOptions, programParamList);
    LOG.info(AndroidCommonUtils.command2string(commandLine));
    final String[] commands = ArrayUtil.toStringArray(commandLine);
    final Process process;
    if (testingManager != null) {
        process = testingManager.getCommandExecutor().createProcess(commands, Collections.<String, String>emptyMap());
    } else {
        process = Runtime.getRuntime().exec(commands);
    }
    final HashMap<AndroidCompilerMessageKind, List<String>> messages = new HashMap<AndroidCompilerMessageKind, List<String>>(3);
    messages.put(AndroidCompilerMessageKind.ERROR, new ArrayList<String>());
    messages.put(AndroidCompilerMessageKind.WARNING, new ArrayList<String>());
    messages.put(AndroidCompilerMessageKind.INFORMATION, new ArrayList<String>());
    AndroidCommonUtils.handleDexCompilationResult(process, StringUtil.join(commandLine, " "), outFilePath, messages, multiDex);
    AndroidJpsUtil.addMessages(context, messages, builderName, srcTargetName);
    final boolean success = messages.get(AndroidCompilerMessageKind.ERROR).size() == 0;
    if (success) {
        final List<String> srcFiles = new ArrayList<String>();
        for (String compileTargetPath : compileTargets) {
            final File compileTarget = new File(compileTargetPath);
            if (compileTarget.isFile()) {
                srcFiles.add(compileTargetPath);
            } else if (compileTarget.isDirectory()) {
                AndroidJpsUtil.processClassFilesAndJarsRecursively(compileTarget, new Processor<File>() {

                    @Override
                    public boolean process(File file) {
                        if (file.isFile()) {
                            srcFiles.add(file.getPath());
                        }
                        return true;
                    }
                });
            }
        }
        outputConsumer.registerOutputFile(outFile, srcFiles);
    }
    return success;
}
Also used : AndroidBuildTestingManager(org.jetbrains.android.util.AndroidBuildTestingManager) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) Processor(com.intellij.util.Processor) BuildToolInfo(com.android.sdklib.BuildToolInfo) HashMap(com.intellij.util.containers.HashMap) AndroidCompilerMessageKind(org.jetbrains.android.util.AndroidCompilerMessageKind) AndroidDxRunner(org.jetbrains.android.compiler.tools.AndroidDxRunner) JpsAndroidDexCompilerConfiguration(org.jetbrains.jps.android.model.JpsAndroidDexCompilerConfiguration) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) FileUtilRt(com.intellij.openapi.util.io.FileUtilRt) File(java.io.File)

Aggregations

CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)75 File (java.io.File)34 IOException (java.io.IOException)22 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)18 JpsModule (org.jetbrains.jps.model.module.JpsModule)15 HashMap (com.intellij.util.containers.HashMap)11 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)11 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)9 ArrayList (java.util.ArrayList)9 THashSet (gnu.trove.THashSet)8 Nullable (org.jetbrains.annotations.Nullable)8 ProjectBuildException (org.jetbrains.jps.incremental.ProjectBuildException)8 IAndroidTarget (com.android.sdklib.IAndroidTarget)7 NotNull (org.jetbrains.annotations.NotNull)7 BuildMessage (org.jetbrains.jps.incremental.messages.BuildMessage)6 AndroidCompilerMessageKind (org.jetbrains.android.util.AndroidCompilerMessageKind)5 FailSafeClassReader (com.intellij.compiler.instrumentation.FailSafeClassReader)4 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)4 Pair (com.intellij.openapi.util.Pair)3 THashMap (gnu.trove.THashMap)3