Search in sources :

Example 16 with CompilerMessage

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

the class GreclipseBuilder method build.

@Override
public ExitCode build(final CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, OutputConsumer outputConsumer) throws ProjectBuildException, IOException {
    if (!useGreclipse(context))
        return ModuleLevelBuilder.ExitCode.NOTHING_DONE;
    try {
        final List<File> toCompile = myHelper.collectChangedFiles(context, dirtyFilesHolder, false, true, Ref.create(false));
        if (toCompile.isEmpty()) {
            return ExitCode.NOTHING_DONE;
        }
        Map<ModuleBuildTarget, String> outputDirs = GroovyBuilder.getCanonicalModuleOutputs(context, chunk, this);
        if (outputDirs == null) {
            return ExitCode.ABORT;
        }
        JpsProject project = context.getProjectDescriptor().getProject();
        GreclipseSettings greclipseSettings = GreclipseJpsCompilerSettings.getSettings(project);
        if (greclipseSettings == null) {
            String message = "Compiler settings component not initialized for " + project;
            LOG.error(message);
            context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, message));
            return ExitCode.ABORT;
        }
        ClassLoader loader = createGreclipseLoader(greclipseSettings.greclipsePath);
        if (loader == null) {
            context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, "Invalid jar path in the compiler settings: '" + greclipseSettings.greclipsePath + "'"));
            return ExitCode.ABORT;
        }
        final JpsJavaExtensionService javaExt = JpsJavaExtensionService.getInstance();
        final JpsJavaCompilerConfiguration compilerConfig = javaExt.getCompilerConfiguration(project);
        assert compilerConfig != null;
        final Set<JpsModule> modules = chunk.getModules();
        ProcessorConfigProfile profile = null;
        if (modules.size() == 1) {
            profile = compilerConfig.getAnnotationProcessingProfile(modules.iterator().next());
        } else {
            String message = JavaBuilder.validateCycle(chunk, javaExt, compilerConfig, modules);
            if (message != null) {
                context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, message));
                return ExitCode.ABORT;
            }
        }
        String mainOutputDir = outputDirs.get(chunk.representativeTarget());
        final List<String> args = createCommandLine(context, chunk, toCompile, mainOutputDir, profile, greclipseSettings);
        if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) {
            LOG.debug("Compiling with args: " + args);
        }
        Boolean notified = COMPILER_VERSION_INFO.get(context);
        if (notified != Boolean.TRUE) {
            context.processMessage(new CompilerMessage("", BuildMessage.Kind.INFO, "Using Groovy-Eclipse to compile Java & Groovy sources"));
            COMPILER_VERSION_INFO.set(context, Boolean.TRUE);
        }
        context.processMessage(new ProgressMessage("Compiling java & groovy [" + chunk.getPresentableShortName() + "]"));
        StringWriter out = new StringWriter();
        StringWriter err = new StringWriter();
        HashMap<String, List<String>> outputMap = ContainerUtil.newHashMap();
        boolean success = performCompilation(args, out, err, outputMap, context, chunk);
        List<GroovycOutputParser.OutputItem> items = ContainerUtil.newArrayList();
        for (String src : outputMap.keySet()) {
            //noinspection ConstantConditions
            for (String classFile : outputMap.get(src)) {
                items.add(new GroovycOutputParser.OutputItem(FileUtil.toSystemIndependentName(mainOutputDir + classFile), FileUtil.toSystemIndependentName(src)));
            }
        }
        MultiMap<ModuleBuildTarget, GroovycOutputParser.OutputItem> successfullyCompiled = myHelper.processCompiledFiles(context, chunk, outputDirs, mainOutputDir, items);
        EclipseOutputParser parser = new EclipseOutputParser(getPresentableName(), chunk);
        List<CompilerMessage> messages = ContainerUtil.concat(parser.parseMessages(out.toString()), parser.parseMessages(err.toString()));
        boolean hasError = false;
        for (CompilerMessage message : messages) {
            if (message.getKind() == BuildMessage.Kind.ERROR) {
                hasError = true;
            }
            context.processMessage(message);
        }
        if (!success && !hasError) {
            context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, "Compilation failed"));
        }
        myHelper.updateDependencies(context, toCompile, successfullyCompiled, new DefaultOutputConsumer(outputConsumer), this);
        return ExitCode.OK;
    } catch (Exception e) {
        throw new ProjectBuildException(e);
    }
}
Also used : JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService) StringWriter(java.io.StringWriter) JpsProject(org.jetbrains.jps.model.JpsProject) URLClassLoader(java.net.URLClassLoader) IOException(java.io.IOException) JpsModule(org.jetbrains.jps.model.module.JpsModule) ProcessorConfigProfile(org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile) File(java.io.File)

Example 17 with CompilerMessage

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

the class GroovyBuilder method getCanonicalModuleOutputs.

@Nullable
static Map<ModuleBuildTarget, String> getCanonicalModuleOutputs(CompileContext context, ModuleChunk chunk, Builder builder) {
    Map<ModuleBuildTarget, String> finalOutputs = new LinkedHashMap<>();
    for (ModuleBuildTarget target : chunk.getTargets()) {
        File moduleOutputDir = target.getOutputDir();
        if (moduleOutputDir == null) {
            context.processMessage(new CompilerMessage(builder.getPresentableName(), BuildMessage.Kind.ERROR, "Output directory not specified for module " + target.getModule().getName()));
            return null;
        }
        //noinspection ResultOfMethodCallIgnored
        moduleOutputDir.mkdirs();
        String moduleOutputPath = FileUtil.toCanonicalPath(moduleOutputDir.getPath());
        assert moduleOutputPath != null;
        finalOutputs.put(target, moduleOutputPath.endsWith("/") ? moduleOutputPath : moduleOutputPath + "/");
    }
    return finalOutputs;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with CompilerMessage

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

the class GroovycOutputParser method getCompilerMessages.

public List<CompilerMessage> getCompilerMessages() {
    ArrayList<CompilerMessage> messages = new ArrayList<>(compilerMessages);
    final StringBuffer unparsedBuffer = getStdErr();
    if (unparsedBuffer.length() != 0) {
        String msg = unparsedBuffer.toString();
        if (msg.contains(GroovyRtConstants.NO_GROOVY)) {
            messages.add(reportNoGroovy());
        } else {
            messages.add(new CompilerMessage("Groovyc", BuildMessage.Kind.INFO, "While compiling " + myChunk.getPresentableShortName() + ":" + msg));
        }
    }
    if (myExitCode != 0) {
        for (CompilerMessage message : messages) {
            if (message.getKind() == BuildMessage.Kind.ERROR) {
                return messages;
            }
        }
        messages.add(new CompilerMessage("Groovyc", BuildMessage.Kind.ERROR, "Internal groovyc error: code " + myExitCode));
    }
    return messages;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) ArrayList(java.util.ArrayList)

Example 19 with CompilerMessage

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

the class JpsGroovycRunner method updateDependencies.

void updateDependencies(CompileContext context, List<File> toCompile, MultiMap<T, GroovycOutputParser.OutputItem> successfullyCompiled, final GroovyOutputConsumer outputConsumer, Builder builder) throws IOException {
    JavaBuilderUtil.registerFilesToCompile(context, toCompile);
    if (!successfullyCompiled.isEmpty()) {
        final Callbacks.Backend callback = JavaBuilderUtil.getDependenciesRegistrar(context);
        for (Map.Entry<T, Collection<GroovycOutputParser.OutputItem>> entry : successfullyCompiled.entrySet()) {
            final T target = entry.getKey();
            final Collection<GroovycOutputParser.OutputItem> compiled = entry.getValue();
            for (GroovycOutputParser.OutputItem item : compiled) {
                final String sourcePath = FileUtil.toSystemIndependentName(item.sourcePath);
                final String outputPath = FileUtil.toSystemIndependentName(item.outputPath);
                final File outputFile = new File(outputPath);
                final File srcFile = new File(sourcePath);
                try {
                    final byte[] bytes = FileUtil.loadFileBytes(outputFile);
                    if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) {
                        LOG.info("registerCompiledClass " + outputFile + " from " + srcFile);
                    }
                    outputConsumer.registerCompiledClass(target, srcFile, outputFile, bytes);
                    callback.associate(outputPath, sourcePath, new FailSafeClassReader(bytes));
                } catch (Throwable e) {
                    // need this to make sure that unexpected errors in, for example, ASM will not ruin the compilation
                    final String message = "Class dependency information may be incomplete! Error parsing generated class " + item.outputPath;
                    LOG.info(message, e);
                    context.processMessage(new CompilerMessage(builder.getPresentableName(), BuildMessage.Kind.WARNING, message + "\n" + CompilerMessage.getTextFromThrowable(e), sourcePath));
                }
                JavaBuilderUtil.registerSuccessfullyCompiled(context, srcFile);
            }
        }
    }
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) Callbacks(org.jetbrains.jps.builders.java.dependencyView.Callbacks) MultiMap(com.intellij.util.containers.MultiMap) File(java.io.File) FailSafeClassReader(com.intellij.compiler.instrumentation.FailSafeClassReader)

Example 20 with CompilerMessage

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

the class AndroidGradleJps method createCompilerMessages.

/**
   * Adapter method to create IDEA CompilerMessages from an Android build Message.
   *
   * If the Android build message has multiple source locations, this will create multiple CompilerMesssages with the same kind and
   * messageText, but different source positions.
   */
@NotNull
public static List<CompilerMessage> createCompilerMessages(@NotNull Message message) {
    final BuildMessage.Kind kind;
    switch(message.getKind()) {
        case INFO:
            kind = BuildMessage.Kind.INFO;
            break;
        case WARNING:
            kind = BuildMessage.Kind.WARNING;
            break;
        case ERROR:
            kind = BuildMessage.Kind.ERROR;
            break;
        default:
            kind = BuildMessage.Kind.PROGRESS;
    }
    List<CompilerMessage> compilerMessages = new ArrayList<CompilerMessage>();
    for (SourceFilePosition filePosition : message.getSourceFilePositions()) {
        File sourceFile = filePosition.getFile().getSourceFile();
        String sourceFilePath = sourceFile != null ? sourceFile.getAbsolutePath() : null;
        SourcePosition pos = filePosition.getPosition();
        compilerMessages.add(new CompilerMessage(COMPILER_NAME, kind, message.getText().trim(), sourceFilePath, pos.getStartOffset(), pos.getEndOffset(), pos.getEndOffset(), pos.getEndLine(), pos.getEndColumn()));
    }
    return Collections.unmodifiableList(compilerMessages);
}
Also used : BuildMessage(org.jetbrains.jps.incremental.messages.BuildMessage) SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) SourcePosition(com.android.ide.common.blame.SourcePosition) ArrayList(java.util.ArrayList) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

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