mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Import maven compiler configuration for different compilerIds if the related IDE compilers support is available (IDEA-196548)
This commit is contained in:
Generated
+1
@@ -542,6 +542,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/maven/artifact-resolver-m2/intellij.maven.artifactResolver.m2.iml" filepath="$PROJECT_DIR$/plugins/maven/artifact-resolver-m2/intellij.maven.artifactResolver.m2.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/maven/artifact-resolver-m3/intellij.maven.artifactResolver.m3.iml" filepath="$PROJECT_DIR$/plugins/maven/artifact-resolver-m3/intellij.maven.artifactResolver.m3.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/maven/artifact-resolver-m31/intellij.maven.artifactResolver.m31.iml" filepath="$PROJECT_DIR$/plugins/maven/artifact-resolver-m31/intellij.maven.artifactResolver.m31.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/maven/error-prone-compiler/intellij.maven.errorProne.compiler.iml" filepath="$PROJECT_DIR$/plugins/maven/error-prone-compiler/intellij.maven.errorProne.compiler.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/maven/jps-plugin/intellij.maven.jps.iml" filepath="$PROJECT_DIR$/plugins/maven/jps-plugin/intellij.maven.jps.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/maven/maven-server-api/intellij.maven.server.iml" filepath="$PROJECT_DIR$/plugins/maven/maven-server-api/intellij.maven.server.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/maven/maven2-server-impl/intellij.maven.server.m2.impl.iml" filepath="$PROJECT_DIR$/plugins/maven/maven2-server-impl/intellij.maven.server.m2.impl.iml" />
|
||||
|
||||
@@ -376,12 +376,16 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
|
||||
public void setAdditionalOptions(@NotNull Module module, @NotNull List<String> options) {
|
||||
JpsJavaCompilerOptions settings = getCompilerSettings();
|
||||
if (settings != null) {
|
||||
String previous = settings.ADDITIONAL_OPTIONS_OVERRIDE.getOrDefault(module.getName(), settings.ADDITIONAL_OPTIONS_STRING);
|
||||
String newValue = ParametersListUtil.join(options);
|
||||
if (!newValue.equals(previous)) {
|
||||
settings.ADDITIONAL_OPTIONS_OVERRIDE.put(module.getName(), newValue);
|
||||
BuildManager.getInstance().clearState(myProject);
|
||||
}
|
||||
setAdditionalOptions(settings, module, options);
|
||||
}
|
||||
}
|
||||
|
||||
public void setAdditionalOptions(@NotNull JpsJavaCompilerOptions settings, @NotNull Module module, @NotNull List<String> options) {
|
||||
String previous = settings.ADDITIONAL_OPTIONS_OVERRIDE.getOrDefault(module.getName(), settings.ADDITIONAL_OPTIONS_STRING);
|
||||
String newValue = ParametersListUtil.join(options);
|
||||
if (!newValue.equals(previous)) {
|
||||
settings.ADDITIONAL_OPTIONS_OVERRIDE.put(module.getName(), newValue);
|
||||
BuildManager.getInstance().clearState(myProject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module relativePaths="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="intellij.maven" />
|
||||
<orderEntry type="module" module-name="intellij.errorProne" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// 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.intellij.errorProne
|
||||
|
||||
import com.intellij.compiler.CompilerConfiguration
|
||||
import com.intellij.compiler.CompilerConfigurationImpl
|
||||
import com.intellij.compiler.impl.javaCompiler.BackendCompiler
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.idea.maven.importing.MavenCompilerExtension
|
||||
import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
*/
|
||||
class MavenCompilerErrorProneExtension : MavenCompilerExtension {
|
||||
override fun getMavenCompilerId(): String = "javac-with-errorprone"
|
||||
|
||||
override fun getCompiler(project: Project): BackendCompiler {
|
||||
val compilerConfiguration = CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl
|
||||
return compilerConfiguration.registeredJavaCompilers.find { it is ErrorProneJavaBackendCompiler }!!
|
||||
}
|
||||
|
||||
override fun getOptions(project: Project): JpsJavaCompilerOptions {
|
||||
return ErrorProneCompilerConfiguration.getOptions(project)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.jps.build" />
|
||||
<orderEntry type="module" module-name="intellij.maven.server.m3.common" scope="TEST" />
|
||||
<orderEntry type="library" scope="TEST" name="assertJ" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.maven.errorProne.compiler" scope="RUNTIME" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// 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
|
||||
|
||||
import com.intellij.compiler.CompilerConfiguration
|
||||
import com.intellij.compiler.CompilerConfigurationImpl
|
||||
import com.intellij.compiler.impl.javaCompiler.BackendCompiler
|
||||
import com.intellij.compiler.impl.javaCompiler.eclipse.EclipseCompiler
|
||||
import com.intellij.compiler.impl.javaCompiler.eclipse.EclipseCompilerConfiguration
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
*/
|
||||
class MavenCompilerEclipseExtension : MavenCompilerExtension {
|
||||
override fun getMavenCompilerId(): String = "eclipse"
|
||||
|
||||
override fun getCompiler(project: Project): BackendCompiler {
|
||||
val compilerConfiguration = CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl
|
||||
return compilerConfiguration.registeredJavaCompilers.find { it is EclipseCompiler }!!
|
||||
}
|
||||
|
||||
override fun getOptions(project: Project): JpsJavaCompilerOptions {
|
||||
return EclipseCompilerConfiguration.getOptions(project, EclipseCompilerConfiguration::class.java)
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// 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;
|
||||
|
||||
import com.intellij.compiler.impl.javaCompiler.BackendCompiler;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
*/
|
||||
public interface MavenCompilerExtension {
|
||||
ExtensionPointName<MavenCompilerExtension> EP_NAME = ExtensionPointName.create("org.jetbrains.idea.maven.compiler");
|
||||
|
||||
/**
|
||||
* Id of the maven compiler, see the role-hint of the @plexus.component with role="org.codehaus.plexus.compiler.Compiler".
|
||||
* Note, this can be not equal to {@link BackendCompiler#getId()}
|
||||
*
|
||||
* @return maven compiler id
|
||||
*/
|
||||
String getMavenCompilerId();
|
||||
|
||||
BackendCompiler getCompiler(Project project);
|
||||
|
||||
JpsJavaCompilerOptions getOptions(Project project);
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
// 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
|
||||
|
||||
import com.intellij.compiler.CompilerConfiguration
|
||||
import com.intellij.compiler.CompilerConfigurationImpl
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.openapi.util.text.StringUtil.nullize
|
||||
import com.intellij.util.containers.ContainerUtil.addIfNotNull
|
||||
import org.jdom.Element
|
||||
import org.jetbrains.idea.maven.project.*
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
*/
|
||||
class MavenCompilerImporter : MavenImporter("org.apache.maven.plugins", "maven-compiler-plugin") {
|
||||
private val LOG = Logger.getInstance("#org.jetbrains.idea.maven.importing.MavenCompilerImporter")
|
||||
|
||||
override fun processChangedModulesOnly(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun preProcess(module: Module,
|
||||
mavenProject: MavenProject,
|
||||
changes: MavenProjectChanges,
|
||||
modifiableModelsProvider: IdeModifiableModelsProvider) {
|
||||
if (!MavenProjectsManager.getInstance(module.project).importingSettings.isUseMavenCompilerArguments) return
|
||||
val config = getConfig(mavenProject) ?: return
|
||||
|
||||
var compilers = modifiableModelsProvider.getUserData<MutableSet<String>>(COMPILERS)
|
||||
if (compilers == null) {
|
||||
compilers = mutableSetOf()
|
||||
modifiableModelsProvider.putUserData(COMPILERS, compilers)
|
||||
}
|
||||
compilers.add(getCompilerId(config))
|
||||
}
|
||||
|
||||
override fun process(modifiableModelsProvider: IdeModifiableModelsProvider,
|
||||
module: Module,
|
||||
rootModel: MavenRootModelAdapter,
|
||||
mavenModel: MavenProjectsTree,
|
||||
mavenProject: MavenProject,
|
||||
changes: MavenProjectChanges,
|
||||
mavenProjectToModuleName: Map<MavenProject, String>,
|
||||
postTasks: List<MavenProjectsProcessorTask>) {
|
||||
if (!MavenProjectsManager.getInstance(module.project).importingSettings.isUseMavenCompilerArguments) return
|
||||
|
||||
val compilers = modifiableModelsProvider.getUserData(COMPILERS)
|
||||
val isMultipleCompilersUsed = compilers != null && compilers.size > 1
|
||||
|
||||
val compilerConfiguration = getConfig(mavenProject) ?: return
|
||||
val compilerId = getCompilerId(compilerConfiguration)
|
||||
|
||||
MavenCompilerExtension.EP_NAME.extensions.find { compilerId == it.mavenCompilerId }?.run {
|
||||
importCompilerConfiguration(module, compilerConfiguration, this, !isMultipleCompilersUsed)
|
||||
}
|
||||
}
|
||||
|
||||
private fun importCompilerConfiguration(module: Module,
|
||||
compilerMavenConfiguration: Element,
|
||||
extension: MavenCompilerExtension,
|
||||
useAsDefault: Boolean) {
|
||||
val options = mutableListOf<String>()
|
||||
val parameters = compilerMavenConfiguration.getChild("parameters")
|
||||
|
||||
if (parameters?.textTrim?.toBoolean() == true) {
|
||||
options += "-parameters"
|
||||
}
|
||||
|
||||
val compilerArguments = compilerMavenConfiguration.getChild("compilerArguments")
|
||||
if (compilerArguments != null) {
|
||||
for (compilerArgument in compilerArguments.children) {
|
||||
options.add("-" + compilerArgument.name)
|
||||
addIfNotNull(options, nullize(compilerArgument.textTrim))
|
||||
}
|
||||
}
|
||||
|
||||
addIfNotNull(options, nullize(compilerMavenConfiguration.getChildTextTrim("compilerArgument")))
|
||||
|
||||
val compilerArgs = compilerMavenConfiguration.getChild("compilerArgs")
|
||||
if (compilerArgs != null) {
|
||||
for (arg in compilerArgs.getChildren("arg")) {
|
||||
addIfNotNull(options, nullize(arg.textTrim))
|
||||
}
|
||||
for (compilerArg in compilerArgs.getChildren("compilerArg")) {
|
||||
addIfNotNull(options, nullize(compilerArg.textTrim))
|
||||
}
|
||||
}
|
||||
|
||||
val compilerOptions = extension.getOptions(module.project)
|
||||
val compilerConfiguration = CompilerConfiguration.getInstance(module.project) as CompilerConfigurationImpl
|
||||
compilerConfiguration.setAdditionalOptions(compilerOptions, module, options)
|
||||
|
||||
if (useAsDefault) {
|
||||
val backendCompiler = extension.getCompiler(module.project)
|
||||
if (compilerConfiguration.defaultCompiler !== backendCompiler) {
|
||||
val compilers = compilerConfiguration.registeredJavaCompilers
|
||||
if (compilers.contains(backendCompiler)) {
|
||||
compilerConfiguration.defaultCompiler = backendCompiler
|
||||
}
|
||||
else {
|
||||
LOG.error(backendCompiler.toString() + " is not registered.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val COMPILERS = Key.create<MutableSet<String>>("maven.compilers")
|
||||
|
||||
private fun getCompilerId(config: Element): String {
|
||||
var compilerId = config.getChildTextTrim("compilerId")
|
||||
if (StringUtil.isEmpty(compilerId) || "javac" == compilerId) {
|
||||
compilerId = "javac"
|
||||
}
|
||||
return compilerId
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// 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
|
||||
|
||||
import com.intellij.compiler.CompilerConfiguration
|
||||
import com.intellij.compiler.CompilerConfigurationImpl
|
||||
import com.intellij.compiler.impl.javaCompiler.BackendCompiler
|
||||
import com.intellij.compiler.impl.javaCompiler.javac.JavacConfiguration
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
*/
|
||||
class MavenCompilerJavacExtension : MavenCompilerExtension {
|
||||
override fun getMavenCompilerId(): String = "javac"
|
||||
|
||||
override fun getCompiler(project: Project): BackendCompiler {
|
||||
return (CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl).javacCompiler
|
||||
}
|
||||
|
||||
override fun getOptions(project: Project): JpsJavaCompilerOptions {
|
||||
return JavacConfiguration.getOptions(project, JavacConfiguration::class.java)
|
||||
}
|
||||
}
|
||||
-42
@@ -33,7 +33,6 @@ import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.JavaCompilerConfigurationProxy;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -43,14 +42,10 @@ import org.jetbrains.idea.maven.model.MavenConstants;
|
||||
import org.jetbrains.idea.maven.project.*;
|
||||
import org.jetbrains.idea.maven.utils.MavenUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.intellij.openapi.util.text.StringUtil.nullize;
|
||||
import static com.intellij.util.containers.ContainerUtil.addIfNotNull;
|
||||
|
||||
public class MavenModuleImporter {
|
||||
|
||||
public static final String SUREFIRE_PLUGIN_LIBRARY_NAME = "maven-surefire-plugin urls";
|
||||
@@ -107,7 +102,6 @@ public class MavenModuleImporter {
|
||||
configFolders();
|
||||
configDependencies();
|
||||
configLanguageLevel();
|
||||
configCompilerArguments();
|
||||
}
|
||||
|
||||
public void preConfigFacets() {
|
||||
@@ -408,40 +402,4 @@ public class MavenModuleImporter {
|
||||
|
||||
myRootModelAdapter.setLanguageLevel(level);
|
||||
}
|
||||
|
||||
private void configCompilerArguments() {
|
||||
List<String> options = new ArrayList<>();
|
||||
|
||||
Element compilerConfiguration = myMavenProject.getPluginConfiguration("org.apache.maven.plugins", "maven-compiler-plugin");
|
||||
if (compilerConfiguration != null) {
|
||||
Element parameters = compilerConfiguration.getChild("parameters");
|
||||
if (parameters != null && Boolean.parseBoolean(parameters.getTextTrim())) {
|
||||
options.add("-parameters");
|
||||
}
|
||||
|
||||
if(!mySettings.isUseMavenCompilerArguments()) return;
|
||||
|
||||
Element compilerArguments = compilerConfiguration.getChild("compilerArguments");
|
||||
if (compilerArguments != null) {
|
||||
for (Element compilerArgument : compilerArguments.getChildren()) {
|
||||
options.add("-" + compilerArgument.getName());
|
||||
addIfNotNull(options, nullize(compilerArgument.getTextTrim()));
|
||||
}
|
||||
}
|
||||
|
||||
addIfNotNull(options, nullize(compilerConfiguration.getChildTextTrim("compilerArgument")));
|
||||
|
||||
Element compilerArgs = compilerConfiguration.getChild("compilerArgs");
|
||||
if (compilerArgs != null) {
|
||||
for (Element arg: compilerArgs.getChildren("arg")) {
|
||||
addIfNotNull(options, nullize(arg.getTextTrim()));
|
||||
}
|
||||
for (Element compilerArg: compilerArgs.getChildren("compilerArg")) {
|
||||
addIfNotNull(options, nullize(compilerArg.getTextTrim()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JavaCompilerConfigurationProxy.setAdditionalOptions(myModule.getProject(), myModule, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<idea-plugin url="https://www.jetbrains.com/idea">
|
||||
<extensions defaultExtensionNs="org.jetbrains.idea.maven">
|
||||
<compiler implementation="org.intellij.errorProne.MavenCompilerErrorProneExtension"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
<extensionPoints>
|
||||
<extensionPoint name="importer" interface="org.jetbrains.idea.maven.importing.MavenImporter"/>
|
||||
<extensionPoint name="compiler" interface="org.jetbrains.idea.maven.importing.MavenCompilerExtension"/>
|
||||
<extensionPoint name="manifestImporter" interface="org.jetbrains.idea.maven.importing.ManifestImporter"/>
|
||||
<extensionPoint name="additional.importing.settings" interface="org.jetbrains.idea.maven.project.AdditionalMavenImportingSettings"/>
|
||||
<extensionPoint name="archetypesProvider" interface="org.jetbrains.idea.maven.indices.MavenArchetypesProvider"/>
|
||||
@@ -34,6 +35,7 @@
|
||||
|
||||
<depends>com.intellij.properties</depends>
|
||||
<depends optional="true" config-file="groovy-support.xml">org.intellij.groovy</depends>
|
||||
<depends optional="true" config-file="errorProne-compiler-support.xml">Error-prone plugin</depends>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<applicationInitializedListener implementation="org.jetbrains.idea.maven.utils.MavenEnvironmentRegistrar"/>
|
||||
@@ -318,8 +320,12 @@
|
||||
<param name="delimiters/delimiter" disableReferences="true"/>
|
||||
</pluginDescriptor>
|
||||
|
||||
<importer implementation="org.jetbrains.idea.maven.importing.MavenCompilerImporter"/>
|
||||
<importer implementation="org.jetbrains.idea.maven.importing.MavenCompilerAnnotationProcessorPathsImporter"/>
|
||||
<importer implementation="org.jetbrains.idea.maven.importing.ExternalAnnotationsImporter"/>
|
||||
|
||||
<compiler implementation="org.jetbrains.idea.maven.importing.MavenCompilerJavacExtension"/>
|
||||
<compiler implementation="org.jetbrains.idea.maven.importing.MavenCompilerEclipseExtension"/>
|
||||
<executionEnvironmentProvider implementation="org.jetbrains.idea.maven.execution.MavenApplicationConfigurationExecutionEnvironmentProvider"/>
|
||||
</extensions>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user