From baeb3ad7a43a8ca811947c7ec6b406dfce6e74da Mon Sep 17 00:00:00 2001 From: jiong Date: Fri, 26 Mar 2021 10:25:21 +0800 Subject: [PATCH] remove some code --- .../plugin/intellij/task/InstallAppTask.java | 7 ++-- .../ui/NocalhostConsoleWindowFactory.java | 4 +- .../ui/NocalhostSettingComponent.java | 38 +++++++------------ .../plugin/intellij/ui/NocalhostWindow.java | 10 ++--- .../intellij/ui/NocalhostWindowFactory.java | 2 +- .../ui/PortForwardConfigurationDialog.java | 5 +-- .../ui/action/workload/EndDevelopAction.java | 3 +- .../ui/action/workload/ResetAction.java | 3 +- .../action/workload/StartDevelopAction.java | 1 - .../ui/console/NocalhostErrorWindow.java | 20 ++-------- .../ui/console/NocalhostOutputWindow.java | 13 ++----- .../plugin/intellij/ui/vfs/AppConfigFile.java | 1 - .../plugin/intellij/ui/vfs/ConfigFile.java | 1 - 13 files changed, 34 insertions(+), 74 deletions(-) diff --git a/src/main/java/dev/nocalhost/plugin/intellij/task/InstallAppTask.java b/src/main/java/dev/nocalhost/plugin/intellij/task/InstallAppTask.java index 4b8ef259..363cd54b 100644 --- a/src/main/java/dev/nocalhost/plugin/intellij/task/InstallAppTask.java +++ b/src/main/java/dev/nocalhost/plugin/intellij/task/InstallAppTask.java @@ -37,7 +37,6 @@ import dev.nocalhost.plugin.intellij.exception.NocalhostExecuteCmdException; import dev.nocalhost.plugin.intellij.exception.NocalhostNotifier; import dev.nocalhost.plugin.intellij.topic.DevSpaceListUpdatedNotifier; -import dev.nocalhost.plugin.intellij.utils.KubeConfigUtil; import lombok.SneakyThrows; public class InstallAppTask extends Task.Backgroundable { @@ -58,10 +57,10 @@ public class InstallAppTask extends Task.Backgroundable { private final Project project; private final DevSpace devSpace; private final Application application; - private NhctlInstallOptions opts; + private final NhctlInstallOptions opts; - private NhctlCommand nhctlCommand = ServiceManager.getService(NhctlCommand.class); - String productPagePort; + private final NhctlCommand nhctlCommand = ServiceManager.getService(NhctlCommand.class); + private String productPagePort; public InstallAppTask(@Nullable Project project, DevSpace devSpace, Application application, NhctlInstallOptions opts) { super(project, "Installing application: " + application.getContext().getApplicationName(), false); diff --git a/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostConsoleWindowFactory.java b/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostConsoleWindowFactory.java index 7e97fb5f..7e504c26 100644 --- a/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostConsoleWindowFactory.java +++ b/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostConsoleWindowFactory.java @@ -55,7 +55,7 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo } private void errorPrint(String title, String contentMsg, String eMessage) { - NocalhostErrorWindow nocalhostErrorWindow = new NocalhostErrorWindow(project, toolWindow, title, contentMsg, eMessage); + NocalhostErrorWindow nocalhostErrorWindow = new NocalhostErrorWindow(project, title, contentMsg, eMessage); ContentManager contentManager = toolWindow.getContentManager(); Content content = ContentFactory.SERVICE.getInstance().createContent(nocalhostErrorWindow.getPanel(), nocalhostErrorWindow.getTitle(), false); contentManager.addContent(content); @@ -63,7 +63,7 @@ private void errorPrint(String title, String contentMsg, String eMessage) { } private void createOutputWindow() { - NocalhostOutputWindow nocalhostOutputWindow = new NocalhostOutputWindow(project, toolWindow); + NocalhostOutputWindow nocalhostOutputWindow = new NocalhostOutputWindow(project); ContentManager contentManager = toolWindow.getContentManager(); Content content = ContentFactory.SERVICE.getInstance().createContent(nocalhostOutputWindow.getPanel(), "OUTPUT", false); diff --git a/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostSettingComponent.java b/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostSettingComponent.java index 7f832536..e1058ee8 100644 --- a/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostSettingComponent.java +++ b/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostSettingComponent.java @@ -33,22 +33,16 @@ public class NocalhostSettingComponent { private final JPanel settingPanel; - private final JBTextField nhctlField; private final TextFieldWithBrowseButton nhctlBinary; - private final JButton nhctlTestButton; - private final JPanel nhctlPanel; - private final JBTextField kubeField; private final TextFieldWithBrowseButton kubectlBinary; - private final JButton kubectlTestButton; - private final JPanel kubectlPanel; private final JBTextArea showVersion; public NocalhostSettingComponent() { - nhctlField = new JBTextField(); + JBTextField nhctlField = new JBTextField(); nhctlField.getEmptyText().appendText("nhctl"); nhctlBinary = new TextFieldWithBrowseButton(nhctlField); - kubeField = new JBTextField(); + JBTextField kubeField = new JBTextField(); kubeField.getEmptyText().appendText("kubectl"); kubectlBinary = new TextFieldWithBrowseButton(kubeField); nhctlBinary.addBrowseFolderListener("", "Select nhctl binary", null, @@ -57,14 +51,14 @@ public NocalhostSettingComponent() { kubectlBinary.addBrowseFolderListener("", "Select kubectl binary", null, FileChooseUtil.singleFileChooserDescriptor(), TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT); - nhctlTestButton = new JButton("Test"); + JButton nhctlTestButton = new JButton("Test"); nhctlTestButton.addActionListener(new TestNhctlListener()); - nhctlPanel = new JPanel(new BorderLayout()); + JPanel nhctlPanel = new JPanel(new BorderLayout()); nhctlPanel.add(nhctlBinary, BorderLayout.CENTER); nhctlPanel.add(nhctlTestButton, BorderLayout.EAST); - kubectlTestButton = new JButton("Test"); + JButton kubectlTestButton = new JButton("Test"); kubectlTestButton.addActionListener(new TestKubectlListener()); - kubectlPanel = new JPanel(new BorderLayout()); + JPanel kubectlPanel = new JPanel(new BorderLayout()); kubectlPanel.add(kubectlBinary, BorderLayout.CENTER); kubectlPanel.add(kubectlTestButton, BorderLayout.EAST); @@ -115,12 +109,10 @@ public void actionPerformed(ActionEvent e) { String nhctl = StringUtils.isBlank(nhctlBinary.getText()) ? "nhctl" : nhctlBinary.getText(); final Map environment = new HashMap<>(EnvironmentUtil.getEnvironmentMap()); environment.put("DISABLE_SPINNER", "true"); - if (SystemInfo.isMac || SystemInfo.isLinux) { - if (StringUtils.contains(nhctl, "/")) { - String path = environment.get("PATH"); - path = nhctl.substring(0, nhctl.lastIndexOf("/")) + ":" + path; - environment.put("PATH", path); - } + if ((SystemInfo.isMac || SystemInfo.isLinux) && StringUtils.contains(nhctl, "/")) { + String path = environment.get("PATH"); + path = nhctl.substring(0, nhctl.lastIndexOf("/")) + ":" + path; + environment.put("PATH", path); } GeneralCommandLine commandLine = new GeneralCommandLine(Lists.newArrayList(nhctl, "version")).withEnvironment(environment); commandLine.setCharset(CharsetToolkit.getDefaultSystemCharset()); @@ -143,12 +135,10 @@ public void actionPerformed(ActionEvent e) { String kubectl = StringUtils.isBlank(kubectlBinary.getText()) ? "kubectl" : kubectlBinary.getText(); final Map environment = new HashMap<>(EnvironmentUtil.getEnvironmentMap()); environment.put("DISABLE_SPINNER", "true"); - if (SystemInfo.isMac || SystemInfo.isLinux) { - if (StringUtils.contains(kubectl, "/")) { - String path = environment.get("PATH"); - path = kubectl.substring(0, kubectl.lastIndexOf("/")) + ":" + path; - environment.put("PATH", path); - } + if ((SystemInfo.isMac || SystemInfo.isLinux) && StringUtils.contains(kubectl, "/")) { + String path = environment.get("PATH"); + path = kubectl.substring(0, kubectl.lastIndexOf("/")) + ":" + path; + environment.put("PATH", path); } GeneralCommandLine commandLine = new GeneralCommandLine(Lists.newArrayList(kubectl, "version")).withEnvironment(environment); commandLine.setCharset(CharsetToolkit.getDefaultSystemCharset()); diff --git a/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostWindow.java b/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostWindow.java index 022ab06e..4e800bee 100644 --- a/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostWindow.java +++ b/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostWindow.java @@ -12,7 +12,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.SimpleToolWindowPanel; -import com.intellij.openapi.wm.ToolWindow; import com.intellij.ui.JBColor; import com.intellij.ui.components.JBScrollPane; @@ -41,15 +40,12 @@ public class NocalhostWindow { private static final Logger LOG = Logger.getInstance(NocalhostWindow.class); private final Project project; - private final ToolWindow toolWindow; - private SimpleToolWindowPanel panel; + private final SimpleToolWindowPanel panel; private NocalhostTree tree; - private JBScrollPane scrollPane; - public NocalhostWindow(Project project, ToolWindow toolWindow) { + public NocalhostWindow(Project project) { this.project = project; - this.toolWindow = toolWindow; checkNocalhostVersion(); @@ -110,7 +106,7 @@ private void toggleContent() { if (StringUtils.isNotBlank(jwt)) { tree = new NocalhostTree(project); tree.updateDevSpaces(); - scrollPane = new JBScrollPane(tree); + JBScrollPane scrollPane = new JBScrollPane(tree); scrollPane.setBorder(new TopLineBorder(new JBColor(0xD5D5D5, 0x323232), 1)); panel.add(scrollPane); } else { diff --git a/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostWindowFactory.java b/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostWindowFactory.java index b2883c65..d7fa2da0 100644 --- a/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostWindowFactory.java +++ b/src/main/java/dev/nocalhost/plugin/intellij/ui/NocalhostWindowFactory.java @@ -13,7 +13,7 @@ public class NocalhostWindowFactory implements ToolWindowFactory, DumbAware { @Override public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) { - NocalhostWindow nocalhostWindow = new NocalhostWindow(project, toolWindow); + NocalhostWindow nocalhostWindow = new NocalhostWindow(project); ContentManager contentManager = toolWindow.getContentManager(); Content content = ContentFactory.SERVICE.getInstance().createContent(nocalhostWindow.getPanel(), "", false); diff --git a/src/main/java/dev/nocalhost/plugin/intellij/ui/PortForwardConfigurationDialog.java b/src/main/java/dev/nocalhost/plugin/intellij/ui/PortForwardConfigurationDialog.java index 94062dcb..34a9870c 100644 --- a/src/main/java/dev/nocalhost/plugin/intellij/ui/PortForwardConfigurationDialog.java +++ b/src/main/java/dev/nocalhost/plugin/intellij/ui/PortForwardConfigurationDialog.java @@ -64,8 +64,7 @@ public class PortForwardConfigurationDialog extends DialogWrapper { private final ResourceNode node; private final Project project; - private JPanel dialogPanel; - private JScrollPane scrollPane; + private final JPanel dialogPanel; private JPanel listPanel; private JBTextField startTextField; @@ -300,7 +299,7 @@ public void run(@NotNull ProgressIndicator indicator) { private void setupStopPanel() { listPanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true)); - scrollPane = new JBScrollPane(listPanel); + JScrollPane scrollPane = new JBScrollPane(listPanel); scrollPane.setPreferredSize(new Dimension(-1, 400)); GridConstraints scrollPaneConstraints = new GridConstraints(); diff --git a/src/main/java/dev/nocalhost/plugin/intellij/ui/action/workload/EndDevelopAction.java b/src/main/java/dev/nocalhost/plugin/intellij/ui/action/workload/EndDevelopAction.java index d20cc63b..66b74a80 100644 --- a/src/main/java/dev/nocalhost/plugin/intellij/ui/action/workload/EndDevelopAction.java +++ b/src/main/java/dev/nocalhost/plugin/intellij/ui/action/workload/EndDevelopAction.java @@ -15,16 +15,15 @@ import java.io.IOException; -import dev.nocalhost.plugin.intellij.exception.NocalhostNotifier; import dev.nocalhost.plugin.intellij.commands.NhctlCommand; import dev.nocalhost.plugin.intellij.commands.OutputCapturedNhctlCommand; import dev.nocalhost.plugin.intellij.commands.data.NhctlDescribeOptions; import dev.nocalhost.plugin.intellij.commands.data.NhctlDescribeService; import dev.nocalhost.plugin.intellij.commands.data.NhctlDevEndOptions; import dev.nocalhost.plugin.intellij.exception.NocalhostExecuteCmdException; +import dev.nocalhost.plugin.intellij.exception.NocalhostNotifier; import dev.nocalhost.plugin.intellij.topic.DevSpaceListUpdatedNotifier; import dev.nocalhost.plugin.intellij.ui.tree.node.ResourceNode; -import dev.nocalhost.plugin.intellij.utils.KubeConfigUtil; import icons.NocalhostIcons; public class EndDevelopAction extends AnAction { diff --git a/src/main/java/dev/nocalhost/plugin/intellij/ui/action/workload/ResetAction.java b/src/main/java/dev/nocalhost/plugin/intellij/ui/action/workload/ResetAction.java index 01dc7204..8e55089f 100644 --- a/src/main/java/dev/nocalhost/plugin/intellij/ui/action/workload/ResetAction.java +++ b/src/main/java/dev/nocalhost/plugin/intellij/ui/action/workload/ResetAction.java @@ -14,12 +14,11 @@ import java.io.IOException; -import dev.nocalhost.plugin.intellij.exception.NocalhostNotifier; import dev.nocalhost.plugin.intellij.commands.NhctlCommand; import dev.nocalhost.plugin.intellij.commands.data.NhctlResetOptions; import dev.nocalhost.plugin.intellij.exception.NocalhostExecuteCmdException; +import dev.nocalhost.plugin.intellij.exception.NocalhostNotifier; import dev.nocalhost.plugin.intellij.ui.tree.node.ResourceNode; -import dev.nocalhost.plugin.intellij.utils.KubeConfigUtil; public class ResetAction extends AnAction { private static final Logger LOG = Logger.getInstance(ResetAction.class); diff --git a/src/main/java/dev/nocalhost/plugin/intellij/ui/action/workload/StartDevelopAction.java b/src/main/java/dev/nocalhost/plugin/intellij/ui/action/workload/StartDevelopAction.java index 35bfff8e..f6fb6b3b 100644 --- a/src/main/java/dev/nocalhost/plugin/intellij/ui/action/workload/StartDevelopAction.java +++ b/src/main/java/dev/nocalhost/plugin/intellij/ui/action/workload/StartDevelopAction.java @@ -41,7 +41,6 @@ import dev.nocalhost.plugin.intellij.ui.StartDevelopContainerChooseDialog; import dev.nocalhost.plugin.intellij.ui.tree.node.ResourceNode; import dev.nocalhost.plugin.intellij.utils.FileChooseUtil; -import dev.nocalhost.plugin.intellij.utils.KubeConfigUtil; import icons.NocalhostIcons; public class StartDevelopAction extends AnAction { diff --git a/src/main/java/dev/nocalhost/plugin/intellij/ui/console/NocalhostErrorWindow.java b/src/main/java/dev/nocalhost/plugin/intellij/ui/console/NocalhostErrorWindow.java index dc592d37..192d448f 100644 --- a/src/main/java/dev/nocalhost/plugin/intellij/ui/console/NocalhostErrorWindow.java +++ b/src/main/java/dev/nocalhost/plugin/intellij/ui/console/NocalhostErrorWindow.java @@ -4,31 +4,19 @@ import com.intellij.execution.ui.ConsoleView; import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.openapi.project.Project; -import com.intellij.openapi.wm.ToolWindow; import javax.swing.*; public class NocalhostErrorWindow extends NocalhostConsoleWindow { - private final Project project; - private final ToolWindow toolWindow; + private final LogPanel panel; + private final String title; - private LogPanel panel; - private ConsoleView consoleView; - - private String title; - private String content; - private String eMessage; - - public NocalhostErrorWindow(Project project, ToolWindow toolWindow, String title, String content, String eMessage) { - this.project = project; - this.toolWindow = toolWindow; + public NocalhostErrorWindow(Project project, String title, String content, String eMessage) { this.title = title; - this.content = content; - this.eMessage = eMessage; - consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole(); + ConsoleView consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole(); panel = new LogPanel(false); consoleView.print( diff --git a/src/main/java/dev/nocalhost/plugin/intellij/ui/console/NocalhostOutputWindow.java b/src/main/java/dev/nocalhost/plugin/intellij/ui/console/NocalhostOutputWindow.java index c426ccf7..ed32ec56 100644 --- a/src/main/java/dev/nocalhost/plugin/intellij/ui/console/NocalhostOutputWindow.java +++ b/src/main/java/dev/nocalhost/plugin/intellij/ui/console/NocalhostOutputWindow.java @@ -9,7 +9,6 @@ import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.wm.ToolWindow; import org.apache.commons.lang3.ArrayUtils; @@ -18,17 +17,11 @@ import dev.nocalhost.plugin.intellij.topic.NocalhostOutputAppendNotifier; public class NocalhostOutputWindow { - private final Project project; - private final ToolWindow toolWindow; - private LogPanel panel; + private final LogPanel panel; + private final ConsoleView consoleView; - - private ConsoleView consoleView; - - public NocalhostOutputWindow(Project project, ToolWindow toolWindow) { - this.project = project; - this.toolWindow = toolWindow; + public NocalhostOutputWindow(Project project) { consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole(); diff --git a/src/main/java/dev/nocalhost/plugin/intellij/ui/vfs/AppConfigFile.java b/src/main/java/dev/nocalhost/plugin/intellij/ui/vfs/AppConfigFile.java index 2962328d..d275ad85 100644 --- a/src/main/java/dev/nocalhost/plugin/intellij/ui/vfs/AppConfigFile.java +++ b/src/main/java/dev/nocalhost/plugin/intellij/ui/vfs/AppConfigFile.java @@ -28,7 +28,6 @@ import dev.nocalhost.plugin.intellij.exception.NocalhostNotifier; import dev.nocalhost.plugin.intellij.ui.tree.node.ApplicationNode; import dev.nocalhost.plugin.intellij.utils.DataUtils; -import dev.nocalhost.plugin.intellij.utils.KubeConfigUtil; import lombok.AllArgsConstructor; import lombok.SneakyThrows; diff --git a/src/main/java/dev/nocalhost/plugin/intellij/ui/vfs/ConfigFile.java b/src/main/java/dev/nocalhost/plugin/intellij/ui/vfs/ConfigFile.java index 3668fbc2..7cd93a3b 100644 --- a/src/main/java/dev/nocalhost/plugin/intellij/ui/vfs/ConfigFile.java +++ b/src/main/java/dev/nocalhost/plugin/intellij/ui/vfs/ConfigFile.java @@ -28,7 +28,6 @@ import dev.nocalhost.plugin.intellij.exception.NocalhostNotifier; import dev.nocalhost.plugin.intellij.ui.tree.node.ResourceNode; import dev.nocalhost.plugin.intellij.utils.DataUtils; -import dev.nocalhost.plugin.intellij.utils.KubeConfigUtil; import lombok.AllArgsConstructor; import lombok.SneakyThrows;