mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
run/debug plugin with alternative jdk (IDEA-70756 )
This commit is contained in:
@@ -30,8 +30,10 @@ import com.intellij.openapi.options.SettingsEditor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkType;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.SdkModificator;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -54,6 +56,11 @@ public class PluginRunConfiguration extends RunConfigurationBase implements Modu
|
||||
public String PROGRAM_PARAMETERS;
|
||||
@NonNls private static final String NAME = "name";
|
||||
@NonNls private static final String MODULE = "module";
|
||||
@NonNls private static final String ALTERNATIVE_PATH_ELEMENT = "alternative-path";
|
||||
@NonNls private static final String PATH = "path";
|
||||
@NonNls private static final String ALTERNATIVE_PATH_ENABLED_ATTR = "alternative-path-enabled";
|
||||
private String ALTERNATIVE_JRE_PATH = null;
|
||||
private boolean ALTERNATIVE_JRE_PATH_ENABLED = false;
|
||||
|
||||
public PluginRunConfiguration(final Project project, final ConfigurationFactory factory, final String name) {
|
||||
super(project, factory, name);
|
||||
@@ -111,8 +118,19 @@ public class PluginRunConfiguration extends RunConfigurationBase implements Modu
|
||||
|
||||
fillParameterList(vm, VM_PARAMETERS);
|
||||
fillParameterList(params.getProgramParametersList(), PROGRAM_PARAMETERS);
|
||||
|
||||
@NonNls String libPath = ideaJdk.getHomePath() + File.separator + "lib";
|
||||
Sdk usedIdeaJdk = ideaJdk;
|
||||
if (isAlternativeJreEnabled() && !StringUtil.isEmptyOrSpaces(getAlternativeJrePath())) {
|
||||
try {
|
||||
usedIdeaJdk = (Sdk)usedIdeaJdk.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
throw new ExecutionException(e.getMessage());
|
||||
}
|
||||
final SdkModificator sdkToSetUp = usedIdeaJdk.getSdkModificator();
|
||||
sdkToSetUp.setHomePath(getAlternativeJrePath());
|
||||
sdkToSetUp.commitChanges();
|
||||
}
|
||||
@NonNls String libPath = usedIdeaJdk.getHomePath() + File.separator + "lib";
|
||||
vm.add("-Xbootclasspath/a:" + libPath + File.separator + "boot.jar");
|
||||
|
||||
vm.defineProperty("idea.config.path", canonicalSandbox + File.separator + "config");
|
||||
@@ -123,8 +141,8 @@ public class PluginRunConfiguration extends RunConfigurationBase implements Modu
|
||||
vm.defineProperty("idea.smooth.progress", "false");
|
||||
vm.defineProperty("apple.laf.useScreenMenuBar", "true");
|
||||
}
|
||||
|
||||
String buildNumber = IdeaJdk.getBuildNumber(ideaJdk.getHomePath());
|
||||
|
||||
String buildNumber = IdeaJdk.getBuildNumber(usedIdeaJdk.getHomePath());
|
||||
if (buildNumber != null) {
|
||||
if (buildNumber.startsWith("IC")) {
|
||||
vm.defineProperty("idea.platform.prefix", "Idea");
|
||||
@@ -146,9 +164,9 @@ public class PluginRunConfiguration extends RunConfigurationBase implements Modu
|
||||
}
|
||||
}
|
||||
|
||||
params.setWorkingDirectory(ideaJdk.getHomePath() + File.separator + "bin" + File.separator);
|
||||
params.setWorkingDirectory(usedIdeaJdk.getHomePath() + File.separator + "bin" + File.separator);
|
||||
|
||||
params.setJdk(ideaJdk);
|
||||
params.setJdk(usedIdeaJdk);
|
||||
|
||||
params.getClassPath().addFirst(libPath + File.separator + "log4j.jar");
|
||||
params.getClassPath().addFirst(libPath + File.separator + "jdom.jar");
|
||||
@@ -159,7 +177,7 @@ public class PluginRunConfiguration extends RunConfigurationBase implements Modu
|
||||
params.getClassPath().addFirst(libPath + File.separator + "bootstrap.jar");
|
||||
params.getClassPath().addFirst(libPath + File.separator + "idea.jar");
|
||||
params.getClassPath().addFirst(libPath + File.separator + "idea_rt.jar");
|
||||
params.getClassPath().addFirst(((JavaSdkType)ideaJdk.getSdkType()).getToolsPath(ideaJdk));
|
||||
params.getClassPath().addFirst(((JavaSdkType)usedIdeaJdk.getSdkType()).getToolsPath(usedIdeaJdk));
|
||||
|
||||
params.setMainClass("com.intellij.idea.Main");
|
||||
|
||||
@@ -171,6 +189,22 @@ public class PluginRunConfiguration extends RunConfigurationBase implements Modu
|
||||
return state;
|
||||
}
|
||||
|
||||
public String getAlternativeJrePath() {
|
||||
return ALTERNATIVE_JRE_PATH;
|
||||
}
|
||||
|
||||
public void setAlternativeJrePath(String ALTERNATIVE_JRE_PATH) {
|
||||
this.ALTERNATIVE_JRE_PATH = ALTERNATIVE_JRE_PATH;
|
||||
}
|
||||
|
||||
public boolean isAlternativeJreEnabled() {
|
||||
return ALTERNATIVE_JRE_PATH_ENABLED;
|
||||
}
|
||||
|
||||
public void setAlternativeJreEnabled(boolean ALTERNATIVE_JRE_PATH_ENABLED) {
|
||||
this.ALTERNATIVE_JRE_PATH_ENABLED = ALTERNATIVE_JRE_PATH_ENABLED;
|
||||
}
|
||||
|
||||
private static void fillParameterList(ParametersList list, String value) {
|
||||
final String[] parameters = value != null ? value.split(" ") : null;
|
||||
for (int i = 0; parameters != null && i < parameters.length; i++) {
|
||||
@@ -221,6 +255,12 @@ public class PluginRunConfiguration extends RunConfigurationBase implements Modu
|
||||
myModuleName = module.getAttributeValue(NAME);
|
||||
}
|
||||
DefaultJDOMExternalizer.readExternal(this, element);
|
||||
final Element altElement = element.getChild(ALTERNATIVE_PATH_ELEMENT);
|
||||
if (altElement != null) {
|
||||
ALTERNATIVE_JRE_PATH = altElement.getAttributeValue(PATH);
|
||||
final String enabledAttr = altElement.getAttributeValue(ALTERNATIVE_PATH_ENABLED_ATTR);
|
||||
ALTERNATIVE_JRE_PATH_ENABLED = enabledAttr != null && Boolean.parseBoolean(enabledAttr);
|
||||
}
|
||||
super.readExternal(element);
|
||||
}
|
||||
|
||||
@@ -235,6 +275,12 @@ public class PluginRunConfiguration extends RunConfigurationBase implements Modu
|
||||
}));
|
||||
element.addContent(moduleElement);
|
||||
DefaultJDOMExternalizer.writeExternal(this, element);
|
||||
if (!StringUtil.isEmptyOrSpaces(ALTERNATIVE_JRE_PATH)) {
|
||||
Element altElement = new Element(ALTERNATIVE_PATH_ELEMENT);
|
||||
altElement.setAttribute(PATH, ALTERNATIVE_JRE_PATH);
|
||||
altElement.setAttribute(ALTERNATIVE_PATH_ENABLED_ATTR, String.valueOf(ALTERNATIVE_JRE_PATH_ENABLED));
|
||||
element.addContent(altElement);
|
||||
}
|
||||
super.writeExternal(element);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.jetbrains.idea.devkit.run;
|
||||
|
||||
import com.intellij.execution.ExecutionBundle;
|
||||
import com.intellij.execution.configurations.LogFileOptions;
|
||||
import com.intellij.execution.ui.AlternativeJREPanel;
|
||||
import com.intellij.ide.ui.ListCellRendererWrapper;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -55,6 +56,7 @@ public class PluginRunConfigurationEditor extends SettingsEditor<PluginRunConfig
|
||||
private final LabeledComponent<RawCommandLineEditor> myVMParameters = new LabeledComponent<RawCommandLineEditor>();
|
||||
private final LabeledComponent<RawCommandLineEditor> myProgramParameters = new LabeledComponent<RawCommandLineEditor>();
|
||||
private JComponent anchor;
|
||||
private AlternativeJREPanel myAlternativeJREPanel = new AlternativeJREPanel();
|
||||
|
||||
@NonNls private final JCheckBox myShowLogs = new JCheckBox(DevKitBundle.message("show.smth", "idea.log"));
|
||||
|
||||
@@ -130,6 +132,7 @@ public class PluginRunConfigurationEditor extends SettingsEditor<PluginRunConfig
|
||||
myModules.setSelectedItem(prc.getModule());
|
||||
getVMParameters().setText(prc.VM_PARAMETERS);
|
||||
getProgramParameters().setText(prc.PROGRAM_PARAMETERS);
|
||||
myAlternativeJREPanel.init(prc.getAlternativeJrePath(), prc.isAlternativeJreEnabled());
|
||||
}
|
||||
|
||||
|
||||
@@ -137,6 +140,8 @@ public class PluginRunConfigurationEditor extends SettingsEditor<PluginRunConfig
|
||||
prc.setModule(((Module)myModules.getSelectedItem()));
|
||||
prc.VM_PARAMETERS = getVMParameters().getText();
|
||||
prc.PROGRAM_PARAMETERS = getProgramParameters().getText();
|
||||
prc.setAlternativeJrePath(myAlternativeJREPanel.getPath());
|
||||
prc.setAlternativeJreEnabled(myAlternativeJREPanel.isPathEnabled());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -163,7 +168,7 @@ public class PluginRunConfigurationEditor extends SettingsEditor<PluginRunConfig
|
||||
myProgramParameters.getComponent().setDialogCaption(myProgramParameters.getRawText());
|
||||
myProgramParameters.setLabelLocation(BorderLayout.WEST);
|
||||
|
||||
GridBagConstraints gc = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP);
|
||||
GridBagConstraints gc = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 0, 0, 0), UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP);
|
||||
wholePanel.add(myVMParameters, gc);
|
||||
wholePanel.add(myProgramParameters, gc);
|
||||
gc.gridwidth = 1;
|
||||
@@ -177,7 +182,9 @@ public class PluginRunConfigurationEditor extends SettingsEditor<PluginRunConfig
|
||||
gc.gridx = 0;
|
||||
gc.gridy = 4;
|
||||
gc.gridwidth = 2;
|
||||
|
||||
|
||||
wholePanel.add(myAlternativeJREPanel, gc);
|
||||
gc.gridy = 5;
|
||||
wholePanel.add(myShowLogs, gc);
|
||||
return wholePanel;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user