mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-233108 - added groovy-eclipse import support into maven
GitOrigin-RevId: c5a2cc4ea2944037eb17da99f18aa0a33e22786b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6f39ece64e
commit
1784d68ee0
+8
@@ -28,4 +28,12 @@ public class GreclipseIdeaCompilerSettings implements PersistentStateComponent<G
|
||||
public static GreclipseSettings getSettings(@NotNull Project project) {
|
||||
return ServiceManager.getService(project, GreclipseIdeaCompilerSettings.class).mySettings;
|
||||
}
|
||||
|
||||
public static void setGrEclipsePath(@NotNull Project project, @NotNull String path){
|
||||
ServiceManager.getService(project, GreclipseIdeaCompilerSettings.class).mySettings.greclipsePath = path;
|
||||
}
|
||||
|
||||
public static void setGrCmdParams(@NotNull Project project, @NotNull String cmdLineParams){
|
||||
ServiceManager.getService(project, GreclipseIdeaCompilerSettings.class).mySettings.cmdLineParams = cmdLineParams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.workspaceModel.core" />
|
||||
<orderEntry type="module" module-name="intellij.platform.workspaceModel.ide" />
|
||||
<orderEntry type="module" module-name="intellij.repository.search" />
|
||||
<orderEntry type="module" module-name="intellij.groovy.jps" scope="TEST" />
|
||||
<orderEntry type="library" name="StreamEx" level="project" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.pom.Navigatable
|
||||
import org.jetbrains.annotations.Nls
|
||||
import org.jetbrains.idea.maven.buildtool.quickfix.OffMavenOfflineModeQuickFix
|
||||
import org.jetbrains.idea.maven.buildtool.quickfix.OpenMavenSettingsQuickFix
|
||||
import org.jetbrains.idea.maven.buildtool.quickfix.UseBundledMavenQuickFix
|
||||
@@ -96,6 +97,11 @@ class MavenSyncConsole(private val myProject: Project) {
|
||||
mySyncView.onEvent(mySyncId, OutputBuildEventImpl(parentId, toPrint, stdout))
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun addWarning(@Nls text: String, @Nls description: String) = doIfImportInProcess {
|
||||
mySyncView.onEvent(mySyncId, MessageEventImpl(mySyncId, MessageEvent.Kind.WARNING, "Compiler", text, description))
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun finishImport() {
|
||||
debugLog("Maven sync: finishImport")
|
||||
|
||||
+20
@@ -1,9 +1,13 @@
|
||||
// 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.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.maven.project.MavenProject;
|
||||
@@ -11,6 +15,10 @@ import org.jetbrains.idea.maven.project.ResolveContext;
|
||||
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.compiler.CompilerOptions;
|
||||
import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
@@ -42,4 +50,16 @@ public interface MavenCompilerExtension {
|
||||
@NotNull NativeMavenProjectHolder nativeMavenProject,
|
||||
@NotNull MavenEmbedderWrapper embedder,
|
||||
@NotNull ResolveContext context) throws MavenProcessCanceledException { return false; }
|
||||
|
||||
default void configureOptions(CompilerOptions compilerOptions,
|
||||
Module module,
|
||||
MavenProject mavenProject,
|
||||
List<String> compilerArgs) {
|
||||
if(compilerOptions instanceof JpsJavaCompilerOptions){
|
||||
JpsJavaCompilerOptions javaCompilerOptions = (JpsJavaCompilerOptions)compilerOptions;
|
||||
|
||||
CompilerConfigurationImpl compilerConfiguration = (CompilerConfigurationImpl)CompilerConfiguration.getInstance(module.getProject());
|
||||
compilerConfiguration.setAdditionalOptions(javaCompilerOptions, module, compilerArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+57
-48
@@ -12,11 +12,13 @@ import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.util.containers.ContainerUtil.addIfNotNull
|
||||
import com.intellij.util.text.nullize
|
||||
import org.jdom.Element
|
||||
import org.jetbrains.annotations.NotNull
|
||||
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.MavenLog
|
||||
import org.jetbrains.idea.maven.utils.MavenProcessCanceledException
|
||||
import org.jetbrains.jps.model.java.compiler.CompilerOptions
|
||||
import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions
|
||||
|
||||
/**
|
||||
@@ -94,7 +96,7 @@ class MavenCompilerImporter : MavenImporter("org.apache.maven.plugins", "maven-c
|
||||
|
||||
for (compilerExtension in MavenCompilerExtension.EP_NAME.extensions) {
|
||||
if (mavenConfiguration.value != null && compilerId == compilerExtension.mavenCompilerId) {
|
||||
importCompilerConfiguration(module, mavenConfiguration.value!!, compilerExtension)
|
||||
importCompilerConfiguration(module, mavenConfiguration.value!!, compilerExtension, mavenProject)
|
||||
}
|
||||
else {
|
||||
// cleanup obsolete options
|
||||
@@ -132,55 +134,15 @@ class MavenCompilerImporter : MavenImporter("org.apache.maven.plugins", "maven-c
|
||||
|
||||
private fun importCompilerConfiguration(module: Module,
|
||||
compilerMavenConfiguration: Element,
|
||||
extension: MavenCompilerExtension) {
|
||||
val compilerOptions = extension.getCompiler(module.project)?.options as? JpsJavaCompilerOptions ?: return
|
||||
|
||||
val options = mutableListOf<String>()
|
||||
val parameters = compilerMavenConfiguration.getChild("parameters")
|
||||
|
||||
if (parameters?.textTrim?.toBoolean() == true) {
|
||||
options += "-parameters"
|
||||
}
|
||||
|
||||
val compilerArguments = compilerMavenConfiguration.getChild("compilerArguments")
|
||||
if (compilerArguments != null) {
|
||||
val unresolvedArgs = mutableSetOf<String>()
|
||||
val effectiveArguments = compilerArguments.children.map {
|
||||
val key = it.name.run { if (startsWith("-")) this else "-$this" }
|
||||
val value = getResolvedText(it)
|
||||
if (value == null && hasUnresolvedProperty(it.textTrim)) {
|
||||
unresolvedArgs += key
|
||||
}
|
||||
key to value
|
||||
}.toMap()
|
||||
|
||||
effectiveArguments.forEach { key, value ->
|
||||
if (key.startsWith("-A") && value != null) {
|
||||
options.add("$key=$value")
|
||||
}
|
||||
else if (key !in unresolvedArgs) {
|
||||
options.add(key)
|
||||
addIfNotNull(options, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addIfNotNull(options, getResolvedText(compilerMavenConfiguration.getChildTextTrim("compilerArgument")))
|
||||
|
||||
val compilerArgs = compilerMavenConfiguration.getChild("compilerArgs")
|
||||
if (compilerArgs != null) {
|
||||
for (arg in compilerArgs.getChildren("arg")) {
|
||||
addIfNotNull(options, getResolvedText(arg))
|
||||
}
|
||||
for (compilerArg in compilerArgs.getChildren("compilerArg")) {
|
||||
addIfNotNull(options, getResolvedText(compilerArg))
|
||||
}
|
||||
}
|
||||
|
||||
val compilerConfiguration = CompilerConfiguration.getInstance(module.project) as CompilerConfigurationImpl
|
||||
compilerConfiguration.setAdditionalOptions(compilerOptions, module, options)
|
||||
extension: MavenCompilerExtension,
|
||||
mavenProject: MavenProject) {
|
||||
val compilerOptions = extension.getCompiler(module.project)?.options
|
||||
val compilerArgs = collectCompilerArgs(compilerMavenConfiguration);
|
||||
extension.configureOptions(compilerOptions, module, mavenProject, compilerArgs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
companion object {
|
||||
private val COMPILERS = Key.create<MutableSet<String>>("maven.compilers")
|
||||
private val DEFAULT_COMPILER_IS_RESOLVED = Key.create<Boolean>("default.compiler.resolved")
|
||||
@@ -218,5 +180,52 @@ class MavenCompilerImporter : MavenImporter("org.apache.maven.plugins", "maven-c
|
||||
private fun getResolvedText(it: Element): String? {
|
||||
return getResolvedText(it.textTrim)
|
||||
}
|
||||
|
||||
private fun collectCompilerArgs(compilerMavenConfiguration: Element): List<String> {
|
||||
|
||||
|
||||
val options = mutableListOf<String>()
|
||||
val parameters = compilerMavenConfiguration.getChild("parameters")
|
||||
|
||||
if (parameters?.textTrim?.toBoolean() == true) {
|
||||
options += "-parameters"
|
||||
}
|
||||
|
||||
val compilerArguments = compilerMavenConfiguration.getChild("compilerArguments")
|
||||
if (compilerArguments != null) {
|
||||
val unresolvedArgs = mutableSetOf<String>()
|
||||
val effectiveArguments = compilerArguments.children.map {
|
||||
val key = it.name.run { if (startsWith("-")) this else "-$this" }
|
||||
val value = getResolvedText(it)
|
||||
if (value == null && hasUnresolvedProperty(it.textTrim)) {
|
||||
unresolvedArgs += key
|
||||
}
|
||||
key to value
|
||||
}.toMap()
|
||||
|
||||
effectiveArguments.forEach { key, value ->
|
||||
if (key.startsWith("-A") && value != null) {
|
||||
options.add("$key=$value")
|
||||
}
|
||||
else if (key !in unresolvedArgs) {
|
||||
options.add(key)
|
||||
addIfNotNull(options, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addIfNotNull(options, getResolvedText(compilerMavenConfiguration.getChildTextTrim("compilerArgument")))
|
||||
|
||||
val compilerArgs = compilerMavenConfiguration.getChild("compilerArgs")
|
||||
if (compilerArgs != null) {
|
||||
for (arg in compilerArgs.getChildren("arg")) {
|
||||
addIfNotNull(options, getResolvedText(arg))
|
||||
}
|
||||
for (compilerArg in compilerArgs.getChildren("compilerArg")) {
|
||||
addIfNotNull(options, getResolvedText(compilerArg))
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
// Copyright 2000-2020 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.plugins.groovy
|
||||
|
||||
import com.intellij.compiler.CompilerConfiguration
|
||||
import com.intellij.compiler.CompilerConfigurationImpl
|
||||
import com.intellij.compiler.impl.javaCompiler.BackendCompiler
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.idea.maven.execution.SyncBundle
|
||||
import org.jetbrains.idea.maven.importing.MavenCompilerExtension
|
||||
import org.jetbrains.idea.maven.project.MavenProject
|
||||
import org.jetbrains.idea.maven.project.MavenProjectsManager
|
||||
import org.jetbrains.jps.model.java.compiler.CompilerOptions
|
||||
import org.jetbrains.plugins.groovy.compiler.GreclipseIdeaCompiler
|
||||
import org.jetbrains.plugins.groovy.compiler.GreclipseIdeaCompilerSettings
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class MavenCompilerGrEclipseExtension : MavenCompilerExtension {
|
||||
override fun getMavenCompilerId(): String = "groovy-eclipse-compiler"
|
||||
|
||||
override fun getCompiler(project: Project): BackendCompiler? {
|
||||
val compilerConfiguration = CompilerConfiguration.getInstance(project) as CompilerConfigurationImpl
|
||||
return compilerConfiguration.registeredJavaCompilers.find { it is GreclipseIdeaCompiler }
|
||||
}
|
||||
|
||||
override fun configureOptions(compilerOptions: CompilerOptions?,
|
||||
module: Module,
|
||||
mavenProject: MavenProject,
|
||||
compilerArgs: MutableList<String>) {
|
||||
val eclipseBatchId = mavenProject.plugins.filter { it.artifactId == "maven-compiler-plugin" && it.groupId == "org.apache.maven.plugins" }
|
||||
.flatMap { it.dependencies }
|
||||
.find { it.groupId == "org.codehaus.groovy" && it.artifactId == "groovy-eclipse-batch" }
|
||||
val batchLib = mavenProject.dependencies.find { it.mavenId == eclipseBatchId }
|
||||
|
||||
if (batchLib != null) {
|
||||
GreclipseIdeaCompilerSettings.setGrEclipsePath(module.project, batchLib.file.absolutePath);
|
||||
GreclipseIdeaCompilerSettings.setGrCmdParams(module.project, compilerArgs.joinToString(" "));
|
||||
}
|
||||
else {
|
||||
MavenProjectsManager.getInstance(module.project).syncConsole.addWarning(
|
||||
SyncBundle.message("maven.sync.warnings.eclipse.batch.compiler.no.dependency"),
|
||||
SyncBundle.message("maven.sync.warnings.eclipse.batch.compiler.no.dependency.desc")
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@
|
||||
<importer implementation="org.jetbrains.idea.maven.plugins.groovy.GroovyGmavenPlusImporter"/>
|
||||
<importer implementation="org.jetbrains.idea.maven.plugins.groovy.GroovyEclipseCompilerImporter"/>
|
||||
|
||||
<compiler implementation="org.jetbrains.idea.maven.plugins.groovy.MavenCompilerGrEclipseExtension"/>
|
||||
|
||||
<pluginDescriptor mavenId="org.codehaus.groovy.maven:gmaven-plugin">
|
||||
<param name="source" languageProvider="org.jetbrains.idea.maven.plugins.groovy.MavenGroovyLanguageProvider"/>
|
||||
</pluginDescriptor>
|
||||
|
||||
@@ -10,3 +10,8 @@ maven.sync.dependencies.artifact.download=Downloading {0}
|
||||
|
||||
maven.sync.quickfixes.nomaven=Maven version is not defined
|
||||
maven.sync.quickfixes.maven360=You use Maven 3.6.0, there could be issues importing multimodule project. It is recommended to upgrade or downgrade Maven version
|
||||
|
||||
|
||||
maven.sync.warnings.eclipse.batch.compiler.no.dependency=Dependency org.codehaus.groovy:groovy-eclipse-batch not properly registered
|
||||
maven.sync.warnings.eclipse.batch.compiler.no.dependency.desc=To use groovy-eclipse-compiler you need to specify a Groovy artifact as a build dependency in addition to the maven-compiler-plugin dependency.\
|
||||
The Groovy dependency version should match the compiler version.
|
||||
@@ -5,11 +5,13 @@
|
||||
package org.jetbrains.idea.maven.importing;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import org.jetbrains.idea.maven.MavenImportingTestCase;
|
||||
import org.jetbrains.idea.maven.server.MavenServerManager;
|
||||
import org.jetbrains.plugins.groovy.compiler.GreclipseIdeaCompilerSettings;
|
||||
import org.jetbrains.plugins.groovy.config.GroovyConfigUtils;
|
||||
|
||||
import java.io.File;
|
||||
@@ -224,6 +226,9 @@ public class GroovyImporterTest extends MavenImportingTestCase {
|
||||
"src/test/groovy",
|
||||
"src/test/java");
|
||||
assertTestResources("project", "src/test/resources");
|
||||
|
||||
GreclipseIdeaCompilerSettings compilerSettings = ServiceManager.getService(myProject, GreclipseIdeaCompilerSettings.class);
|
||||
assertEquals("", compilerSettings.getState().greclipsePath);
|
||||
}
|
||||
|
||||
public void testAddingCustomGroovySpecificSources() {
|
||||
@@ -655,4 +660,8 @@ public class GroovyImporterTest extends MavenImportingTestCase {
|
||||
assertExcludes("project", "target");
|
||||
}
|
||||
|
||||
public void testGrEclipseMavenPlugin(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user