Search in sources :

Example 11 with ProcessorConfigProfile

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

the class CompilerConfigurationImpl method loadProfilesFromOldFormat.

private void loadProfilesFromOldFormat(Element processing) {
    // collect data
    final boolean isEnabled = Boolean.parseBoolean(processing.getAttributeValue(JpsJavaCompilerConfigurationSerializer.ENABLED, "false"));
    final boolean isUseClasspath = Boolean.parseBoolean(processing.getAttributeValue("useClasspath", "true"));
    final StringBuilder processorPath = new StringBuilder();
    final Set<String> optionPairs = new HashSet<>();
    final Set<String> processors = new HashSet<>();
    final List<Couple<String>> modulesToProcess = new ArrayList<>();
    for (Object child : processing.getChildren("processorPath")) {
        final Element pathElement = (Element) child;
        final String path = pathElement.getAttributeValue("value", (String) null);
        if (path != null) {
            if (processorPath.length() > 0) {
                processorPath.append(File.pathSeparator);
            }
            processorPath.append(path);
        }
    }
    for (Object child : processing.getChildren("processor")) {
        final Element processorElement = (Element) child;
        final String proc = processorElement.getAttributeValue(JpsJavaCompilerConfigurationSerializer.NAME, (String) null);
        if (proc != null) {
            processors.add(proc);
        }
        final StringTokenizer tokenizer = new StringTokenizer(processorElement.getAttributeValue("options", ""), " ", false);
        while (tokenizer.hasMoreTokens()) {
            final String pair = tokenizer.nextToken();
            optionPairs.add(pair);
        }
    }
    for (Object child : processing.getChildren("processModule")) {
        final Element moduleElement = (Element) child;
        final String name = moduleElement.getAttributeValue(JpsJavaCompilerConfigurationSerializer.NAME, (String) null);
        if (name == null) {
            continue;
        }
        final String dir = moduleElement.getAttributeValue("generatedDirName", (String) null);
        modulesToProcess.add(Couple.of(name, dir));
    }
    myDefaultProcessorsProfile.setEnabled(false);
    myDefaultProcessorsProfile.setObtainProcessorsFromClasspath(isUseClasspath);
    if (processorPath.length() > 0) {
        myDefaultProcessorsProfile.setProcessorPath(processorPath.toString());
    }
    if (!optionPairs.isEmpty()) {
        for (String pair : optionPairs) {
            final int index = pair.indexOf("=");
            if (index > 0) {
                myDefaultProcessorsProfile.setOption(pair.substring(0, index), pair.substring(index + 1));
            }
        }
    }
    for (String processor : processors) {
        myDefaultProcessorsProfile.addProcessor(processor);
    }
    final Map<String, Set<String>> dirNameToModulesMap = new HashMap<>();
    for (Couple<String> moduleDirPair : modulesToProcess) {
        final String dir = moduleDirPair.getSecond();
        Set<String> set = dirNameToModulesMap.get(dir);
        if (set == null) {
            set = new HashSet<>();
            dirNameToModulesMap.put(dir, set);
        }
        set.add(moduleDirPair.getFirst());
    }
    int profileIndex = 0;
    for (Map.Entry<String, Set<String>> entry : dirNameToModulesMap.entrySet()) {
        final String dirName = entry.getKey();
        final ProcessorConfigProfile profile = new ProcessorConfigProfileImpl(myDefaultProcessorsProfile);
        profile.setName("Profile" + (++profileIndex));
        profile.setEnabled(isEnabled);
        profile.setGeneratedSourcesDirectoryName(dirName, false);
        for (String moduleName : entry.getValue()) {
            profile.addModuleName(moduleName);
        }
        myModuleProcessorProfiles.add(profile);
    }
}
Also used : Element(org.jdom.Element) ProcessorConfigProfileImpl(org.jetbrains.jps.model.java.impl.compiler.ProcessorConfigProfileImpl) ProcessorConfigProfile(org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile)

Example 12 with ProcessorConfigProfile

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

the class AnnotationProcessorsPanel method initProfiles.

public void initProfiles(ProcessorConfigProfile defaultProfile, Collection<ProcessorConfigProfile> moduleProfiles) {
    myDefaultProfile.initFrom(defaultProfile);
    myModuleProfiles.clear();
    for (ProcessorConfigProfile profile : moduleProfiles) {
        ProcessorConfigProfile copy = new ProcessorConfigProfileImpl("");
        copy.initFrom(profile);
        myModuleProfiles.add(copy);
    }
    final RootNode root = (RootNode) myTree.getModel().getRoot();
    root.sync();
    final DefaultMutableTreeNode node = TreeUtil.findNodeWithObject(root, myDefaultProfile);
    if (node != null) {
        TreeUtil.selectNode(myTree, node);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ProcessorConfigProfile(org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile) ProcessorConfigProfileImpl(org.jetbrains.jps.model.java.impl.compiler.ProcessorConfigProfileImpl)

Example 13 with ProcessorConfigProfile

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

the class ModuleBuildTarget method getOutputRoots.

@NotNull
@Override
public Collection<File> getOutputRoots(CompileContext context) {
    Collection<File> result = new SmartList<>();
    final File outputDir = getOutputDir();
    if (outputDir != null) {
        result.add(outputDir);
    }
    final JpsModule module = getModule();
    final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(module.getProject());
    final ProcessorConfigProfile profile = configuration.getAnnotationProcessingProfile(module);
    if (profile.isEnabled()) {
        final File annotationOut = ProjectPaths.getAnnotationProcessorGeneratedSourcesOutputDir(module, isTests(), profile);
        if (annotationOut != null) {
            result.add(annotationOut);
        }
    }
    return result;
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) ProcessorConfigProfile(org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile) SmartList(com.intellij.util.SmartList) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with ProcessorConfigProfile

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

the class AnnotationsExcludedJavaSourceRootProvider method isExcludedFromCompilation.

@Override
public boolean isExcludedFromCompilation(@NotNull JpsModule module, @NotNull JpsModuleSourceRoot root) {
    final JpsJavaCompilerConfiguration compilerConfig = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(module.getProject());
    final ProcessorConfigProfile profile = compilerConfig.getAnnotationProcessingProfile(module);
    if (!profile.isEnabled()) {
        return false;
    }
    final File outputDir = ProjectPaths.getAnnotationProcessorGeneratedSourcesOutputDir(module, JavaSourceRootType.TEST_SOURCE == root.getRootType(), profile);
    return outputDir != null && FileUtil.filesEqual(outputDir, root.getFile());
}
Also used : JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) ProcessorConfigProfile(org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile) File(java.io.File)

Example 15 with ProcessorConfigProfile

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

the class JpsJavaCompilerConfigurationImpl method getAnnotationProcessingProfile.

@Override
@NotNull
public ProcessorConfigProfile getAnnotationProcessingProfile(JpsModule module) {
    Map<JpsModule, ProcessorConfigProfile> map = myAnnotationProcessingProfileMap;
    if (map == null) {
        map = new HashMap<>();
        final Map<String, JpsModule> namesMap = new HashMap<>();
        for (JpsModule m : module.getProject().getModules()) {
            namesMap.put(m.getName(), m);
        }
        if (!namesMap.isEmpty()) {
            for (ProcessorConfigProfile profile : getAnnotationProcessingProfiles()) {
                for (String name : profile.getModuleNames()) {
                    final JpsModule mod = namesMap.get(name);
                    if (mod != null) {
                        map.put(mod, profile);
                    }
                }
            }
        }
        myAnnotationProcessingProfileMap = map;
    }
    final ProcessorConfigProfile profile = map.get(module);
    return profile != null ? profile : getDefaultAnnotationProcessingProfile();
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) ProcessorConfigProfile(org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ProcessorConfigProfile (org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile)15 JpsJavaCompilerConfiguration (org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration)6 ProcessorConfigProfileImpl (org.jetbrains.jps.model.java.impl.compiler.ProcessorConfigProfileImpl)5 File (java.io.File)4 NotNull (org.jetbrains.annotations.NotNull)4 JpsModule (org.jetbrains.jps.model.module.JpsModule)4 Element (org.jdom.Element)3 CompilerConfigurationImpl (com.intellij.compiler.CompilerConfigurationImpl)2 State (com.intellij.openapi.components.State)1 Module (com.intellij.openapi.module.Module)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 SmartList (com.intellij.util.SmartList)1 Accessor (com.intellij.util.xmlb.Accessor)1 SkipDefaultValuesSerializationFilters (com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters)1 THashSet (gnu.trove.THashSet)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1