mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-108202 Create maven configured workspace.
Support 'jdkName' property.
This commit is contained in:
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.maven.importing.configurers;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
public class MavenIdeaPluginConfigurer extends MavenModuleConfigurer {
|
||||
@Override
|
||||
public void configure(@NotNull MavenProject mavenProject, @NotNull Project project, @Nullable Module module) {
|
||||
if (module == null) return;
|
||||
|
||||
Element cfg = mavenProject.getPluginConfiguration("com.googlecode", "maven-idea-plugin");
|
||||
if (cfg == null) return;
|
||||
|
||||
|
||||
// Configure SDK name
|
||||
configureJdk(cfg, module);
|
||||
}
|
||||
|
||||
private static void configureJdk(Element cfg, @NotNull Module module) {
|
||||
String jdkName = cfg.getChildTextTrim("jdkName");
|
||||
if (StringUtil.isEmptyOrSpaces(jdkName)) return;
|
||||
|
||||
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
|
||||
String currentSdkName = null;
|
||||
Sdk sdk = rootManager.getSdk();
|
||||
if (sdk != null) {
|
||||
currentSdkName = sdk.getName();
|
||||
}
|
||||
|
||||
if (!jdkName.equals(currentSdkName)) {
|
||||
ModifiableRootModel model = rootManager.getModifiableModel();
|
||||
|
||||
if (jdkName.equals(ProjectRootManager.getInstance(model.getProject()).getProjectSdkName())) {
|
||||
model.inheritSdk();
|
||||
}
|
||||
else {
|
||||
Sdk jdk = ProjectJdkTable.getInstance().findJdk(jdkName);
|
||||
if (jdk != null) {
|
||||
model.setSdk(jdk);
|
||||
}
|
||||
else {
|
||||
model.setInvalidSdk(jdkName, JavaSdk.getInstance().getName());
|
||||
}
|
||||
}
|
||||
|
||||
model.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -41,7 +41,10 @@ public abstract class MavenModuleConfigurer {
|
||||
for (MavenModuleConfigurer configurer : new MavenModuleConfigurer[]{
|
||||
new MavenCompilerConfigurer(),
|
||||
new MavenEncodingConfigurer(),
|
||||
new MavenAnnotationProcessorConfigurer()}) {
|
||||
new MavenAnnotationProcessorConfigurer(),
|
||||
|
||||
new MavenIdeaPluginConfigurer()
|
||||
}) {
|
||||
|
||||
if (!Boolean.parseBoolean(System.getProperty("idea.maven.disable." + configurer.getClass().getSimpleName()))) {
|
||||
configurers.add(configurer);
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package org.jetbrains.idea.maven.plugins
|
||||
|
||||
import com.intellij.openapi.roots.ModuleRootManager
|
||||
import org.jetbrains.idea.maven.dom.MavenDomTestCase
|
||||
|
||||
/**
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
class MavenIdeaPluginTest extends MavenDomTestCase {
|
||||
|
||||
public void testConfigureJdk() {
|
||||
importProject("""
|
||||
<groupId>test</groupId>
|
||||
<artifactId>project</artifactId>
|
||||
<version>1</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.googlecode</groupId>
|
||||
<artifactId>maven-idea-plugin</artifactId>
|
||||
<version>1.6.1</version>
|
||||
|
||||
<configuration>
|
||||
<jdkName>invalidJdk</jdkName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
""")
|
||||
|
||||
def module = getModule("project")
|
||||
assert module != null;
|
||||
|
||||
assert !ModuleRootManager.getInstance(module).sdkInherited
|
||||
assert ModuleRootManager.getInstance(module).sdk == null
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user