Search in sources :

Example 6 with JpsProject

use of org.jetbrains.jps.model.JpsProject in project android by JetBrains.

the class AndroidGradleBuilder method buildStarted.

/**
   * Disables IDEA's Java and Android builders for Gradle-imported projects. They are no longer needed since we build with Gradle.
   */
@Override
public void buildStarted(CompileContext context) {
    JpsProject project = context.getProjectDescriptor().getProject();
    if (AndroidGradleJps.hasAndroidGradleFacet(project)) {
        JavaBuilder.IS_ENABLED.set(context, false);
        AndroidSourceGeneratingBuilder.IS_ENABLED.set(context, false);
    }
}
Also used : JpsProject(org.jetbrains.jps.model.JpsProject)

Example 7 with JpsProject

use of org.jetbrains.jps.model.JpsProject 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 8 with JpsProject

use of org.jetbrains.jps.model.JpsProject in project intellij-community by JetBrains.

the class JavaBuilder method preferTargetJdkCompiler.

private static boolean preferTargetJdkCompiler(CompileContext context) {
    Boolean val = PREFER_TARGT_JDK_COMPILER.get(context);
    if (val == null) {
        final JpsProject project = context.getProjectDescriptor().getProject();
        final JpsJavaCompilerConfiguration config = JpsJavaExtensionService.getInstance().getCompilerConfiguration(project);
        // default
        val = config != null ? config.getCompilerOptions(JavaCompilers.JAVAC_ID).PREFER_TARGET_JDK_COMPILER : Boolean.TRUE;
        PREFER_TARGT_JDK_COMPILER.set(context, val);
    }
    return val;
}
Also used : JpsProject(org.jetbrains.jps.model.JpsProject)

Example 9 with JpsProject

use of org.jetbrains.jps.model.JpsProject in project intellij-community by JetBrains.

the class JavaBuilder method getJavaModuleIndex.

private static JavaModuleIndex getJavaModuleIndex(CompileContext context) {
    JpsProject project = context.getProjectDescriptor().getProject();
    File storageRoot = context.getProjectDescriptor().dataManager.getDataPaths().getDataStorageRoot();
    return JpsJavaExtensionService.getInstance().getJavaModuleIndex(project, storageRoot);
}
Also used : JpsProject(org.jetbrains.jps.model.JpsProject)

Example 10 with JpsProject

use of org.jetbrains.jps.model.JpsProject in project intellij-community by JetBrains.

the class JavaBuilder method loadCommonJavacOptions.

private static void loadCommonJavacOptions(@NotNull CompileContext context, @NotNull JavaCompilingTool compilingTool) {
    final List<String> options = new ArrayList<>();
    final List<String> vmOptions = new ArrayList<>();
    final JpsProject project = context.getProjectDescriptor().getProject();
    final JpsJavaCompilerConfiguration compilerConfig = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project);
    final JpsJavaCompilerOptions compilerOptions = compilerConfig.getCurrentCompilerOptions();
    if (compilerOptions.DEBUGGING_INFO) {
        options.add("-g");
    }
    if (compilerOptions.DEPRECATION) {
        options.add("-deprecation");
    }
    if (compilerOptions.GENERATE_NO_WARNINGS) {
        options.add("-nowarn");
    }
    if (compilerOptions instanceof EclipseCompilerOptions) {
        final EclipseCompilerOptions eclipseOptions = (EclipseCompilerOptions) compilerOptions;
        if (eclipseOptions.PROCEED_ON_ERROR) {
            options.add("-proceedOnError");
        }
    }
    final String customArgs = compilerOptions.ADDITIONAL_OPTIONS_STRING;
    if (customArgs != null) {
        final StringTokenizer customOptsTokenizer = new StringTokenizer(customArgs, " \t\r\n");
        boolean skip = false;
        boolean targetOptionFound = false;
        while (customOptsTokenizer.hasMoreTokens()) {
            final String userOption = customOptsTokenizer.nextToken();
            if (FILTERED_OPTIONS.contains(userOption)) {
                skip = true;
                targetOptionFound = "-target".equals(userOption);
                continue;
            }
            if (skip) {
                skip = false;
                if (targetOptionFound) {
                    targetOptionFound = false;
                    USER_DEFINED_BYTECODE_TARGET.set(context, userOption);
                }
            } else {
                if (!FILTERED_SINGLE_OPTIONS.contains(userOption)) {
                    if (userOption.startsWith("-J-")) {
                        vmOptions.add(userOption.substring("-J".length()));
                    } else {
                        options.add(userOption);
                    }
                }
            }
        }
    }
    for (ExternalJavacOptionsProvider extension : JpsServiceManager.getInstance().getExtensions(ExternalJavacOptionsProvider.class)) {
        vmOptions.addAll(extension.getOptions(compilingTool));
    }
    if (JavaCompilers.ECLIPSE_ID.equals(compilingTool.getId())) {
        for (String option : options) {
            if (option.startsWith("-proceedOnError")) {
                Utils.PROCEED_ON_ERROR_KEY.set(context, Boolean.TRUE);
                break;
            }
        }
    }
    JAVAC_OPTIONS.set(context, options);
    JAVAC_VM_OPTIONS.set(context, vmOptions);
}
Also used : JpsProject(org.jetbrains.jps.model.JpsProject) ContainerUtil.newArrayList(com.intellij.util.containers.ContainerUtil.newArrayList)

Aggregations

JpsProject (org.jetbrains.jps.model.JpsProject)17 File (java.io.File)8 IOException (java.io.IOException)4 NotNull (org.jetbrains.annotations.NotNull)4 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)4 JpsModule (org.jetbrains.jps.model.module.JpsModule)4 THashSet (gnu.trove.THashSet)3 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)3 JpsJavaExtensionService (org.jetbrains.jps.model.java.JpsJavaExtensionService)3 JpsCompilerExcludes (org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes)3 JpsJavaCompilerConfiguration (org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration)3 THashMap (gnu.trove.THashMap)2 FileFilter (java.io.FileFilter)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 ElixirCompilerOptions (org.elixir_lang.jps.model.ElixirCompilerOptions)2 ProjectBuildException (org.jetbrains.jps.incremental.ProjectBuildException)2 ResourcesTarget (org.jetbrains.jps.incremental.ResourcesTarget)2 OneToManyPathsMapping (org.jetbrains.jps.incremental.storage.OneToManyPathsMapping)2 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)2