mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-81929: Support java -jar run configurations
This commit is contained in:
+7
-39
@@ -21,20 +21,16 @@ import com.intellij.execution.configuration.EnvironmentVariablesComponent;
|
||||
import com.intellij.execution.configurations.*;
|
||||
import com.intellij.execution.filters.TextConsoleBuilderFactory;
|
||||
import com.intellij.execution.junit.RefactoringListeners;
|
||||
import com.intellij.execution.process.KillableColoredProcessHandler;
|
||||
import com.intellij.execution.process.OSProcessHandler;
|
||||
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.extensions.Extensions;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.options.SettingsEditor;
|
||||
import com.intellij.openapi.options.SettingsEditorGroup;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.DefaultJDOMExternalizer;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -81,7 +77,7 @@ public class ApplicationConfiguration extends ModuleBasedConfiguration<JavaRunCo
|
||||
|
||||
@Override
|
||||
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) throws ExecutionException {
|
||||
final JavaCommandLineState state = new JavaApplicationCommandLineState(this, env);
|
||||
final JavaCommandLineState state = new JavaApplicationCommandLineState<ApplicationConfiguration>(this, env);
|
||||
JavaRunConfigurationModule module = getConfigurationModule();
|
||||
state.setConsoleBuilder(TextConsoleBuilderFactory.getInstance().createBuilder(getProject(), module.getSearchScope()));
|
||||
return state;
|
||||
@@ -253,14 +249,9 @@ public class ApplicationConfiguration extends ModuleBasedConfiguration<JavaRunCo
|
||||
PathMacroManager.getInstance(getProject()).collapsePathsRecursively(element);
|
||||
}
|
||||
|
||||
public static class JavaApplicationCommandLineState extends JavaCommandLineState {
|
||||
|
||||
private final ApplicationConfiguration myConfiguration;
|
||||
|
||||
public JavaApplicationCommandLineState(@NotNull final ApplicationConfiguration configuration,
|
||||
final ExecutionEnvironment environment) {
|
||||
super(environment);
|
||||
myConfiguration = configuration;
|
||||
public static class JavaApplicationCommandLineState<T extends ApplicationConfiguration> extends BaseJavaApplicationCommandLineState<T> {
|
||||
public JavaApplicationCommandLineState(@NotNull final T configuration, final ExecutionEnvironment environment) {
|
||||
super(environment, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -269,37 +260,14 @@ public class ApplicationConfiguration extends ModuleBasedConfiguration<JavaRunCo
|
||||
final JavaRunConfigurationModule module = myConfiguration.getConfigurationModule();
|
||||
|
||||
final int classPathType = JavaParametersUtil.getClasspathType(module,
|
||||
myConfiguration.MAIN_CLASS_NAME,
|
||||
myConfiguration.MAIN_CLASS_NAME,
|
||||
false);
|
||||
final String jreHome = myConfiguration.ALTERNATIVE_JRE_PATH_ENABLED ? myConfiguration.ALTERNATIVE_JRE_PATH
|
||||
: null;
|
||||
final String jreHome = myConfiguration.ALTERNATIVE_JRE_PATH_ENABLED ? myConfiguration.ALTERNATIVE_JRE_PATH : null;
|
||||
JavaParametersUtil.configureModule(module, params, classPathType, jreHome);
|
||||
JavaParametersUtil.configureConfiguration(params, myConfiguration);
|
||||
|
||||
params.setMainClass(myConfiguration.MAIN_CLASS_NAME);
|
||||
for(RunConfigurationExtension ext: Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) {
|
||||
ext.updateJavaParameters(myConfiguration, params, getRunnerSettings());
|
||||
}
|
||||
setupJavaParameters(params);
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected OSProcessHandler startProcess() throws ExecutionException {
|
||||
OSProcessHandler handler = SystemInfo.isWindows ? super.startProcess() : KillableColoredProcessHandler.create(createCommandLine());
|
||||
RunnerSettings runnerSettings = getRunnerSettings();
|
||||
JavaRunConfigurationExtensionManager.getInstance().attachExtensionsToProcess(myConfiguration, handler, runnerSettings);
|
||||
return handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean ansiColoringEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected ApplicationConfiguration getConfiguration() {
|
||||
return myConfiguration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.application;
|
||||
|
||||
import com.intellij.execution.CommonJavaRunConfigurationParameters;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.JavaRunConfigurationExtensionManager;
|
||||
import com.intellij.execution.RunConfigurationExtension;
|
||||
import com.intellij.execution.configurations.JavaCommandLineState;
|
||||
import com.intellij.execution.configurations.JavaParameters;
|
||||
import com.intellij.execution.configurations.RunConfigurationBase;
|
||||
import com.intellij.execution.configurations.RunnerSettings;
|
||||
import com.intellij.execution.process.KillableColoredProcessHandler;
|
||||
import com.intellij.execution.process.OSProcessHandler;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.util.JavaParametersUtil;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class BaseJavaApplicationCommandLineState<T extends RunConfigurationBase&CommonJavaRunConfigurationParameters> extends JavaCommandLineState {
|
||||
protected final T myConfiguration;
|
||||
|
||||
public BaseJavaApplicationCommandLineState(ExecutionEnvironment environment, @NotNull final T configuration) {
|
||||
super(environment);
|
||||
myConfiguration = configuration;
|
||||
}
|
||||
|
||||
protected void setupJavaParameters(JavaParameters params) throws ExecutionException {
|
||||
JavaParametersUtil.configureConfiguration(params, myConfiguration);
|
||||
|
||||
for(RunConfigurationExtension ext: Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) {
|
||||
ext.updateJavaParameters(getConfiguration(), params, getRunnerSettings());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected OSProcessHandler startProcess() throws ExecutionException {
|
||||
OSProcessHandler handler = SystemInfo.isWindows ? super.startProcess() : KillableColoredProcessHandler.create(createCommandLine());
|
||||
RunnerSettings runnerSettings = getRunnerSettings();
|
||||
JavaRunConfigurationExtensionManager.getInstance().attachExtensionsToProcess(getConfiguration(), handler, runnerSettings);
|
||||
return handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean ansiColoringEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected T getConfiguration() {
|
||||
return myConfiguration;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.jar;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.application.BaseJavaApplicationCommandLineState;
|
||||
import com.intellij.execution.configurations.JavaParameters;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.util.JavaParametersUtil;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JarApplicationCommandLineState extends BaseJavaApplicationCommandLineState<JarApplicationConfiguration> {
|
||||
public JarApplicationCommandLineState(@NotNull final JarApplicationConfiguration configuration, final ExecutionEnvironment environment) {
|
||||
super(environment, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JavaParameters createJavaParameters() throws ExecutionException {
|
||||
final JavaParameters params = new JavaParameters();
|
||||
final String jreHome = myConfiguration.isAlternativeJrePathEnabled() ? myConfiguration.getAlternativeJrePath() : null;
|
||||
params.setJdk(JavaParametersUtil.createProjectJdk(myConfiguration.getProject(), jreHome));
|
||||
setupJavaParameters(params);
|
||||
params.setJarPath(FileUtil.toSystemDependentName(myConfiguration.getJarPath()));
|
||||
return params;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="530" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="73391" class="com.intellij.execution.ui.CommonJavaParametersPanel" binding="myCommonProgramParameters">
|
||||
<constraints>
|
||||
<grid row="1" 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/>
|
||||
</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"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="a09fc" class="com.intellij.execution.ui.AlternativeJREPanel" binding="myAlternativeJREPanel">
|
||||
<constraints>
|
||||
<grid row="2" 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/>
|
||||
</component>
|
||||
<component id="cab16" class="com.intellij.openapi.ui.LabeledComponent" binding="myJarPathComponent" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="0" 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>
|
||||
<labelLocation value="West"/>
|
||||
<text value="Path to &JAR"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.jar;
|
||||
|
||||
import com.intellij.execution.ui.AlternativeJREPanel;
|
||||
import com.intellij.execution.ui.CommonJavaParametersPanel;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.SettingsEditor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.LabeledComponent;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.ui.PanelWithAnchor;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class JarApplicationConfigurable extends SettingsEditor<JarApplicationConfiguration> implements PanelWithAnchor {
|
||||
private CommonJavaParametersPanel myCommonProgramParameters;
|
||||
private LabeledComponent<TextFieldWithBrowseButton> myJarPathComponent;
|
||||
private JPanel myWholePanel;
|
||||
|
||||
private AlternativeJREPanel myAlternativeJREPanel;
|
||||
private final Project myProject;
|
||||
private JComponent myAnchor;
|
||||
|
||||
public JarApplicationConfigurable(final Project project) {
|
||||
myProject = project;
|
||||
myAnchor = UIUtil.mergeComponentsWithAnchor(myJarPathComponent, myCommonProgramParameters, myAlternativeJREPanel);
|
||||
}
|
||||
|
||||
public void applyEditorTo(final JarApplicationConfiguration configuration) throws ConfigurationException {
|
||||
myCommonProgramParameters.applyTo(configuration);
|
||||
configuration.setAlternativeJrePath(myAlternativeJREPanel.getPath());
|
||||
configuration.setAlternativeJrePathEnabled(myAlternativeJREPanel.isPathEnabled());
|
||||
configuration.setJarPath(FileUtil.toSystemIndependentName(myJarPathComponent.getComponent().getText()));
|
||||
}
|
||||
|
||||
public void resetEditorFrom(final JarApplicationConfiguration configuration) {
|
||||
myCommonProgramParameters.reset(configuration);
|
||||
myJarPathComponent.getComponent().setText(FileUtil.toSystemDependentName(configuration.getJarPath()));
|
||||
myAlternativeJREPanel.init(configuration.getAlternativeJrePath(), configuration.isAlternativeJrePathEnabled());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JComponent createEditor() {
|
||||
return myWholePanel;
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
myJarPathComponent = new LabeledComponent<TextFieldWithBrowseButton>();
|
||||
TextFieldWithBrowseButton textFieldWithBrowseButton = new TextFieldWithBrowseButton();
|
||||
textFieldWithBrowseButton.addBrowseFolderListener("Choose Jar File", null, myProject,
|
||||
new FileChooserDescriptor(false, false, true, true, false, false));
|
||||
myJarPathComponent.setComponent(textFieldWithBrowseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getAnchor() {
|
||||
return myAnchor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnchor(@Nullable JComponent anchor) {
|
||||
myAnchor = anchor;
|
||||
myCommonProgramParameters.setAnchor(anchor);
|
||||
myAlternativeJREPanel.setAnchor(anchor);
|
||||
myJarPathComponent.setAnchor(anchor);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* 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.jar;
|
||||
|
||||
import com.intellij.diagnostic.logging.LogConfigurationPanel;
|
||||
import com.intellij.execution.*;
|
||||
import com.intellij.execution.configuration.EnvironmentVariablesComponent;
|
||||
import com.intellij.execution.configurations.*;
|
||||
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.options.SettingsEditor;
|
||||
import com.intellij.openapi.options.SettingsEditorGroup;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters;
|
||||
import com.intellij.util.xmlb.XmlSerializer;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JarApplicationConfiguration extends RunConfigurationBase implements CommonJavaRunConfigurationParameters {
|
||||
private static final SkipDefaultValuesSerializationFilters SERIALIZATION_FILTERS = new SkipDefaultValuesSerializationFilters();
|
||||
private JarApplicationConfigurationBean myBean = new JarApplicationConfigurationBean();
|
||||
private Map<String, String> myEnvs = new LinkedHashMap<String, String>();
|
||||
|
||||
public JarApplicationConfiguration(Project project, ConfigurationFactory factory, String name) {
|
||||
super(project, factory, name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
|
||||
SettingsEditorGroup<JarApplicationConfiguration> group = new SettingsEditorGroup<JarApplicationConfiguration>();
|
||||
group.addEditor(ExecutionBundle.message("run.configuration.configuration.tab.title"), new JarApplicationConfigurable(getProject()));
|
||||
JavaRunConfigurationExtensionManager.getInstance().appendEditors(this, group);
|
||||
group.addEditor(ExecutionBundle.message("logs.tab.title"), new LogConfigurationPanel<JarApplicationConfiguration>());
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(Element element) throws InvalidDataException {
|
||||
PathMacroManager.getInstance(getProject()).expandPaths(element);
|
||||
super.readExternal(element);
|
||||
JavaRunConfigurationExtensionManager.getInstance().readExternal(this, element);
|
||||
XmlSerializer.deserializeInto(myBean, element);
|
||||
EnvironmentVariablesComponent.readExternal(element, getEnvs());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) throws WriteExternalException {
|
||||
super.writeExternal(element);
|
||||
JavaRunConfigurationExtensionManager.getInstance().writeExternal(this, element);
|
||||
XmlSerializer.serializeInto(myBean, element, SERIALIZATION_FILTERS);
|
||||
EnvironmentVariablesComponent.writeExternal(element, getEnvs());
|
||||
PathMacroManager.getInstance(getProject()).collapsePathsRecursively(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkConfiguration() throws RuntimeConfigurationException {
|
||||
JavaParametersUtil.checkAlternativeJRE(this);
|
||||
ProgramParametersUtil.checkWorkingDirectoryExist(this, getProject(), null);
|
||||
File jarFile = new File(getJarPath());
|
||||
if (!jarFile.exists()) {
|
||||
throw new RuntimeConfigurationWarning("Jar file '" + jarFile.getAbsolutePath() + "' doesn't exist");
|
||||
}
|
||||
JavaRunConfigurationExtensionManager.checkConfigurationIsValid(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
|
||||
return new JarApplicationCommandLineState(this, environment);
|
||||
}
|
||||
|
||||
public String getJarPath() {
|
||||
return myBean.JAR_PATH;
|
||||
}
|
||||
|
||||
public void setJarPath(String jarPath) {
|
||||
myBean.JAR_PATH = jarPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVMParameters(String value) {
|
||||
myBean.VM_PARAMETERS = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVMParameters() {
|
||||
return myBean.VM_PARAMETERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlternativeJrePathEnabled() {
|
||||
return myBean.ALTERNATIVE_JRE_PATH_ENABLED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlternativeJrePathEnabled(boolean enabled) {
|
||||
myBean.ALTERNATIVE_JRE_PATH_ENABLED = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlternativeJrePath() {
|
||||
return myBean.ALTERNATIVE_JRE_PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlternativeJrePath(String path) {
|
||||
myBean.ALTERNATIVE_JRE_PATH = path;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getRunClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getPackage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProgramParameters(@Nullable String value) {
|
||||
myBean.PROGRAM_PARAMETERS = value;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getProgramParameters() {
|
||||
return myBean.PROGRAM_PARAMETERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorkingDirectory(@Nullable String value) {
|
||||
myBean.WORKING_DIRECTORY = value;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getWorkingDirectory() {
|
||||
return myBean.WORKING_DIRECTORY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnvs(@NotNull Map<String, String> envs) {
|
||||
myEnvs.clear();
|
||||
myEnvs.putAll(envs);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, String> getEnvs() {
|
||||
return myEnvs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassParentEnvs(boolean passParentEnvs) {
|
||||
myBean.PASS_PARENT_ENVS = passParentEnvs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPassParentEnvs() {
|
||||
return myBean.PASS_PARENT_ENVS;
|
||||
}
|
||||
|
||||
private static class JarApplicationConfigurationBean {
|
||||
public String JAR_PATH = "";
|
||||
public String VM_PARAMETERS = "";
|
||||
public String PROGRAM_PARAMETERS = "";
|
||||
public String WORKING_DIRECTORY = "";
|
||||
public boolean ALTERNATIVE_JRE_PATH_ENABLED;
|
||||
public String ALTERNATIVE_JRE_PATH = "";
|
||||
public boolean PASS_PARENT_ENVS = true;
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.jar;
|
||||
|
||||
import com.intellij.execution.ExecutionBundle;
|
||||
import com.intellij.execution.configuration.ConfigurationFactoryEx;
|
||||
import com.intellij.execution.configurations.ConfigurationType;
|
||||
import com.intellij.execution.configurations.ConfigurationTypeBase;
|
||||
import com.intellij.execution.configurations.RunConfiguration;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JarApplicationConfigurationType extends ConfigurationTypeBase implements ConfigurationType {
|
||||
public JarApplicationConfigurationType() {
|
||||
super("JarApplication", ExecutionBundle.message("jar.application.configuration.name"),
|
||||
ExecutionBundle.message("jar.application.configuration.description"), AllIcons.FileTypes.Archive);
|
||||
addFactory(new ConfigurationFactoryEx(this) {
|
||||
@Override
|
||||
public void onNewConfigurationCreated(@NotNull RunConfiguration configuration) {
|
||||
JarApplicationConfiguration jarApplicationConfiguration = (JarApplicationConfiguration)configuration;
|
||||
if (StringUtil.isEmpty(jarApplicationConfiguration.getWorkingDirectory())) {
|
||||
String baseDir = FileUtil.toSystemIndependentName(StringUtil.notNullize(configuration.getProject().getBasePath()));
|
||||
jarApplicationConfiguration.setWorkingDirectory(baseDir);
|
||||
}
|
||||
}
|
||||
|
||||
public RunConfiguration createTemplateConfiguration(Project project) {
|
||||
return new JarApplicationConfiguration(project, this, "");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.jar;
|
||||
|
||||
import com.intellij.debugger.impl.GenericDebuggerRunner;
|
||||
import com.intellij.execution.configurations.RunProfile;
|
||||
import com.intellij.execution.executors.DefaultDebugExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JarApplicationDebuggerRunner extends GenericDebuggerRunner {
|
||||
@Override
|
||||
public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) {
|
||||
return DefaultDebugExecutor.EXECUTOR_ID.equals(executorId) && profile instanceof JarApplicationConfiguration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getRunnerId() {
|
||||
return "JarDebug";
|
||||
}
|
||||
}
|
||||
@@ -30,15 +30,16 @@ import java.io.File;
|
||||
public class ProcessProxyFactoryImpl extends ProcessProxyFactory {
|
||||
public ProcessProxy createCommandLineProxy(final JavaCommandLine javaCmdLine) throws ExecutionException {
|
||||
ProcessProxyImpl proxy = null;
|
||||
if (ProcessProxyImpl.useLauncher()) {
|
||||
final JavaParameters javaParameters = javaCmdLine.getJavaParameters();
|
||||
String mainClass = javaParameters.getMainClass();
|
||||
if (ProcessProxyImpl.useLauncher() && mainClass != null) {
|
||||
try {
|
||||
proxy = new ProcessProxyImpl();
|
||||
final JavaParameters javaParameters = javaCmdLine.getJavaParameters();
|
||||
JavaSdkUtil.addRtJar(javaParameters.getClassPath());
|
||||
final ParametersList vmParametersList = javaParameters.getVMParametersList();
|
||||
vmParametersList.defineProperty(ProcessProxyImpl.PROPERTY_PORT_NUMBER, String.valueOf(proxy.getPortNumber()));
|
||||
vmParametersList.defineProperty(ProcessProxyImpl.PROPERTY_BINPATH, PathManager.getBinPath());
|
||||
javaParameters.getProgramParametersList().prepend(javaParameters.getMainClass());
|
||||
javaParameters.getProgramParametersList().prepend(mainClass);
|
||||
javaParameters.setMainClass(ProcessProxyImpl.LAUNCH_MAIN_CLASS);
|
||||
}
|
||||
catch (ProcessProxyImpl.NoMoreSocketsException e) {
|
||||
|
||||
@@ -27,7 +27,6 @@ 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;
|
||||
@@ -118,7 +117,7 @@ public class JavaParametersUtil {
|
||||
return jreHome == null ? JavaParameters.getModuleJdk(module) : createAlternativeJdk(jreHome);
|
||||
}
|
||||
|
||||
private static Sdk createProjectJdk(final Project project, final String jreHome) throws CantRunException {
|
||||
public static Sdk createProjectJdk(final Project project, final String jreHome) throws CantRunException {
|
||||
return jreHome == null ? createProjectJdk(project) : createAlternativeJdk(jreHome);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ public class CommandLineBuilder {
|
||||
if (exePath == null) {
|
||||
throw new CantRunException(ExecutionBundle.message("run.configuration.cannot.find.vm.executable"));
|
||||
}
|
||||
if (javaParameters.getMainClass() == null) {
|
||||
if (javaParameters.getMainClass() == null && javaParameters.getJarPath() == null) {
|
||||
throw new CantRunException(ExecutionBundle.message("main.class.is.not.specified.error.message"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user