--- /dev/null
+/*
+ * 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();
+ }
+ }
+}
--- /dev/null
+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
+ }
+
+}