From 524d4c7b9cfdaedb80248718dd42c9b3eab617f8 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 27 Aug 2021 08:47:55 +0300 Subject: [PATCH 1/5] UCT run configuration development --- resources/META-INF/plugin.xml | 3 + .../UctConfigurationFactory.java | 41 ++ .../configurations/UctRunConfiguration.java | 245 ++++++++++++ .../UctRunConfigurationOptions.java | 113 ++++++ .../UctRunConfigurationType.java | 45 +++ .../configurations/UctSettingsEditor.form | 189 ++++++++++ .../configurations/UctSettingsEditor.java | 349 ++++++++++++++++++ .../execution/filters/UctPhpFileFilter.java | 105 ++++++ .../filters/UctResultFileFilter.java | 104 ++++++ .../settings/UctSettingsService.java | 79 ++++ .../util/module/UctModuleLocatorUtil.java | 149 ++++++++ .../versioning/IssueSeverityLevel.java | 81 ++++ .../versioning/SupportedVersion.java | 67 ++++ 13 files changed, 1570 insertions(+) create mode 100644 src/com/magento/idea/magento2uct/execution/configurations/UctConfigurationFactory.java create mode 100644 src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java create mode 100644 src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java create mode 100644 src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java create mode 100644 src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form create mode 100644 src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java create mode 100644 src/com/magento/idea/magento2uct/execution/filters/UctPhpFileFilter.java create mode 100644 src/com/magento/idea/magento2uct/execution/filters/UctResultFileFilter.java create mode 100644 src/com/magento/idea/magento2uct/settings/UctSettingsService.java create mode 100644 src/com/magento/idea/magento2uct/util/module/UctModuleLocatorUtil.java create mode 100644 src/com/magento/idea/magento2uct/versioning/IssueSeverityLevel.java create mode 100644 src/com/magento/idea/magento2uct/versioning/SupportedVersion.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 8901b735b..b7c9d2ffa 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -116,6 +116,7 @@ + @@ -285,6 +286,8 @@ + + diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctConfigurationFactory.java b/src/com/magento/idea/magento2uct/execution/configurations/UctConfigurationFactory.java new file mode 100644 index 000000000..bf1f333c2 --- /dev/null +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctConfigurationFactory.java @@ -0,0 +1,41 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.execution.configurations; + +import com.intellij.execution.configurations.ConfigurationFactory; +import com.intellij.execution.configurations.ConfigurationType; +import com.intellij.execution.configurations.RunConfiguration; +import com.intellij.openapi.components.BaseState; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class UctConfigurationFactory extends ConfigurationFactory { + + /** + * UCT configuration factory constructor. + * + * @param type ConfigurationType + */ + protected UctConfigurationFactory(final @NotNull ConfigurationType type) { + super(type); + } + + @Override + public @NotNull String getId() { + return UctRunConfigurationType.ID; + } + + @Override + public @NotNull RunConfiguration createTemplateConfiguration(final @NotNull Project project) { + return new UctRunConfiguration(project, this, UctRunConfigurationType.TITLE); + } + + @Override + public @Nullable Class getOptionsClass() { + return UctRunConfigurationOptions.class; + } +} diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java new file mode 100644 index 000000000..d69d6914e --- /dev/null +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java @@ -0,0 +1,245 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.execution.configurations; + +import com.intellij.execution.ExecutionException; +import com.intellij.execution.Executor; +import com.intellij.execution.configurations.CommandLineState; +import com.intellij.execution.configurations.ConfigurationFactory; +import com.intellij.execution.configurations.GeneralCommandLine; +import com.intellij.execution.configurations.LocatableConfigurationBase; +import com.intellij.execution.configurations.RunConfiguration; +import com.intellij.execution.configurations.RunProfileState; +import com.intellij.execution.configurations.RuntimeConfigurationException; +import com.intellij.execution.process.OSProcessHandler; +import com.intellij.execution.process.ProcessHandler; +import com.intellij.execution.process.ProcessHandlerFactory; +import com.intellij.execution.process.ProcessTerminatedListener; +import com.intellij.execution.runners.ExecutionEnvironment; +import com.intellij.openapi.options.SettingsEditor; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.NlsActions; +import com.jetbrains.php.config.PhpProjectConfigurationFacade; +import com.jetbrains.php.config.commandLine.PhpCommandSettings; +import com.jetbrains.php.config.commandLine.PhpCommandSettingsBuilder; +import com.jetbrains.php.config.interpreters.PhpInterpreter; +import com.magento.idea.magento2uct.execution.filters.UctPhpFileFilter; +import com.magento.idea.magento2uct.execution.filters.UctResultFileFilter; +import com.magento.idea.magento2uct.settings.UctSettingsService; +import com.magento.idea.magento2uct.versioning.IssueSeverityLevel; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class UctRunConfiguration extends LocatableConfigurationBase { + + /** + * UCT run configuration constructor. + * + * @param project Project + * @param factory ConfigurationFactory + * @param name String + */ + protected UctRunConfiguration( + final @NotNull Project project, + final @NotNull ConfigurationFactory factory, + final @Nullable String name + ) { + super(project, factory, name); + } + + @Override + protected @NotNull UctRunConfigurationOptions getOptions() { + return (UctRunConfigurationOptions) super.getOptions(); + } + + /** + * Set script name setting. + * + * @param scriptName String + */ + public void setScriptName(final String scriptName) { + getOptions().setScriptName(scriptName); + } + + /** + * Get script name setting. + * + * @return String + */ + public String getScriptName() { + return getOptions().getScriptName(); + } + + /** + * Set project root setting. + * + * @param projectRoot String + */ + public void setProjectRoot(final String projectRoot) { + getOptions().setProjectRoot(projectRoot); + } + + /** + * Get project root setting. + * + * @return String + */ + public String getProjectRoot() { + return getOptions().getProjectRoot(); + } + + /** + * Set coming version setting. + * + * @param comingVersion String + */ + public void setComingVersion(final String comingVersion) { + getOptions().setComingVersion(comingVersion); + } + + /** + * Get coming version setting. + * + * @return String + */ + public String getComingVersion() { + return getOptions().getComingVersion(); + } + + /** + * Set minimum issue severity level setting. + * + * @param minIssueLevel int + */ + public void setMinIssueLevel(final int minIssueLevel) { + getOptions().setMinIssueLevel(minIssueLevel); + } + + /** + * Get minimum issue severity level setting. + * + * @return int + */ + public int getMinIssueLevel() { + return getOptions().getMinIssueLevel(); + } + + /** + * Set ignoring for current version issues setting. + * + * @param hasIgnoreCurrentVersionIssues boolean + */ + public void setHasIgnoreCurrentVersionIssues(final boolean hasIgnoreCurrentVersionIssues) { + getOptions().setHasIgnoreCurrentVersionIssues(hasIgnoreCurrentVersionIssues); + } + + /** + * Check if has ignoring for current version issues setting. + * + * @return boolean + */ + public boolean hasIgnoreCurrentVersionIssues() { + return getOptions().hasIgnoreCurrentVersionIssues(); + } + + @Override + public @NotNull SettingsEditor getConfigurationEditor() { + return new UctSettingsEditor(getProject()); + } + + @Override + public void checkConfiguration() throws RuntimeConfigurationException { + super.checkConfiguration(); + } + + @Override + public @Nullable @NlsActions.ActionText String suggestedName() { + return UctRunConfigurationType.SHORT_TITLE; + } + + @Override + public @Nullable RunProfileState getState( + final @NotNull Executor executor, + final @NotNull ExecutionEnvironment environment + ) throws ExecutionException { + return new CommandLineState(environment) { + + @Override + protected @NotNull ProcessHandler startProcess() throws ExecutionException { + final UctSettingsService settingsService = + UctSettingsService.getInstance(getProject()); + PhpInterpreter interpreter = PhpProjectConfigurationFacade + .getInstance(getProject()) + .getInterpreter(); + + if (interpreter == null) { + throw new ExecutionException( + "Please, specify interpreter option in the PHP settings" + ); + } + + if (getScriptName().isEmpty()) { + throw new ExecutionException("The UCT executable path is not specified"); + } else { + if (settingsService != null) { + settingsService.setUctExecutablePath(getScriptName()); + } + } + + if (getComingVersion().isEmpty()) { + throw new ExecutionException("The coming/target version is not specified"); + } + + if (getProjectRoot().isEmpty()) { + throw new ExecutionException("The project root is not specified"); + } + + final PhpCommandSettings commandSettingsBuilder = + PhpCommandSettingsBuilder.create(getProject(), interpreter, false); + + commandSettingsBuilder.setScript(getScriptName()); + commandSettingsBuilder.addArgument("upgrade:check"); + + if (!getComingVersion().isEmpty()) { + commandSettingsBuilder.addArgument("--coming-version=" + getComingVersion()); + } + + commandSettingsBuilder.addArgument(getProjectRoot()); + + final GeneralCommandLine commandLine = + commandSettingsBuilder.createGeneralCommandLine(); + + final IssueSeverityLevel severityLevel = + IssueSeverityLevel.getByLevel(getMinIssueLevel()); + final IssueSeverityLevel defaultSeverityLevel = + IssueSeverityLevel.getDefaultIssueSeverityLevel(); + + if (!severityLevel.equals(defaultSeverityLevel)) { + commandLine + .addParameter("--min-issue-level=".concat(severityLevel.getLabel())); + } + + if (hasIgnoreCurrentVersionIssues()) { + commandLine.addParameter("--ignore-current-version-compatibility-issues"); + } + commandLine.addParameter("--ansi"); + + final OSProcessHandler processHandler = ProcessHandlerFactory + .getInstance() + .createColoredProcessHandler(commandLine); + + ProcessTerminatedListener.attach(processHandler); + + this.addConsoleFilters( + new UctResultFileFilter(getProject()), + new UctPhpFileFilter(getProject()) + ); + + return processHandler; + } + }; + } +} diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java new file mode 100644 index 000000000..17e9c53fd --- /dev/null +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java @@ -0,0 +1,113 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.execution.configurations; + +import com.intellij.execution.configurations.LocatableRunConfigurationOptions; +import com.intellij.openapi.components.StoredProperty; + +public class UctRunConfigurationOptions extends LocatableRunConfigurationOptions { + + private final StoredProperty myScriptName = string("") + .provideDelegate(this, "scriptName"); + private final StoredProperty projectRoot = string("") + .provideDelegate(this, "projectRoot"); + private final StoredProperty comingVersion = string("") + .provideDelegate(this, "comingVersion"); + private final StoredProperty minIssueLevel = property(3) + .provideDelegate(this, "minIssueLevel"); + private final StoredProperty hasIgnoreCurrentVersionIssues = property(false) + .provideDelegate(this, "hasIgnoreCurrentVersionIssues"); + + /** + * Set script name setting. + * + * @param scriptName String + */ + public void setScriptName(final String scriptName) { + myScriptName.setValue(this, scriptName); + } + + /** + * Get script name setting. + * + * @return String + */ + public String getScriptName() { + return myScriptName.getValue(this) != null ? myScriptName.getValue(this) : ""; + } + + /** + * Set project root setting. + * + * @param projectRoot String + */ + public void setProjectRoot(final String projectRoot) { + this.projectRoot.setValue(this, projectRoot); + } + + /** + * Get project root setting. + * + * @return String + */ + public String getProjectRoot() { + return projectRoot.getValue(this) != null ? projectRoot.getValue(this) : ""; + } + + /** + * Set coming version setting. + * + * @param comingVersion String + */ + public void setComingVersion(final String comingVersion) { + this.comingVersion.setValue(this, comingVersion); + } + + /** + * Get coming version setting. + * + * @return String + */ + public String getComingVersion() { + return comingVersion.getValue(this) != null ? comingVersion.getValue(this) : ""; + } + + /** + * Set minimum issue severity level setting. + * + * @param minIssueLevel int + */ + public void setMinIssueLevel(final int minIssueLevel) { + this.minIssueLevel.setValue(this, minIssueLevel); + } + + /** + * Get minimum issue severity level setting. + * + * @return int + */ + public int getMinIssueLevel() { + return minIssueLevel.getValue(this); + } + + /** + * Set ignoring for current version issues setting. + * + * @param hasIgnoreCurrentVersionIssues boolean + */ + public void setHasIgnoreCurrentVersionIssues(final boolean hasIgnoreCurrentVersionIssues) { + this.hasIgnoreCurrentVersionIssues.setValue(this, hasIgnoreCurrentVersionIssues); + } + + /** + * Check if has ignoring for current version issues setting. + * + * @return boolean + */ + public boolean hasIgnoreCurrentVersionIssues() { + return hasIgnoreCurrentVersionIssues.getValue(this); + } +} diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java new file mode 100644 index 000000000..c10e1e22c --- /dev/null +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java @@ -0,0 +1,45 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.execution.configurations; + +import com.intellij.execution.configurations.ConfigurationFactory; +import com.intellij.execution.configurations.ConfigurationType; +import com.magento.idea.magento2plugin.MagentoIcons; +import javax.swing.Icon; +import org.jetbrains.annotations.NotNull; + +public class UctRunConfigurationType implements ConfigurationType { + + public static final String ID = "UctRunConfigurationType"; + public static final String TITLE = "Upgrade Compatibility Tool"; + public static final String SHORT_TITLE = "UCT Run"; + private static final String DESCRIPTION = "Magento 2 Upgrade Compatibility Tool Configuration"; + + @Override + public @NotNull String getDisplayName() { + return TITLE; + } + + @Override + public String getConfigurationTypeDescription() { + return DESCRIPTION; + } + + @Override + public Icon getIcon() { + return MagentoIcons.ADOBE; + } + + @Override + public @NotNull String getId() { + return ID; + } + + @Override + public ConfigurationFactory[] getConfigurationFactories() { + return new ConfigurationFactory[]{new UctConfigurationFactory(this)}; + } +} diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form new file mode 100644 index 000000000..498854c24 --- /dev/null +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form @@ -0,0 +1,189 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java new file mode 100644 index 000000000..046f79507 --- /dev/null +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java @@ -0,0 +1,349 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.execution.configurations; + +import com.intellij.openapi.fileChooser.FileChooserDescriptor; +import com.intellij.openapi.options.SettingsEditor; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.LabeledComponent; +import com.intellij.openapi.ui.TextBrowseFolderListener; +import com.intellij.openapi.ui.TextFieldWithBrowseButton; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.ui.DocumentAdapter; +import com.intellij.ui.JBColor; +import com.intellij.util.ui.UIUtil; +import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; +import com.magento.idea.magento2uct.settings.UctSettingsService; +import com.magento.idea.magento2uct.util.module.UctModuleLocatorUtil; +import com.magento.idea.magento2uct.versioning.IssueSeverityLevel; +import com.magento.idea.magento2uct.versioning.SupportedVersion; +import java.awt.Color; +import java.nio.file.Path; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JSeparator; +import javax.swing.event.DocumentEvent; +import org.jetbrains.annotations.NotNull; + +public class UctSettingsEditor extends SettingsEditor { + + private final Project project; + private String uctExecutablePath; + private boolean hasNotInnerExecutable; + + private JPanel contentPanel; + private LabeledComponent myScriptName; + private LabeledComponent projectRoot; + private JComboBox comingVersion; + private JComboBox minIssueLevel; + private JRadioButton hasIgnoreCurrentVersionIssues; + private JPanel warningPanel; + private JLabel myScriptNameLabel;//NOPMD + private JLabel comingVersionLabel;//NOPMD + private JLabel myScriptNameError;//NOPMD + private JLabel comingVersionError;//NOPMD + private JLabel minIssueLevelLabel;//NOPMD + private JLabel minIssueLevelComment;//NOPMD + private JLabel hasIgnoreCurrentVersionIssuesComment;//NOPMD + private JLabel hasIgnoreCurrentVersionIssuesComment2;//NOPMD + private JLabel projectRootLabel;//NOPMD + private JLabel projectRootComment;//NOPMD + private JLabel infoLabel;//NOPMD + private JLabel infoLabel2;//NOPMD + private JLabel uctLookupFailedWarning;//NOPMD + + /** + * Form constructor. + * + * @param project Project + */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + public UctSettingsEditor(final @NotNull Project project) { + super(); + this.project = project; + initializeComboboxSources(); + validateSettingsForm(); + infoLabel.setForeground(JBColor.blue); + infoLabel2.setForeground(JBColor.blue); + uctLookupFailedWarning.setForeground(JBColor.orange); + uctLookupFailedWarning.setVisible(false); + warningPanel.setVisible(false); + } + + @Override + protected void resetEditorFrom(final @NotNull UctRunConfiguration uctRunConfiguration) { + lookupUctExecutablePath(uctRunConfiguration); + + if (uctExecutablePath != null) { + myScriptName.getComponent().setText(uctExecutablePath); + } + + if (!uctRunConfiguration.getProjectRoot().isEmpty()) { + projectRoot.getComponent().setText(uctRunConfiguration.getProjectRoot()); + } else { + final String projectRootCandidate = project.getBasePath() != null + ? project.getBasePath() + : ""; + + projectRoot.getComponent().setText(projectRootCandidate); + uctRunConfiguration.setProjectRoot(projectRootCandidate); + } + + if (!uctRunConfiguration.getComingVersion().isEmpty()) { + final String storedComingVersion = uctRunConfiguration.getComingVersion(); + setSelectedValueByItsKey(comingVersion, storedComingVersion); + } + + if (uctRunConfiguration.getMinIssueLevel() > 0) { + final IssueSeverityLevel storedLevel = + IssueSeverityLevel.getByLevel(uctRunConfiguration.getMinIssueLevel()); + setSelectedValueByItsKey(minIssueLevel, String.valueOf(storedLevel.getLevel())); + } + + hasIgnoreCurrentVersionIssues.setSelected( + uctRunConfiguration.hasIgnoreCurrentVersionIssues() + ); + } + + @Override + protected void applyEditorTo(final @NotNull UctRunConfiguration uctRunConfiguration) { + uctRunConfiguration.setScriptName(myScriptName.getComponent().getText()); + uctRunConfiguration.setProjectRoot(projectRoot.getComponent().getText()); + + final ComboBoxItemData selectedComingVersion = + (ComboBoxItemData) comingVersion.getSelectedItem(); + + if (selectedComingVersion != null) { + uctRunConfiguration.setComingVersion(selectedComingVersion.getKey()); + } else { + uctRunConfiguration.setComingVersion(""); + } + + final ComboBoxItemData selectedMinIssueLevel = + (ComboBoxItemData) minIssueLevel.getSelectedItem(); + + if (selectedMinIssueLevel != null) { + int severityLevel = IssueSeverityLevel.getDefaultIssueSeverityLevel().getLevel(); + final String minIssueLevelValue = selectedMinIssueLevel.getKey(); + + if (!minIssueLevelValue.isEmpty()) { + severityLevel = Integer.parseInt(minIssueLevelValue); + } + uctRunConfiguration.setMinIssueLevel(severityLevel); + } + + uctRunConfiguration.setHasIgnoreCurrentVersionIssues( + hasIgnoreCurrentVersionIssues.isSelected() + ); + } + + @Override + protected @NotNull JComponent createEditor() { + return contentPanel; + } + + /** + * Try to find UCT inside the project. + * + * @param uctRunConfiguration UctRunConfiguration + */ + private void lookupUctExecutablePath( + final @NotNull UctRunConfiguration uctRunConfiguration + ) { + final String storedUctExecutable = getStoredUctExecutablePath(uctRunConfiguration); + + if (storedUctExecutable != null) { + uctExecutablePath = storedUctExecutable; + return; + } + final VirtualFile uctExecutableVf = UctModuleLocatorUtil.locateUctExecutable(project); + + if (uctExecutableVf == null) { + warningPanel.setVisible(true); + uctLookupFailedWarning.setVisible(true); + } else { + uctExecutablePath = uctExecutableVf.getPath(); + } + } + + /** + * Get stored UCT executable path (in settings). + * + * @param uctRunConfiguration UctRunConfiguration + * + * @return String + */ + private String getStoredUctExecutablePath( + final @NotNull UctRunConfiguration uctRunConfiguration + ) { + String uctExecutablePath; + + if (!uctRunConfiguration.getScriptName().isEmpty()) { + uctExecutablePath = uctRunConfiguration.getScriptName(); + + if (VfsUtil.findFile(Path.of(uctExecutablePath), false) != null) { + return uctExecutablePath; + } else { + uctRunConfiguration.setScriptName(""); + } + } + final UctSettingsService settingsService = UctSettingsService.getInstance(project); + + if (settingsService == null) { + return null; + } + uctExecutablePath = settingsService.getUctExecutablePath(); + + if (!uctExecutablePath.isEmpty()) { + if (VfsUtil.findFile(Path.of(uctExecutablePath), false) != null) { + return uctExecutablePath; + } else { + settingsService.setUctExecutablePath(""); + } + } + + return null; + } + + /** + * Initialize combobox sources. + */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + private void initializeComboboxSources() { + comingVersion.addItem(new ComboBoxItemData("", "Choose a target version")); + + for (final String version : SupportedVersion.getSupportedVersions()) { + comingVersion.addItem(new ComboBoxItemData(version, version)); + } + + minIssueLevel.addItem( + new ComboBoxItemData("", "Choose a minimum issue level to show in report") + ); + + for (final IssueSeverityLevel level : IssueSeverityLevel.getSeverityLabels()) { + minIssueLevel.addItem( + new ComboBoxItemData(String.valueOf(level.getLevel()), level.getLabel()) + ); + } + } + + /** + * Validate settings form. + */ + private void validateSettingsForm() { + comingVersionError.setText(""); + myScriptNameError.setText(""); + myScriptNameError.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL)); + myScriptNameError.setForeground(new Color(252, 119, 83)); + comingVersionError.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL)); + comingVersionError.setForeground(new Color(252, 119, 83)); + + validateExecutablePathField(); + validateComingVersionField((ComboBoxItemData) comingVersion.getSelectedItem()); + + myScriptName + .getComponent() + .getTextField() + .getDocument() + .addDocumentListener(new DocumentAdapter() { + @SuppressWarnings("PMD.AccessorMethodGeneration") + @Override + protected void textChanged(@NotNull DocumentEvent event) { + validateExecutablePathField(); + } + }); + + comingVersion.addItemListener(event -> { + final ComboBoxItemData selectedItem = (ComboBoxItemData) event.getItem(); + + validateComingVersionField(selectedItem); + }); + } + + /** + * Validate executable path field. + */ + private void validateExecutablePathField() { + final String executableScript = myScriptName.getComponent().getText(); + + if (executableScript.isEmpty()) { + myScriptNameError.setText("Please, specify UCT executable (bin/uct)"); + } else { + uctLookupFailedWarning.setVisible(false); + warningPanel.setVisible(false); + myScriptNameError.setText(""); + } + } + + /** + * Validate coming version field. + * + * @param selectedItem ComboBoxItemData + */ + private void validateComingVersionField(final ComboBoxItemData selectedItem) { + if (selectedItem != null && selectedItem.getKey().isEmpty()) { + comingVersionError.setText("Please, specify target version"); + } else { + comingVersionError.setText(""); + } + } + + /** + * Set selected combobox item by key. + * + * @param comboBox JComboBox[ComboBoxItemData] + * @param key String + */ + private void setSelectedValueByItsKey( + final JComboBox comboBox, + final String key + ) { + for (int index = 0; index < comboBox.getItemCount(); index++) { + if (comboBox.getItemAt(index).getKey().equals(key)) { + comboBox.setSelectedIndex(index); + } + } + } + + private void createUIComponents() { + myScriptName = new LabeledComponent<>(); + myScriptName.setComponent(new TextFieldWithBrowseButton()); + myScriptName + .getComponent() + .addBrowseFolderListener( + new TextBrowseFolderListener( + new FileChooserDescriptor( + true, + false, + false, + false, + false, + false + ) + ) + ); + projectRoot = new LabeledComponent<>(); + projectRoot.setComponent(new TextFieldWithBrowseButton()); + projectRoot + .getComponent() + .addBrowseFolderListener( + new TextBrowseFolderListener( + new FileChooserDescriptor( + false, + true, + false, + false, + false, + false + ) + ) + ); + } +} diff --git a/src/com/magento/idea/magento2uct/execution/filters/UctPhpFileFilter.java b/src/com/magento/idea/magento2uct/execution/filters/UctPhpFileFilter.java new file mode 100644 index 000000000..2c912c525 --- /dev/null +++ b/src/com/magento/idea/magento2uct/execution/filters/UctPhpFileFilter.java @@ -0,0 +1,105 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.execution.filters; + +import com.intellij.execution.filters.FileHyperlinkInfoBase; +import com.intellij.execution.filters.Filter; +import com.intellij.execution.filters.HyperlinkInfo; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; +import java.nio.file.Path; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class UctPhpFileFilter implements Filter { + + private static final String UCT_RESULT_PHP_FILE_LINE_PREFIX = "File:"; + private static final String FILENAME_PATTERN = + "(?:\\p{Alpha}:)?(?:/|\\\\)[^:]*[^:<>/\\?\\\\]+(?:\\.[^:<>/\\?\\\\]+)?"; + private final Project project; + + /** + * UCT result php file filter constructor. + * + * @param project Project + */ + public UctPhpFileFilter( + final @NotNull Project project + ) { + this.project = project; + } + + @Override + public @Nullable Result applyFilter(final @NotNull String line, final int entireLength) { + if (!canContainUctPhpFileLink(line)) { + return null; + } + + final int textStartOffset = entireLength - line.length(); + final Pattern pattern = Pattern.compile(FILENAME_PATTERN); + final Matcher matcher = pattern.matcher(line); + ResultItem item = null; + + while (matcher.find()) { + if (item == null) { + try { + final String filePathCandidate = matcher.group(0).trim(); + final int matchedStart = line.indexOf(filePathCandidate); + final int matchedEnd = matchedStart + filePathCandidate.length(); + + item = new ResultItem( + textStartOffset + matchedStart, + textStartOffset + matchedEnd, + buildHyperLinkInfo(filePathCandidate) + ); + } catch (IllegalStateException | IndexOutOfBoundsException exception) { + // go to the next finding. + } + } + } + + if (item != null) { + return new Result( + item.getHighlightStartOffset(), + item.getHighlightEndOffset(), + item.getHyperlinkInfo() + ); + } + + return null; + } + + /** + * Build hyper link info. + * + * @param filePathCandidate String + * + * @return HyperlinkInfo + */ + protected HyperlinkInfo buildHyperLinkInfo(final @NotNull String filePathCandidate) { + return new FileHyperlinkInfoBase(project, 0, 0) { + + @Override + protected @Nullable VirtualFile getVirtualFile() { + return VfsUtil.findFile(Path.of(filePathCandidate), false); + } + }; + } + + /** + * Check if line can contain UCT php file link. + * + * @param line String + * + * @return boolean + */ + private boolean canContainUctPhpFileLink(final @NotNull String line) { + return line.contains(UCT_RESULT_PHP_FILE_LINE_PREFIX); + } +} diff --git a/src/com/magento/idea/magento2uct/execution/filters/UctResultFileFilter.java b/src/com/magento/idea/magento2uct/execution/filters/UctResultFileFilter.java new file mode 100644 index 000000000..1c107868b --- /dev/null +++ b/src/com/magento/idea/magento2uct/execution/filters/UctResultFileFilter.java @@ -0,0 +1,104 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.execution.filters; + +import com.intellij.execution.filters.FileHyperlinkInfoBase; +import com.intellij.execution.filters.Filter; +import com.intellij.execution.filters.HyperlinkInfo; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; +import java.nio.file.Path; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class UctResultFileFilter implements Filter { + + private static final String UCT_RESULT_FILE_FORMAT_PREFIX = "Result exported to '"; + private static final String UCT_RESULT_FILE_FORMAT_REGEX = "Result exported to '(.*)'"; + private final Project project; + + /** + * UCT result file filter constructor. + * + * @param project Project + */ + public UctResultFileFilter( + final @NotNull Project project + ) { + this.project = project; + } + + @Override + public @Nullable Result applyFilter(final @NotNull String line, final int entireLength) { + if (!canContainUctResult(line)) { + return null; + } + + final int textStartOffset = entireLength - line.length(); + final Pattern pattern = Pattern.compile(UCT_RESULT_FILE_FORMAT_REGEX); + final Matcher matcher = pattern.matcher(line); + ResultItem item = null; + + while (matcher.find()) { + if (item == null) { + try { + final String filePathCandidate = matcher.group(1); + final int matchedStart = line.indexOf(filePathCandidate); + final int matchedEnd = matchedStart + filePathCandidate.length(); + + item = new ResultItem( + textStartOffset + matchedStart, + textStartOffset + matchedEnd, + buildHyperLinkInfo(filePathCandidate) + ); + } catch (IllegalStateException | IndexOutOfBoundsException exception) { + // go to the next finding. + } + } + } + + if (item != null) { + return new Result( + item.getHighlightStartOffset(), + item.getHighlightEndOffset(), + item.getHyperlinkInfo() + ); + } + + return null; + } + + /** + * Build hyper link info. + * + * @param filePathCandidate String + * + * @return HyperlinkInfo + */ + protected HyperlinkInfo buildHyperLinkInfo(final @NotNull String filePathCandidate) { + return new FileHyperlinkInfoBase(project, 0, 0) { + + @Override + protected @Nullable VirtualFile getVirtualFile() { + return VfsUtil.findFile(Path.of(filePathCandidate), false); + } + }; + } + + /** + * Check if line can contain UCT result file link. + * + * @param line String + * + * @return boolean + */ + private boolean canContainUctResult(final @NotNull String line) { + return line.contains(UCT_RESULT_FILE_FORMAT_PREFIX); + } +} diff --git a/src/com/magento/idea/magento2uct/settings/UctSettingsService.java b/src/com/magento/idea/magento2uct/settings/UctSettingsService.java new file mode 100644 index 000000000..2f6ffe870 --- /dev/null +++ b/src/com/magento/idea/magento2uct/settings/UctSettingsService.java @@ -0,0 +1,79 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.settings; + +import com.intellij.openapi.components.PersistentStateComponent; +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.components.State; +import com.intellij.openapi.components.Storage; +import com.intellij.openapi.project.Project; +import com.intellij.util.xmlb.XmlSerializerUtil; +import com.intellij.util.xmlb.annotations.Property; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@State(name = "Magento2UctSettings", storages = @Storage(UctSettingsService.M2_UCT_SETTINGS_XML)) +public class UctSettingsService implements PersistentStateComponent { + + public static final String M2_UCT_SETTINGS_XML = "magento2uct.xml"; + + @Property + private String uctExecutablePath; + + /** + * UCT run configuration independent settings storage constructor. + */ + public UctSettingsService() { + } + + /** + * UCT run configuration independent settings storage constructor. + * + * @param uctExecutablePath String + */ + public UctSettingsService(final String uctExecutablePath) { + this.uctExecutablePath = uctExecutablePath; + } + + /** + * Get settings service. + * + * @param project Project + * + * @return UctSettingsService + */ + public @Nullable static UctSettingsService getInstance(final @NotNull Project project) { + return ServiceManager.getService(project, UctSettingsService.class); + } + + /** + * Get UCT executable path for the project. + * + * @return String + */ + public String getUctExecutablePath() { + return !uctExecutablePath.isEmpty() ? uctExecutablePath : ""; + } + + /** + * Set UCT executable path. + * + * @param uctExecutablePath String + */ + public void setUctExecutablePath(final String uctExecutablePath) { + this.uctExecutablePath = uctExecutablePath; + } + + @Override + public @Nullable UctSettingsService getState() { + return this; + } + + @Override + public void loadState(final @NotNull UctSettingsService state) { + XmlSerializerUtil.copyBean(state, this); + } +} diff --git a/src/com/magento/idea/magento2uct/util/module/UctModuleLocatorUtil.java b/src/com/magento/idea/magento2uct/util/module/UctModuleLocatorUtil.java new file mode 100644 index 000000000..6c29fcbc4 --- /dev/null +++ b/src/com/magento/idea/magento2uct/util/module/UctModuleLocatorUtil.java @@ -0,0 +1,149 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.util.module; + +import com.intellij.json.psi.JsonFile; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiManager; +import com.magento.idea.magento2plugin.magento.files.ComposerJson; +import com.magento.idea.magento2plugin.magento.packages.File; +import java.nio.file.Path; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public final class UctModuleLocatorUtil { + + private static final String UCT_COMPOSER_NAME = "magento\\/upgrade-compatibility-tool"; + private static final String UCT_EXECUTABLE_RELATIVE_PATH = "bin" + File.separator + "uct"; + + private UctModuleLocatorUtil() { + } + + /** + * Find UCT executable for the specified project. + * + * @param project Project + * + * @return VirtualFile + */ + public static @Nullable VirtualFile locateUctExecutable(final @NotNull Project project) { + final PsiDirectory uctModuleDir = locateModule(project); + + if (uctModuleDir == null) { + return null; + } + + return VfsUtil.findFile( + Path.of( + uctModuleDir.getVirtualFile().getPath() + + File.separator + + UCT_EXECUTABLE_RELATIVE_PATH + ), + false + ); + } + + /** + * Find UCT module base directory. + * + * @param project Project + * + * @return PsiDirectory + */ + public static @Nullable PsiDirectory locateModule(final @NotNull Project project) { + final String projectBasePath = project.getBasePath(); + + if (projectBasePath == null) { + return null; + } + final VirtualFile projectBaseVf = VfsUtil.findFile(Path.of(projectBasePath), false); + + if (projectBaseVf == null) { + return null; + } + final PsiManager psiManager = PsiManager.getInstance(project); + final PsiDirectory projectBaseDir = psiManager.findDirectory(projectBaseVf); + + if (projectBaseDir == null) { + return null; + } + final PsiFile composerConfigurationFile = projectBaseDir.findFile(ComposerJson.FILE_NAME); + + if (composerConfigurationFile instanceof JsonFile) { + final boolean hasUctAsProjectDependency = composerConfigurationFile + .getText() + .contains(UCT_COMPOSER_NAME); + + if (hasUctAsProjectDependency) { + PsiDirectory uctBaseDir = findSubdirectoryByPath( + projectBaseDir, + "vendor".concat(File.separator) + .concat("magento") + .concat(File.separator) + .concat("module-upgrade-compatibility-tool") + ); + if (uctBaseDir == null) { + uctBaseDir = findSubdirectoryByPath( + projectBaseDir, + "app".concat(File.separator) + .concat("code") + .concat(File.separator) + .concat("Magento") + .concat(File.separator) + .concat("UpgradeCompatibilityTool") + ); + } + if (uctBaseDir != null) { + return uctBaseDir; + } + } + + for (final PsiDirectory subDir : projectBaseDir.getSubdirectories()) { + final PsiFile composerFile = subDir.findFile(ComposerJson.FILE_NAME); + + if (composerFile == null) { + continue; + } + final boolean isUctModule = composerFile.getText().contains(UCT_COMPOSER_NAME); + + if (isUctModule) { + return subDir; + } + } + } + + return null; + } + + /** + * Find subdirectory by path. + * + * @param parentDir PsiDirectory + * @param path String + * + * @return PsiDirectory + */ + private static @Nullable PsiDirectory findSubdirectoryByPath( + final @NotNull PsiDirectory parentDir, + final @NotNull String path + ) { + final String[] pathParts = path.split(File.separator); + PsiDirectory lookupDir = parentDir; + + for (final String pathPart : pathParts) { + if (lookupDir == null) { + return null; + } + lookupDir = lookupDir.findSubdirectory(pathPart); + } + + return lookupDir; + } +} diff --git a/src/com/magento/idea/magento2uct/versioning/IssueSeverityLevel.java b/src/com/magento/idea/magento2uct/versioning/IssueSeverityLevel.java new file mode 100644 index 000000000..0844242b1 --- /dev/null +++ b/src/com/magento/idea/magento2uct/versioning/IssueSeverityLevel.java @@ -0,0 +1,81 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.versioning; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +public enum IssueSeverityLevel { + + WARNING(3), + ERROR(2), + CRITICAL(1); + + private final int level; + + /** + * ENUM constructor. + * + * @param level int + */ + IssueSeverityLevel(final int level) { + this.level = level; + } + + /** + * Get severity level. + * + * @return int + */ + public int getLevel() { + return level; + } + + /** + * Get severity label. + * + * @return String + */ + public String getLabel() { + return this.toString(); + } + + /** + * Get issue severity level by level value. + * + * @param level int + * + * @return IssueSeverityLevel + */ + public static IssueSeverityLevel getByLevel(final int level) { + for (final IssueSeverityLevel issueSeverityLevel : IssueSeverityLevel.values()) { + if (issueSeverityLevel.getLevel() == level) { + return issueSeverityLevel; + } + } + + return getDefaultIssueSeverityLevel(); + } + + /** + * Get severity levels. + * + * @return List[IssueSeverityLevel] + */ + public static List getSeverityLabels() { + return new LinkedList<>(Arrays.asList(IssueSeverityLevel.values())); + } + + /** + * Get default issue severity level. + * + * @return IssueSeverityLevel + */ + public static IssueSeverityLevel getDefaultIssueSeverityLevel() { + return WARNING; + } +} diff --git a/src/com/magento/idea/magento2uct/versioning/SupportedVersion.java b/src/com/magento/idea/magento2uct/versioning/SupportedVersion.java new file mode 100644 index 000000000..70a717296 --- /dev/null +++ b/src/com/magento/idea/magento2uct/versioning/SupportedVersion.java @@ -0,0 +1,67 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.versioning; + +import java.util.LinkedList; +import java.util.List; + +public enum SupportedVersion { + + V2_3_0("2.3.0"), + V2_3_1("2.3.1"), + V2_3_2("2.3.2"), + V2_3_2_p2("2.3.2-p2"), + V2_3_3("2.3.3"), + V2_3_3_p1("2.3.3-p1"), + V2_3_4("2.3.4"), + V2_3_4_p1("2.3.4-p1"), + V2_3_4_p2("2.3.4-p2"), + V2_3_5("2.3.5"), + V2_3_5_p1("2.3.5-p1"), + V2_3_5_p2("2.3.5-p2"), + V2_3_6("2.3.6"), + V2_3_6_p1("2.3.6-p1"), + V2_3_7("2.3.7"), + V2_3_7_p1("2.3.7-p1"), + V2_4_0("2.4.0"), + V2_4_0_p1("2.4.0-p1"), + V2_4_1("2.4.1"), + V2_4_1_p1("2.4.1-p1"), + V2_4_2("2.4.2"), + V2_4_2_p1("2.4.2-p1"), + V2_4_2_p2("2.4.2-p2"), + V2_4_3("2.4.3"); + + private final String version; + + SupportedVersion(final String version) { + this.version = version; + } + + /** + * Get version. + * + * @return String + */ + public String getVersion() { + return version; + } + + /** + * Get supported versions. + * + * @return List[String] + */ + public static List getSupportedVersions() { + final List versions = new LinkedList<>(); + + for (final SupportedVersion version : SupportedVersion.values()) { + versions.add(version.getVersion()); + } + + return versions; + } +} From 8203f15389375bf01e10c7afa88b745fea32401d Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Mon, 30 Aug 2021 12:31:58 +0300 Subject: [PATCH 2/5] UCT run configuration development (download UCT if it is not found) --- .../idea/magento2plugin/MagentoIcons.java | 5 + .../execution/DownloadUctCommand.java | 117 ++++++++++++++++++ .../configurations/UctRunConfiguration.java | 33 ++++- .../UctRunConfigurationOptions.java | 20 +++ .../UctRunConfigurationType.java | 2 +- .../configurations/UctSettingsEditor.form | 34 +++-- .../configurations/UctSettingsEditor.java | 54 ++++++-- .../module/UctExecutableValidatorUtil.java | 36 ++++++ 8 files changed, 283 insertions(+), 18 deletions(-) create mode 100644 src/com/magento/idea/magento2uct/execution/DownloadUctCommand.java create mode 100644 src/com/magento/idea/magento2uct/util/module/UctExecutableValidatorUtil.java diff --git a/src/com/magento/idea/magento2plugin/MagentoIcons.java b/src/com/magento/idea/magento2plugin/MagentoIcons.java index 172a8ec79..1f579f1c9 100644 --- a/src/com/magento/idea/magento2plugin/MagentoIcons.java +++ b/src/com/magento/idea/magento2plugin/MagentoIcons.java @@ -10,6 +10,11 @@ @SuppressWarnings({"PMD.ClassNamingConventions"}) public class MagentoIcons { + public static final Icon WEB_API = IconLoader.getIcon("/icons/webapi.png", MagentoIcons.class); public static final Icon MODULE = IconLoader.getIcon("/icons/module.png", MagentoIcons.class); + public static final Icon PLUGIN_ICON = IconLoader.getIcon( + "/META-INF/pluginIcon.svg", + MagentoIcons.class + ); } diff --git a/src/com/magento/idea/magento2uct/execution/DownloadUctCommand.java b/src/com/magento/idea/magento2uct/execution/DownloadUctCommand.java new file mode 100644 index 000000000..2c5484e27 --- /dev/null +++ b/src/com/magento/idea/magento2uct/execution/DownloadUctCommand.java @@ -0,0 +1,117 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.execution; + +import com.intellij.execution.ExecutionException; +import com.intellij.execution.configurations.GeneralCommandLine; +import com.intellij.execution.filters.TextConsoleBuilderFactory; +import com.intellij.execution.process.OSProcessHandler; +import com.intellij.execution.process.ProcessHandlerFactory; +import com.intellij.execution.process.ProcessTerminatedListener; +import com.intellij.execution.ui.ConsoleView; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.wm.RegisterToolWindowTask; +import com.intellij.openapi.wm.ToolWindow; +import com.intellij.openapi.wm.ToolWindowAnchor; +import com.intellij.openapi.wm.ToolWindowId; +import com.intellij.openapi.wm.ToolWindowManager; +import com.intellij.ui.content.Content; +import org.jetbrains.annotations.NotNull; + +public final class DownloadUctCommand { + + private static final String TAB_TITLE = "Create UCT project"; + private final Project project; + + /** + * Download UCT command constructor. + * + * @param project Project + */ + public DownloadUctCommand(final @NotNull Project project) { + this.project = project; + } + + /** + * Start UCT downloading process. + */ + public void execute() { + final ConsoleView consoleView = createConsole(); + try { + final OSProcessHandler processHandler = createProcessHandler(); + consoleView.attachToProcess(processHandler); + processHandler.startNotify(); + } catch (ExecutionException exception) { + //NOPMD + } + } + + /** + * Create process handler. + * + * @return OSProcessHandler + */ + private OSProcessHandler createProcessHandler() throws ExecutionException { + final GeneralCommandLine commandLine = new GeneralCommandLine(); + commandLine.setWorkDirectory(project.getBasePath()); + commandLine.setExePath("composer"); + commandLine.addParameters( + "create-project", + "magento/upgrade-compatibility-tool", + "uct", + "--repository", + "https://repo.magento.com", + "--ansi" + ); + + final OSProcessHandler processHandler = ProcessHandlerFactory + .getInstance() + .createColoredProcessHandler(commandLine); + + ProcessTerminatedListener.attach(processHandler); + + return processHandler; + } + + /** + * Create console view. + * + * @return ConsoleView + */ + private ConsoleView createConsole() { + ToolWindow toolWindow = ToolWindowManager + .getInstance(project) + .getToolWindow(ToolWindowId.RUN); + + if (toolWindow == null) { + toolWindow = ToolWindowManager.getInstance(project).registerToolWindow( + new RegisterToolWindowTask( + ToolWindowId.RUN, + ToolWindowAnchor.BOTTOM, + null, + false, + true, + true, + true, + null, + null, + null + ) + ); + } + final ConsoleView consoleView = TextConsoleBuilderFactory.getInstance() + .createBuilder(project) + .getConsole(); + final Content content = toolWindow + .getContentManager() + .getFactory() + .createContent(consoleView.getComponent(), TAB_TITLE, true); + toolWindow.getContentManager().addContent(content); + toolWindow.show(); + + return consoleView; + } +} diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java index d69d6914e..5421c949d 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java @@ -7,6 +7,7 @@ import com.intellij.execution.ExecutionException; import com.intellij.execution.Executor; +import com.intellij.execution.RunManager; import com.intellij.execution.configurations.CommandLineState; import com.intellij.execution.configurations.ConfigurationFactory; import com.intellij.execution.configurations.GeneralCommandLine; @@ -29,6 +30,7 @@ import com.magento.idea.magento2uct.execution.filters.UctPhpFileFilter; import com.magento.idea.magento2uct.execution.filters.UctResultFileFilter; import com.magento.idea.magento2uct.settings.UctSettingsService; +import com.magento.idea.magento2uct.util.module.UctExecutableValidatorUtil; import com.magento.idea.magento2uct.versioning.IssueSeverityLevel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -145,6 +147,24 @@ public boolean hasIgnoreCurrentVersionIssues() { return getOptions().hasIgnoreCurrentVersionIssues(); } + /** + * Set is settings is newly created. + * + * @param isNewlyCreated boolean + */ + public void setIsNewlyCreated(final boolean isNewlyCreated) { + getOptions().setIsNewlyCreated(isNewlyCreated); + } + + /** + * Check if run configuration settings is newly created setting. + * + * @return boolean + */ + public boolean isNewlyCreated() { + return getOptions().isNewlyCreated(); + } + @Override public @NotNull SettingsEditor getConfigurationEditor() { return new UctSettingsEditor(getProject()); @@ -157,7 +177,10 @@ public void checkConfiguration() throws RuntimeConfigurationException { @Override public @Nullable @NlsActions.ActionText String suggestedName() { - return UctRunConfigurationType.SHORT_TITLE; + return this.getName().isEmpty() ? RunManager.getInstance(getProject()).suggestUniqueName( + UctRunConfigurationType.SHORT_TITLE, + this.getType() + ) : this.getName(); } @Override @@ -181,14 +204,20 @@ public void checkConfiguration() throws RuntimeConfigurationException { ); } + final boolean isValidPath = UctExecutableValidatorUtil.validate(getScriptName()); + if (getScriptName().isEmpty()) { throw new ExecutionException("The UCT executable path is not specified"); } else { - if (settingsService != null) { + if (settingsService != null && isValidPath) { settingsService.setUctExecutablePath(getScriptName()); } } + if (!isValidPath) { + throw new ExecutionException("The UCT executable path is not valid"); + } + if (getComingVersion().isEmpty()) { throw new ExecutionException("The coming/target version is not specified"); } diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java index 17e9c53fd..3136c1888 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java @@ -20,6 +20,8 @@ public class UctRunConfigurationOptions extends LocatableRunConfigurationOptions .provideDelegate(this, "minIssueLevel"); private final StoredProperty hasIgnoreCurrentVersionIssues = property(false) .provideDelegate(this, "hasIgnoreCurrentVersionIssues"); + private final StoredProperty isNewlyCreated = property(true) + .provideDelegate(this, "isNewlyCreated"); /** * Set script name setting. @@ -110,4 +112,22 @@ public void setHasIgnoreCurrentVersionIssues(final boolean hasIgnoreCurrentVersi public boolean hasIgnoreCurrentVersionIssues() { return hasIgnoreCurrentVersionIssues.getValue(this); } + + /** + * Set is settings is newly created. + * + * @param isNewlyCreated boolean + */ + public void setIsNewlyCreated(final boolean isNewlyCreated) { + this.isNewlyCreated.setValue(this, isNewlyCreated); + } + + /** + * Check if run configuration settings is newly created setting. + * + * @return boolean + */ + public boolean isNewlyCreated() { + return isNewlyCreated.getValue(this); + } } diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java index c10e1e22c..cf4a55e46 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java @@ -30,7 +30,7 @@ public String getConfigurationTypeDescription() { @Override public Icon getIcon() { - return MagentoIcons.ADOBE; + return MagentoIcons.PLUGIN_ICON; } @Override diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form index 498854c24..99d59b3a8 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form @@ -3,7 +3,7 @@ - + @@ -135,6 +135,7 @@ + @@ -157,13 +158,13 @@ - - + + - + - + @@ -174,14 +175,33 @@ - + - + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java index 046f79507..95f713da6 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java @@ -5,6 +5,7 @@ package com.magento.idea.magento2uct.execution.configurations; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.project.Project; @@ -17,26 +18,29 @@ import com.intellij.ui.JBColor; import com.intellij.util.ui.UIUtil; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; +import com.magento.idea.magento2uct.execution.DownloadUctCommand; import com.magento.idea.magento2uct.settings.UctSettingsService; +import com.magento.idea.magento2uct.util.module.UctExecutableValidatorUtil; import com.magento.idea.magento2uct.util.module.UctModuleLocatorUtil; import com.magento.idea.magento2uct.versioning.IssueSeverityLevel; import com.magento.idea.magento2uct.versioning.SupportedVersion; import java.awt.Color; +import java.awt.Container; import java.nio.file.Path; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; -import javax.swing.JSeparator; import javax.swing.event.DocumentEvent; +import org.jdesktop.swingx.JXHyperlink; import org.jetbrains.annotations.NotNull; public class UctSettingsEditor extends SettingsEditor { private final Project project; private String uctExecutablePath; - private boolean hasNotInnerExecutable; private JPanel contentPanel; private LabeledComponent myScriptName; @@ -58,6 +62,7 @@ public class UctSettingsEditor extends SettingsEditor { private JLabel infoLabel;//NOPMD private JLabel infoLabel2;//NOPMD private JLabel uctLookupFailedWarning;//NOPMD + private JXHyperlink installTypeOne;//NOPMD /** * Form constructor. @@ -75,6 +80,7 @@ public UctSettingsEditor(final @NotNull Project project) { uctLookupFailedWarning.setForeground(JBColor.orange); uctLookupFailedWarning.setVisible(false); warningPanel.setVisible(false); + installTypeOne.addActionListener(event -> downloadUctAction()); } @Override @@ -83,6 +89,7 @@ protected void resetEditorFrom(final @NotNull UctRunConfiguration uctRunConfigur if (uctExecutablePath != null) { myScriptName.getComponent().setText(uctExecutablePath); + uctRunConfiguration.setScriptName(uctExecutablePath); } if (!uctRunConfiguration.getProjectRoot().isEmpty()) { @@ -114,6 +121,9 @@ protected void resetEditorFrom(final @NotNull UctRunConfiguration uctRunConfigur @Override protected void applyEditorTo(final @NotNull UctRunConfiguration uctRunConfiguration) { + if (uctRunConfiguration.isNewlyCreated()) { + uctRunConfiguration.setIsNewlyCreated(false); + } uctRunConfiguration.setScriptName(myScriptName.getComponent().getText()); uctRunConfiguration.setProjectRoot(projectRoot.getComponent().getText()); @@ -149,6 +159,35 @@ protected void applyEditorTo(final @NotNull UctRunConfiguration uctRunConfigurat return contentPanel; } + /** + * Download UCT action. + */ + private void downloadUctAction() { + ApplicationManager.getApplication().invokeAndWait( + () -> { + final DownloadUctCommand command = new DownloadUctCommand(project); + command.execute(); + } + ); + ApplicationManager.getApplication().invokeAndWait( + () -> { + final Container parent = this.getComponent().getFocusCycleRootAncestor(); + + if (parent != null) { + parent.setVisible(false); + } + JOptionPane.showMessageDialog( + null, + "Open UCT Run Configuration after project updates indexes for newly " + + "created files.\nThe UCT runnable will be " + + "filled automatically.", + "The UCT is installed successfully", + JOptionPane.INFORMATION_MESSAGE + ); + } + ); + } + /** * Try to find UCT inside the project. * @@ -188,11 +227,10 @@ private String getStoredUctExecutablePath( if (!uctRunConfiguration.getScriptName().isEmpty()) { uctExecutablePath = uctRunConfiguration.getScriptName(); - if (VfsUtil.findFile(Path.of(uctExecutablePath), false) != null) { - return uctExecutablePath; - } else { - uctRunConfiguration.setScriptName(""); - } + return uctExecutablePath; + } + if (!uctRunConfiguration.isNewlyCreated()) { + return null; } final UctSettingsService settingsService = UctSettingsService.getInstance(project); @@ -202,7 +240,7 @@ private String getStoredUctExecutablePath( uctExecutablePath = settingsService.getUctExecutablePath(); if (!uctExecutablePath.isEmpty()) { - if (VfsUtil.findFile(Path.of(uctExecutablePath), false) != null) { + if (UctExecutableValidatorUtil.validate(uctExecutablePath)) { return uctExecutablePath; } else { settingsService.setUctExecutablePath(""); diff --git a/src/com/magento/idea/magento2uct/util/module/UctExecutableValidatorUtil.java b/src/com/magento/idea/magento2uct/util/module/UctExecutableValidatorUtil.java new file mode 100644 index 000000000..23c8fe591 --- /dev/null +++ b/src/com/magento/idea/magento2uct/util/module/UctExecutableValidatorUtil.java @@ -0,0 +1,36 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.util.module; + +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; +import java.nio.file.Path; +import org.jetbrains.annotations.NotNull; + +public final class UctExecutableValidatorUtil { + + private static final String UCT_EXECUTABLE_FILENAME = "uct"; + + private UctExecutableValidatorUtil() { + } + + /** + * Check if uct executable candidate is valid. + * + * @param executablePathCandidate String + * + * @return boolean + */ + public static boolean validate(final @NotNull String executablePathCandidate) { + final VirtualFile vfs = VfsUtil.findFile(Path.of(executablePathCandidate), false); + + if (vfs == null) { + return false; + } + + return vfs.getName().equals(UCT_EXECUTABLE_FILENAME); + } +} From 56aecb80c29dac361305c49d4919f069fe514b4f Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 3 Sep 2021 02:13:19 +0300 Subject: [PATCH 3/5] Enhanced UCT run configuration --- resources/META-INF/plugin.xml | 2 +- resources/icons/pluginIcon16x16.svg | 13 ++++ resources/icons/pluginIcon64x64.svg | 13 ++++ .../idea/magento2plugin/MagentoIcons.java | 8 +-- .../execution/DownloadUctCommand.java | 34 +++++++++- .../configurations/UctRunConfiguration.java | 27 ++++++++ .../UctRunConfigurationOptions.java | 20 ++++++ .../UctRunConfigurationType.java | 2 +- .../configurations/UctSettingsEditor.form | 68 +++++++++++++++---- .../configurations/UctSettingsEditor.java | 62 +++++++++-------- .../module/UctModulePathValidatorUtil.java | 34 ++++++++++ 11 files changed, 233 insertions(+), 50 deletions(-) create mode 100644 resources/icons/pluginIcon16x16.svg create mode 100644 resources/icons/pluginIcon64x64.svg create mode 100644 src/com/magento/idea/magento2uct/util/module/UctModulePathValidatorUtil.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index beaede7cf..1ceabdab5 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -24,7 +24,7 @@ - + diff --git a/resources/icons/pluginIcon16x16.svg b/resources/icons/pluginIcon16x16.svg new file mode 100644 index 000000000..b20a279c1 --- /dev/null +++ b/resources/icons/pluginIcon16x16.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/icons/pluginIcon64x64.svg b/resources/icons/pluginIcon64x64.svg new file mode 100644 index 000000000..b3fc9884a --- /dev/null +++ b/resources/icons/pluginIcon64x64.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/com/magento/idea/magento2plugin/MagentoIcons.java b/src/com/magento/idea/magento2plugin/MagentoIcons.java index 1f579f1c9..dc83eab99 100644 --- a/src/com/magento/idea/magento2plugin/MagentoIcons.java +++ b/src/com/magento/idea/magento2plugin/MagentoIcons.java @@ -13,8 +13,8 @@ public class MagentoIcons { public static final Icon WEB_API = IconLoader.getIcon("/icons/webapi.png", MagentoIcons.class); public static final Icon MODULE = IconLoader.getIcon("/icons/module.png", MagentoIcons.class); - public static final Icon PLUGIN_ICON = IconLoader.getIcon( - "/META-INF/pluginIcon.svg", - MagentoIcons.class - ); + public static final Icon PLUGIN_ICON_SMALL = + IconLoader.getIcon("/icons/pluginIcon16x16.svg", MagentoIcons.class); + public static final Icon PLUGIN_ICON_MEDIUM = + IconLoader.getIcon("/icons/pluginIcon64x64.svg", MagentoIcons.class); } diff --git a/src/com/magento/idea/magento2uct/execution/DownloadUctCommand.java b/src/com/magento/idea/magento2uct/execution/DownloadUctCommand.java index 2c5484e27..339e1d312 100644 --- a/src/com/magento/idea/magento2uct/execution/DownloadUctCommand.java +++ b/src/com/magento/idea/magento2uct/execution/DownloadUctCommand.java @@ -7,18 +7,22 @@ import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.GeneralCommandLine; +import com.intellij.execution.configurations.PtyCommandLine; import com.intellij.execution.filters.TextConsoleBuilderFactory; import com.intellij.execution.process.OSProcessHandler; import com.intellij.execution.process.ProcessHandlerFactory; import com.intellij.execution.process.ProcessTerminatedListener; import com.intellij.execution.ui.ConsoleView; +import com.intellij.icons.AllIcons; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.wm.RegisterToolWindowTask; import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowAnchor; import com.intellij.openapi.wm.ToolWindowId; import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.ui.content.Content; +import com.magento.idea.magento2plugin.MagentoIcons; import org.jetbrains.annotations.NotNull; public final class DownloadUctCommand { @@ -55,7 +59,7 @@ public void execute() { * @return OSProcessHandler */ private OSProcessHandler createProcessHandler() throws ExecutionException { - final GeneralCommandLine commandLine = new GeneralCommandLine(); + final GeneralCommandLine commandLine = createGeneralCommandLine(true); commandLine.setWorkDirectory(project.getBasePath()); commandLine.setExePath("composer"); commandLine.addParameters( @@ -76,6 +80,30 @@ private OSProcessHandler createProcessHandler() throws ExecutionException { return processHandler; } + /** + * Create general command line. + * + * @param withPty boolean + * + * @return GeneralCommandLine + */ + private GeneralCommandLine createGeneralCommandLine(boolean withPty) { + GeneralCommandLine commandLine; + + if (withPty) { + if (!SystemInfo.isWindows) { + commandLine = new PtyCommandLine().withInitialColumns(2500); + } else { + commandLine = new GeneralCommandLine(); + commandLine.getEnvironment().putIfAbsent("TERM", "xterm"); + } + } else { + commandLine = new GeneralCommandLine(); + } + + return commandLine; + } + /** * Create console view. * @@ -97,7 +125,7 @@ private ConsoleView createConsole() { true, true, null, - null, + AllIcons.Actions.Execute, null ) ); @@ -109,6 +137,8 @@ private ConsoleView createConsole() { .getContentManager() .getFactory() .createContent(consoleView.getComponent(), TAB_TITLE, true); + content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE); + content.setIcon(MagentoIcons.PLUGIN_ICON_SMALL); toolWindow.getContentManager().addContent(content); toolWindow.show(); diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java index 5421c949d..7948cfe24 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java @@ -31,6 +31,7 @@ import com.magento.idea.magento2uct.execution.filters.UctResultFileFilter; import com.magento.idea.magento2uct.settings.UctSettingsService; import com.magento.idea.magento2uct.util.module.UctExecutableValidatorUtil; +import com.magento.idea.magento2uct.util.module.UctModulePathValidatorUtil; import com.magento.idea.magento2uct.versioning.IssueSeverityLevel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -93,6 +94,24 @@ public String getProjectRoot() { return getOptions().getProjectRoot(); } + /** + * Set path to analyse setting. + * + * @param modulePath String + */ + public void setModulePath(final String modulePath) { + getOptions().setModulePath(modulePath); + } + + /** + * Get path to analyse. + * + * @return String + */ + public String getModulePath() { + return getOptions().getModulePath(); + } + /** * Set coming version setting. * @@ -246,6 +265,14 @@ public void checkConfiguration() throws RuntimeConfigurationException { final IssueSeverityLevel defaultSeverityLevel = IssueSeverityLevel.getDefaultIssueSeverityLevel(); + if (!getModulePath().isEmpty()) { + if (UctModulePathValidatorUtil.validate(getModulePath())) { + commandLine.addParameter("--module-path=".concat(getModulePath())); + } else { + throw new ExecutionException("The path to analyse is not valid"); + } + } + if (!severityLevel.equals(defaultSeverityLevel)) { commandLine .addParameter("--min-issue-level=".concat(severityLevel.getLabel())); diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java index 3136c1888..f0150e9c9 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java @@ -14,6 +14,8 @@ public class UctRunConfigurationOptions extends LocatableRunConfigurationOptions .provideDelegate(this, "scriptName"); private final StoredProperty projectRoot = string("") .provideDelegate(this, "projectRoot"); + private final StoredProperty modulePath = string("") + .provideDelegate(this, "modulePath"); private final StoredProperty comingVersion = string("") .provideDelegate(this, "comingVersion"); private final StoredProperty minIssueLevel = property(3) @@ -59,6 +61,24 @@ public String getProjectRoot() { return projectRoot.getValue(this) != null ? projectRoot.getValue(this) : ""; } + /** + * Set path to analyse setting. + * + * @param modulePath String + */ + public void setModulePath(final String modulePath) { + this.modulePath.setValue(this, modulePath); + } + + /** + * Get path to analyse. + * + * @return String + */ + public String getModulePath() { + return modulePath.getValue(this) != null ? modulePath.getValue(this) : ""; + } + /** * Set coming version setting. * diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java index cf4a55e46..72d56cd20 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java @@ -30,7 +30,7 @@ public String getConfigurationTypeDescription() { @Override public Icon getIcon() { - return MagentoIcons.PLUGIN_ICON; + return MagentoIcons.PLUGIN_ICON_SMALL; } @Override diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form index 99d59b3a8..102f5c938 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form @@ -1,16 +1,16 @@
- + - + - + @@ -23,13 +23,13 @@ - + - + @@ -54,7 +54,7 @@ - + @@ -62,13 +62,13 @@ - + - + @@ -76,7 +76,7 @@ - + @@ -86,7 +86,7 @@ - + @@ -94,7 +94,7 @@ - + @@ -131,7 +131,7 @@ - + @@ -141,7 +141,7 @@ - + @@ -150,7 +150,7 @@ - + @@ -161,7 +161,7 @@ - + @@ -204,6 +204,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java index 95f713da6..f2c1803bf 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java @@ -12,11 +12,11 @@ import com.intellij.openapi.ui.LabeledComponent; import com.intellij.openapi.ui.TextBrowseFolderListener; import com.intellij.openapi.ui.TextFieldWithBrowseButton; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.DocumentAdapter; import com.intellij.ui.JBColor; import com.intellij.util.ui.UIUtil; +import com.magento.idea.magento2plugin.MagentoIcons; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; import com.magento.idea.magento2uct.execution.DownloadUctCommand; import com.magento.idea.magento2uct.settings.UctSettingsService; @@ -26,7 +26,6 @@ import com.magento.idea.magento2uct.versioning.SupportedVersion; import java.awt.Color; import java.awt.Container; -import java.nio.file.Path; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; @@ -45,6 +44,7 @@ public class UctSettingsEditor extends SettingsEditor { private JPanel contentPanel; private LabeledComponent myScriptName; private LabeledComponent projectRoot; + private LabeledComponent modulePath; private JComboBox comingVersion; private JComboBox minIssueLevel; private JRadioButton hasIgnoreCurrentVersionIssues; @@ -63,6 +63,9 @@ public class UctSettingsEditor extends SettingsEditor { private JLabel infoLabel2;//NOPMD private JLabel uctLookupFailedWarning;//NOPMD private JXHyperlink installTypeOne;//NOPMD + private JLabel licenseWarning;//NOPMD + private JLabel modulePathComment;//NOPMD + private JLabel modulePathLabel;//NOPMD /** * Form constructor. @@ -102,6 +105,7 @@ protected void resetEditorFrom(final @NotNull UctRunConfiguration uctRunConfigur projectRoot.getComponent().setText(projectRootCandidate); uctRunConfiguration.setProjectRoot(projectRootCandidate); } + modulePath.getComponent().setText(uctRunConfiguration.getModulePath()); if (!uctRunConfiguration.getComingVersion().isEmpty()) { final String storedComingVersion = uctRunConfiguration.getComingVersion(); @@ -126,6 +130,7 @@ protected void applyEditorTo(final @NotNull UctRunConfiguration uctRunConfigurat } uctRunConfiguration.setScriptName(myScriptName.getComponent().getText()); uctRunConfiguration.setProjectRoot(projectRoot.getComponent().getText()); + uctRunConfiguration.setModulePath(modulePath.getComponent().getText()); final ComboBoxItemData selectedComingVersion = (ComboBoxItemData) comingVersion.getSelectedItem(); @@ -182,7 +187,8 @@ private void downloadUctAction() { + "created files.\nThe UCT runnable will be " + "filled automatically.", "The UCT is installed successfully", - JOptionPane.INFORMATION_MESSAGE + JOptionPane.INFORMATION_MESSAGE, + MagentoIcons.PLUGIN_ICON_MEDIUM ); } ); @@ -350,38 +356,40 @@ private void setSelectedValueByItsKey( } } + @SuppressWarnings({"PMD.UnusedPrivateMethod"}) private void createUIComponents() { myScriptName = new LabeledComponent<>(); myScriptName.setComponent(new TextFieldWithBrowseButton()); myScriptName .getComponent() - .addBrowseFolderListener( - new TextBrowseFolderListener( - new FileChooserDescriptor( - true, - false, - false, - false, - false, - false - ) - ) - ); + .addBrowseFolderListener(new TextBrowseFolderListener(getFileChooserDescriptor())); projectRoot = new LabeledComponent<>(); projectRoot.setComponent(new TextFieldWithBrowseButton()); projectRoot .getComponent() - .addBrowseFolderListener( - new TextBrowseFolderListener( - new FileChooserDescriptor( - false, - true, - false, - false, - false, - false - ) - ) - ); + .addBrowseFolderListener(new TextBrowseFolderListener(getDirChooserDescriptor())); + modulePath = new LabeledComponent<>(); + modulePath.setComponent(new TextFieldWithBrowseButton()); + modulePath + .getComponent() + .addBrowseFolderListener(new TextBrowseFolderListener(getDirChooserDescriptor())); + } + + /** + * Get file chooser descriptor. + * + * @return FileChooserDescriptor + */ + private FileChooserDescriptor getFileChooserDescriptor() { + return new FileChooserDescriptor(false, true, false, false, false, false); + } + + /** + * Get directory chooser descriptor. + * + * @return FileChooserDescriptor + */ + private FileChooserDescriptor getDirChooserDescriptor() { + return new FileChooserDescriptor(false, true, false, false, false, false); } } diff --git a/src/com/magento/idea/magento2uct/util/module/UctModulePathValidatorUtil.java b/src/com/magento/idea/magento2uct/util/module/UctModulePathValidatorUtil.java new file mode 100644 index 000000000..a9ad4b513 --- /dev/null +++ b/src/com/magento/idea/magento2uct/util/module/UctModulePathValidatorUtil.java @@ -0,0 +1,34 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.util.module; + +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; +import java.nio.file.Path; +import org.jetbrains.annotations.NotNull; + +public final class UctModulePathValidatorUtil { + + private UctModulePathValidatorUtil() { + } + + /** + * Check if uct module path candidate is valid. + * + * @param modulePathCandidate String + * + * @return boolean + */ + public static boolean validate(final @NotNull String modulePathCandidate) { + final VirtualFile vfs = VfsUtil.findFile(Path.of(modulePathCandidate), false); + + if (vfs == null) { + return false; + } + + return vfs.isDirectory(); + } +} From 6a2b4615158a5401634961b4304173647193cfc3 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 3 Sep 2021 13:22:54 +0300 Subject: [PATCH 4/5] Added the Learn more link to the Addobe Commerce only message --- .../configurations/UctSettingsEditor.form | 60 +++++++++++++++---- .../configurations/UctSettingsEditor.java | 14 +++++ 2 files changed, 61 insertions(+), 13 deletions(-) diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form index 102f5c938..32764cf43 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form @@ -3,7 +3,7 @@ - + @@ -204,18 +204,6 @@ - - - - - - - - - - - - @@ -242,6 +230,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java index f2c1803bf..d52bcdd7c 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java @@ -26,6 +26,8 @@ import com.magento.idea.magento2uct.versioning.SupportedVersion; import java.awt.Color; import java.awt.Container; +import java.net.URI; +import java.net.URISyntaxException; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; @@ -38,6 +40,10 @@ public class UctSettingsEditor extends SettingsEditor { + private static final String LEARN_MORE_URI = + "https://docs.magento.com/user-guide/getting-started.html#product-editions"; + private static final String LEARN_MORE_TEXT = "Learn more. "; + private final Project project; private String uctExecutablePath; @@ -66,6 +72,8 @@ public class UctSettingsEditor extends SettingsEditor { private JLabel licenseWarning;//NOPMD private JLabel modulePathComment;//NOPMD private JLabel modulePathLabel;//NOPMD + private JXHyperlink learnMoreLink;//NOPMD + private JPanel adobeCommercePanel;//NOPMD /** * Form constructor. @@ -78,6 +86,12 @@ public UctSettingsEditor(final @NotNull Project project) { this.project = project; initializeComboboxSources(); validateSettingsForm(); + try { + learnMoreLink.setURI(new URI(LEARN_MORE_URI)); + learnMoreLink.setText(LEARN_MORE_TEXT); + } catch (URISyntaxException exception) { + learnMoreLink.setVisible(false); + } infoLabel.setForeground(JBColor.blue); infoLabel2.setForeground(JBColor.blue); uctLookupFailedWarning.setForeground(JBColor.orange); From 7eeb20feb7c18081f26e1a8cb5a3fe26de0c5430 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 3 Sep 2021 16:41:33 +0300 Subject: [PATCH 5/5] Static check fixes --- .../execution/DownloadUctCommand.java | 20 +++--- .../UctConfigurationFactory.java | 2 +- .../configurations/UctRunConfiguration.java | 31 +++++---- .../UctRunConfigurationOptions.java | 28 ++++---- .../UctRunConfigurationType.java | 4 +- .../configurations/UctSettingsEditor.form | 2 +- .../configurations/UctSettingsEditor.java | 67 ++++++++++++------- .../execution/filters/UctPhpFileFilter.java | 3 +- .../filters/UctResultFileFilter.java | 3 +- .../settings/UctSettingsService.java | 6 +- .../module/UctExecutableValidatorUtil.java | 2 +- .../util/module/UctModuleLocatorUtil.java | 6 ++ .../versioning/SupportedVersion.java | 48 ++++++------- 13 files changed, 120 insertions(+), 102 deletions(-) diff --git a/src/com/magento/idea/magento2uct/execution/DownloadUctCommand.java b/src/com/magento/idea/magento2uct/execution/DownloadUctCommand.java index 339e1d312..11dd8bb4a 100644 --- a/src/com/magento/idea/magento2uct/execution/DownloadUctCommand.java +++ b/src/com/magento/idea/magento2uct/execution/DownloadUctCommand.java @@ -42,15 +42,11 @@ public DownloadUctCommand(final @NotNull Project project) { /** * Start UCT downloading process. */ - public void execute() { + public void execute() throws ExecutionException { final ConsoleView consoleView = createConsole(); - try { - final OSProcessHandler processHandler = createProcessHandler(); - consoleView.attachToProcess(processHandler); - processHandler.startNotify(); - } catch (ExecutionException exception) { - //NOPMD - } + final OSProcessHandler processHandler = createProcessHandler(); + consoleView.attachToProcess(processHandler); + processHandler.startNotify(); } /** @@ -87,15 +83,15 @@ private OSProcessHandler createProcessHandler() throws ExecutionException { * * @return GeneralCommandLine */ - private GeneralCommandLine createGeneralCommandLine(boolean withPty) { + private GeneralCommandLine createGeneralCommandLine(final boolean withPty) { GeneralCommandLine commandLine; if (withPty) { - if (!SystemInfo.isWindows) { - commandLine = new PtyCommandLine().withInitialColumns(2500); - } else { + if (SystemInfo.isWindows) { commandLine = new GeneralCommandLine(); commandLine.getEnvironment().putIfAbsent("TERM", "xterm"); + } else { + commandLine = new PtyCommandLine().withInitialColumns(2500); } } else { commandLine = new GeneralCommandLine(); diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctConfigurationFactory.java b/src/com/magento/idea/magento2uct/execution/configurations/UctConfigurationFactory.java index bf1f333c2..3508bc4d4 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctConfigurationFactory.java +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctConfigurationFactory.java @@ -26,7 +26,7 @@ protected UctConfigurationFactory(final @NotNull ConfigurationType type) { @Override public @NotNull String getId() { - return UctRunConfigurationType.ID; + return UctRunConfigurationType.RUN_CONFIGURATION_TYPE_ID; } @Override diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java index 7948cfe24..130e37196 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java @@ -14,7 +14,6 @@ import com.intellij.execution.configurations.LocatableConfigurationBase; import com.intellij.execution.configurations.RunConfiguration; import com.intellij.execution.configurations.RunProfileState; -import com.intellij.execution.configurations.RuntimeConfigurationException; import com.intellij.execution.process.OSProcessHandler; import com.intellij.execution.process.ProcessHandler; import com.intellij.execution.process.ProcessHandlerFactory; @@ -36,6 +35,12 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +@SuppressWarnings({ + "PMD.NPathComplexity", + "PMD.CyclomaticComplexity", + "PMD.ExcessiveImports", + "PMD.CognitiveComplexity" +}) public class UctRunConfiguration extends LocatableConfigurationBase { /** @@ -154,7 +159,7 @@ public int getMinIssueLevel() { * @param hasIgnoreCurrentVersionIssues boolean */ public void setHasIgnoreCurrentVersionIssues(final boolean hasIgnoreCurrentVersionIssues) { - getOptions().setHasIgnoreCurrentVersionIssues(hasIgnoreCurrentVersionIssues); + getOptions().setIgnoreCurrentVersionIssues(hasIgnoreCurrentVersionIssues); } /** @@ -172,7 +177,7 @@ public boolean hasIgnoreCurrentVersionIssues() { * @param isNewlyCreated boolean */ public void setIsNewlyCreated(final boolean isNewlyCreated) { - getOptions().setIsNewlyCreated(isNewlyCreated); + getOptions().setNewlyCreated(isNewlyCreated); } /** @@ -189,11 +194,6 @@ public boolean isNewlyCreated() { return new UctSettingsEditor(getProject()); } - @Override - public void checkConfiguration() throws RuntimeConfigurationException { - super.checkConfiguration(); - } - @Override public @Nullable @NlsActions.ActionText String suggestedName() { return this.getName().isEmpty() ? RunManager.getInstance(getProject()).suggestUniqueName( @@ -211,9 +211,7 @@ public void checkConfiguration() throws RuntimeConfigurationException { @Override protected @NotNull ProcessHandler startProcess() throws ExecutionException { - final UctSettingsService settingsService = - UctSettingsService.getInstance(getProject()); - PhpInterpreter interpreter = PhpProjectConfigurationFacade + final PhpInterpreter interpreter = PhpProjectConfigurationFacade .getInstance(getProject()) .getInterpreter(); @@ -224,6 +222,8 @@ public void checkConfiguration() throws RuntimeConfigurationException { } final boolean isValidPath = UctExecutableValidatorUtil.validate(getScriptName()); + final UctSettingsService settingsService = + UctSettingsService.getInstance(getProject()); if (getScriptName().isEmpty()) { throw new ExecutionException("The UCT executable path is not specified"); @@ -260,11 +260,6 @@ public void checkConfiguration() throws RuntimeConfigurationException { final GeneralCommandLine commandLine = commandSettingsBuilder.createGeneralCommandLine(); - final IssueSeverityLevel severityLevel = - IssueSeverityLevel.getByLevel(getMinIssueLevel()); - final IssueSeverityLevel defaultSeverityLevel = - IssueSeverityLevel.getDefaultIssueSeverityLevel(); - if (!getModulePath().isEmpty()) { if (UctModulePathValidatorUtil.validate(getModulePath())) { commandLine.addParameter("--module-path=".concat(getModulePath())); @@ -272,6 +267,10 @@ public void checkConfiguration() throws RuntimeConfigurationException { throw new ExecutionException("The path to analyse is not valid"); } } + final IssueSeverityLevel severityLevel = + IssueSeverityLevel.getByLevel(getMinIssueLevel()); + final IssueSeverityLevel defaultSeverityLevel = + IssueSeverityLevel.getDefaultIssueSeverityLevel(); if (!severityLevel.equals(defaultSeverityLevel)) { commandLine diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java index f0150e9c9..395acbfd5 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java @@ -20,9 +20,9 @@ public class UctRunConfigurationOptions extends LocatableRunConfigurationOptions .provideDelegate(this, "comingVersion"); private final StoredProperty minIssueLevel = property(3) .provideDelegate(this, "minIssueLevel"); - private final StoredProperty hasIgnoreCurrentVersionIssues = property(false) + private final StoredProperty ignoreCurrentVersionIssues = property(false) .provideDelegate(this, "hasIgnoreCurrentVersionIssues"); - private final StoredProperty isNewlyCreated = property(true) + private final StoredProperty newlyCreated = property(true) .provideDelegate(this, "isNewlyCreated"); /** @@ -40,7 +40,7 @@ public void setScriptName(final String scriptName) { * @return String */ public String getScriptName() { - return myScriptName.getValue(this) != null ? myScriptName.getValue(this) : ""; + return myScriptName.getValue(this) == null ? "" : myScriptName.getValue(this); } /** @@ -58,7 +58,7 @@ public void setProjectRoot(final String projectRoot) { * @return String */ public String getProjectRoot() { - return projectRoot.getValue(this) != null ? projectRoot.getValue(this) : ""; + return projectRoot.getValue(this) == null ? "" : projectRoot.getValue(this); } /** @@ -76,7 +76,7 @@ public void setModulePath(final String modulePath) { * @return String */ public String getModulePath() { - return modulePath.getValue(this) != null ? modulePath.getValue(this) : ""; + return modulePath.getValue(this) == null ? "" : modulePath.getValue(this); } /** @@ -94,7 +94,7 @@ public void setComingVersion(final String comingVersion) { * @return String */ public String getComingVersion() { - return comingVersion.getValue(this) != null ? comingVersion.getValue(this) : ""; + return comingVersion.getValue(this) == null ? "" : comingVersion.getValue(this); } /** @@ -118,10 +118,10 @@ public int getMinIssueLevel() { /** * Set ignoring for current version issues setting. * - * @param hasIgnoreCurrentVersionIssues boolean + * @param ignoreCurrentVersionIssues boolean */ - public void setHasIgnoreCurrentVersionIssues(final boolean hasIgnoreCurrentVersionIssues) { - this.hasIgnoreCurrentVersionIssues.setValue(this, hasIgnoreCurrentVersionIssues); + public void setIgnoreCurrentVersionIssues(final boolean ignoreCurrentVersionIssues) { + this.ignoreCurrentVersionIssues.setValue(this, ignoreCurrentVersionIssues); } /** @@ -130,16 +130,16 @@ public void setHasIgnoreCurrentVersionIssues(final boolean hasIgnoreCurrentVersi * @return boolean */ public boolean hasIgnoreCurrentVersionIssues() { - return hasIgnoreCurrentVersionIssues.getValue(this); + return ignoreCurrentVersionIssues.getValue(this); } /** * Set is settings is newly created. * - * @param isNewlyCreated boolean + * @param newlyCreated boolean */ - public void setIsNewlyCreated(final boolean isNewlyCreated) { - this.isNewlyCreated.setValue(this, isNewlyCreated); + public void setNewlyCreated(final boolean newlyCreated) { + this.newlyCreated.setValue(this, newlyCreated); } /** @@ -148,6 +148,6 @@ public void setIsNewlyCreated(final boolean isNewlyCreated) { * @return boolean */ public boolean isNewlyCreated() { - return isNewlyCreated.getValue(this); + return newlyCreated.getValue(this); } } diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java index 72d56cd20..e90a5c5b3 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationType.java @@ -13,7 +13,7 @@ public class UctRunConfigurationType implements ConfigurationType { - public static final String ID = "UctRunConfigurationType"; + public static final String RUN_CONFIGURATION_TYPE_ID = "UctRunConfigurationType"; public static final String TITLE = "Upgrade Compatibility Tool"; public static final String SHORT_TITLE = "UCT Run"; private static final String DESCRIPTION = "Magento 2 Upgrade Compatibility Tool Configuration"; @@ -35,7 +35,7 @@ public Icon getIcon() { @Override public @NotNull String getId() { - return ID; + return RUN_CONFIGURATION_TYPE_ID; } @Override diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form index 32764cf43..0475b56a1 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form @@ -84,7 +84,7 @@ - + diff --git a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java index d52bcdd7c..670f2f2e3 100644 --- a/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java +++ b/src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java @@ -5,6 +5,7 @@ package com.magento.idea.magento2uct.execution.configurations; +import com.intellij.execution.ExecutionException; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.options.SettingsEditor; @@ -38,6 +39,7 @@ import org.jdesktop.swingx.JXHyperlink; import org.jetbrains.annotations.NotNull; +@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"}) public class UctSettingsEditor extends SettingsEditor { private static final String LEARN_MORE_URI = @@ -53,7 +55,7 @@ public class UctSettingsEditor extends SettingsEditor { private LabeledComponent modulePath; private JComboBox comingVersion; private JComboBox minIssueLevel; - private JRadioButton hasIgnoreCurrentVersionIssues; + private JRadioButton ignoreCurrentVersionIssues; private JPanel warningPanel; private JLabel myScriptNameLabel;//NOPMD private JLabel comingVersionLabel;//NOPMD @@ -109,15 +111,15 @@ protected void resetEditorFrom(final @NotNull UctRunConfiguration uctRunConfigur uctRunConfiguration.setScriptName(uctExecutablePath); } - if (!uctRunConfiguration.getProjectRoot().isEmpty()) { - projectRoot.getComponent().setText(uctRunConfiguration.getProjectRoot()); - } else { - final String projectRootCandidate = project.getBasePath() != null - ? project.getBasePath() - : ""; + if (uctRunConfiguration.getProjectRoot().isEmpty()) { + final String projectRootCandidate = project.getBasePath() == null + ? "" + : project.getBasePath(); projectRoot.getComponent().setText(projectRootCandidate); uctRunConfiguration.setProjectRoot(projectRootCandidate); + } else { + projectRoot.getComponent().setText(uctRunConfiguration.getProjectRoot()); } modulePath.getComponent().setText(uctRunConfiguration.getModulePath()); @@ -132,7 +134,7 @@ protected void resetEditorFrom(final @NotNull UctRunConfiguration uctRunConfigur setSelectedValueByItsKey(minIssueLevel, String.valueOf(storedLevel.getLevel())); } - hasIgnoreCurrentVersionIssues.setSelected( + ignoreCurrentVersionIssues.setSelected( uctRunConfiguration.hasIgnoreCurrentVersionIssues() ); } @@ -149,10 +151,10 @@ protected void applyEditorTo(final @NotNull UctRunConfiguration uctRunConfigurat final ComboBoxItemData selectedComingVersion = (ComboBoxItemData) comingVersion.getSelectedItem(); - if (selectedComingVersion != null) { - uctRunConfiguration.setComingVersion(selectedComingVersion.getKey()); - } else { + if (selectedComingVersion == null) { uctRunConfiguration.setComingVersion(""); + } else { + uctRunConfiguration.setComingVersion(selectedComingVersion.getKey()); } final ComboBoxItemData selectedMinIssueLevel = @@ -169,7 +171,7 @@ protected void applyEditorTo(final @NotNull UctRunConfiguration uctRunConfigurat } uctRunConfiguration.setHasIgnoreCurrentVersionIssues( - hasIgnoreCurrentVersionIssues.isSelected() + ignoreCurrentVersionIssues.isSelected() ); } @@ -184,26 +186,41 @@ protected void applyEditorTo(final @NotNull UctRunConfiguration uctRunConfigurat private void downloadUctAction() { ApplicationManager.getApplication().invokeAndWait( () -> { - final DownloadUctCommand command = new DownloadUctCommand(project); - command.execute(); + try { + final DownloadUctCommand command = new DownloadUctCommand(project); + command.execute(); + } catch (ExecutionException exception) { + final Container parent = this.getComponent().getFocusCycleRootAncestor(); + + if (parent != null && parent.isVisible()) { + parent.setVisible(false); + JOptionPane.showMessageDialog( + null, + "Could not install the Upgrade Compatibility Tool " + + "for the current project", + "The UCT installation Error", + JOptionPane.ERROR_MESSAGE + ); + } + } } ); ApplicationManager.getApplication().invokeAndWait( () -> { final Container parent = this.getComponent().getFocusCycleRootAncestor(); - if (parent != null) { + if (parent != null && parent.isVisible()) { parent.setVisible(false); + JOptionPane.showMessageDialog( + null, + "Open UCT Run Configuration after project updates indexes for " + + "newly created files.\nThe UCT runnable will be " + + "filled automatically.", + "The UCT is installed successfully", + JOptionPane.INFORMATION_MESSAGE, + MagentoIcons.PLUGIN_ICON_MEDIUM + ); } - JOptionPane.showMessageDialog( - null, - "Open UCT Run Configuration after project updates indexes for newly " - + "created files.\nThe UCT runnable will be " - + "filled automatically.", - "The UCT is installed successfully", - JOptionPane.INFORMATION_MESSAGE, - MagentoIcons.PLUGIN_ICON_MEDIUM - ); } ); } @@ -313,7 +330,7 @@ private void validateSettingsForm() { .addDocumentListener(new DocumentAdapter() { @SuppressWarnings("PMD.AccessorMethodGeneration") @Override - protected void textChanged(@NotNull DocumentEvent event) { + protected void textChanged(final @NotNull DocumentEvent event) { validateExecutablePathField(); } }); diff --git a/src/com/magento/idea/magento2uct/execution/filters/UctPhpFileFilter.java b/src/com/magento/idea/magento2uct/execution/filters/UctPhpFileFilter.java index 2c912c525..d6561a1d7 100644 --- a/src/com/magento/idea/magento2uct/execution/filters/UctPhpFileFilter.java +++ b/src/com/magento/idea/magento2uct/execution/filters/UctPhpFileFilter.java @@ -35,6 +35,7 @@ public UctPhpFileFilter( this.project = project; } + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") @Override public @Nullable Result applyFilter(final @NotNull String line, final int entireLength) { if (!canContainUctPhpFileLink(line)) { @@ -59,7 +60,7 @@ public UctPhpFileFilter( buildHyperLinkInfo(filePathCandidate) ); } catch (IllegalStateException | IndexOutOfBoundsException exception) { - // go to the next finding. + continue; } } } diff --git a/src/com/magento/idea/magento2uct/execution/filters/UctResultFileFilter.java b/src/com/magento/idea/magento2uct/execution/filters/UctResultFileFilter.java index 1c107868b..16a9e824d 100644 --- a/src/com/magento/idea/magento2uct/execution/filters/UctResultFileFilter.java +++ b/src/com/magento/idea/magento2uct/execution/filters/UctResultFileFilter.java @@ -34,6 +34,7 @@ public UctResultFileFilter( this.project = project; } + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") @Override public @Nullable Result applyFilter(final @NotNull String line, final int entireLength) { if (!canContainUctResult(line)) { @@ -58,7 +59,7 @@ public UctResultFileFilter( buildHyperLinkInfo(filePathCandidate) ); } catch (IllegalStateException | IndexOutOfBoundsException exception) { - // go to the next finding. + continue; } } } diff --git a/src/com/magento/idea/magento2uct/settings/UctSettingsService.java b/src/com/magento/idea/magento2uct/settings/UctSettingsService.java index 2f6ffe870..0242ceead 100644 --- a/src/com/magento/idea/magento2uct/settings/UctSettingsService.java +++ b/src/com/magento/idea/magento2uct/settings/UctSettingsService.java @@ -23,9 +23,7 @@ public class UctSettingsService implements PersistentStateComponent