added option to specify context module for JAR application configuration (IDEA-81929)

This commit is contained in:
nik
2014-09-05 12:02:08 +04:00
parent e1719a15f6
commit 45595ef17b
9 changed files with 105 additions and 10 deletions
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.execution.jar.JarApplicationConfigurable">
<grid id="27dc6" binding="myWholePanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myWholePanel" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="530" height="400"/>
@@ -16,7 +16,7 @@
</component>
<vspacer id="9634c">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="a09fc" class="com.intellij.execution.ui.AlternativeJREPanel" binding="myAlternativeJREPanel">
@@ -34,6 +34,16 @@
<text value="Path to &amp;JAR"/>
</properties>
</component>
<component id="6fe96" class="com.intellij.openapi.ui.LabeledComponent" binding="myModuleComponent">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<componentClass value="com.intellij.application.options.ModulesComboBox"/>
<labelLocation value="West"/>
<text value="Search sources using m&amp;odule's classpath"/>
</properties>
</component>
</children>
</grid>
</form>
@@ -15,6 +15,7 @@
*/
package com.intellij.execution.jar;
import com.intellij.application.options.ModulesComboBox;
import com.intellij.execution.ui.AlternativeJREPanel;
import com.intellij.execution.ui.CommonJavaParametersPanel;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
@@ -34,6 +35,7 @@ import javax.swing.*;
public class JarApplicationConfigurable extends SettingsEditor<JarApplicationConfiguration> implements PanelWithAnchor {
private CommonJavaParametersPanel myCommonProgramParameters;
private LabeledComponent<TextFieldWithBrowseButton> myJarPathComponent;
private LabeledComponent<ModulesComboBox> myModuleComponent;
private JPanel myWholePanel;
private AlternativeJREPanel myAlternativeJREPanel;
@@ -43,6 +45,9 @@ public class JarApplicationConfigurable extends SettingsEditor<JarApplicationCon
public JarApplicationConfigurable(final Project project) {
myProject = project;
myAnchor = UIUtil.mergeComponentsWithAnchor(myJarPathComponent, myCommonProgramParameters, myAlternativeJREPanel);
ModulesComboBox modulesComboBox = myModuleComponent.getComponent();
modulesComboBox.allowEmptySelection("<whole project>");
modulesComboBox.fillModules(project);
}
public void applyEditorTo(final JarApplicationConfiguration configuration) throws ConfigurationException {
@@ -50,12 +55,14 @@ public class JarApplicationConfigurable extends SettingsEditor<JarApplicationCon
configuration.setAlternativeJrePath(myAlternativeJREPanel.getPath());
configuration.setAlternativeJrePathEnabled(myAlternativeJREPanel.isPathEnabled());
configuration.setJarPath(FileUtil.toSystemIndependentName(myJarPathComponent.getComponent().getText()));
configuration.setModule(myModuleComponent.getComponent().getSelectedModule());
}
public void resetEditorFrom(final JarApplicationConfiguration configuration) {
myCommonProgramParameters.reset(configuration);
myJarPathComponent.getComponent().setText(FileUtil.toSystemDependentName(configuration.getJarPath()));
myAlternativeJREPanel.init(configuration.getAlternativeJrePath(), configuration.isAlternativeJrePathEnabled());
myModuleComponent.getComponent().setSelectedModule(configuration.getModule());
}
@NotNull
@@ -23,6 +23,7 @@ import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.util.JavaParametersUtil;
import com.intellij.execution.util.ProgramParametersUtil;
import com.intellij.openapi.components.PathMacroManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.options.SettingsEditorGroup;
import com.intellij.openapi.project.Project;
@@ -41,13 +42,15 @@ import java.util.Map;
/**
* @author nik
*/
public class JarApplicationConfiguration extends RunConfigurationBase implements CommonJavaRunConfigurationParameters {
public class JarApplicationConfiguration extends RunConfigurationBase implements CommonJavaRunConfigurationParameters, SearchScopeProvidingRunProfile {
private static final SkipDefaultValuesSerializationFilters SERIALIZATION_FILTERS = new SkipDefaultValuesSerializationFilters();
private JarApplicationConfigurationBean myBean = new JarApplicationConfigurationBean();
private Map<String, String> myEnvs = new LinkedHashMap<String, String>();
private JavaRunConfigurationModule myConfigurationModule;
public JarApplicationConfiguration(Project project, ConfigurationFactory factory, String name) {
super(project, factory, name);
myConfigurationModule = new JavaRunConfigurationModule(project, true);
}
@NotNull
@@ -67,6 +70,15 @@ public class JarApplicationConfiguration extends RunConfigurationBase implements
JavaRunConfigurationExtensionManager.getInstance().readExternal(this, element);
XmlSerializer.deserializeInto(myBean, element);
EnvironmentVariablesComponent.readExternal(element, getEnvs());
myConfigurationModule.readExternal(element);
}
public void setModule(Module module) {
myConfigurationModule.setModule(module);
}
public Module getModule() {
return myConfigurationModule.getModule();
}
@Override
@@ -76,6 +88,9 @@ public class JarApplicationConfiguration extends RunConfigurationBase implements
XmlSerializer.serializeInto(myBean, element, SERIALIZATION_FILTERS);
EnvironmentVariablesComponent.writeExternal(element, getEnvs());
PathMacroManager.getInstance(getProject()).collapsePathsRecursively(element);
if (myConfigurationModule.getModule() != null) {
myConfigurationModule.writeExternal(element);
}
}
@Override
@@ -89,6 +104,13 @@ public class JarApplicationConfiguration extends RunConfigurationBase implements
JavaRunConfigurationExtensionManager.checkConfigurationIsValid(this);
}
@NotNull
@Override
public Module[] getModules() {
Module module = myConfigurationModule.getModule();
return module != null ? new Module[] {module}: Module.EMPTY_ARRAY;
}
@Nullable
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
@@ -19,5 +19,5 @@ package com.intellij.execution.configurations;
/**
* @author spleaner
*/
public interface ModuleRunProfile extends RunProfileWithCompileBeforeLaunchOption {
public interface ModuleRunProfile extends RunProfileWithCompileBeforeLaunchOption, SearchScopeProvidingRunProfile {
}
@@ -28,8 +28,8 @@ public class SearchScopeProvider {
@NotNull
public static GlobalSearchScope createSearchScope(@NotNull Project project, @Nullable RunProfile runProfile) {
Module[] modules = null;
if (runProfile instanceof ModuleRunProfile) {
modules = ((ModuleRunProfile)runProfile).getModules();
if (runProfile instanceof SearchScopeProvidingRunProfile) {
modules = ((SearchScopeProvidingRunProfile)runProfile).getModules();
}
if (modules == null || modules.length == 0) {
return GlobalSearchScope.allScope(project);
@@ -0,0 +1,34 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.configurations;
import com.intellij.openapi.module.Module;
import org.jetbrains.annotations.NotNull;
/**
* Base interface for run configurations that can specify which part of the project should be used to search sources. This information
* will be used to provide more accurate navigation to sources from stack traces, debugger, etc
*
* @author nik
*/
public interface SearchScopeProvidingRunProfile extends RunProfile {
/**
* @return modules where to search sources for this configuration
*/
@NotNull
Module[] getModules();
}
@@ -3,6 +3,7 @@ package com.intellij.application.options;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleType;
import com.intellij.ui.ListCellRendererWrapper;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -10,10 +11,20 @@ import javax.swing.*;
* @author yole
*/
public class ModuleListCellRenderer extends ListCellRendererWrapper<Module> {
private final String myEmptySelectionText;
public ModuleListCellRenderer() {
this("[none]");
}
public ModuleListCellRenderer(@NotNull String emptySelectionText) {
myEmptySelectionText = emptySelectionText;
}
@Override
public void customize(JList list, Module module, int index, boolean selected, boolean hasFocus) {
if (module == null) {
setText("[none]");
setText(myEmptySelectionText);
}
else {
setIcon(ModuleType.get(module).getIcon());
@@ -36,6 +36,7 @@ import java.util.List;
*/
public class ModulesComboBox extends ComboBox {
private final SortedComboBoxModel<Module> myModel;
private boolean myAllowEmptySelection;
public ModulesComboBox() {
this(new SortedComboBoxModel<Module>(ModulesAlphaComparator.INSTANCE));
@@ -58,8 +59,17 @@ public class ModulesComboBox extends ComboBox {
setRenderer(new ModuleListCellRenderer());
}
public void allowEmptySelection(@NotNull String emptySelectionText) {
myAllowEmptySelection = true;
myModel.add(null);
setRenderer(new ModuleListCellRenderer(emptySelectionText));
}
public void setModules(@NotNull Collection<Module> modules) {
myModel.setAll(modules);
if (myAllowEmptySelection) {
myModel.add(null);
}
}
public void fillModules(@NotNull Project project) {
@@ -29,8 +29,9 @@ public class ModulesAlphaComparator implements Comparator<Module>{
@Override
public int compare(Module module1, Module module2) {
final String name1 = module1.getName();
final String name2 = module2.getName();
return name1.compareToIgnoreCase(name2);
if (module1 == null && module2 == null) return 0;
if (module1 == null && module2 != null) return -1;
if (module1 != null && module2 == null) return 1;
return module1.getName().compareToIgnoreCase(module2.getName());
}
}