private void configEncoding() { if (Boolean.parseBoolean(System.getProperty("maven.disable.encode.import"))) return; String encoding = myMavenProject.getEncoding(); if (encoding != null) { try { EncodingProjectManager.getInstance(myModule.getProject()) .setEncoding(myMavenProject.getDirectoryFile(), Charset.forName(encoding)); } catch (UnsupportedCharsetException ignored) { /**/ } catch (IllegalCharsetNameException ignored) { /**/ } } }
private void configAnnotationProcessors() { if (Boolean.parseBoolean(System.getProperty("idea.maven.keep.annotation.processors"))) return; Sdk sdk = ModuleRootManager.getInstance(myModule).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; } } } CompilerConfigurationImpl compilerConfiguration = (CompilerConfigurationImpl) CompilerConfiguration.getInstance(myModule.getProject()); ProcessorConfigProfile currentProfile = compilerConfiguration.getAnnotationProcessingConfiguration(myModule); String moduleProfileName = PROFILE_PREFIX + myModule.getName(); if (currentProfile != compilerConfiguration.getDefaultProcessorProfile() && !MAVEN_DEFAULT_ANNOTATION_PROFILE.equals(currentProfile.getName()) && !moduleProfileName.equals(currentProfile.getName())) { return; } ProcessorConfigProfile moduleProfile = compilerConfiguration.findModuleProcessorProfile(moduleProfileName); ProcessorConfigProfile defaultMavenProfile = compilerConfiguration.findModuleProcessorProfile(MAVEN_DEFAULT_ANNOTATION_PROFILE); if (shouldEnableAnnotationProcessors()) { String annotationProcessorDirectory = getRelativeAnnotationProcessorDirectory(false); if (annotationProcessorDirectory == null) { annotationProcessorDirectory = DEFAULT_ANNOTATION_PATH_OUTPUT; } String testAnnotationProcessorDirectory = getRelativeAnnotationProcessorDirectory(true); if (testAnnotationProcessorDirectory == null) { testAnnotationProcessorDirectory = DEFAULT_TEST_ANNOTATION_OUTPUT; } Map<String, String> options = myMavenProject.getAnnotationProcessorOptions(); List<String> processors = myMavenProject.getDeclaredAnnotationProcessors(); if (processors == null && options.isEmpty() && DEFAULT_ANNOTATION_PATH_OUTPUT.equals(annotationProcessorDirectory.replace('\\', '/')) && DEFAULT_TEST_ANNOTATION_OUTPUT.equals( testAnnotationProcessorDirectory.replace('\\', '/'))) { if (moduleProfile != null) { compilerConfiguration.removeModuleProcessorProfile(moduleProfile); } if (defaultMavenProfile == null) { defaultMavenProfile = new ProcessorConfigProfileImpl(MAVEN_DEFAULT_ANNOTATION_PROFILE); defaultMavenProfile.setEnabled(true); defaultMavenProfile.setOutputRelativeToContentRoot(true); defaultMavenProfile.setObtainProcessorsFromClasspath(true); defaultMavenProfile.setGeneratedSourcesDirectoryName( DEFAULT_ANNOTATION_PATH_OUTPUT, false); defaultMavenProfile.setGeneratedSourcesDirectoryName( DEFAULT_TEST_ANNOTATION_OUTPUT, true); compilerConfiguration.addModuleProcessorProfile(defaultMavenProfile); } defaultMavenProfile.addModuleName(myModule.getName()); } else { if (defaultMavenProfile != null) { defaultMavenProfile.removeModuleName(myModule.getName()); if (defaultMavenProfile.getModuleNames().isEmpty()) { compilerConfiguration.removeModuleProcessorProfile(defaultMavenProfile); } } if (moduleProfile == null) { moduleProfile = new ProcessorConfigProfileImpl(moduleProfileName); moduleProfile.setOutputRelativeToContentRoot(true); moduleProfile.setEnabled(true); moduleProfile.setObtainProcessorsFromClasspath(true); moduleProfile.addModuleName(myModule.getName()); compilerConfiguration.addModuleProcessorProfile(moduleProfile); } moduleProfile.setGeneratedSourcesDirectoryName(annotationProcessorDirectory, false); moduleProfile.setGeneratedSourcesDirectoryName(testAnnotationProcessorDirectory, true); moduleProfile.clearProcessorOptions(); for (Map.Entry<String, String> entry : options.entrySet()) { moduleProfile.setOption(entry.getKey(), entry.getValue()); } moduleProfile.clearProcessors(); if (processors != null) { for (String processor : processors) { moduleProfile.addProcessor(processor); } } } } else { if (defaultMavenProfile != null) { defaultMavenProfile.removeModuleName(myModule.getName()); if (defaultMavenProfile.getModuleNames().isEmpty()) { compilerConfiguration.removeModuleProcessorProfile(defaultMavenProfile); } } if (moduleProfile != null) { compilerConfiguration.removeModuleProcessorProfile(moduleProfile); } } }