[maven] IDEA-340501 convert MavenAnnotationProcessorConfigurator to kotlin

GitOrigin-RevId: 9dac7c4f36b058d0e0c2cbd2f087e99964bef6bf
This commit is contained in:
Dmitry Kichinsky
2024-01-28 10:23:43 +00:00
committed by intellij-monorepo-bot
parent 62344997a4
commit 3ffa433f71
2 changed files with 408 additions and 464 deletions
@@ -1,538 +1,502 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.maven.importing;
package org.jetbrains.idea.maven.importing
import com.intellij.compiler.CompilerConfiguration;
import com.intellij.compiler.CompilerConfigurationImpl;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.OrderEnumerator;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.platform.workspace.jps.entities.ModuleEntity;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.util.Consumer;
import com.intellij.util.ExceptionUtil;
import com.intellij.util.ObjectUtils;
import com.intellij.util.containers.ContainerUtil;
import kotlin.sequences.SequencesKt;
import org.jdom.Element;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.execution.SyncBundle;
import org.jetbrains.idea.maven.model.MavenArtifact;
import org.jetbrains.idea.maven.model.MavenArtifactInfo;
import org.jetbrains.idea.maven.model.MavenId;
import org.jetbrains.idea.maven.project.*;
import org.jetbrains.idea.maven.server.MavenArtifactResolveResult;
import org.jetbrains.idea.maven.server.MavenEmbedderWrapper;
import org.jetbrains.idea.maven.server.NativeMavenProjectHolder;
import org.jetbrains.idea.maven.utils.MavenProcessCanceledException;
import org.jetbrains.jps.model.java.JavaSourceRootType;
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile;
import org.jetbrains.jps.model.java.impl.compiler.ProcessorConfigProfileImpl;
import org.jetbrains.jps.util.JpsPathUtil;
import com.intellij.compiler.CompilerConfiguration
import com.intellij.compiler.CompilerConfigurationImpl
import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.OrderEnumerator
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.NlsSafe
import com.intellij.openapi.util.Pair
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.text.StringUtil
import com.intellij.pom.java.LanguageLevel
import com.intellij.util.Consumer
import com.intellij.util.ExceptionUtil
import com.intellij.util.containers.ContainerUtil
import org.jdom.Element
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.idea.maven.execution.SyncBundle
import org.jetbrains.idea.maven.importing.MavenWorkspaceConfigurator.*
import org.jetbrains.idea.maven.model.MavenArtifactInfo
import org.jetbrains.idea.maven.model.MavenId
import org.jetbrains.idea.maven.project.*
import org.jetbrains.idea.maven.server.MavenEmbedderWrapper
import org.jetbrains.idea.maven.server.NativeMavenProjectHolder
import org.jetbrains.idea.maven.utils.MavenProcessCanceledException
import org.jetbrains.jps.model.java.JavaSourceRootType
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile
import org.jetbrains.jps.model.java.impl.compiler.ProcessorConfigProfileImpl
import org.jetbrains.jps.util.JpsPathUtil
import java.io.File
import java.nio.file.Path
import java.util.*
import java.util.function.Function
import java.io.File;
import java.nio.file.Path;
import java.util.*;
import java.util.function.Function;
import static com.intellij.openapi.roots.OrderEnumerator.orderEntries;
private const val PROFILE_PREFIX = "Annotation profile for "
const val MAVEN_DEFAULT_ANNOTATION_PROFILE: String = "Maven default annotation processors profile"
private const val DEFAULT_ANNOTATION_PATH_OUTPUT = "target/generated-sources/annotations"
private const val DEFAULT_TEST_ANNOTATION_OUTPUT = "target/generated-test-sources/test-annotations"
private const val DEFAULT_BSC_ANNOTATION_PATH_OUTPUT = "target/generated-sources/apt"
private const val DEFAULT_BSC_TEST_ANNOTATION_OUTPUT = "target/generated-sources/apt-test"
val MAVEN_BSC_DEFAULT_ANNOTATION_PROFILE: String = MavenAnnotationProcessorConfiguratorUtil.getModuleProfileName(
"maven-processor-plugin default configuration")
private val ANNOTATION_PROCESSOR_MODULE_NAMES = Key.create<MutableMap<MavenProject, MutableList<String>>>(
"ANNOTATION_PROCESSOR_MODULE_NAMES")
@ApiStatus.Internal
public class MavenAnnotationProcessorConfigurator extends MavenImporter implements MavenWorkspaceConfigurator {
private static final String PROFILE_PREFIX = "Annotation profile for ";
public static final String MAVEN_DEFAULT_ANNOTATION_PROFILE = "Maven default annotation processors profile";
private static final String DEFAULT_ANNOTATION_PATH_OUTPUT = "target/generated-sources/annotations";
private static final String DEFAULT_TEST_ANNOTATION_OUTPUT = "target/generated-test-sources/test-annotations";
public static final String MAVEN_BSC_DEFAULT_ANNOTATION_PROFILE = getModuleProfileName("maven-processor-plugin default configuration");
private static final String DEFAULT_BSC_ANNOTATION_PATH_OUTPUT = "target/generated-sources/apt";
private static final String DEFAULT_BSC_TEST_ANNOTATION_OUTPUT = "target/generated-sources/apt-test";
private static final Key<Map<MavenProject, List<String>>> ANNOTATION_PROCESSOR_MODULE_NAMES =
Key.create("ANNOTATION_PROCESSOR_MODULE_NAMES");
public MavenAnnotationProcessorConfigurator() {
super("org.apache.maven.plugins", "maven-compiler-plugin");
class MavenAnnotationProcessorConfigurator : MavenImporter("org.apache.maven.plugins",
"maven-compiler-plugin"), MavenWorkspaceConfigurator {
override fun isApplicable(mavenProject: MavenProject): Boolean {
return true
}
@Override
public boolean isApplicable(MavenProject mavenProject) {
return true;
override fun isMigratedToConfigurator(): Boolean {
return true
}
@Override
public boolean isMigratedToConfigurator() {
return true;
}
@Override
public void beforeModelApplied(@NotNull MavenWorkspaceConfigurator.MutableModelContext context) {
Map<MavenId, List<String>> mavenProjectToModuleNamesCache = new HashMap<>();
for (MavenProjectWithModules<ModuleEntity> each : SequencesKt.asIterable(context.getMavenProjectsWithModules())) {
List<String> moduleNames =
ContainerUtil.mapNotNull(each.getModules(), it -> it.getType().getContainsCode() ? it.getModule().getName() : null);
mavenProjectToModuleNamesCache.put(each.getMavenProject().getMavenId(), moduleNames);
override fun beforeModelApplied(context: MutableModelContext) {
val mavenProjectToModuleNamesCache: MutableMap<MavenId, List<String>> = HashMap()
for (each in context.mavenProjectsWithModules.asIterable()) {
val moduleNames = each.modules.mapNotNull { if (it.type.containsCode) it.module.name else null }
mavenProjectToModuleNamesCache[each.mavenProject.mavenId] = moduleNames
}
var changedOnlyProjects = SequencesKt.mapNotNull(context.getMavenProjectsWithModules(), it -> {
return it.getChanges().hasChanges() ? it.getMavenProject() : null;
});
val changedOnlyProjects = context.mavenProjectsWithModules.mapNotNull { if (it.changes.hasChanges()) it.mavenProject else null }
var map = new HashMap<MavenProject, List<String>>();
collectProcessorModuleNames(SequencesKt.asIterable(changedOnlyProjects),
moduleName -> mavenProjectToModuleNamesCache.get(moduleName),
map);
ANNOTATION_PROCESSOR_MODULE_NAMES.set(context, map);
val map = HashMap<MavenProject, MutableList<String>>()
collectProcessorModuleNames(changedOnlyProjects.asIterable(),
Function { moduleName: MavenId -> mavenProjectToModuleNamesCache[moduleName] },
map)
ANNOTATION_PROCESSOR_MODULE_NAMES[context] = map
}
@Override
public void process(@NotNull IdeModifiableModelsProvider modifiableModelsProvider,
@NotNull Module module,
@NotNull MavenRootModelAdapter rootModel,
@NotNull MavenProjectsTree mavenModel,
@NotNull MavenProject mavenProject,
@NotNull MavenProjectChanges changes,
@NotNull Map<MavenProject, String> mavenProjectToModuleName,
@NotNull List<MavenProjectsProcessorTask> postTasks) {
Element config = getConfig(mavenProject, "annotationProcessorPaths");
if (config == null) return;
override fun process(modifiableModelsProvider: IdeModifiableModelsProvider,
module: Module,
rootModel: MavenRootModelAdapter,
mavenModel: MavenProjectsTree,
mavenProject: MavenProject,
changes: MavenProjectChanges,
mavenProjectToModuleName: Map<MavenProject, String>,
postTasks: List<MavenProjectsProcessorTask>) {
val config = getConfig(mavenProject, "annotationProcessorPaths")
if (config == null) return
String annotationTargetDir = mavenProject.getAnnotationProcessorDirectory(false);
val annotationTargetDir = mavenProject.getAnnotationProcessorDirectory(false)
// directory must exist before compilation start to be recognized as source root
new File(rootModel.toPath(annotationTargetDir).getPath()).mkdirs();
rootModel.addGeneratedJavaSourceFolder(annotationTargetDir, JavaSourceRootType.SOURCE, false);
File(rootModel.toPath(annotationTargetDir).path).mkdirs()
rootModel.addGeneratedJavaSourceFolder(annotationTargetDir, JavaSourceRootType.SOURCE, false)
Map<MavenProject, List<String>> map = ANNOTATION_PROCESSOR_MODULE_NAMES.get(modifiableModelsProvider, new HashMap<>());
collectProcessorModuleNames(List.of(mavenProject),
mavenId -> {
MavenProject mavenArtifact = mavenModel.findProject(mavenId);
if (mavenArtifact == null) return null;
String moduleName = mavenProjectToModuleName.get(mavenArtifact);
if (moduleName == null) return null;
return List.of(moduleName);
val map = ANNOTATION_PROCESSOR_MODULE_NAMES[modifiableModelsProvider, HashMap()]
collectProcessorModuleNames(java.util.List.of(mavenProject),
{ mavenId: MavenId? ->
val mavenArtifact = mavenModel.findProject(mavenId)
if (mavenArtifact == null) return@collectProcessorModuleNames null
val moduleName = mavenProjectToModuleName[mavenArtifact]
if (moduleName == null) return@collectProcessorModuleNames null
java.util.List.of(moduleName)
},
map);
ANNOTATION_PROCESSOR_MODULE_NAMES.set(modifiableModelsProvider, map);
map)
ANNOTATION_PROCESSOR_MODULE_NAMES[modifiableModelsProvider] = map
}
private void collectProcessorModuleNames(Iterable<MavenProject> projects,
Function<@NotNull MavenId, @Nullable List<String>> moduleNameByProjectId,
Map<MavenProject, List<String>> result) {
for (var mavenProject : projects) {
if (!shouldEnableAnnotationProcessors(mavenProject)) continue;
private fun collectProcessorModuleNames(projects: Iterable<MavenProject>,
moduleNameByProjectId: Function<MavenId, List<String>?>,
result: MutableMap<MavenProject, MutableList<String>>) {
for (mavenProject in projects) {
if (!shouldEnableAnnotationProcessors(mavenProject)) continue
Element config = getConfig(mavenProject, "annotationProcessorPaths");
if (config == null) continue;
val config = getConfig(mavenProject, "annotationProcessorPaths")
if (config == null) continue
for (MavenArtifactInfo info : getProcessorArtifactInfos(config)) {
var mavenId = new MavenId(info.getGroupId(), info.getArtifactId(), info.getVersion());
for (info in getProcessorArtifactInfos(config)) {
val mavenId = MavenId(info.groupId, info.artifactId, info.version)
var processorModuleNames = moduleNameByProjectId.apply(mavenId);
val processorModuleNames = moduleNameByProjectId.apply(mavenId)
if (processorModuleNames != null) {
result.computeIfAbsent(mavenProject, __ -> new ArrayList<>()).addAll(processorModuleNames);
result.computeIfAbsent(mavenProject) { _: MavenProject? -> ArrayList() }.addAll(processorModuleNames)
}
}
}
}
@Override
public void afterModelApplied(@NotNull MavenWorkspaceConfigurator.AppliedModelContext context) {
Map<String, Module> nameToModuleCache = new HashMap<>();
for (MavenProjectWithModules<Module> each : SequencesKt.asIterable(context.getMavenProjectsWithModules())) {
for (ModuleWithType<Module> moduleWithType : each.getModules()) {
Module module = moduleWithType.getModule();
nameToModuleCache.put(module.getName(), module);
override fun afterModelApplied(context: AppliedModelContext) {
val nameToModuleCache: MutableMap<String, Module> = HashMap()
for (each in context.mavenProjectsWithModules.asIterable()) {
for (moduleWithType in each.modules) {
val module = moduleWithType.module
nameToModuleCache[module.name] = module
}
}
Function<@NotNull String, @Nullable Module> moduleByName = moduleName -> nameToModuleCache.get(moduleName);
val moduleByName = Function { moduleName: String -> nameToModuleCache[moduleName] }
Map<MavenProject, List<String>> perProjectProcessorModuleNames = ANNOTATION_PROCESSOR_MODULE_NAMES.get(context, Map.of());
val perProjectProcessorModuleNames: Map<MavenProject, MutableList<String>> = ANNOTATION_PROCESSOR_MODULE_NAMES[context, java.util.Map.of()]
var changedOnly = SequencesKt.filter(context.getMavenProjectsWithModules(), it -> it.getChanges().hasChanges());
var projectWithModules = SequencesKt.map(changedOnly, it -> {
List<String> processorModuleNames = perProjectProcessorModuleNames.getOrDefault(it.getMavenProject(), List.of());
return new MavenProjectWithProcessorModules(it.getMavenProject(), it.getModules(), processorModuleNames);
});
val changedOnly = context.mavenProjectsWithModules.filter { it: MavenProjectWithModules<Module> -> it.changes.hasChanges() }
val projectWithModules = changedOnly.map { it: MavenProjectWithModules<Module> ->
val processorModuleNames = perProjectProcessorModuleNames.getOrDefault(it.mavenProject, listOf())
MavenProjectWithProcessorModules(it.mavenProject, it.modules, processorModuleNames)
}
configureProfiles(context.getProject(),
context.getMavenProjectsTree(),
SequencesKt.asIterable(projectWithModules),
moduleByName);
configureProfiles(context.project,
context.mavenProjectsTree,
projectWithModules.asIterable(),
moduleByName)
}
@Override
public void postProcess(Module module,
MavenProject mavenProject,
MavenProjectChanges changes,
IdeModifiableModelsProvider modifiableModelsProvider) {
var processorModuleNames =
ANNOTATION_PROCESSOR_MODULE_NAMES.get(modifiableModelsProvider, Map.of()).getOrDefault(mavenProject, List.of());
override fun postProcess(module: Module,
mavenProject: MavenProject,
changes: MavenProjectChanges,
modifiableModelsProvider: IdeModifiableModelsProvider) {
val processorModuleNames =
ANNOTATION_PROCESSOR_MODULE_NAMES[modifiableModelsProvider, java.util.Map.of()].getOrDefault(mavenProject, listOf())
var moduleWithType = new ModuleWithType<Module>() {
@Override
public Module getModule() {
return module;
}
val moduleWithType: ModuleWithType<Module> = object : ModuleWithType<Module> {
override val module: Module
get() = module
@NotNull
@Override
public MavenModuleType getType() {
return StandardMavenModuleType.SINGLE_MODULE;
}
};
var projectWithModules = new MavenProjectWithProcessorModules(mavenProject,
List.of(moduleWithType),
processorModuleNames);
configureProfiles(module.getProject(),
MavenProjectsManager.getInstance(module.getProject()).getProjectsTree(),
List.of(projectWithModules),
moduleName -> modifiableModelsProvider.findIdeModule(moduleName));
override val type: MavenModuleType
get() = StandardMavenModuleType.SINGLE_MODULE
}
val projectWithModules = MavenProjectWithProcessorModules(mavenProject,
listOf(moduleWithType),
processorModuleNames)
configureProfiles(module.project,
MavenProjectsManager.getInstance(module.project).projectsTree,
java.util.List.of(projectWithModules)
) { moduleName: String? ->
modifiableModelsProvider.findIdeModule(
moduleName!!)
}
}
private static class MavenProjectWithProcessorModules {
private final MavenProject mavenProject;
private final List<ModuleWithType<Module>> mavenProjectModules;
private final List<String> processorModuleNames;
private class MavenProjectWithProcessorModules(val mavenProject: MavenProject,
val mavenProjectModules: List<ModuleWithType<Module>>,
val processorModuleNames: List<String>)
private MavenProjectWithProcessorModules(MavenProject mavenProject,
List<ModuleWithType<Module>> mavenProjectModules,
List<String> processorModuleNames) {
this.mavenProject = mavenProject;
this.mavenProjectModules = mavenProjectModules;
this.processorModuleNames = processorModuleNames;
}
}
@Throws(MavenProcessCanceledException::class)
override fun resolve(project: Project,
mavenProject: MavenProject,
nativeMavenProject: NativeMavenProjectHolder,
embedder: MavenEmbedderWrapper) {
val config = getConfig(mavenProject, "annotationProcessorPaths")
if (config == null) return
private static void configureProfiles(Project project,
MavenProjectsTree tree,
Iterable<MavenProjectWithProcessorModules> projectsWithModules,
Function<@NotNull String, @Nullable Module> moduleByName) {
CompilerConfigurationImpl compilerConfiguration = (CompilerConfigurationImpl)CompilerConfiguration.getInstance(project);
for (var it : projectsWithModules) {
MavenProject rootProject = ObjectUtils.notNull(tree.findRootProject(it.mavenProject), it.mavenProject);
for (var moduleWithType : it.mavenProjectModules) {
Module module = moduleWithType.getModule();
MavenModuleType moduleType = moduleWithType.getType();
if (!isLevelMoreThan6(module)) continue;
if (shouldEnableAnnotationProcessors(it.mavenProject) && moduleType.getContainsCode()) {
var processorModules = ContainerUtil.mapNotNull(it.processorModuleNames, eachName -> moduleByName.apply(eachName));
var profileIsDefault = createOrUpdateProfile(it.mavenProject, module, processorModules, compilerConfiguration);
if (profileIsDefault != null) {
cleanAndMergeModuleProfiles(rootProject, compilerConfiguration, profileIsDefault.first, profileIsDefault.second, module);
}
}
else {
cleanAndMergeModuleProfiles(rootProject, compilerConfiguration, null, false, module);
}
}
}
}
@Nullable
private static Pair<@NotNull ProcessorConfigProfile, @NotNull Boolean>
createOrUpdateProfile(@NotNull MavenProject mavenProject,
@NotNull Module module,
@NotNull List<Module> processorModules,
@NotNull CompilerConfigurationImpl compilerConfiguration) {
List<String> processors = mavenProject.getDeclaredAnnotationProcessors();
Map<String, String> options = mavenProject.getAnnotationProcessorOptions();
boolean outputRelativeToContentRoot;
String annotationProcessorDirectory;
String testAnnotationProcessorDirectory;
if (MavenImportUtil.isMainOrTestSubmodule(module.getName())) {
outputRelativeToContentRoot = false;
annotationProcessorDirectory = getAnnotationsDirectoryRelativeTo(mavenProject, false, mavenProject.getOutputDirectory());
testAnnotationProcessorDirectory = getAnnotationsDirectoryRelativeTo(mavenProject, true, mavenProject.getTestOutputDirectory());
}
else {
String mavenProjectDirectory = mavenProject.getDirectory();
outputRelativeToContentRoot = true;
annotationProcessorDirectory = getAnnotationsDirectoryRelativeTo(mavenProject, false, mavenProjectDirectory);
testAnnotationProcessorDirectory = getAnnotationsDirectoryRelativeTo(mavenProject, true, mavenProjectDirectory);
}
String annotationProcessorPath = getAnnotationProcessorPath(mavenProject, processorModules);
final boolean isDefault;
final String moduleProfileName;
boolean isDefaultSettings = ContainerUtil.isEmpty(processors)
&& options.isEmpty()
&& StringUtil.isEmpty(annotationProcessorPath);
if (isDefaultSettings
&& DEFAULT_ANNOTATION_PATH_OUTPUT.equals(FileUtil.toSystemIndependentName(annotationProcessorDirectory))
&& DEFAULT_TEST_ANNOTATION_OUTPUT.equals(FileUtil.toSystemIndependentName(testAnnotationProcessorDirectory))) {
moduleProfileName = MAVEN_DEFAULT_ANNOTATION_PROFILE;
isDefault = true;
}
else if (isDefaultSettings
&& DEFAULT_BSC_ANNOTATION_PATH_OUTPUT.equals(FileUtil.toSystemIndependentName(annotationProcessorDirectory))
&& DEFAULT_BSC_TEST_ANNOTATION_OUTPUT.equals(FileUtil.toSystemIndependentName(testAnnotationProcessorDirectory))) {
moduleProfileName = MAVEN_BSC_DEFAULT_ANNOTATION_PROFILE;
isDefault = true;
}
else {
moduleProfileName = getModuleProfileName(module.getName());
isDefault = false;
}
ProcessorConfigProfile moduleProfile =
getModuleProfile(module, mavenProject, compilerConfiguration, moduleProfileName, outputRelativeToContentRoot,
annotationProcessorDirectory, testAnnotationProcessorDirectory);
if (moduleProfile == null) return null;
if (StringUtil.isNotEmpty(annotationProcessorPath)) {
moduleProfile.setObtainProcessorsFromClasspath(false);
moduleProfile.setProcessorPath(annotationProcessorPath);
}
return Pair.pair(moduleProfile, isDefault);
}
@NotNull
public static String getModuleProfileName(@NotNull @NlsSafe String moduleName) {
return PROFILE_PREFIX + moduleName;
}
@Override
public void resolve(Project project,
MavenProject mavenProject,
NativeMavenProjectHolder nativeMavenProject,
MavenEmbedderWrapper embedder) throws MavenProcessCanceledException {
Element config = getConfig(mavenProject, "annotationProcessorPaths");
if (config == null) return;
List<MavenArtifactInfo> artifactsInfo = getProcessorArtifactInfos(config);
val artifactsInfo = getProcessorArtifactInfos(config)
if (artifactsInfo.isEmpty()) {
return;
return
}
List<MavenArtifactInfo> externalArtifacts = new ArrayList<>();
var mavenProjectsManager = MavenProjectsManager.getInstance(project);
var tree = mavenProjectsManager.getProjectsTree();
for (MavenArtifactInfo info : artifactsInfo) {
MavenProject mavenArtifact = tree.findProject(new MavenId(info.getGroupId(), info.getArtifactId(), info.getVersion()));
val externalArtifacts: MutableList<MavenArtifactInfo> = ArrayList()
val mavenProjectsManager = MavenProjectsManager.getInstance(project)
val tree = mavenProjectsManager.projectsTree
for (info in artifactsInfo) {
val mavenArtifact = tree.findProject(MavenId(info.groupId, info.artifactId, info.version))
if (mavenArtifact == null) {
externalArtifacts.add(info);
externalArtifacts.add(info)
}
}
try {
MavenArtifactResolveResult annotationProcessors = embedder
.resolveArtifactTransitively(new ArrayList<>(externalArtifacts), new ArrayList<>(mavenProject.getRemoteRepositories()));
val annotationProcessors = embedder
.resolveArtifactTransitively(ArrayList(externalArtifacts), ArrayList(mavenProject.remoteRepositories))
if (annotationProcessors.problem != null) {
MavenResolveResultProblemProcessor.notifySyncForProblem(project, annotationProcessors.problem);
MavenResolveResultProblemProcessor.notifySyncForProblem(project, annotationProcessors.problem!!)
}
else {
mavenProject.addAnnotationProcessors(annotationProcessors.mavenResolvedArtifacts);
mavenProject.addAnnotationProcessors(annotationProcessors.mavenResolvedArtifacts)
}
}
catch (Exception e) {
String message = e.getMessage() != null ? e.getMessage() : ExceptionUtil.getThrowableText(e);
MavenProjectsManager.getInstance(project).getSyncConsole()
.addWarning(SyncBundle.message("maven.sync.annotation.processor.problem"), message);
catch (e: Exception) {
val message = if (e.message != null) e.message else ExceptionUtil.getThrowableText(e)
MavenProjectsManager.getInstance(project).syncConsole.addWarning(SyncBundle.message("maven.sync.annotation.processor.problem"), message!!)
}
}
@NotNull
private static List<MavenArtifactInfo> getProcessorArtifactInfos(Element config) {
List<MavenArtifactInfo> artifacts = new ArrayList<>();
Consumer<Element> addToArtifacts = path -> {
String groupId = path.getChildTextTrim("groupId");
String artifactId = path.getChildTextTrim("artifactId");
String version = path.getChildTextTrim("version");
private fun configureProfiles(project: Project,
tree: MavenProjectsTree,
projectsWithModules: Iterable<MavenProjectWithProcessorModules>,
moduleByName: Function<String, Module?>) {
val compilerConfiguration = CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl
for (it in projectsWithModules) {
val rootProject = tree.findRootProject(it.mavenProject)
for (moduleWithType in it.mavenProjectModules) {
val module = moduleWithType.module
val moduleType = moduleWithType.type
if (!isLevelMoreThan6(module)) continue
if (shouldEnableAnnotationProcessors(it.mavenProject) && moduleType.containsCode) {
val processorModules = it.processorModuleNames.mapNotNull { moduleByName.apply(it) }
val profileIsDefault = createOrUpdateProfile(it.mavenProject, module, processorModules, compilerConfiguration)
if (profileIsDefault != null) {
cleanAndMergeModuleProfiles(rootProject, compilerConfiguration, profileIsDefault.first, profileIsDefault.second, module)
}
}
else {
cleanAndMergeModuleProfiles(rootProject, compilerConfiguration, null, false, module)
}
}
}
}
private fun createOrUpdateProfile(mavenProject: MavenProject,
module: Module,
processorModules: List<Module>,
compilerConfiguration: CompilerConfigurationImpl): Pair<ProcessorConfigProfile, Boolean>? {
val processors = mavenProject.declaredAnnotationProcessors
val options = mavenProject.annotationProcessorOptions
val outputRelativeToContentRoot: Boolean
val annotationProcessorDirectory: String
val testAnnotationProcessorDirectory: String
if (MavenImportUtil.isMainOrTestSubmodule(module.name)) {
outputRelativeToContentRoot = false
annotationProcessorDirectory = getAnnotationsDirectoryRelativeTo(mavenProject, false, mavenProject.outputDirectory)
testAnnotationProcessorDirectory = getAnnotationsDirectoryRelativeTo(mavenProject, true, mavenProject.testOutputDirectory)
}
else {
val mavenProjectDirectory = mavenProject.directory
outputRelativeToContentRoot = true
annotationProcessorDirectory = getAnnotationsDirectoryRelativeTo(mavenProject, false, mavenProjectDirectory)
testAnnotationProcessorDirectory = getAnnotationsDirectoryRelativeTo(mavenProject, true, mavenProjectDirectory)
}
val annotationProcessorPath = getAnnotationProcessorPath(mavenProject, processorModules)
val isDefault: Boolean
val moduleProfileName: String
val isDefaultSettings = (ContainerUtil.isEmpty(processors)
&& options.isEmpty()
&& StringUtil.isEmpty(annotationProcessorPath))
if (isDefaultSettings && DEFAULT_ANNOTATION_PATH_OUTPUT == FileUtil.toSystemIndependentName(
annotationProcessorDirectory) && DEFAULT_TEST_ANNOTATION_OUTPUT == FileUtil.toSystemIndependentName(
testAnnotationProcessorDirectory)) {
moduleProfileName = MAVEN_DEFAULT_ANNOTATION_PROFILE
isDefault = true
}
else if (isDefaultSettings && DEFAULT_BSC_ANNOTATION_PATH_OUTPUT == FileUtil.toSystemIndependentName(
annotationProcessorDirectory) && DEFAULT_BSC_TEST_ANNOTATION_OUTPUT == FileUtil.toSystemIndependentName(
testAnnotationProcessorDirectory)) {
moduleProfileName = MAVEN_BSC_DEFAULT_ANNOTATION_PROFILE
isDefault = true
}
else {
moduleProfileName = MavenAnnotationProcessorConfiguratorUtil.getModuleProfileName(module.name)
isDefault = false
}
val moduleProfile =
getModuleProfile(module, mavenProject, compilerConfiguration, moduleProfileName, outputRelativeToContentRoot,
annotationProcessorDirectory, testAnnotationProcessorDirectory)
if (moduleProfile == null) return null
if (StringUtil.isNotEmpty(annotationProcessorPath)) {
moduleProfile.isObtainProcessorsFromClasspath = false
moduleProfile.setProcessorPath(annotationProcessorPath)
}
return Pair.pair(moduleProfile, isDefault)
}
private fun getProcessorArtifactInfos(config: Element): List<MavenArtifactInfo> {
val artifacts: MutableList<MavenArtifactInfo> = ArrayList()
val addToArtifacts = Consumer { path: Element ->
val groupId = path.getChildTextTrim("groupId")
val artifactId = path.getChildTextTrim("artifactId")
val version = path.getChildTextTrim("version")
val classifier = path.getChildTextTrim("classifier")
String classifier = path.getChildTextTrim("classifier");
//String type = path.getChildTextTrim("type");
artifacts.add(new MavenArtifactInfo(groupId, artifactId, version, "jar", classifier));
};
for (Element path : config.getChildren("path")) {
addToArtifacts.consume(path);
artifacts.add(MavenArtifactInfo(groupId, artifactId, version, "jar", classifier))
}
for (Element dependency : config.getChildren("dependency")) {
addToArtifacts.consume(dependency);
for (path in config.getChildren("path")) {
addToArtifacts.consume(path)
}
for (Element annotationProcessorPath : config.getChildren("annotationProcessorPath")) {
addToArtifacts.consume(annotationProcessorPath);
for (dependency in config.getChildren("dependency")) {
addToArtifacts.consume(dependency)
}
return artifacts;
for (annotationProcessorPath in config.getChildren("annotationProcessorPath")) {
addToArtifacts.consume(annotationProcessorPath)
}
return artifacts
}
@Nullable
private static ProcessorConfigProfile getModuleProfile(Module module,
MavenProject mavenProject,
CompilerConfigurationImpl compilerConfiguration,
String moduleProfileName,
boolean outputRelativeToContentRoot,
String annotationProcessorDirectory,
String testAnnotationProcessorDirectory) {
ProcessorConfigProfile moduleProfile = compilerConfiguration.findModuleProcessorProfile(moduleProfileName);
private fun getModuleProfile(module: Module,
mavenProject: MavenProject,
compilerConfiguration: CompilerConfigurationImpl,
moduleProfileName: String,
outputRelativeToContentRoot: Boolean,
annotationProcessorDirectory: String,
testAnnotationProcessorDirectory: String): ProcessorConfigProfile? {
var moduleProfile = compilerConfiguration.findModuleProcessorProfile(moduleProfileName)
if (moduleProfile == null) {
moduleProfile = new ProcessorConfigProfileImpl(moduleProfileName);
moduleProfile.setEnabled(true);
compilerConfiguration.addModuleProcessorProfile(moduleProfile);
moduleProfile = ProcessorConfigProfileImpl(moduleProfileName)
moduleProfile.setEnabled(true)
compilerConfiguration.addModuleProcessorProfile(moduleProfile)
}
if (!moduleProfile.isEnabled()) return null;
if (!moduleProfile.isEnabled) return null
moduleProfile.setObtainProcessorsFromClasspath(true);
moduleProfile.isObtainProcessorsFromClasspath = true
moduleProfile.setOutputRelativeToContentRoot(outputRelativeToContentRoot);
moduleProfile.setGeneratedSourcesDirectoryName(annotationProcessorDirectory, false);
moduleProfile.setGeneratedSourcesDirectoryName(testAnnotationProcessorDirectory, true);
moduleProfile.isOutputRelativeToContentRoot = outputRelativeToContentRoot
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.clearProcessorOptions()
for ((key, value) in mavenProject.annotationProcessorOptions) {
moduleProfile.setOption(key, value)
}
moduleProfile.clearProcessors();
final List<String> processors = mavenProject.getDeclaredAnnotationProcessors();
moduleProfile.clearProcessors()
val processors = mavenProject.declaredAnnotationProcessors
if (processors != null) {
for (String processor : processors) {
moduleProfile.addProcessor(processor);
for (processor in processors) {
moduleProfile.addProcessor(processor)
}
}
moduleProfile.addModuleName(module.getName());
return moduleProfile;
moduleProfile.addModuleName(module.name)
return moduleProfile
}
private static boolean isLevelMoreThan6(Module module) {
Sdk sdk = ReadAction.compute(() -> ModuleRootManager.getInstance(module).getSdk());
private fun isLevelMoreThan6(module: Module): Boolean {
val sdk = ReadAction.compute<Sdk?, RuntimeException> { ModuleRootManager.getInstance(module).sdk }
if (sdk != null) {
String versionString = sdk.getVersionString();
LanguageLevel languageLevel = LanguageLevel.parse(versionString);
if (languageLevel != null && languageLevel.isLessThan(LanguageLevel.JDK_1_6)) return false;
val versionString = sdk.versionString
val languageLevel = LanguageLevel.parse(versionString)
if (languageLevel != null && languageLevel.isLessThan(LanguageLevel.JDK_1_6)) return false
}
return true;
return true
}
private static @NotNull String getAnnotationProcessorPath(@NotNull MavenProject mavenProject,
@NotNull List<Module> processorModules) {
StringJoiner annotationProcessorPath = new StringJoiner(File.pathSeparator);
private fun getAnnotationProcessorPath(mavenProject: MavenProject,
processorModules: List<Module>): String {
val annotationProcessorPath = StringJoiner(File.pathSeparator)
Consumer<String> resultAppender = path -> annotationProcessorPath.add(FileUtil.toSystemDependentName(path));
for (MavenArtifact artifact : mavenProject.getExternalAnnotationProcessors()) {
resultAppender.consume(artifact.getPath());
val resultAppender = Consumer { path: String? ->
annotationProcessorPath.add(FileUtil.toSystemDependentName(
path!!))
}
for (Module module : processorModules) {
OrderEnumerator enumerator = orderEntries(module).withoutSdk().productionOnly().runtimeOnly().recursively();
for (artifact in mavenProject.externalAnnotationProcessors) {
resultAppender.consume(artifact.path)
}
for (String url : enumerator.classes().getUrls()) {
resultAppender.consume(JpsPathUtil.urlToPath(url));
for (module in processorModules) {
val enumerator = OrderEnumerator.orderEntries(module).withoutSdk().productionOnly().runtimeOnly().recursively()
for (url in enumerator.classes().urls) {
resultAppender.consume(JpsPathUtil.urlToPath(url))
}
}
return annotationProcessorPath.toString();
return annotationProcessorPath.toString()
}
private static void cleanAndMergeModuleProfiles(@NotNull MavenProject rootProject,
@NotNull CompilerConfigurationImpl compilerConfiguration,
@Nullable ProcessorConfigProfile moduleProfile,
boolean isDefault,
@NotNull Module module) {
List<ProcessorConfigProfile> profiles = new ArrayList<>(compilerConfiguration.getModuleProcessorProfiles());
for (ProcessorConfigProfile p : profiles) {
if (p != moduleProfile) {
p.removeModuleName(module.getName());
if (p.getModuleNames().isEmpty() && p.getName().startsWith(PROFILE_PREFIX)) {
compilerConfiguration.removeModuleProcessorProfile(p);
private fun cleanAndMergeModuleProfiles(rootProject: MavenProject,
compilerConfiguration: CompilerConfigurationImpl,
moduleProfile: ProcessorConfigProfile?,
isDefault: Boolean,
module: Module) {
val profiles: List<ProcessorConfigProfile> = ArrayList(compilerConfiguration.moduleProcessorProfiles)
for (p in profiles) {
if (p !== moduleProfile) {
p.removeModuleName(module.name)
if (p.moduleNames.isEmpty() && p.name.startsWith(PROFILE_PREFIX)) {
compilerConfiguration.removeModuleProcessorProfile(p)
}
}
if (!isDefault && moduleProfile != null && isSimilarProfiles(p, moduleProfile)) {
moduleProfile.setEnabled(p.isEnabled());
final String mavenProjectRootProfileName = getModuleProfileName(rootProject.getDisplayName());
ProcessorConfigProfile mergedProfile = compilerConfiguration.findModuleProcessorProfile(mavenProjectRootProfileName);
moduleProfile.isEnabled = p.isEnabled
val mavenProjectRootProfileName = MavenAnnotationProcessorConfiguratorUtil.getModuleProfileName(rootProject.displayName)
var 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);
mergedProfile = ProcessorConfigProfileImpl(moduleProfile)
mergedProfile.setName(mavenProjectRootProfileName)
compilerConfiguration.addModuleProcessorProfile(mergedProfile)
mergedProfile.addModuleNames(p.moduleNames)
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);
else if (p === mergedProfile || isSimilarProfiles(mergedProfile, moduleProfile)) {
if (moduleProfile !== mergedProfile) {
mergedProfile.addModuleNames(moduleProfile.moduleNames)
moduleProfile.clearModuleNames()
compilerConfiguration.removeModuleProcessorProfile(moduleProfile)
}
if (p != mergedProfile) {
mergedProfile.addModuleNames(p.getModuleNames());
p.clearModuleNames();
compilerConfiguration.removeModuleProcessorProfile(p);
if (p !== mergedProfile) {
mergedProfile.addModuleNames(p.moduleNames)
p.clearModuleNames()
compilerConfiguration.removeModuleProcessorProfile(p)
}
}
}
}
}
private static boolean isSimilarProfiles(@Nullable ProcessorConfigProfile profile1, @Nullable ProcessorConfigProfile profile2) {
if (profile1 == null || profile2 == null) return false;
private fun isSimilarProfiles(profile1: ProcessorConfigProfile?, profile2: ProcessorConfigProfile?): Boolean {
if (profile1 == null || profile2 == null) return false
ProcessorConfigProfileImpl p1 = new ProcessorConfigProfileImpl(profile1);
p1.setName("tmp");
p1.setEnabled(true);
p1.clearModuleNames();
ProcessorConfigProfileImpl p2 = new ProcessorConfigProfileImpl(profile2);
p2.setName("tmp");
p2.setEnabled(true);
p2.clearModuleNames();
return p1.equals(p2);
val p1 = ProcessorConfigProfileImpl(profile1)
p1.name = "tmp"
p1.isEnabled = true
p1.clearModuleNames()
val p2 = ProcessorConfigProfileImpl(profile2)
p2.name = "tmp"
p2.isEnabled = true
p2.clearModuleNames()
return p1 == p2
}
@NotNull
private static String getAnnotationsDirectoryRelativeTo(MavenProject mavenProject, boolean isTest, String relativeTo) {
var annotationProcessorDirectory = mavenProject.getAnnotationProcessorDirectory(isTest);
Path path = Path.of(annotationProcessorDirectory);
if (!path.isAbsolute()) {
return annotationProcessorDirectory;
private fun getAnnotationsDirectoryRelativeTo(mavenProject: MavenProject, isTest: Boolean, relativeTo: String): String {
val annotationProcessorDirectory = mavenProject.getAnnotationProcessorDirectory(isTest)
val path = Path.of(annotationProcessorDirectory)
if (!path.isAbsolute) {
return annotationProcessorDirectory
}
try {
return Path.of(relativeTo).relativize(path).toString();
return try {
Path.of(relativeTo).relativize(path).toString()
}
catch (IllegalArgumentException e) {
return isTest ? DEFAULT_TEST_ANNOTATION_OUTPUT : DEFAULT_ANNOTATION_PATH_OUTPUT;
catch (e: IllegalArgumentException) {
if (isTest) DEFAULT_TEST_ANNOTATION_OUTPUT else DEFAULT_ANNOTATION_PATH_OUTPUT
}
}
private static boolean shouldEnableAnnotationProcessors(MavenProject mavenProject) {
if ("pom".equals(mavenProject.getPackaging())) return false;
private fun shouldEnableAnnotationProcessors(mavenProject: MavenProject): Boolean {
if ("pom" == mavenProject.packaging) return false
return mavenProject.getProcMode() != MavenProject.ProcMode.NONE
|| mavenProject.findPlugin("org.bsc.maven", "maven-processor-plugin") != null;
return (mavenProject.procMode != MavenProject.ProcMode.NONE
|| mavenProject.findPlugin("org.bsc.maven", "maven-processor-plugin") != null)
}
}
@ApiStatus.Internal
object MavenAnnotationProcessorConfiguratorUtil {
fun getModuleProfileName(moduleName: @NlsSafe String): String {
return PROFILE_PREFIX + moduleName
}
}
@@ -23,7 +23,9 @@ import com.intellij.openapi.util.io.FileUtil
import com.intellij.testFramework.UsefulTestCase
import junit.framework.TestCase
import kotlinx.coroutines.runBlocking
import org.jetbrains.idea.maven.importing.MavenAnnotationProcessorConfigurator
import org.jetbrains.idea.maven.importing.MAVEN_BSC_DEFAULT_ANNOTATION_PROFILE
import org.jetbrains.idea.maven.importing.MAVEN_DEFAULT_ANNOTATION_PROFILE
import org.jetbrains.idea.maven.importing.MavenAnnotationProcessorConfiguratorUtil.getModuleProfileName
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile
import org.jetbrains.jps.model.java.impl.compiler.ProcessorConfigProfileImpl
import org.junit.Assert
@@ -132,21 +134,16 @@ class AnnotationProcessorImportingTest : MavenMultiVersionImportingTestCase() {
val compilerConfiguration = CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl
assertEquals(
compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.MAVEN_DEFAULT_ANNOTATION_PROFILE)?.moduleNames,
compilerConfiguration.findModuleProcessorProfile(MAVEN_DEFAULT_ANNOTATION_PROFILE)?.moduleNames,
setOf("module1", "module4"))
assertNull(compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.MAVEN_BSC_DEFAULT_ANNOTATION_PROFILE))
assertNull(compilerConfiguration.findModuleProcessorProfile(MAVEN_BSC_DEFAULT_ANNOTATION_PROFILE))
val projectProfile = compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.getModuleProfileName("project"))
val projectProfile = compilerConfiguration.findModuleProcessorProfile(getModuleProfileName("project"))
assertNotNull(projectProfile)
assertEquals(projectProfile!!.moduleNames, setOf("module2"))
assertEquals(projectProfile.processors, setOf("com.test.SourceCodeGeneratingAnnotationProcessor2"))
assertNull(compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.getModuleProfileName("module3")))
assertNull(compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.getModuleProfileName("module3_1")))
assertNull(compilerConfiguration.findModuleProcessorProfile(getModuleProfileName("module3")))
assertNull(compilerConfiguration.findModuleProcessorProfile(getModuleProfileName("module3_1")))
assertEquals(compilerConfiguration.moduleProcessorProfiles.size, 2)
}
@@ -172,10 +169,8 @@ class AnnotationProcessorImportingTest : MavenMultiVersionImportingTestCase() {
val compilerConfiguration = CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl
assertNull(compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.MAVEN_DEFAULT_ANNOTATION_PROFILE))
val profile = compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.getModuleProfileName("project"))
assertNull(compilerConfiguration.findModuleProcessorProfile(MAVEN_DEFAULT_ANNOTATION_PROFILE))
val profile = compilerConfiguration.findModuleProcessorProfile(getModuleProfileName("project"))
assertNotNull(profile)
assertTrue(profile!!.getGeneratedSourcesDirectoryName(false).replace('\\', '/').endsWith("out/generated"))
}
@@ -209,11 +204,9 @@ class AnnotationProcessorImportingTest : MavenMultiVersionImportingTestCase() {
val compilerConfiguration = CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl
assertNull(compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.MAVEN_DEFAULT_ANNOTATION_PROFILE))
assertNull(compilerConfiguration.findModuleProcessorProfile(MAVEN_DEFAULT_ANNOTATION_PROFILE))
val processorOptions =
compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.getModuleProfileName("project"))?.processorOptions
compilerConfiguration.findModuleProcessorProfile(getModuleProfileName("project"))?.processorOptions
assertEquals(processorOptions, mapOf("opt1" to "111", "opt2" to "222", "opt3" to "333", "opt4" to "444", "justKey" to ""))
}
@@ -271,10 +264,8 @@ class AnnotationProcessorImportingTest : MavenMultiVersionImportingTestCase() {
val compilerConfiguration = CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl
assertNull(compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.MAVEN_DEFAULT_ANNOTATION_PROFILE))
val profile = compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.getModuleProfileName("project"))
assertNull(compilerConfiguration.findModuleProcessorProfile(MAVEN_DEFAULT_ANNOTATION_PROFILE))
val profile = compilerConfiguration.findModuleProcessorProfile(getModuleProfileName("project"))
assertNotNull(profile)
assertTrue(profile!!.getGeneratedSourcesDirectoryName(false).replace('\\', '/').endsWith("target/metamodel"))
assertTrue(profile.getGeneratedSourcesDirectoryName(true).replace('\\', '/').endsWith("target/metamodelTest"))
@@ -333,10 +324,8 @@ class AnnotationProcessorImportingTest : MavenMultiVersionImportingTestCase() {
val compilerConfiguration = CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl
assertNull(compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.MAVEN_DEFAULT_ANNOTATION_PROFILE))
val profile = compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.getModuleProfileName("project"))
assertNull(compilerConfiguration.findModuleProcessorProfile(MAVEN_DEFAULT_ANNOTATION_PROFILE))
val profile = compilerConfiguration.findModuleProcessorProfile(getModuleProfileName("project"))
assertNotNull(profile)
assertTrue(profile!!.getGeneratedSourcesDirectoryName(false).replace('\\', '/').endsWith("target/metamodel"))
assertTrue(profile.getGeneratedSourcesDirectoryName(true).replace('\\', '/').endsWith("target/metamodelTest"))
@@ -385,8 +374,7 @@ class AnnotationProcessorImportingTest : MavenMultiVersionImportingTestCase() {
val compilerConfiguration = CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl
TestCase.assertEquals(
compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.getModuleProfileName("project"))?.processors,
compilerConfiguration.findModuleProcessorProfile(getModuleProfileName("project"))?.processors,
hashSetOf("com.test.SourceCodeGeneratingAnnotationProcessor2", "com.mysema.query.apt.jpa.JPAAnnotationProcessor"))
}
@@ -422,8 +410,7 @@ class AnnotationProcessorImportingTest : MavenMultiVersionImportingTestCase() {
assertTrue(annotationProcessors.any { "com.google.dagger" == it!!.groupId && "dagger" == it.artifactId && "2.2" == it.version })
val config = CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl
val projectProfile = config.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.getModuleProfileName("project"))
val projectProfile = config.findModuleProcessorProfile(getModuleProfileName("project"))
assertNotNull(projectProfile)
val path = projectProfile!!.processorPath
assertTrue(path.contains(FileUtil.toSystemDependentName("/com/google/dagger/dagger-compiler/2.2/dagger-compiler-2.2.jar")))
@@ -463,8 +450,7 @@ class AnnotationProcessorImportingTest : MavenMultiVersionImportingTestCase() {
val config = CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl
val projectProfile = config.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.getModuleProfileName("project"))
val projectProfile = config.findModuleProcessorProfile(getModuleProfileName("project"))
assertNotNull(projectProfile)
val path = projectProfile!!.processorPath
assertTrue(path.contains(FileUtil.toSystemDependentName("/com/google/dagger/dagger-compiler/2.2/dagger-compiler-2.2.jar")))
@@ -525,13 +511,11 @@ class AnnotationProcessorImportingTest : MavenMultiVersionImportingTestCase() {
val config = CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl
val defaultProfile = config.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.MAVEN_DEFAULT_ANNOTATION_PROFILE)
val defaultProfile = config.findModuleProcessorProfile(MAVEN_DEFAULT_ANNOTATION_PROFILE)
assertNotNull(defaultProfile)
UsefulTestCase.assertSameElements(defaultProfile!!.moduleNames, "m1")
val projectProfile = config.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.getModuleProfileName("project"))
val projectProfile = config.findModuleProcessorProfile(getModuleProfileName("project"))
assertNotNull(projectProfile)
UsefulTestCase.assertSameElements(projectProfile!!.moduleNames, "m2")
val path = projectProfile.processorPath
@@ -548,24 +532,20 @@ class AnnotationProcessorImportingTest : MavenMultiVersionImportingTestCase() {
""".trimIndent())
val compilerConfiguration = CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl
var profile = compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.MAVEN_DEFAULT_ANNOTATION_PROFILE)
var profile = compilerConfiguration.findModuleProcessorProfile(MAVEN_DEFAULT_ANNOTATION_PROFILE)
Assert.assertNotNull(profile)
Assert.assertTrue(profile!!.isEnabled)
WriteAction.runAndWait<RuntimeException> {
val p = compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.MAVEN_DEFAULT_ANNOTATION_PROFILE)
val p = compilerConfiguration.findModuleProcessorProfile(MAVEN_DEFAULT_ANNOTATION_PROFILE)
p!!.isEnabled = false
}
profile = compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.MAVEN_DEFAULT_ANNOTATION_PROFILE)
profile = compilerConfiguration.findModuleProcessorProfile(MAVEN_DEFAULT_ANNOTATION_PROFILE)
Assert.assertNotNull(profile)
Assert.assertFalse(profile!!.isEnabled)
importProjectAsync()
profile = compilerConfiguration.findModuleProcessorProfile(
MavenAnnotationProcessorConfigurator.MAVEN_DEFAULT_ANNOTATION_PROFILE)
profile = compilerConfiguration.findModuleProcessorProfile(MAVEN_DEFAULT_ANNOTATION_PROFILE)
Assert.assertNotNull(profile)
Assert.assertFalse(profile!!.isEnabled)
}
@@ -591,7 +571,7 @@ class AnnotationProcessorImportingTest : MavenMultiVersionImportingTestCase() {
@Test
fun testRemoveEmptyInnerProfile() = runBlocking {
val compilerConfiguration = CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl
val profileName = MavenAnnotationProcessorConfigurator.getModuleProfileName("test-profile")
val profileName =getModuleProfileName("test-profile")
WriteAction.runAndWait<RuntimeException> {
val moduleProfile: ProcessorConfigProfile = ProcessorConfigProfileImpl(profileName)
moduleProfile.isEnabled = true