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);
}
}
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);
}
}
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;
}
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());
}
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();
}
Aggregations