Search in sources :

Example 1 with JpsJavaCompilerConfiguration

use of org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration in project intellij-community by JetBrains.

the class FilteredResourceRootDescriptor method createFileFilter.

@NotNull
@Override
public FileFilter createFileFilter() {
    final JpsProject project = getTarget().getModule().getProject();
    final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project);
    final JpsCompilerExcludes excludes = configuration.getCompilerExcludes();
    return file -> !excludes.isExcluded(file) && configuration.isResourceFile(file, getRootFile());
}
Also used : JpsProject(org.jetbrains.jps.model.JpsProject) JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) FileFilter(java.io.FileFilter) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) ResourcesTarget(org.jetbrains.jps.incremental.ResourcesTarget) Set(java.util.Set) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService) NotNull(org.jetbrains.annotations.NotNull) File(java.io.File) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) JpsProject(org.jetbrains.jps.model.JpsProject) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JpsJavaCompilerConfiguration

use of org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration in project intellij-community by JetBrains.

the class ModuleBuildTarget method writeConfiguration.

@Override
public void writeConfiguration(ProjectDescriptor pd, PrintWriter out) {
    final JpsModule module = getModule();
    int fingerprint = getDependenciesFingerprint();
    for (JavaSourceRootDescriptor root : pd.getBuildRootIndex().getTargetRoots(this, null)) {
        fingerprint += FileUtil.fileHashCode(root.getRootFile());
    }
    final LanguageLevel level = JpsJavaExtensionService.getInstance().getLanguageLevel(module);
    if (level != null) {
        fingerprint += level.name().hashCode();
    }
    final JpsJavaCompilerConfiguration config = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(module.getProject());
    final String bytecodeTarget = config.getByteCodeTargetLevel(module.getName());
    if (bytecodeTarget != null) {
        fingerprint += bytecodeTarget.hashCode();
    }
    final CompilerEncodingConfiguration encodingConfig = pd.getEncodingConfiguration();
    final String encoding = encodingConfig.getPreferredModuleEncoding(module);
    if (encoding != null) {
        fingerprint += encoding.hashCode();
    }
    out.write(Integer.toHexString(fingerprint));
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)

Example 3 with JpsJavaCompilerConfiguration

use of org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration in project intellij-community by JetBrains.

the class ModuleBuildTarget method computeRootDescriptors.

@NotNull
@Override
public List<JavaSourceRootDescriptor> computeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) {
    List<JavaSourceRootDescriptor> roots = new ArrayList<>();
    JavaSourceRootType type = isTests() ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE;
    Iterable<ExcludedJavaSourceRootProvider> excludedRootProviders = JpsServiceManager.getInstance().getExtensions(ExcludedJavaSourceRootProvider.class);
    final JpsJavaCompilerConfiguration compilerConfig = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(myModule.getProject());
    roots_loop: for (JpsTypedModuleSourceRoot<JavaSourceRootProperties> sourceRoot : myModule.getSourceRoots(type)) {
        if (index.isExcludedFromModule(sourceRoot.getFile(), myModule)) {
            continue;
        }
        for (ExcludedJavaSourceRootProvider provider : excludedRootProviders) {
            if (provider.isExcludedFromCompilation(myModule, sourceRoot)) {
                continue roots_loop;
            }
        }
        final String packagePrefix = sourceRoot.getProperties().getPackagePrefix();
        // consider annotation processors output for generated sources, if contained under some source root
        Set<File> excludes = computeRootExcludes(sourceRoot.getFile(), index);
        final ProcessorConfigProfile profile = compilerConfig.getAnnotationProcessingProfile(myModule);
        if (profile.isEnabled()) {
            final File outputDir = ProjectPaths.getAnnotationProcessorGeneratedSourcesOutputDir(myModule, JavaSourceRootType.TEST_SOURCE == sourceRoot.getRootType(), profile);
            if (outputDir != null && FileUtil.isAncestor(sourceRoot.getFile(), outputDir, true)) {
                excludes = ContainerUtil.newTroveSet(FileUtil.FILE_HASHING_STRATEGY, excludes);
                excludes.add(outputDir);
            }
        }
        roots.add(new JavaSourceRootDescriptor(sourceRoot.getFile(), this, false, false, packagePrefix, excludes));
    }
    return roots;
}
Also used : JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) THashSet(gnu.trove.THashSet) Set(java.util.Set) ExcludedJavaSourceRootProvider(org.jetbrains.jps.builders.java.ExcludedJavaSourceRootProvider) JpsTypedModuleSourceRoot(org.jetbrains.jps.model.module.JpsTypedModuleSourceRoot) ArrayList(java.util.ArrayList) ProcessorConfigProfile(org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with JpsJavaCompilerConfiguration

use of org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration in project intellij-plugins by JetBrains.

the class FlexResourceBuildTarget method writeConfiguration.

@Override
public void writeConfiguration(ProjectDescriptor pd, final PrintWriter out) {
    out.println("Module: " + getModule().getName());
    for (JpsFlexBuildConfiguration bc : getModule().getProperties().getBuildConfigurations()) {
        if (!bc.isSkipCompile() && FlexCommonUtils.canHaveResourceFiles(bc.getNature()) && bc.getCompilerOptions().getResourceFilesMode() != JpsFlexCompilerOptions.ResourceFilesMode.None) {
            out.print("BC: " + bc.getName());
            out.print(", output folder: " + PathUtilRt.getParentPath(bc.getActualOutputFilePath()));
            out.print(", mode: " + bc.getCompilerOptions().getResourceFilesMode());
            if (bc.getCompilerOptions().getResourceFilesMode() == JpsFlexCompilerOptions.ResourceFilesMode.ResourcePatterns) {
                final JpsJavaCompilerConfiguration c = JpsJavaExtensionService.getInstance().getCompilerConfiguration(getModule().getProject());
                if (c != null) {
                    out.print(", patterns: " + StringUtil.join(c.getResourcePatterns(), " "));
                }
            }
            out.println();
        }
    }
}
Also used : JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) JpsFlexBuildConfiguration(com.intellij.flex.model.bc.JpsFlexBuildConfiguration)

Example 5 with JpsJavaCompilerConfiguration

use of org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration 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)

Aggregations

JpsJavaCompilerConfiguration (org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration)24 File (java.io.File)9 ProcessorConfigProfile (org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile)6 IOException (java.io.IOException)5 JpsCompilerExcludes (org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes)4 JpsModule (org.jetbrains.jps.model.module.JpsModule)4 NotNull (org.jetbrains.annotations.NotNull)3 JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)3 JpsProject (org.jetbrains.jps.model.JpsProject)3 JpsJavaCompilerOptions (org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions)3 JpsFlexBuildConfiguration (com.intellij.flex.model.bc.JpsFlexBuildConfiguration)2 Set (java.util.Set)2 Element (org.jdom.Element)2 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)2 JpsJavaExtensionService (org.jetbrains.jps.model.java.JpsJavaExtensionService)2 EclipseCompilerOptions (org.jetbrains.jps.model.java.compiler.EclipseCompilerOptions)2 RmicCompilerOptions (org.jetbrains.jps.model.java.compiler.RmicCompilerOptions)2 FlexResourceBuildTarget (com.intellij.flex.build.FlexResourceBuildTarget)1 SmartList (com.intellij.util.SmartList)1 THashMap (gnu.trove.THashMap)1