diff --git a/java/java-impl/intellij.java.impl.iml b/java/java-impl/intellij.java.impl.iml
index ae87c9eab1fc..ace7c7a34c71 100644
--- a/java/java-impl/intellij.java.impl.iml
+++ b/java/java-impl/intellij.java.impl.iml
@@ -62,6 +62,7 @@
+
diff --git a/java/java-impl/src/META-INF/JavaPlugin.xml b/java/java-impl/src/META-INF/JavaPlugin.xml
index 3e59b77f086a..fdf1c03e0c98 100644
--- a/java/java-impl/src/META-INF/JavaPlugin.xml
+++ b/java/java-impl/src/META-INF/JavaPlugin.xml
@@ -548,6 +548,9 @@
order="after compileBeforeRunNoErrorCheck"/>
+
diff --git a/java/java-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJavaSdkProvider.java b/java/java-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJavaSdkProvider.java
new file mode 100644
index 000000000000..316b6d2356c3
--- /dev/null
+++ b/java/java-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJavaSdkProvider.java
@@ -0,0 +1,32 @@
+// Copyright 2000-2019 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 com.intellij.openapi.externalSystem.service.execution;
+
+import com.intellij.openapi.projectRoots.JavaSdk;
+import com.intellij.openapi.projectRoots.JdkUtil;
+import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.projectRoots.SdkType;
+import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public class ExternalSystemJavaSdkProvider implements ExternalSystemJdkProvider {
+ @NotNull
+ @Override
+ public SdkType getJavaSdkType() {
+ return JavaSdk.getInstance();
+ }
+
+ @NotNull
+ @Override
+ public Sdk getInternalJdk() {
+ return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
+ }
+
+ @NotNull
+ @Override
+ public Sdk createJdk(@Nullable String jdkName, @NotNull String homePath) {
+ SdkType javaSdk = getJavaSdkType();
+ String sdkName = jdkName != null ? jdkName : javaSdk.suggestSdkName(null, homePath);
+ return ((JavaSdk)javaSdk).createJdk(sdkName, homePath, !JdkUtil.checkForJdk(homePath));
+ }
+}
diff --git a/platform/external-system-impl/intellij.platform.externalSystem.impl.iml b/platform/external-system-impl/intellij.platform.externalSystem.impl.iml
index 5d65de10f719..50a2a405c81e 100644
--- a/platform/external-system-impl/intellij.platform.externalSystem.impl.iml
+++ b/platform/external-system-impl/intellij.platform.externalSystem.impl.iml
@@ -13,11 +13,9 @@
-
-
@@ -25,9 +23,6 @@
-
-
-
diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/RemoteExternalSystemCommunicationManager.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/RemoteExternalSystemCommunicationManager.java
index 2775ea484016..18a2ae7d35cb 100644
--- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/RemoteExternalSystemCommunicationManager.java
+++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/RemoteExternalSystemCommunicationManager.java
@@ -3,7 +3,6 @@ package com.intellij.openapi.externalSystem.service;
import com.intellij.CommonBundle;
import com.intellij.configurationStore.StorageUtilKt;
-import com.intellij.core.JavaCoreBundle;
import com.intellij.debugger.ui.DebuggerView;
import com.intellij.execution.DefaultExecutionResult;
import com.intellij.execution.ExecutionException;
@@ -26,6 +25,7 @@ import com.intellij.openapi.externalSystem.ExternalSystemManager;
import com.intellij.openapi.externalSystem.model.ExternalSystemException;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener;
+import com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkProvider;
import com.intellij.openapi.externalSystem.service.notification.ExternalSystemProgressNotificationManager;
import com.intellij.openapi.externalSystem.service.remote.ExternalSystemProgressNotificationManagerImpl;
import com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProgressNotificationManager;
@@ -33,14 +33,12 @@ import com.intellij.openapi.externalSystem.service.remote.wrapper.ExternalSystem
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
import com.intellij.openapi.externalSystem.util.ExternalSystemConstants;
import com.intellij.openapi.module.EmptyModuleType;
-import com.intellij.openapi.module.JavaModuleType;
import com.intellij.openapi.module.ModuleType;
-import com.intellij.openapi.module.StdModuleTypes;
import com.intellij.openapi.project.ProjectBundle;
+import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.projectRoots.SimpleJavaSdkType;
import com.intellij.openapi.roots.DependencyScope;
import com.intellij.openapi.util.ShutDownTracker;
-import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.PsiBundle;
import com.intellij.serialization.ObjectSerializer;
import com.intellij.ui.PlaceHolder;
@@ -126,12 +124,13 @@ public class RemoteExternalSystemCommunicationManager implements ExternalSystemC
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ExtensionPointName.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(StorageUtilKt.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ExternalSystemTaskNotificationListener.class));
- ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(StdModuleTypes.class));
- ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(JavaModuleType.class));
- ExternalSystemApiUtil.addBundle(params.getClassPath(), "messages.JavaCoreBundle", JavaCoreBundle.class);
+
+ // java plugin jar if it's installed
+ Class extends SdkType> javaSdkClass = ExternalSystemJdkProvider.getInstance().getJavaSdkType().getClass();
+ ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(javaSdkClass));
+
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ModuleType.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(EmptyModuleType.class));
- ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(LanguageLevel.class));
// add Kotlin runtime
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(Unit.class));
diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/DefaultExternalSystemJdkProvider.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/DefaultExternalSystemJdkProvider.java
new file mode 100644
index 000000000000..4205df32e70d
--- /dev/null
+++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/DefaultExternalSystemJdkProvider.java
@@ -0,0 +1,33 @@
+// Copyright 2000-2019 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 com.intellij.openapi.externalSystem.service.execution;
+
+import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.projectRoots.SdkType;
+import com.intellij.openapi.projectRoots.SimpleJavaSdkType;
+import com.intellij.util.SystemProperties;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public class DefaultExternalSystemJdkProvider implements ExternalSystemJdkProvider {
+ @NotNull
+ @Override
+ public SdkType getJavaSdkType() {
+ return SimpleJavaSdkType.getInstance();
+ }
+
+ @NotNull
+ @Override
+ public Sdk getInternalJdk() {
+ final String jdkHome = SystemProperties.getJavaHome();
+ SimpleJavaSdkType simpleJavaSdkType = SimpleJavaSdkType.getInstance();
+ return simpleJavaSdkType.createJdk(simpleJavaSdkType.suggestSdkName(null, jdkHome), jdkHome);
+ }
+
+ @NotNull
+ @Override
+ public Sdk createJdk(@Nullable String jdkName, @NotNull String homePath) {
+ SimpleJavaSdkType simpleJavaSdkType = SimpleJavaSdkType.getInstance();
+ String sdkName = jdkName != null ? jdkName : simpleJavaSdkType.suggestSdkName(null, homePath);
+ return simpleJavaSdkType.createJdk(sdkName, homePath);
+ }
+}
diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJavaUtil.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJavaUtil.java
deleted file mode 100644
index 8050aa9238b1..000000000000
--- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJavaUtil.java
+++ /dev/null
@@ -1,47 +0,0 @@
-// 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 com.intellij.openapi.externalSystem.service.execution;
-
-import com.intellij.openapi.projectRoots.*;
-import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl;
-import com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * todo [Vlad, IDEA-187832]: move to `external-system-java` module
- */
-@ApiStatus.Experimental
-public class ExternalSystemJavaUtil {
- @Nullable
- static SdkType getJavaSdk() {
- try {
- return JavaSdk.getInstance();
- }
- catch (Throwable ignore) {
- }
- return null;
- }
-
- @Nullable
- static Sdk getInternalJdk() {
- ProjectJdkTable projectJdkTable = ProjectJdkTable.getInstance();
- try {
- if (projectJdkTable instanceof JavaAwareProjectJdkTableImpl) {
- return ((JavaAwareProjectJdkTableImpl)projectJdkTable).getInternalJdk();
- }
- }
- catch (Throwable ignore) {
- // todo [Vlad, IDEA-187832]: extract to `external-system-java` module
- }
- return null;
- }
-
- @Nullable
- static Sdk tryAddJdk(String homePath) {
- SdkType javaSdk = getJavaSdk();
- if (javaSdk == null) return null;
- Sdk jdk = ((JavaSdk)javaSdk).createJdk(javaSdk.suggestSdkName(null, homePath), homePath, !JdkUtil.checkForJdk(homePath));
- SdkConfigurationUtil.addSdk(jdk);
- return jdk;
- }
-}
diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJdkProvider.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJdkProvider.java
new file mode 100644
index 000000000000..d7d3a6fa99ec
--- /dev/null
+++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJdkProvider.java
@@ -0,0 +1,25 @@
+// Copyright 2000-2019 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 com.intellij.openapi.externalSystem.service.execution;
+
+import com.intellij.openapi.components.ServiceManager;
+import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.projectRoots.SdkType;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+@ApiStatus.Experimental
+public interface ExternalSystemJdkProvider {
+ static ExternalSystemJdkProvider getInstance() {
+ return ServiceManager.getService(ExternalSystemJdkProvider.class);
+ }
+
+ @NotNull
+ SdkType getJavaSdkType();
+
+ @NotNull
+ Sdk getInternalJdk();
+
+ @NotNull
+ Sdk createJdk(@Nullable String jdkName, @NotNull String homePath);
+}
diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJdkUtil.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJdkUtil.java
index ad4ea58a57fb..2ebda38df6ca 100644
--- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJdkUtil.java
+++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJdkUtil.java
@@ -6,7 +6,7 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.*;
-import com.intellij.openapi.projectRoots.impl.JavaDependentSdkType;
+import com.intellij.openapi.projectRoots.impl.DependentSdkType;
import com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.ProjectRootManager;
@@ -14,7 +14,6 @@ import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.EnvironmentUtil;
-import com.intellij.util.SystemProperties;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -70,7 +69,6 @@ public class ExternalSystemJdkUtil {
// Workaround for projects without project Jdk
SdkType jdkType = getJavaSdk();
- if (jdkType == null) return getInternalJdk();
return ProjectJdkTable.getInstance()
.getSdksOfType(jdkType).stream()
.filter(it -> isValidJdk(it.getHomePath()))
@@ -144,8 +142,10 @@ public class ExternalSystemJdkUtil {
private static Sdk findReferencedJDK(Project project) {
Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk();
- if (projectSdk != null && projectSdk.getSdkType() instanceof JavaDependentSdkType) {
- final JavaDependentSdkType sdkType = (JavaDependentSdkType)projectSdk.getSdkType();
+ if (projectSdk != null
+ && projectSdk.getSdkType() instanceof DependentSdkType
+ && projectSdk.getSdkType() instanceof JavaSdkType) {
+ final JavaSdkType sdkType = (JavaSdkType)projectSdk.getSdkType();
final String jdkPath = FileUtil.toSystemIndependentName(new File(sdkType.getBinPath(projectSdk)).getParent());
return Arrays.stream(ProjectJdkTable.getInstance().getAllJdks())
.filter(sdk -> {
@@ -165,9 +165,7 @@ public class ExternalSystemJdkUtil {
@NotNull
public static SdkType getJavaSdkType() {
- // JavaSdk.getInstance() can be null for non-java IDE
- SdkType javaSdk = getJavaSdk();
- return javaSdk == null ? SimpleJavaSdkType.getInstance() : javaSdk;
+ return getJavaSdk();
}
public static boolean isValidJdk(@Nullable String homePath) {
@@ -176,46 +174,18 @@ public class ExternalSystemJdkUtil {
@NotNull
public static Sdk addJdk(String homePath) {
- Sdk jdk;
- if (isJavaSdkPresent()) {
- jdk = ExternalSystemJavaUtil.tryAddJdk(homePath);
- if (jdk != null) {
- return jdk;
- }
- }
- SimpleJavaSdkType simpleJavaSdkType = SimpleJavaSdkType.getInstance();
- jdk = simpleJavaSdkType.createJdk(simpleJavaSdkType.suggestSdkName(null, homePath), homePath);
+ Sdk jdk = ExternalSystemJdkProvider.getInstance().createJdk(null, homePath);
SdkConfigurationUtil.addSdk(jdk);
return jdk;
}
- @Nullable
+ @NotNull
private static SdkType getJavaSdk() {
- if (isJavaSdkPresent()) {
- return ExternalSystemJavaUtil.getJavaSdk();
- }
- return null;
+ return ExternalSystemJdkProvider.getInstance().getJavaSdkType();
}
@NotNull
private static Sdk getInternalJdk() {
- if (isJavaSdkPresent()) {
- Sdk internalJdk = ExternalSystemJavaUtil.getInternalJdk();
- if (internalJdk != null) return internalJdk;
- }
- final String jdkHome = SystemProperties.getJavaHome();
- SimpleJavaSdkType simpleJavaSdkType = SimpleJavaSdkType.getInstance();
- return simpleJavaSdkType.createJdk(simpleJavaSdkType.suggestSdkName(null, jdkHome), jdkHome);
- }
-
- // todo [Vlad, IDEA-187832]: extract to `external-system-java` module
- private static boolean isJavaSdkPresent() {
- try {
- Class.forName("com.intellij.openapi.projectRoots.impl.JavaSdkImpl");
- return true;
- }
- catch (Throwable ignore) {
- return false;
- }
+ return ExternalSystemJdkProvider.getInstance().getInternalJdk();
}
}
\ No newline at end of file
diff --git a/platform/platform-resources/src/META-INF/ExternalSystemExtensions.xml b/platform/platform-resources/src/META-INF/ExternalSystemExtensions.xml
index cebe93b3dcfd..fb0a6a8d6ae9 100644
--- a/platform/platform-resources/src/META-INF/ExternalSystemExtensions.xml
+++ b/platform/platform-resources/src/META-INF/ExternalSystemExtensions.xml
@@ -75,6 +75,9 @@
+
+