Delete applets support

GitOrigin-RevId: c78d50aa62adbe1afce6827e0c52f04468622b0b
This commit is contained in:
Dmitry Jemerov
2019-10-09 11:02:23 +00:00
committed by intellij-monorepo-bot
parent 033823e7fe
commit 0d70c5334a
8 changed files with 0 additions and 993 deletions
@@ -1,220 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.execution.applet.AppletConfigurable">
<grid id="e5f4d" binding="myWholePanel" layout-manager="GridLayoutManager" row-count="8" 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="133" y="39" width="708" height="584"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="ccef6" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="fa258" class="javax.swing.JRadioButton" binding="myMainClass">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text resource-bundle="messages/ExecutionBundle" key="applet.configuration.applet.class.option"/>
</properties>
</component>
<component id="74d77" class="javax.swing.JRadioButton" binding="myURL">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/ExecutionBundle" key="applet.configuration.url.label"/>
</properties>
</component>
</children>
</grid>
<component id="5dbf7" class="com.intellij.openapi.ui.LabeledComponent" binding="myPolicyFile">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<componentClass value="com.intellij.openapi.ui.TextFieldWithBrowseButton"/>
<labelInsets top="0" left="0" bottom="0" right="0"/>
<labelLocation value="West"/>
<text resource-bundle="messages/ExecutionBundle" key="applet.configuration.policy.file.label"/>
</properties>
</component>
<component id="67632" class="com.intellij.openapi.ui.LabeledComponent" binding="myVMParameters">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="400" height="-1"/>
</grid>
</constraints>
<properties>
<componentClass value="com.intellij.ui.RawCommandLineEditor"/>
<labelInsets top="0" left="0" bottom="0" right="0"/>
<labelLocation value="West"/>
<text resource-bundle="messages/ExecutionBundle" key="applet.configuration.vm.parameters.for.appletviewer.label"/>
</properties>
</component>
<component id="eac49" class="com.intellij.openapi.ui.LabeledComponent" binding="myModule">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<componentClass value="com.intellij.application.options.ModulesComboBox"/>
<labelLocation value="West"/>
<text resource-bundle="messages/ExecutionBundle" key="application.configuration.use.classpath.and.jdk.of.module.label"/>
</properties>
</component>
<grid id="c178e" layout-manager="GridLayoutManager" row-count="2" 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>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="dbe39" binding="myHTMLOptions" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<clientProperties>
<BorderFactoryClass class="java.lang.String" value=""/>
</clientProperties>
<border type="none"/>
<children>
<component id="a2b70" class="com.intellij.ui.components.JBLabel" binding="myHtmlFileLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/ExecutionBundle" key="applet.configuration.url.html.file.label"/>
</properties>
</component>
<component id="9aa99" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myHtmlFile">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
</children>
</grid>
<grid id="71bb1" binding="myClassOptions" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
</properties>
<clientProperties>
<BorderFactoryClass class="java.lang.String" value=""/>
</clientProperties>
<border type="none"/>
<children>
<grid id="32908" layout-manager="GridLayoutManager" row-count="1" 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>
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<clientProperties>
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithoutIndent"/>
</clientProperties>
<border type="none" title-resource-bundle="messages/ExecutionBundle" title-key="applet.configuration.applet.parameters.label"/>
<children>
<grid id="814cb" binding="myTablePlace" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="-1" height="100"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
<component id="36125" class="com.intellij.ui.components.JBLabel" binding="myClassNameLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/ExecutionBundle" key="applet.configuration.applet.class.label"/>
</properties>
</component>
<component id="70a46" class="com.intellij.ui.EditorTextFieldWithBrowseButton" binding="myClassName" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="60aa" class="com.intellij.ui.components.JBLabel" binding="myWidthLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/ExecutionBundle" key="applet.configuration.width.label"/>
</properties>
</component>
<component id="575e9" class="javax.swing.JTextField" binding="myWidth">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="50" height="-1"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="3cd8" class="javax.swing.JLabel" binding="myHeightLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/ExecutionBundle" key="applet.configuration.height.label"/>
</properties>
</component>
<component id="16d37" class="javax.swing.JTextField" binding="myHeight">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="50" height="-1"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<vspacer id="8b063">
<constraints>
<grid row="7" 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="9e31a" class="javax.swing.JSeparator">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="b2d36" class="com.intellij.execution.ui.JrePathEditor" binding="myJrePathEditor">
<constraints>
<grid row="6" 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>
</children>
</grid>
</form>
@@ -1,315 +0,0 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.applet;
import com.intellij.application.options.ModulesComboBox;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.configurations.ConfigurationUtil;
import com.intellij.execution.impl.CheckableRunConfigurationEditor;
import com.intellij.execution.ui.ClassBrowser;
import com.intellij.execution.ui.ConfigurationModuleSelector;
import com.intellij.execution.ui.DefaultJreSelector;
import com.intellij.execution.ui.JrePathEditor;
import com.intellij.ide.util.ClassFilter;
import com.intellij.ide.util.TreeClassChooser;
import com.intellij.ide.util.TreeClassChooserFactory;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.module.Module;
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.text.StringUtil;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.ui.*;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.table.TableView;
import com.intellij.util.SmartList;
import com.intellij.util.ui.ColumnInfo;
import com.intellij.util.ui.ListTableModel;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.table.TableCellEditor;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class AppletConfigurable extends SettingsEditor<AppletConfiguration>
implements CheckableRunConfigurationEditor<AppletConfiguration>, PanelWithAnchor {
private static final String HTTP_PREFIX = "http:/";
private static final ColumnInfo[] PARAMETER_COLUMNS = {
new MyColumnInfo(ExecutionBundle.message("applet.configuration.parameter.name.column")) {
@Override
public String valueOf(final AppletParameter appletParameter) {
return appletParameter.getName();
}
@Override
public void setValue(final AppletParameter appletParameter, final String name) {
appletParameter.setName(name);
}
},
new MyColumnInfo(ExecutionBundle.message("applet.configuration.parameter.value.column")) {
@Override
public String valueOf(final AppletParameter appletParameter) {
return appletParameter.getValue();
}
@Override
public void setValue(final AppletParameter appletParameter, final String value) {
appletParameter.setValue(value);
}
}
};
private JPanel myWholePanel;
private JRadioButton myMainClass;
private JRadioButton myURL;
private JPanel myClassOptions;
private JPanel myHTMLOptions;
private LabeledComponent<TextFieldWithBrowseButton> myPolicyFile;
private LabeledComponent<RawCommandLineEditor> myVMParameters;
private EditorTextFieldWithBrowseButton myClassName;
private TextFieldWithBrowseButton myHtmlFile;
private JTextField myWidth;
private JTextField myHeight;
private LabeledComponent<ModulesComboBox> myModule;
private JPanel myTablePlace;
private JBLabel myHtmlFileLabel;
private JBLabel myClassNameLabel;
private JBLabel myWidthLabel;
private JLabel myHeightLabel;
private JrePathEditor myJrePathEditor;
private JComponent anchor;
private final Project myProject;
private final ConfigurationModuleSelector myModuleSelector;
private final ListTableModel<AppletParameter> myParameters;
private final TableView myTable;
public AppletConfigurable(final Project project) {
myProject = project;
myClassNameLabel.setLabelFor(myClassName.getChildComponent());
myHtmlFileLabel.setLabelFor(myHtmlFile.getTextField());
myWidthLabel.setLabelFor(myWidth);
myHeightLabel.setLabelFor(myHeight);
myModuleSelector = new ConfigurationModuleSelector(project, getModuleComponent());
myJrePathEditor.setDefaultJreSelector(DefaultJreSelector.fromModuleDependencies(getModuleComponent(), true));
myTablePlace.setLayout(new BorderLayout());
myParameters = new ListTableModel<>(PARAMETER_COLUMNS);
myTable = new TableView<>(myParameters);
myTable.getEmptyText().setText(ExecutionBundle.message("no.parameters"));
myTablePlace.add(
ToolbarDecorator.createDecorator(myTable)
.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
addParameter();
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
removeParameter();
}
}).disableUpDownActions().createPanel(), BorderLayout.CENTER);
ButtonGroup appletRadioButtonGroup = new ButtonGroup();
appletRadioButtonGroup.add(myMainClass);
appletRadioButtonGroup.add(myURL);
myMainClass.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
changePanel();
}
});
myURL.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
changePanel();
}
});
getPolicyFileComponent().addBrowseFolderListener(ExecutionBundle.message("select.applet.policy.file.dialog.title"), null, myProject,
FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
getHtmlPathComponent().addBrowseFolderListener(ExecutionBundle.message("choose.html.file.dialog.title"), null, myProject,
FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
String title = ExecutionBundle.message("choose.applet.class.dialog.title");
new ClassBrowser.MainClassBrowser<EditorTextField>(myProject, myModuleSelector, title) {
@Override
protected TreeClassChooser createClassChooser(ClassFilter.ClassFilterWithScope classFilter) {
Project project = getProject();
Module module = myModuleSelector.getModule();
GlobalSearchScope scope =
module != null ? GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module) : GlobalSearchScope.allScope(project);
PsiClass appletClass = JavaPsiFacade.getInstance(project).findClass("java.applet.Applet", scope);
return TreeClassChooserFactory.getInstance(project).createInheritanceClassChooser(
title, classFilter.getScope(), appletClass, false, false, ConfigurationUtil.PUBLIC_INSTANTIATABLE_CLASS);
}
}.setField(getClassNameComponent());
myHTMLOptions.setVisible(false);
setAnchor(myVMParameters.getLabel());
}
private void changePanel() {
if (myMainClass.isSelected()) {
myClassOptions.setVisible(true);
myHTMLOptions.setVisible(false);
}
else {
myHTMLOptions.setVisible(true);
myClassOptions.setVisible(false);
}
}
private void removeParameter() {
TableUtil.removeSelectedItems(myTable);
}
private void addParameter() {
List<AppletParameter> newItems = new ArrayList<>(myParameters.getItems());
AppletParameter parameter = new AppletParameter("newParameter", "");
newItems.add(parameter);
myParameters.setItems(newItems);
int index = newItems.size() - 1;
myTable.getSelectionModel().setSelectionInterval(index, index);
myTable.scrollRectToVisible(myTable.getCellRect(index, 0, true));
}
private ModulesComboBox getModuleComponent() {
return myModule.getComponent();
}
private TextFieldWithBrowseButton getPolicyFileComponent() {
return myPolicyFile.getComponent();
}
private static List<AppletParameter> cloneParameters(@NotNull List<AppletParameter> items) {
List<AppletParameter> params = new SmartList<>();
for (AppletParameter appletParameter : items) {
params.add(new AppletParameter(appletParameter.getName(), appletParameter.getValue()));
}
return params;
}
private JTextField getWidthComponent() {
return myWidth;
}
private EditorTextFieldWithBrowseButton getClassNameComponent() {
return myClassName;
}
private TextFieldWithBrowseButton getHtmlPathComponent() {
return myHtmlFile;
}
private static String toSystemFormat(String s) {
s = s.trim();
return s.length() == 0 ? null : s.replace(File.separatorChar, '/');
}
@Override
public void applyEditorTo(@NotNull final AppletConfiguration configuration) {
checkEditorData(configuration);
myTable.stopEditing();
configuration.getOptions().setAppletParameters(cloneParameters(myParameters.getItems()));
}
@Override
public void resetEditorFrom(@NotNull AppletConfiguration runConfiguration) {
AppletConfigurationOptions configuration = runConfiguration.getOptions();
getClassNameComponent().setText(configuration.getMainClassName());
String presentableHtmlName = configuration.getHtmlFileName();
if (presentableHtmlName != null && !StringUtil.startsWithIgnoreCase(presentableHtmlName, HTTP_PREFIX)) {
presentableHtmlName = presentableHtmlName.replace('/', File.separatorChar);
}
getHtmlPathComponent().setText(presentableHtmlName);
getPolicyFileComponent().setText(runConfiguration.getPolicyFile());
getVMParametersComponent().setText(configuration.getVmParameters());
getWidthComponent().setText(Integer.toString(configuration.getWidth()));
getHeightComponent().setText(Integer.toString(configuration.getHeight()));
(configuration.getHtmlUsed() ? myURL : myMainClass).setSelected(true);
changePanel();
myParameters.setItems(cloneParameters(configuration.getAppletParameters()));
myModuleSelector.reset(runConfiguration);
myJrePathEditor.setPathOrName(configuration.getAlternativeJrePath(), configuration.isAlternativeJrePathEnabled());
}
private RawCommandLineEditor getVMParametersComponent() {
return myVMParameters.getComponent();
}
private JTextField getHeightComponent() {
return myHeight;
}
@NotNull
@Override
public JComponent createEditor() {
return myWholePanel;
}
@Override
public void checkEditorData(@NotNull AppletConfiguration runConfiguration) {
AppletConfigurationOptions configuration = runConfiguration.getOptions();
runConfiguration.setMainClassName(getClassNameComponent().getText().trim());
configuration.setHtmlFileName(toSystemFormat(getHtmlPathComponent().getText()));
configuration.setVmParameters(getVMParametersComponent().getText().trim());
runConfiguration.setPolicyFile(getPolicyFileComponent().getText());
myModuleSelector.applyTo(runConfiguration);
try { configuration.setWidth(Integer.parseInt(getWidthComponent().getText())); } catch (NumberFormatException ignored) { }
try { configuration.setHeight(Integer.parseInt(getHeightComponent().getText())); } catch (NumberFormatException ignored) { }
configuration.setHtmlUsed(myURL.isSelected());
configuration.setAlternativeJrePath(myJrePathEditor.getJrePathOrName());
configuration.setAlternativeJrePathEnabled(myJrePathEditor.isAlternativeJreSelected());
}
private void createUIComponents() {
myClassName = new EditorTextFieldWithBrowseButton(myProject, true);
}
@Override
public JComponent getAnchor() {
return anchor;
}
@Override
public void setAnchor(JComponent anchor) {
this.anchor = anchor;
myModule.setAnchor(anchor);
myPolicyFile.setAnchor(anchor);
myVMParameters.setAnchor(anchor);
myJrePathEditor.setAnchor(anchor);
myHtmlFileLabel.setAnchor(anchor);
}
private static abstract class MyColumnInfo extends ColumnInfo<AppletParameter, String> {
MyColumnInfo(final String name) {
super(name);
}
@Override
public TableCellEditor getEditor(final AppletParameter item) {
final JTextField textField = new JTextField();
textField.setBorder(BorderFactory.createLineBorder(JBColor.BLACK));
return new DefaultCellEditor(textField);
}
@Override
public boolean isCellEditable(final AppletParameter appletParameter) {
return true;
}
}
}
@@ -1,257 +0,0 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.applet;
import com.intellij.execution.*;
import com.intellij.execution.configurations.*;
import com.intellij.execution.junit.RefactoringListeners;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.util.JavaParametersUtil;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.JdkUtil;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.refactoring.listeners.RefactoringElementListener;
import com.intellij.util.xmlb.annotations.Transient;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
public class AppletConfiguration extends ModuleBasedConfiguration<JavaRunConfigurationModule, AppletConfigurationOptions>
implements SingleClassConfiguration, RefactoringListenerProvider, PersistentStateComponent<AppletConfigurationOptions> {
public AppletConfiguration(@NotNull Project project, @NotNull ConfigurationFactory factory) {
super(new JavaRunConfigurationModule(project, false), factory);
}
@NotNull
@Override
public AppletConfigurationOptions getOptions() {
return (AppletConfigurationOptions)super.getOptions();
}
@Override
public void setMainClass(final PsiClass psiClass) {
final Module originalModule = getConfigurationModule().getModule();
setMainClassName(JavaExecutionUtil.getRuntimeQualifiedName(psiClass));
setModule(JavaExecutionUtil.findModule(psiClass));
restoreOriginalModule(originalModule);
}
@Override
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) throws ExecutionException {
return new JavaCommandLineState(env) {
private AppletHtmlFile myHtmlURL = null;
@Override
protected JavaParameters createJavaParameters() throws ExecutionException {
final JavaParameters params = new JavaParameters();
myHtmlURL = getHtmlURL();
final int classPathType = myHtmlURL.isHttp() ? JavaParameters.JDK_ONLY : JavaParameters.JDK_AND_CLASSES;
final RunConfigurationModule runConfigurationModule = getConfigurationModule();
JavaParametersUtil.configureModule(runConfigurationModule, params, classPathType, getOptions().isAlternativeJrePathEnabled() ? getOptions().getAlternativeJrePath() : null);
final String policyFileParameter = getPolicyFileParameter();
if (policyFileParameter != null) {
params.getVMParametersList().add(policyFileParameter);
}
params.getVMParametersList().addParametersString(getOptions().getVmParameters());
params.setMainClass("sun.applet.AppletViewer");
params.getProgramParametersList().add(myHtmlURL.getUrl());
return params;
}
@Override
@NotNull
protected OSProcessHandler startProcess() throws ExecutionException {
final OSProcessHandler handler = super.startProcess();
final AppletHtmlFile htmlUrl = myHtmlURL;
if (htmlUrl != null) {
handler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(@NotNull ProcessEvent event) {
htmlUrl.deleteFile();
}
});
}
return handler;
}
};
}
@Override
@NotNull
public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
return new AppletConfigurable(getProject());
}
private String getPolicyFileParameter() {
if (!StringUtil.isEmpty(getOptions().getPolicyFile())) {
//noinspection SpellCheckingInspection
return "-Djava.security.policy=" + getPolicyFile();
}
return null;
}
@Transient
public String getPolicyFile() {
return ExternalizablePath.localPathValue(getOptions().getPolicyFile());
}
public void setPolicyFile(final String localPath) {
getOptions().setPolicyFile(ExternalizablePath.urlValue(localPath));
}
@Override
public Collection<Module> getValidModules() {
return JavaRunConfigurationModule.getModulesForClass(getProject(), getOptions().getMainClassName());
}
@Override
public RefactoringElementListener getRefactoringElementListener(final PsiElement element) {
if (getOptions().getHtmlUsed()) {
return null;
}
return RefactoringListeners.getClassOrPackageListener(element, new RefactoringListeners.SingleClassConfigurationAccessor(this));
}
@Override
@Transient
public PsiClass getMainClass() {
return getConfigurationModule().findClass(getOptions().getMainClassName());
}
@Override
public String suggestedName() {
if (getOptions().getMainClassName() == null) {
return null;
}
return ProgramRunnerUtil.shortenName(JavaExecutionUtil.getShortClassName(getOptions().getMainClassName()), 0);
}
@Override
public void setMainClassName(@Nullable String qualifiedName) {
getOptions().setMainClassName(qualifiedName);
}
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
if (getOptions().isAlternativeJrePathEnabled() && (StringUtil.isEmptyOrSpaces(getOptions().getAlternativeJrePath()) || !JdkUtil.checkForJre(getOptions().getAlternativeJrePath()))) {
throw new RuntimeConfigurationWarning(ExecutionBundle.message("jre.not.valid.error.message", getOptions().getAlternativeJrePath()));
}
getConfigurationModule().checkForWarning();
if (getOptions().getHtmlUsed()) {
if (getOptions().getHtmlFileName() == null) {
throw new RuntimeConfigurationWarning(ExecutionBundle.message("html.file.not.specified.error.message"));
}
try {
new URL(getHtmlURL().getUrl());
}
catch (CantRunException | MalformedURLException ex) {
checkUrlIsValid(ex);
}
}
else {
getConfigurationModule().checkClassName(getOptions().getMainClassName(), ExecutionBundle.message("no.applet.class.specified.error.message"));
}
}
private void checkUrlIsValid(Exception ex) throws RuntimeConfigurationWarning {
throw new RuntimeConfigurationWarning("URL " + getOptions().getHtmlFileName() + " is not valid: " + ex.getLocalizedMessage());
}
private AppletHtmlFile getHtmlURL() throws CantRunException {
if (getOptions().getHtmlUsed()) {
if (getOptions().getHtmlFileName() == null) {
throw new CantRunException(ExecutionBundle.message("html.file.not.specified.error.message"));
}
return new AppletHtmlFile(getOptions().getHtmlFileName(), null);
}
else {
if (getOptions().getMainClassName() == null) {
throw new CantRunException(ExecutionBundle.message("class.not.specified.error.message"));
}
// generate html
try {
return generateAppletTempPage();
}
catch (IOException ignored) {
throw new CantRunException(ExecutionBundle.message("failed.to.generate.wrapper.error.message"));
}
}
}
@NotNull
private AppletHtmlFile generateAppletTempPage() throws IOException {
final File tempFile = FileUtil.createTempFile("AppletPage", ".html");
try (FileWriter writer = new FileWriter(tempFile)) {
writer.write("<html>\n" +
"<head>\n" +
"<title>" + getOptions().getMainClassName() + "</title>\n" +
"</head>\n" +
"<applet codebase=\".\"\n" +
"code=\"" + getOptions().getMainClassName() + "\"\n" +
"name=\"" + getOptions().getMainClassName() + "\"\n" +
"width=" + getOptions().getWidth() + "\n" +
"height=" + getOptions().getHeight() + "\n" +
"align=top>\n");
for (AppletParameter parameter : getOptions().getAppletParameters()) {
writer.write("<param name=\"" + parameter.getName() + "\" value=\"" + parameter.getValue() + "\">\n");
}
writer.write("</applet>\n</body>\n</html>\n");
}
return new AppletHtmlFile(tempFile.getAbsolutePath(), tempFile);
}
private static class AppletHtmlFile {
private final String myHtmlFile;
private final File myFileToDelete;
@NonNls
protected static final String FILE_PREFIX = "file:/";
@NonNls
protected static final String HTTP_PREFIX = "http:/";
@NonNls
protected static final String HTTPS_PREFIX = "https:/";
protected AppletHtmlFile(final String htmlFile, final File fileToDelete) {
myHtmlFile = htmlFile;
myFileToDelete = fileToDelete;
}
public String getUrl() {
if (!StringUtil.startsWithIgnoreCase(myHtmlFile, FILE_PREFIX) && !isHttp()) {
try {
//noinspection deprecation
return new File(myHtmlFile).toURL().toString();
}
catch (MalformedURLException ignored) {
}
}
return myHtmlFile;
}
public boolean isHttp() {
return StringUtil.startsWithIgnoreCase(myHtmlFile, HTTP_PREFIX) || StringUtil.startsWithIgnoreCase(myHtmlFile, HTTPS_PREFIX);
}
public void deleteFile() {
if (myFileToDelete != null) {
//noinspection ResultOfMethodCallIgnored
myFileToDelete.delete();
}
}
}
}
@@ -1,31 +0,0 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.applet
import com.intellij.execution.ExternalizablePath
import com.intellij.execution.JvmConfigurationOptions
import com.intellij.openapi.application.PathManager
import com.intellij.util.xmlb.annotations.*
class AppletConfigurationOptions : JvmConfigurationOptions() {
@get:OptionTag("HTML_FILE_NAME")
var htmlFileName: String? by string()
@get:OptionTag("HTML_USED")
var htmlUsed by property(false)
@get:OptionTag("WIDTH")
var width: Int by property(400)
@get:OptionTag("HEIGHT")
var height: Int by property(300)
@get:OptionTag("POLICY_FILE")
var policyFile: String? by string(ExternalizablePath.urlValue("${PathManager.getHomePath()}/bin/appletviewer.policy"))
@get:Property(surroundWithTag = false)
@get:XCollection()
var appletParameters: MutableList<AppletParameter> by list()
}
@Tag("parameter")
data class AppletParameter(@get:Attribute("name") var name: String? = null, @get:Attribute("value") var value: String? = null)
@@ -1,107 +0,0 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.applet;
import com.intellij.execution.JavaExecutionUtil;
import com.intellij.execution.Location;
import com.intellij.execution.RunnerAndConfigurationSettings;
import com.intellij.execution.actions.ConfigurationContext;
import com.intellij.execution.configurations.ConfigurationTypeUtil;
import com.intellij.execution.junit.JavaRuntimeConfigurationProducerBase;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiManager;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiClassUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class AppletConfigurationProducer extends JavaRuntimeConfigurationProducerBase {
protected AppletConfigurationProducer() {
super(ConfigurationTypeUtil.findConfigurationType(AppletConfigurationType.class));
}
@Override
public PsiElement getSourceElement() {
return restoreSourceElement();
}
@Override
protected RunnerAndConfigurationSettings createConfigurationByElement(Location location, ConfigurationContext context) {
location = JavaExecutionUtil.stepIntoSingleClass(location);
if (location == null) return null;
final Project project = location.getProject();
final PsiElement element = location.getPsiElement();
PsiClass psiClass = getAppletClass(element, PsiManager.getInstance(project));
if (psiClass == null) return null;
storeSourceElement(psiClass);
RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(project, context);
final AppletConfiguration configuration = (AppletConfiguration)settings.getConfiguration();
configuration.setMainClassName(JavaExecutionUtil.getRuntimeQualifiedName(psiClass));
configuration.setModule(psiClass.isValid() ? ModuleUtilCore.findModuleForPsiElement(psiClass) : null);
configuration.setGeneratedName();
return settings;
}
@Override
public int compareTo(Object o) {
return PREFERED;
}
@Nullable
private static PsiClass getAppletClass(PsiElement element, final PsiManager manager) {
while (element != null) {
if (element instanceof PsiClass) {
final PsiClass aClass = (PsiClass)element;
if (isAppletClass(aClass, manager)){
return aClass;
}
}
element = element.getParent();
}
return null;
}
private static boolean isAppletClass(final PsiClass aClass, final PsiManager manager) {
if (DumbService.isDumb(manager.getProject())) return false;
if (!PsiClassUtil.isRunnableClass(aClass, true)) return false;
final Module module = JavaExecutionUtil.findModule(aClass);
final GlobalSearchScope scope = module != null
? GlobalSearchScope.moduleWithLibrariesScope(module)
: GlobalSearchScope.projectScope(manager.getProject());
PsiClass appletClass = JavaPsiFacade.getInstance(manager.getProject()).findClass("java.applet.Applet", scope);
if (appletClass != null) {
if (aClass.isInheritor(appletClass, true)) return true;
}
appletClass = JavaPsiFacade.getInstance(manager.getProject()).findClass("javax.swing.JApplet", scope);
if (appletClass != null) {
if (aClass.isInheritor(appletClass, true)) return true;
}
return false;
}
@Override
protected RunnerAndConfigurationSettings findExistingByElement(Location location,
@NotNull List<? extends RunnerAndConfigurationSettings> existingConfigurations,
ConfigurationContext context) {
final PsiClass aClass = getAppletClass(location.getPsiElement(), PsiManager.getInstance(location.getProject()));
if (aClass != null) {
for (RunnerAndConfigurationSettings existingConfiguration : existingConfigurations) {
if (Comparing.equal(JavaExecutionUtil.getRuntimeQualifiedName(aClass),
((AppletConfiguration)existingConfiguration.getConfiguration()).getOptions().getMainClassName())) {
return existingConfiguration;
}
}
}
return null;
}
}
@@ -1,34 +0,0 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.applet;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.configurations.SimpleConfigurationType;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.components.BaseState;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.NotNullLazyValue;
import org.jetbrains.annotations.NotNull;
public final class AppletConfigurationType extends SimpleConfigurationType {
AppletConfigurationType() {
super("Applet", ExecutionBundle.message("applet.configuration.name"), ExecutionBundle.message("applet.configuration.description"),
NotNullLazyValue.createValue(() -> AllIcons.RunConfigurations.Applet));
}
@Override
public Class<? extends BaseState> getOptionsClass() {
return AppletConfigurationOptions.class;
}
@NotNull
@Override
public RunConfiguration createTemplateConfiguration(@NotNull Project project) {
return new AppletConfiguration(project, this);
}
@Override
public String getHelpTopic() {
return "reference.dialogs.rundebug.Applet";
}
}
@@ -645,8 +645,6 @@
<favoriteNodeProvider implementation="com.intellij.ide.favoritesTreeView.UsageFavoriteNodeProvider"/>
<configurationType implementation="com.intellij.execution.applet.AppletConfigurationType"/>
<configurationProducer implementation="com.intellij.execution.applet.AppletConfigurationProducer"/>
<configurationType implementation="com.intellij.execution.application.ApplicationConfigurationType"/>
<configurationType implementation="com.intellij.execution.jar.JarApplicationConfigurationType"/>
<configurationType implementation="com.intellij.execution.scratch.JavaScratchConfigurationType"/>
@@ -44,14 +44,6 @@ show.running.list.balloon.hint=Click to navigate
error.common.title=Error
error.running.configuration.message=Error running ''{0}''
select.applet.policy.file.dialog.title=Select Applet Policy File
choose.html.file.dialog.title=Choose HTML File
html.file.not.specified.error.message=Html file not specified
jre.not.valid.error.message=''{0}'' is not valid JRE home
applet.configuration.description=Applet configuration
applet.configuration.name=Applet
application.configuration.description=Java application configuration
application.configuration.name=Application
@@ -69,8 +61,6 @@ show.irrelevant.configurations.action.name={0} more items...
remove.run.configuration.action.name=Remove Configuration
no.parameters=No parameters
run.configuration.edit.default.configuration.settings.text=Edit Templates
run.configuration.edit.default.configuration.settings.description=Edit templates
run.configuration.create.folder.text=Create New Folder
@@ -211,23 +201,8 @@ default.runner.start.action.text=R&un
remote.debug.configuration.description=Remote debug configuration
remote.debug.configuration.display.name=Remote
applet.configuration.url.label=&URL
applet.configuration.applet.class.border=Applet Class
applet.configuration.applet.parameters.label=Applet Parameters
applet.configuration.applet.class.option=&Applet class
applet.configuration.applet.class.label=Applet &class:
button.remove=&Remove
button.add=&Add
applet.configuration.height.label= &Height:
applet.configuration.width.label= &Width:
applet.configuration.url.html.file.label=URL/HTML &file:
applet.configuration.url.border=URL
applet.configuration.vm.parameters.for.appletviewer.label=&VM options for appletviewer:
applet.configuration.policy.file.label=&Policy file:
applet.configuration.parameter.name.column=Name
applet.configuration.parameter.value.column=Value
class.not.specified.error.message=Class not specified.
failed.to.generate.wrapper.error.message=Failed to generate temporary html wrapper for applet class
application.configuration.use.classpath.and.jdk.of.module.label=Use classpath of m&odule:
application.configuration.shorten.command.line.label=Shorten command &line:
@@ -245,7 +220,6 @@ test.method.doesnt.exist.error.message=Test method ''{0}'' doesn''t exist
no.tests.found.in.package.error.message=No tests found in the package ''{0}''
package.does.not.exist.error.message=Package ''{0}'' does not exist
choose.main.class.dialog.title=Choose Main Class
choose.applet.class.dialog.title=Choose Applet Class
junit.configuration.test.runner.parameters.label=Test runner pa&rams:
junit.configuration.test.border=Test
junit.configuration.across.module.dependencies.radio=Across modu&le dependencies
@@ -267,7 +241,6 @@ module.not.specified.error.text=Module not specified
module.is.unloaded.from.project.error.text=Module ''{0}'' is unloaded from the project
module.doesn.t.exist.in.project.error.text=Module ''{0}'' doesn''t exist in project
run.configuration.unnamed.name.prefix=Unnamed
no.applet.class.specified.error.message=No applet class specified
no.main.class.specified.error.text=No main class specified
action.name.save.configuration=Save Configuration
#2 - configuration type description