use of org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile 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.compiler.ProcessorConfigProfile 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.compiler.ProcessorConfigProfile in project intellij-community by JetBrains.
the class AnnotationProcessorsConfigurable method isModified.
public boolean isModified() {
final CompilerConfigurationImpl config = (CompilerConfigurationImpl) CompilerConfiguration.getInstance(myProject);
if (!config.getDefaultProcessorProfile().equals(myMainPanel.getDefaultProfile())) {
return true;
}
final Map<String, ProcessorConfigProfile> configProfiles = new java.util.HashMap<>();
for (ProcessorConfigProfile profile : config.getModuleProcessorProfiles()) {
configProfiles.put(profile.getName(), profile);
}
final List<ProcessorConfigProfile> panelProfiles = myMainPanel.getModuleProfiles();
if (configProfiles.size() != panelProfiles.size()) {
return true;
}
for (ProcessorConfigProfile panelProfile : panelProfiles) {
final ProcessorConfigProfile configProfile = configProfiles.get(panelProfile.getName());
if (configProfile == null || !configProfile.equals(panelProfile)) {
return true;
}
}
return false;
}
use of org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile in project intellij-community by JetBrains.
the class CompilerConfigurationImpl method getState.
@Override
public Element getState() {
Element state = new Element("state");
XmlSerializer.serializeInto(myState, state, new SkipDefaultValuesSerializationFilters() {
@Override
public boolean accepts(@NotNull Accessor accessor, @NotNull Object bean) {
return super.accepts(accessor, bean);
}
});
if (!myAddNotNullAssertions) {
addChild(state, JpsJavaCompilerConfigurationSerializer.ADD_NOTNULL_ASSERTIONS).setAttribute(JpsJavaCompilerConfigurationSerializer.ENABLED, String.valueOf(myAddNotNullAssertions));
}
if (myExcludesConfiguration.getExcludeEntryDescriptions().length > 0) {
myExcludesConfiguration.writeExternal(addChild(state, JpsJavaCompilerConfigurationSerializer.EXCLUDE_FROM_COMPILE));
}
Element resourceExtensions = new Element(JpsJavaCompilerConfigurationSerializer.RESOURCE_EXTENSIONS);
for (String pattern : getRegexpPatterns()) {
addChild(resourceExtensions, JpsJavaCompilerConfigurationSerializer.ENTRY).setAttribute(JpsJavaCompilerConfigurationSerializer.NAME, pattern);
}
if (!JDOMUtil.isEmpty(resourceExtensions)) {
state.addContent(resourceExtensions);
}
if ((myWildcardPatternsInitialized || !myWildcardPatterns.isEmpty()) && !DEFAULT_WILDCARD_PATTERNS.equals(myWildcardPatterns)) {
final Element wildcardPatterns = addChild(state, JpsJavaCompilerConfigurationSerializer.WILDCARD_RESOURCE_PATTERNS);
for (final String wildcardPattern : myWildcardPatterns) {
addChild(wildcardPatterns, JpsJavaCompilerConfigurationSerializer.ENTRY).setAttribute(JpsJavaCompilerConfigurationSerializer.NAME, wildcardPattern);
}
}
Element annotationProcessingSettings = new Element(JpsJavaCompilerConfigurationSerializer.ANNOTATION_PROCESSING);
Element profileElement = new Element("profile");
profileElement.setAttribute("default", "true");
AnnotationProcessorProfileSerializer.writeExternal(myDefaultProcessorsProfile, profileElement);
if (!JDOMUtil.isEmpty(profileElement, 2)) {
annotationProcessingSettings.addContent(profileElement);
}
for (ProcessorConfigProfile profile : myModuleProcessorProfiles) {
Element element = new Element("profile");
AnnotationProcessorProfileSerializer.writeExternal(profile, element);
annotationProcessingSettings.addContent(element);
}
if (!JDOMUtil.isEmpty(annotationProcessingSettings)) {
state.addContent(annotationProcessingSettings);
}
if (!StringUtil.isEmpty(myBytecodeTargetLevel) || !myModuleBytecodeTarget.isEmpty()) {
final Element bytecodeTarget = addChild(state, JpsJavaCompilerConfigurationSerializer.BYTECODE_TARGET_LEVEL);
if (!StringUtil.isEmpty(myBytecodeTargetLevel)) {
bytecodeTarget.setAttribute(JpsJavaCompilerConfigurationSerializer.TARGET_ATTRIBUTE, myBytecodeTargetLevel);
}
if (!myModuleBytecodeTarget.isEmpty()) {
final List<String> moduleNames = new ArrayList<>(myModuleBytecodeTarget.keySet());
Collections.sort(moduleNames, String.CASE_INSENSITIVE_ORDER);
for (String name : moduleNames) {
final Element moduleElement = addChild(bytecodeTarget, JpsJavaCompilerConfigurationSerializer.MODULE);
moduleElement.setAttribute(JpsJavaCompilerConfigurationSerializer.NAME, name);
final String value = myModuleBytecodeTarget.get(name);
moduleElement.setAttribute(JpsJavaCompilerConfigurationSerializer.TARGET_ATTRIBUTE, value != null ? value : "");
}
}
}
return state;
}
use of org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile in project intellij-community by JetBrains.
the class CompilerConfigurationImpl method getAnnotationProcessingConfiguration.
@Override
@NotNull
public ProcessorConfigProfile getAnnotationProcessingConfiguration(Module module) {
Map<Module, ProcessorConfigProfile> map = myProcessorsProfilesMap;
if (map == null) {
map = new HashMap<>();
final Map<String, Module> namesMap = new HashMap<>();
for (Module m : ModuleManager.getInstance(module.getProject()).getModules()) {
namesMap.put(m.getName(), m);
}
if (!namesMap.isEmpty()) {
for (ProcessorConfigProfile profile : myModuleProcessorProfiles) {
for (String name : profile.getModuleNames()) {
final Module mod = namesMap.get(name);
if (mod != null) {
map.put(mod, profile);
}
}
}
}
myProcessorsProfilesMap = map;
}
final ProcessorConfigProfile profile = map.get(module);
return profile != null ? profile : myDefaultProcessorsProfile;
}
Aggregations