mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ES: extract java sdk provider IDEA-187832
GitOrigin-RevId: 4eb55cbb1d415b252be7d94ac7b888080001fbb9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9c5ffd4573
commit
04f0ce478f
@@ -62,6 +62,7 @@
|
||||
<orderEntry type="library" name="javax.activation" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="jaxb-runtime" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.objectSerializer.annotations" />
|
||||
<orderEntry type="module" module-name="intellij.platform.externalSystem.impl" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
@@ -548,6 +548,9 @@
|
||||
order="after compileBeforeRunNoErrorCheck"/>
|
||||
<externalSystem.beforeRunTaskImporter implementation="com.intellij.compiler.options.CompileStepBeforeRunImporter"/>
|
||||
<externalSystemConfigurationHandler implementation="com.intellij.openapi.externalSystem.service.project.settings.ArtifactsImporter"/>
|
||||
<applicationService serviceInterface="com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkProvider"
|
||||
serviceImplementation="com.intellij.openapi.externalSystem.service.execution.ExternalSystemJavaSdkProvider"
|
||||
overrides="true"/>
|
||||
|
||||
<programRunner id="defaultRunRunner" implementation="com.intellij.execution.impl.DefaultJavaProgramRunner"/>
|
||||
|
||||
|
||||
+32
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,9 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="intellij.platform.externalSystem" />
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel.impl" />
|
||||
<orderEntry type="module" module-name="intellij.java.compiler" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.lang.impl" />
|
||||
<orderEntry type="module" module-name="intellij.java.debugger.impl" />
|
||||
<orderEntry type="module" module-name="intellij.java.execution" />
|
||||
<orderEntry type="module" module-name="intellij.platform.vcs" />
|
||||
<orderEntry type="library" name="Groovy" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.testRunner" />
|
||||
@@ -25,9 +23,6 @@
|
||||
<orderEntry type="library" scope="TEST" name="JUnit4" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.testFramework" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.java.testFramework" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.java.compiler.impl" />
|
||||
<orderEntry type="module" module-name="intellij.java.impl" />
|
||||
<orderEntry type="module" module-name="intellij.java" />
|
||||
<orderEntry type="module" module-name="intellij.platform.configurationStore.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.testExtensions" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.java.execution.impl" />
|
||||
|
||||
+7
-8
@@ -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));
|
||||
|
||||
+33
@@ -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);
|
||||
}
|
||||
}
|
||||
-47
@@ -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;
|
||||
}
|
||||
}
|
||||
+25
@@ -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);
|
||||
}
|
||||
+10
-40
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,9 @@
|
||||
<applicationService serviceInterface="com.intellij.openapi.roots.ExternalProjectSystemRegistry"
|
||||
serviceImplementation="com.intellij.openapi.externalSystem.ExternalProjectSystemRegistryImpl" overrides="true"/>
|
||||
|
||||
<applicationService serviceInterface="com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkProvider"
|
||||
serviceImplementation="com.intellij.openapi.externalSystem.service.execution.DefaultExternalSystemJdkProvider"/>
|
||||
|
||||
<statistics.projectUsagesCollector implementation="com.intellij.openapi.externalSystem.statistics.ExternalSystemUsagesCollector"/>
|
||||
<statistics.projectUsagesCollector implementation="com.intellij.openapi.externalSystem.statistics.ExternalSystemSettingsCollector"/>
|
||||
<statistics.counterUsagesCollector groupId="build.tools.actions" version="1"/>
|
||||
|
||||
Reference in New Issue
Block a user