mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
alternative JRE: check jre specified, allow to run with another configured jdk
This commit is contained in:
@@ -21,6 +21,7 @@ import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.ui.ComponentWithBrowseButton;
|
||||
import com.intellij.openapi.ui.TextComponentAccessor;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.GuiUtils;
|
||||
@@ -29,10 +30,12 @@ import com.intellij.ui.PanelWithAnchor;
|
||||
import com.intellij.ui.TextFieldWithHistory;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import sun.plugin2.util.SystemUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@@ -49,16 +52,34 @@ public class AlternativeJREPanel extends JPanel implements PanelWithAnchor {
|
||||
myCbEnabled = new JBCheckBox(ExecutionBundle.message("run.configuration.use.alternate.jre.checkbox"));
|
||||
|
||||
myFieldWithHistory = new TextFieldWithHistory();
|
||||
myFieldWithHistory.setHistorySize(-1);
|
||||
final ArrayList<String> foundJDKs = new ArrayList<String>();
|
||||
final Sdk[] allJDKs = ProjectJdkTable.getInstance().getAllJdks();
|
||||
|
||||
for (Sdk sdk : allJDKs) {
|
||||
foundJDKs.add(sdk.getName());
|
||||
}
|
||||
|
||||
for (JreProvider provider : JreProvider.EP_NAME.getExtensions()) {
|
||||
String path = provider.getJrePath();
|
||||
if (!StringUtil.isEmpty(path)) {
|
||||
foundJDKs.add(path);
|
||||
}
|
||||
}
|
||||
final Sdk[] allJDKs = ProjectJdkTable.getInstance().getAllJdks();
|
||||
|
||||
for (Sdk jdk : allJDKs) {
|
||||
foundJDKs.add(jdk.getHomePath());
|
||||
String homePath = jdk.getHomePath();
|
||||
|
||||
if (!SystemInfo.isMac) {
|
||||
final File jre = new File(jdk.getHomePath(), "jre");
|
||||
if (jre.isDirectory()) {
|
||||
homePath = jre.getPath();
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundJDKs.contains(homePath)) {
|
||||
foundJDKs.add(homePath);
|
||||
}
|
||||
}
|
||||
myFieldWithHistory.setHistory(foundJDKs);
|
||||
myPathField = new ComponentWithBrowseButton<TextFieldWithHistory>(myFieldWithHistory, null);
|
||||
|
||||
@@ -27,6 +27,8 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkType;
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.ex.PathUtilEx;
|
||||
import com.intellij.openapi.roots.*;
|
||||
@@ -36,6 +38,7 @@ import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -128,6 +131,14 @@ public class JavaParametersUtil {
|
||||
}
|
||||
|
||||
private static Sdk createAlternativeJdk(final String jreHome) throws CantRunException {
|
||||
final Sdk configuredJdk = ProjectJdkTable.getInstance().findJdk(jreHome);
|
||||
if (configuredJdk != null) {
|
||||
return configuredJdk;
|
||||
}
|
||||
final boolean isJdk = JavaSdk.checkForJdk(new File(jreHome));
|
||||
if (isJdk) {
|
||||
throw new CantRunException("Jre expected but jdk found");
|
||||
}
|
||||
final Sdk jdk = JavaSdk.getInstance().createJdk("", jreHome);
|
||||
if (jdk == null) throw CantRunException.noJdkConfigured();
|
||||
return jdk;
|
||||
@@ -135,11 +146,12 @@ public class JavaParametersUtil {
|
||||
|
||||
public static void checkAlternativeJRE(CommonJavaRunConfigurationParameters configuration) throws RuntimeConfigurationWarning {
|
||||
if (configuration.isAlternativeJrePathEnabled()) {
|
||||
if (configuration.getAlternativeJrePath() == null ||
|
||||
configuration.getAlternativeJrePath().length() == 0 ||
|
||||
!JavaSdk.checkForJre(configuration.getAlternativeJrePath())) {
|
||||
final String alternativeJrePath = configuration.getAlternativeJrePath();
|
||||
if (alternativeJrePath == null ||
|
||||
alternativeJrePath.length() == 0 ||
|
||||
ProjectJdkTable.getInstance().findJdk(alternativeJrePath) == null && !JavaSdk.checkForJre(alternativeJrePath)) {
|
||||
throw new RuntimeConfigurationWarning(
|
||||
ExecutionBundle.message("jre.path.is.not.valid.jre.home.error.mesage", configuration.getAlternativeJrePath()));
|
||||
ExecutionBundle.message("jre.path.is.not.valid.jre.home.error.mesage", alternativeJrePath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user