use of org.jetbrains.jps.model.java.impl.compiler.ProcessorConfigProfileImpl in project intellij-community by JetBrains.
the class MavenAnnotationProcessorConfigurer method cleanAndMergeModuleProfiles.
private static void cleanAndMergeModuleProfiles(@NotNull MavenProject rootProject, @NotNull CompilerConfigurationImpl compilerConfiguration, @Nullable ProcessorConfigProfile moduleProfile, boolean isDefault, @NotNull Module module) {
List<ProcessorConfigProfile> profiles = ContainerUtil.newArrayList(compilerConfiguration.getModuleProcessorProfiles());
for (ProcessorConfigProfile p : profiles) {
if (p != moduleProfile) {
p.removeModuleName(module.getName());
if (p.getModuleNames().isEmpty()) {
compilerConfiguration.removeModuleProcessorProfile(p);
}
}
if (!isDefault && moduleProfile != null && isSimilarProfiles(p, moduleProfile)) {
final String mavenProjectRootProfileName = PROFILE_PREFIX + rootProject.getDisplayName();
ProcessorConfigProfile mergedProfile = compilerConfiguration.findModuleProcessorProfile(mavenProjectRootProfileName);
if (mergedProfile == null) {
mergedProfile = new ProcessorConfigProfileImpl(moduleProfile);
mergedProfile.setName(mavenProjectRootProfileName);
compilerConfiguration.addModuleProcessorProfile(mergedProfile);
mergedProfile.addModuleNames(p.getModuleNames());
p.clearModuleNames();
compilerConfiguration.removeModuleProcessorProfile(p);
moduleProfile.clearModuleNames();
compilerConfiguration.removeModuleProcessorProfile(moduleProfile);
} else if (p == mergedProfile || isSimilarProfiles(mergedProfile, moduleProfile)) {
if (moduleProfile != mergedProfile) {
mergedProfile.addModuleNames(moduleProfile.getModuleNames());
moduleProfile.clearModuleNames();
compilerConfiguration.removeModuleProcessorProfile(moduleProfile);
}
if (p != mergedProfile) {
mergedProfile.addModuleNames(p.getModuleNames());
p.clearModuleNames();
compilerConfiguration.removeModuleProcessorProfile(p);
}
}
}
}
}
use of org.jetbrains.jps.model.java.impl.compiler.ProcessorConfigProfileImpl in project intellij-community by JetBrains.
the class MavenAnnotationProcessorConfigurer method configure.
@Override
public void configure(@NotNull MavenProject mavenProject, @NotNull Project project, @Nullable Module module) {
if (module == null)
return;
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
if (sdk != null) {
String versionString = sdk.getVersionString();
if (versionString != null) {
if (versionString.contains("1.5") || versionString.contains("1.4") || versionString.contains("1.3") || versionString.contains("1.2")) {
return;
}
}
}
final CompilerConfigurationImpl compilerConfiguration = (CompilerConfigurationImpl) CompilerConfiguration.getInstance(project);
final MavenProject rootProject = ObjectUtils.notNull(MavenProjectsManager.getInstance(project).findRootProject(mavenProject), mavenProject);
if (shouldEnableAnnotationProcessors(mavenProject)) {
final String moduleProfileName;
String annotationProcessorDirectory = getRelativeAnnotationProcessorDirectory(mavenProject, false);
if (annotationProcessorDirectory == null) {
annotationProcessorDirectory = DEFAULT_ANNOTATION_PATH_OUTPUT;
}
String testAnnotationProcessorDirectory = getRelativeAnnotationProcessorDirectory(mavenProject, true);
if (testAnnotationProcessorDirectory == null) {
testAnnotationProcessorDirectory = DEFAULT_TEST_ANNOTATION_OUTPUT;
}
final boolean isDefault;
if (isMavenDefaultAnnotationProcessorConfiguration(annotationProcessorDirectory, testAnnotationProcessorDirectory, mavenProject)) {
moduleProfileName = MAVEN_DEFAULT_ANNOTATION_PROFILE;
isDefault = true;
} else if (isMavenProcessorPluginDefaultConfiguration(annotationProcessorDirectory, testAnnotationProcessorDirectory, mavenProject)) {
moduleProfileName = MAVEN_BSC_DEFAULT_ANNOTATION_PROFILE;
isDefault = true;
} else {
moduleProfileName = PROFILE_PREFIX + module.getName();
isDefault = false;
}
ProcessorConfigProfile moduleProfile = compilerConfiguration.findModuleProcessorProfile(moduleProfileName);
if (moduleProfile == null) {
moduleProfile = new ProcessorConfigProfileImpl(moduleProfileName);
compilerConfiguration.addModuleProcessorProfile(moduleProfile);
}
moduleProfile.setOutputRelativeToContentRoot(true);
moduleProfile.setEnabled(true);
moduleProfile.setObtainProcessorsFromClasspath(true);
moduleProfile.setGeneratedSourcesDirectoryName(annotationProcessorDirectory, false);
moduleProfile.setGeneratedSourcesDirectoryName(testAnnotationProcessorDirectory, true);
moduleProfile.clearProcessorOptions();
for (Map.Entry<String, String> entry : mavenProject.getAnnotationProcessorOptions().entrySet()) {
moduleProfile.setOption(entry.getKey(), entry.getValue());
}
moduleProfile.clearProcessors();
final List<String> processors = mavenProject.getDeclaredAnnotationProcessors();
if (processors != null) {
for (String processor : processors) {
moduleProfile.addProcessor(processor);
}
}
moduleProfile.addModuleName(module.getName());
cleanAndMergeModuleProfiles(rootProject, compilerConfiguration, moduleProfile, isDefault, module);
} else {
cleanAndMergeModuleProfiles(rootProject, compilerConfiguration, null, false, module);
}
}
use of org.jetbrains.jps.model.java.impl.compiler.ProcessorConfigProfileImpl in project intellij-community by JetBrains.
the class CompilerConfigurationImpl method readExternal.
public void readExternal(Element parentNode) {
myState = XmlSerializer.deserialize(parentNode, State.class);
if (!myProject.isDefault()) {
for (Element option : parentNode.getChildren("option")) {
if ("DEFAULT_COMPILER".equals(option.getAttributeValue("name"))) {
break;
}
}
if (myState.BUILD_PROCESS_HEAP_SIZE == DEFAULT_BUILD_PROCESS_HEAP_SIZE) {
final CompilerWorkspaceConfiguration workspace = CompilerWorkspaceConfiguration.getInstance(myProject);
// older version compatibility: as a fallback load this setting from workspace
myState.BUILD_PROCESS_HEAP_SIZE = workspace.COMPILER_PROCESS_HEAP_SIZE;
}
}
final Element notNullAssertions = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.ADD_NOTNULL_ASSERTIONS);
if (notNullAssertions != null) {
myAddNotNullAssertions = Boolean.valueOf(notNullAssertions.getAttributeValue(JpsJavaCompilerConfigurationSerializer.ENABLED, "true"));
}
Element node = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.EXCLUDE_FROM_COMPILE);
if (node != null) {
myExcludesConfiguration.readExternal(node);
}
try {
removeRegexpPatterns();
node = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.RESOURCE_EXTENSIONS);
if (node != null) {
for (final Object o : node.getChildren(JpsJavaCompilerConfigurationSerializer.ENTRY)) {
Element element = (Element) o;
String pattern = element.getAttributeValue(JpsJavaCompilerConfigurationSerializer.NAME);
if (!StringUtil.isEmpty(pattern)) {
addRegexpPattern(pattern);
}
}
}
node = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.WILDCARD_RESOURCE_PATTERNS);
if (node != null) {
myWildcardPatternsInitialized = true;
removeWildcardPatterns();
for (Element element : node.getChildren(JpsJavaCompilerConfigurationSerializer.ENTRY)) {
String pattern = element.getAttributeValue(JpsJavaCompilerConfigurationSerializer.NAME);
if (!StringUtil.isEmpty(pattern)) {
addWildcardResourcePattern(pattern);
}
}
}
} catch (MalformedPatternException e) {
LOG.error(e);
}
myModuleProcessorProfiles.clear();
myProcessorsProfilesMap = null;
final Element annotationProcessingSettings = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.ANNOTATION_PROCESSING);
if (annotationProcessingSettings != null) {
final List profiles = annotationProcessingSettings.getChildren("profile");
if (!profiles.isEmpty()) {
for (Object elem : profiles) {
final Element profileElement = (Element) elem;
final boolean isDefault = "true".equals(profileElement.getAttributeValue("default"));
if (isDefault) {
AnnotationProcessorProfileSerializer.readExternal(myDefaultProcessorsProfile, profileElement);
} else {
final ProcessorConfigProfile profile = new ProcessorConfigProfileImpl("");
AnnotationProcessorProfileSerializer.readExternal(profile, profileElement);
myModuleProcessorProfiles.add(profile);
}
}
} else {
// assuming older format
loadProfilesFromOldFormat(annotationProcessingSettings);
}
}
myBytecodeTargetLevel = null;
myModuleBytecodeTarget.clear();
final Element bytecodeTargetElement = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.BYTECODE_TARGET_LEVEL);
if (bytecodeTargetElement != null) {
myBytecodeTargetLevel = bytecodeTargetElement.getAttributeValue(JpsJavaCompilerConfigurationSerializer.TARGET_ATTRIBUTE);
for (Element elem : bytecodeTargetElement.getChildren(JpsJavaCompilerConfigurationSerializer.MODULE)) {
final String name = elem.getAttributeValue(JpsJavaCompilerConfigurationSerializer.NAME);
if (name == null) {
continue;
}
final String target = elem.getAttributeValue(JpsJavaCompilerConfigurationSerializer.TARGET_ATTRIBUTE);
if (target == null) {
continue;
}
myModuleBytecodeTarget.put(name, target);
}
}
}
use of org.jetbrains.jps.model.java.impl.compiler.ProcessorConfigProfileImpl 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.impl.compiler.ProcessorConfigProfileImpl 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);
}
}
Aggregations