IDEA-248457 Java Application with run targets: show Java language runtimes configured on a target instead of local JDKs

GitOrigin-RevId: c79ffcd9cbcbe783d8ed59492e563f0cbbf3a0a0
This commit is contained in:
Dmitry Avdeev
2020-09-23 11:12:44 +00:00
committed by intellij-monorepo-bot
parent 2ca6f25db0
commit b49b61e9c4
8 changed files with 102 additions and 41 deletions
@@ -156,7 +156,9 @@ public class ApplicationConfiguration extends JavaRunConfigurationBase
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
JavaParametersUtil.checkAlternativeJRE(this);
if (getDefaultTargetName() == null) {
JavaParametersUtil.checkAlternativeJRE(this);
}
final JavaRunConfigurationModule configurationModule = getConfigurationModule();
final PsiClass psiClass =
configurationModule.checkModuleAndClassName(getMainClassName(), ExecutionBundle.message("no.main.class.specified.error.text"));
@@ -11,6 +11,7 @@ import com.intellij.ide.macro.MacrosDialog;
import com.intellij.openapi.ui.LabeledComponent;
import com.intellij.openapi.util.Computable;
import com.intellij.ui.RawCommandLineEditor;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
@@ -106,4 +107,14 @@ public abstract class JavaSettingsEditorBase<T extends JavaRunConfigurationBase>
protected abstract void customizeFragments(List<SettingsEditorFragment<T, ?>> fragments,
ModuleClasspathCombo classpathCombo,
CommonParameterFragments<T> commonParameterFragments);
@Override
public void targetChanged(String targetName) {
SettingsEditorFragment<T, ?> fragment = ContainerUtil.find(getFragments(), f -> CommonJavaFragments.JRE_PATH == f.getId());
if (fragment != null) {
if (((JrePathEditor)fragment.component()).updateModel(targetName)) {
fragment.resetFrom(getRunConfiguration());
}
}
}
}
@@ -29,6 +29,8 @@ import static com.intellij.util.containers.ContainerUtil.exists;
public final class CommonJavaFragments {
public static final String JRE_PATH = "jrePath";
public static <S extends RunConfigurationBase<?>> SettingsEditorFragment<S, JLabel> createBuildBeforeRun(BeforeRunComponent beforeRunComponent) {
String buildAndRun = ExecutionBundle.message("application.configuration.title.build.and.run");
String run = ExecutionBundle.message("application.configuration.title.run");
@@ -133,7 +135,6 @@ public final class CommonJavaFragments {
public static <T extends CommonJavaRunConfigurationParameters> SettingsEditorFragment<T, JrePathEditor> createJrePath(DefaultJreSelector defaultJreSelector) {
JrePathEditor jrePathEditor = new JrePathEditor(false);
jrePathEditor.setDefaultJreSelector(defaultJreSelector);
//noinspection unchecked
ComboBox<JrePathEditor.JreComboBoxItem> comboBox = jrePathEditor.getComponent();
comboBox.setRenderer(new ColoredListCellRenderer<>() {
@Override
@@ -196,7 +197,7 @@ public final class CommonJavaFragments {
jrePathEditor.getLabel().setVisible(false);
jrePathEditor.getComponent().getAccessibleContext().setAccessibleName(jrePathEditor.getLabel().getText());
SettingsEditorFragment<T, JrePathEditor> jrePath =
new SettingsEditorFragment<>("jrePath", ExecutionBundle.message("run.configuration.jre.name"), null, jrePathEditor, 5,
new SettingsEditorFragment<>(JRE_PATH, ExecutionBundle.message("run.configuration.jre.name"), null, jrePathEditor, 5,
(configuration, editor) -> editor.setPathOrName(configuration.getAlternativeJrePath(),
configuration.isAlternativeJrePathEnabled()),
(configuration, editor) -> {
@@ -2,6 +2,9 @@
package com.intellij.execution.ui;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.target.TargetEnvironmentConfiguration;
import com.intellij.execution.target.TargetEnvironmentsManager;
import com.intellij.execution.target.java.JavaLanguageRuntimeConfiguration;
import com.intellij.icons.AllIcons;
import com.intellij.ide.util.BrowseFilesListener;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
@@ -37,7 +40,7 @@ import java.io.File;
import java.util.HashSet;
import java.util.Set;
public class JrePathEditor extends LabeledComponent<ComboBox> implements PanelWithAnchor {
public class JrePathEditor extends LabeledComponent<ComboBox<JrePathEditor.JreComboBoxItem>> implements PanelWithAnchor {
private final JreComboboxEditor myComboboxEditor;
private final DefaultJreItem myDefaultJreItem;
private DefaultJreSelector myDefaultJreSelector;
@@ -76,39 +79,7 @@ public class JrePathEditor extends LabeledComponent<ComboBox> implements PanelWi
}
};
myDefaultJreItem = new DefaultJreItem();
myComboBoxModel.add(myDefaultJreItem);
final Sdk[] allJDKs = ProjectJdkTable.getInstance().getAllJdks();
for (Sdk sdk : allJDKs) {
myComboBoxModel.add(new SdkAsJreItem(sdk));
}
final Set<String> jrePaths = new HashSet<>();
for (JreProvider provider : JreProvider.EP_NAME.getExtensionList()) {
if (provider.isAvailable()) {
String path = provider.getJrePath();
if (!StringUtil.isEmpty(path)) {
jrePaths.add(path);
myComboBoxModel.add(new CustomJreItem(provider));
}
}
}
for (Sdk jdk : allJDKs) {
String homePath = jdk.getHomePath();
if (!SystemInfo.isMac) {
final File jre = new File(jdk.getHomePath(), "jre");
if (jre.isDirectory()) {
homePath = jre.getPath();
}
}
if (jrePaths.add(homePath)) {
myComboBoxModel.add(new CustomJreItem(homePath, null, jdk.getVersionString()));
}
}
if (!editable) {
myComboBoxModel.add(new AddJreItem());
}
buildModel(editable);
myComboBoxModel.setSelectedItem(myDefaultJreItem);
ComboBox<JreComboBoxItem> comboBox = new ComboBox<>(myComboBoxModel);
@@ -168,13 +139,70 @@ public class JrePathEditor extends LabeledComponent<ComboBox> implements PanelWi
updateUI();
}
/**
* @return true if selection update needed
*/
public boolean updateModel(@Nullable String targetName) {
myComboBoxModel.clear();
if (targetName != null) {
TargetEnvironmentConfiguration config = TargetEnvironmentsManager.getInstance().getTargets().findByName(targetName);
if (config != null) {
JavaLanguageRuntimeConfiguration runtime = config.getRuntimes().findByType(JavaLanguageRuntimeConfiguration.class);
if (runtime != null) {
CustomJreItem item = new CustomJreItem(runtime.getHomePath());
myComboBoxModel.add(item);
myComboBoxModel.setSelectedItem(item);
}
return false;
}
}
buildModel(getComponent().isEditable());
return true;
}
private void buildModel(boolean editable) {
myComboBoxModel.add(myDefaultJreItem);
final Sdk[] allJDKs = ProjectJdkTable.getInstance().getAllJdks();
for (Sdk sdk : allJDKs) {
myComboBoxModel.add(new SdkAsJreItem(sdk));
}
final Set<String> jrePaths = new HashSet<>();
for (JreProvider provider : JreProvider.EP_NAME.getExtensionList()) {
if (provider.isAvailable()) {
String path = provider.getJrePath();
if (!StringUtil.isEmpty(path)) {
jrePaths.add(path);
myComboBoxModel.add(new CustomJreItem(provider));
}
}
}
for (Sdk jdk : allJDKs) {
String homePath = jdk.getHomePath();
if (!SystemInfo.isMac) {
final File jre = new File(jdk.getHomePath(), "jre");
if (jre.isDirectory()) {
homePath = jre.getPath();
}
}
if (jrePaths.add(homePath)) {
myComboBoxModel.add(new CustomJreItem(homePath, null, jdk.getVersionString()));
}
}
if (!editable) {
myComboBoxModel.add(new AddJreItem());
}
}
@NotNull
private Runnable getBrowseRunnable() {
return new BrowseFolderRunnable<>(ExecutionBundle.message("run.configuration.select.alternate.jre.label"),
ExecutionBundle.message("run.configuration.select.jre.dir.label"),
null,
BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR,
(ComboBox<JreComboBoxItem>)getComponent(),
getComponent(),
JreComboboxEditor.TEXT_COMPONENT_ACCESSOR);
}
@@ -11,6 +11,7 @@ import com.intellij.execution.target.LanguageRuntimeType;
import com.intellij.execution.target.TargetEnvironmentAwareRunProfile;
import com.intellij.execution.target.TargetEnvironmentsConfigurable;
import com.intellij.execution.target.TargetEnvironmentsManager;
import com.intellij.execution.ui.RunnerAndConfigurationSettingsEditor;
import com.intellij.icons.AllIcons;
import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.DataKey;
@@ -428,7 +429,7 @@ public final class SingleConfigurationConfigurable<Config extends RunConfigurati
String chosenTarget = ((RunOnTargetComboBox)myRunOnComboBox).getSelectedTargetName();
if (!StringUtil.equals(myDefaultTargetName, chosenTarget)) {
setModified(true);
myDefaultTargetName = chosenTarget;
setTargetName(chosenTarget);
}
});
}
@@ -449,7 +450,7 @@ public final class SingleConfigurationConfigurable<Config extends RunConfigurati
LanguageRuntimeType<?> defaultRuntime = ((TargetEnvironmentAwareRunProfile)configuration).getDefaultLanguageRuntimeType();
((RunOnTargetComboBox)myRunOnComboBox).setDefaultLanguageRuntimeTime(defaultRuntime);
resetRunOnComboBox(defaultTargetName);
myDefaultTargetName = defaultTargetName;
setTargetName(defaultTargetName);
}
myIsAllowRunningInParallel = configuration.isAllowRunningInParallel();
@@ -528,4 +529,12 @@ public final class SingleConfigurationConfigurable<Config extends RunConfigurati
myJBScrollPane = wrapWithScrollPane(null);
}
}
private void setTargetName(String chosenTarget) {
myDefaultTargetName = chosenTarget;
SettingsEditor<RunnerAndConfigurationSettings> editor = getEditor();
if (editor instanceof RunnerAndConfigurationSettingsEditor) {
((RunnerAndConfigurationSettingsEditor)editor).targetChanged(chosenTarget);
}
}
}
@@ -34,6 +34,10 @@ public abstract class RunConfigurationFragmentedEditor<Settings extends RunConfi
myExtensionsManager = extensionsManager;
}
public Settings getRunConfiguration() {
return myRunConfiguration;
}
protected Project getProject() {
return myRunConfiguration.getProject();
}
@@ -127,4 +131,6 @@ public abstract class RunConfigurationFragmentedEditor<Settings extends RunConfi
? (RunConfigurationEditorFragment<?,?>)fragment
: null);
}
public void targetChanged(String targetName) {}
}
@@ -36,6 +36,10 @@ public class RunnerAndConfigurationSettingsEditor extends SettingsEditor<RunnerA
: null;
}
public void targetChanged(String targetName) {
myConfigurationEditor.targetChanged(targetName);
}
@Override
protected void resetEditorFrom(@NotNull RunnerAndConfigurationSettings s) {
myConfigurationEditor.resetEditorFrom((RunnerAndConfigurationSettingsImpl)s);
@@ -32,7 +32,7 @@ public interface TargetEnvironmentAwareRunProfile extends RunProfile {
LanguageRuntimeType<?> getDefaultLanguageRuntimeType();
/**
* @return display name of target environment to run on
* @return display name of target environment to run on, or null if local machine target is chosen
* @see TargetEnvironmentConfiguration#getDisplayName()
*/
@Nullable