Skip to content

Commit 158cfa4

Browse files
Static check fixes
1 parent 6a2b461 commit 158cfa4

File tree

11 files changed

+117
-99
lines changed

11 files changed

+117
-99
lines changed

src/com/magento/idea/magento2uct/execution/DownloadUctCommand.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,11 @@ public DownloadUctCommand(final @NotNull Project project) {
4242
/**
4343
* Start UCT downloading process.
4444
*/
45-
public void execute() {
45+
public void execute() throws ExecutionException {
4646
final ConsoleView consoleView = createConsole();
47-
try {
48-
final OSProcessHandler processHandler = createProcessHandler();
49-
consoleView.attachToProcess(processHandler);
50-
processHandler.startNotify();
51-
} catch (ExecutionException exception) {
52-
//NOPMD
53-
}
47+
final OSProcessHandler processHandler = createProcessHandler();
48+
consoleView.attachToProcess(processHandler);
49+
processHandler.startNotify();
5450
}
5551

5652
/**
@@ -87,15 +83,15 @@ private OSProcessHandler createProcessHandler() throws ExecutionException {
8783
*
8884
* @return GeneralCommandLine
8985
*/
90-
private GeneralCommandLine createGeneralCommandLine(boolean withPty) {
86+
private GeneralCommandLine createGeneralCommandLine(final boolean withPty) {
9187
GeneralCommandLine commandLine;
9288

9389
if (withPty) {
94-
if (!SystemInfo.isWindows) {
95-
commandLine = new PtyCommandLine().withInitialColumns(2500);
96-
} else {
90+
if (SystemInfo.isWindows) {
9791
commandLine = new GeneralCommandLine();
9892
commandLine.getEnvironment().putIfAbsent("TERM", "xterm");
93+
} else {
94+
commandLine = new PtyCommandLine().withInitialColumns(2500);
9995
}
10096
} else {
10197
commandLine = new GeneralCommandLine();

src/com/magento/idea/magento2uct/execution/configurations/UctRunConfiguration.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.intellij.execution.configurations.LocatableConfigurationBase;
1515
import com.intellij.execution.configurations.RunConfiguration;
1616
import com.intellij.execution.configurations.RunProfileState;
17-
import com.intellij.execution.configurations.RuntimeConfigurationException;
1817
import com.intellij.execution.process.OSProcessHandler;
1918
import com.intellij.execution.process.ProcessHandler;
2019
import com.intellij.execution.process.ProcessHandlerFactory;
@@ -36,6 +35,12 @@
3635
import org.jetbrains.annotations.NotNull;
3736
import org.jetbrains.annotations.Nullable;
3837

38+
@SuppressWarnings({
39+
"PMD.NPathComplexity",
40+
"PMD.CyclomaticComplexity",
41+
"PMD.ExcessiveImports",
42+
"PMD.CognitiveComplexity"
43+
})
3944
public class UctRunConfiguration extends LocatableConfigurationBase<UctRunConfigurationOptions> {
4045

4146
/**
@@ -154,7 +159,7 @@ public int getMinIssueLevel() {
154159
* @param hasIgnoreCurrentVersionIssues boolean
155160
*/
156161
public void setHasIgnoreCurrentVersionIssues(final boolean hasIgnoreCurrentVersionIssues) {
157-
getOptions().setHasIgnoreCurrentVersionIssues(hasIgnoreCurrentVersionIssues);
162+
getOptions().setIgnoreCurrentVersionIssues(hasIgnoreCurrentVersionIssues);
158163
}
159164

160165
/**
@@ -172,7 +177,7 @@ public boolean hasIgnoreCurrentVersionIssues() {
172177
* @param isNewlyCreated boolean
173178
*/
174179
public void setIsNewlyCreated(final boolean isNewlyCreated) {
175-
getOptions().setIsNewlyCreated(isNewlyCreated);
180+
getOptions().setNewlyCreated(isNewlyCreated);
176181
}
177182

178183
/**
@@ -189,11 +194,6 @@ public boolean isNewlyCreated() {
189194
return new UctSettingsEditor(getProject());
190195
}
191196

192-
@Override
193-
public void checkConfiguration() throws RuntimeConfigurationException {
194-
super.checkConfiguration();
195-
}
196-
197197
@Override
198198
public @Nullable @NlsActions.ActionText String suggestedName() {
199199
return this.getName().isEmpty() ? RunManager.getInstance(getProject()).suggestUniqueName(
@@ -211,9 +211,7 @@ public void checkConfiguration() throws RuntimeConfigurationException {
211211

212212
@Override
213213
protected @NotNull ProcessHandler startProcess() throws ExecutionException {
214-
final UctSettingsService settingsService =
215-
UctSettingsService.getInstance(getProject());
216-
PhpInterpreter interpreter = PhpProjectConfigurationFacade
214+
final PhpInterpreter interpreter = PhpProjectConfigurationFacade
217215
.getInstance(getProject())
218216
.getInterpreter();
219217

@@ -224,6 +222,8 @@ public void checkConfiguration() throws RuntimeConfigurationException {
224222
}
225223

226224
final boolean isValidPath = UctExecutableValidatorUtil.validate(getScriptName());
225+
final UctSettingsService settingsService =
226+
UctSettingsService.getInstance(getProject());
227227

228228
if (getScriptName().isEmpty()) {
229229
throw new ExecutionException("The UCT executable path is not specified");
@@ -260,18 +260,17 @@ public void checkConfiguration() throws RuntimeConfigurationException {
260260
final GeneralCommandLine commandLine =
261261
commandSettingsBuilder.createGeneralCommandLine();
262262

263-
final IssueSeverityLevel severityLevel =
264-
IssueSeverityLevel.getByLevel(getMinIssueLevel());
265-
final IssueSeverityLevel defaultSeverityLevel =
266-
IssueSeverityLevel.getDefaultIssueSeverityLevel();
267-
268263
if (!getModulePath().isEmpty()) {
269264
if (UctModulePathValidatorUtil.validate(getModulePath())) {
270265
commandLine.addParameter("--module-path=".concat(getModulePath()));
271266
} else {
272267
throw new ExecutionException("The path to analyse is not valid");
273268
}
274269
}
270+
final IssueSeverityLevel severityLevel =
271+
IssueSeverityLevel.getByLevel(getMinIssueLevel());
272+
final IssueSeverityLevel defaultSeverityLevel =
273+
IssueSeverityLevel.getDefaultIssueSeverityLevel();
275274

276275
if (!severityLevel.equals(defaultSeverityLevel)) {
277276
commandLine

src/com/magento/idea/magento2uct/execution/configurations/UctRunConfigurationOptions.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public class UctRunConfigurationOptions extends LocatableRunConfigurationOptions
2020
.provideDelegate(this, "comingVersion");
2121
private final StoredProperty<Integer> minIssueLevel = property(3)
2222
.provideDelegate(this, "minIssueLevel");
23-
private final StoredProperty<Boolean> hasIgnoreCurrentVersionIssues = property(false)
23+
private final StoredProperty<Boolean> ignoreCurrentVersionIssues = property(false)
2424
.provideDelegate(this, "hasIgnoreCurrentVersionIssues");
25-
private final StoredProperty<Boolean> isNewlyCreated = property(true)
25+
private final StoredProperty<Boolean> newlyCreated = property(true)
2626
.provideDelegate(this, "isNewlyCreated");
2727

2828
/**
@@ -40,7 +40,7 @@ public void setScriptName(final String scriptName) {
4040
* @return String
4141
*/
4242
public String getScriptName() {
43-
return myScriptName.getValue(this) != null ? myScriptName.getValue(this) : "";
43+
return myScriptName.getValue(this) == null ? "" : myScriptName.getValue(this);
4444
}
4545

4646
/**
@@ -58,7 +58,7 @@ public void setProjectRoot(final String projectRoot) {
5858
* @return String
5959
*/
6060
public String getProjectRoot() {
61-
return projectRoot.getValue(this) != null ? projectRoot.getValue(this) : "";
61+
return projectRoot.getValue(this) == null ? "" : projectRoot.getValue(this);
6262
}
6363

6464
/**
@@ -76,7 +76,7 @@ public void setModulePath(final String modulePath) {
7676
* @return String
7777
*/
7878
public String getModulePath() {
79-
return modulePath.getValue(this) != null ? modulePath.getValue(this) : "";
79+
return modulePath.getValue(this) == null ? "" : modulePath.getValue(this);
8080
}
8181

8282
/**
@@ -94,7 +94,7 @@ public void setComingVersion(final String comingVersion) {
9494
* @return String
9595
*/
9696
public String getComingVersion() {
97-
return comingVersion.getValue(this) != null ? comingVersion.getValue(this) : "";
97+
return comingVersion.getValue(this) == null ? "" : comingVersion.getValue(this);
9898
}
9999

100100
/**
@@ -118,10 +118,10 @@ public int getMinIssueLevel() {
118118
/**
119119
* Set ignoring for current version issues setting.
120120
*
121-
* @param hasIgnoreCurrentVersionIssues boolean
121+
* @param ignoreCurrentVersionIssues boolean
122122
*/
123-
public void setHasIgnoreCurrentVersionIssues(final boolean hasIgnoreCurrentVersionIssues) {
124-
this.hasIgnoreCurrentVersionIssues.setValue(this, hasIgnoreCurrentVersionIssues);
123+
public void setIgnoreCurrentVersionIssues(final boolean ignoreCurrentVersionIssues) {
124+
this.ignoreCurrentVersionIssues.setValue(this, ignoreCurrentVersionIssues);
125125
}
126126

127127
/**
@@ -130,16 +130,16 @@ public void setHasIgnoreCurrentVersionIssues(final boolean hasIgnoreCurrentVersi
130130
* @return boolean
131131
*/
132132
public boolean hasIgnoreCurrentVersionIssues() {
133-
return hasIgnoreCurrentVersionIssues.getValue(this);
133+
return ignoreCurrentVersionIssues.getValue(this);
134134
}
135135

136136
/**
137137
* Set is settings is newly created.
138138
*
139-
* @param isNewlyCreated boolean
139+
* @param newlyCreated boolean
140140
*/
141-
public void setIsNewlyCreated(final boolean isNewlyCreated) {
142-
this.isNewlyCreated.setValue(this, isNewlyCreated);
141+
public void setNewlyCreated(final boolean newlyCreated) {
142+
this.newlyCreated.setValue(this, newlyCreated);
143143
}
144144

145145
/**
@@ -148,6 +148,6 @@ public void setIsNewlyCreated(final boolean isNewlyCreated) {
148148
* @return boolean
149149
*/
150150
public boolean isNewlyCreated() {
151-
return isNewlyCreated.getValue(this);
151+
return newlyCreated.getValue(this);
152152
}
153153
}

src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.form

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<text value="Minimum issue level to show in report. Default is [WARNING]."/>
8585
</properties>
8686
</component>
87-
<component id="18a6c" class="javax.swing.JRadioButton" binding="hasIgnoreCurrentVersionIssues">
87+
<component id="18a6c" class="javax.swing.JRadioButton" binding="ignoreCurrentVersionIssues">
8888
<constraints>
8989
<grid row="10" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
9090
</constraints>

src/com/magento/idea/magento2uct/execution/configurations/UctSettingsEditor.java

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package com.magento.idea.magento2uct.execution.configurations;
77

8+
import com.intellij.execution.ExecutionException;
89
import com.intellij.openapi.application.ApplicationManager;
910
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
1011
import com.intellij.openapi.options.SettingsEditor;
@@ -38,6 +39,7 @@
3839
import org.jdesktop.swingx.JXHyperlink;
3940
import org.jetbrains.annotations.NotNull;
4041

42+
@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"})
4143
public class UctSettingsEditor extends SettingsEditor<UctRunConfiguration> {
4244

4345
private static final String LEARN_MORE_URI =
@@ -53,7 +55,7 @@ public class UctSettingsEditor extends SettingsEditor<UctRunConfiguration> {
5355
private LabeledComponent<TextFieldWithBrowseButton> modulePath;
5456
private JComboBox<ComboBoxItemData> comingVersion;
5557
private JComboBox<ComboBoxItemData> minIssueLevel;
56-
private JRadioButton hasIgnoreCurrentVersionIssues;
58+
private JRadioButton ignoreCurrentVersionIssues;
5759
private JPanel warningPanel;
5860
private JLabel myScriptNameLabel;//NOPMD
5961
private JLabel comingVersionLabel;//NOPMD
@@ -109,15 +111,15 @@ protected void resetEditorFrom(final @NotNull UctRunConfiguration uctRunConfigur
109111
uctRunConfiguration.setScriptName(uctExecutablePath);
110112
}
111113

112-
if (!uctRunConfiguration.getProjectRoot().isEmpty()) {
113-
projectRoot.getComponent().setText(uctRunConfiguration.getProjectRoot());
114-
} else {
115-
final String projectRootCandidate = project.getBasePath() != null
116-
? project.getBasePath()
117-
: "";
114+
if (uctRunConfiguration.getProjectRoot().isEmpty()) {
115+
final String projectRootCandidate = project.getBasePath() == null
116+
? ""
117+
: project.getBasePath();
118118

119119
projectRoot.getComponent().setText(projectRootCandidate);
120120
uctRunConfiguration.setProjectRoot(projectRootCandidate);
121+
} else {
122+
projectRoot.getComponent().setText(uctRunConfiguration.getProjectRoot());
121123
}
122124
modulePath.getComponent().setText(uctRunConfiguration.getModulePath());
123125

@@ -132,7 +134,7 @@ protected void resetEditorFrom(final @NotNull UctRunConfiguration uctRunConfigur
132134
setSelectedValueByItsKey(minIssueLevel, String.valueOf(storedLevel.getLevel()));
133135
}
134136

135-
hasIgnoreCurrentVersionIssues.setSelected(
137+
ignoreCurrentVersionIssues.setSelected(
136138
uctRunConfiguration.hasIgnoreCurrentVersionIssues()
137139
);
138140
}
@@ -149,10 +151,10 @@ protected void applyEditorTo(final @NotNull UctRunConfiguration uctRunConfigurat
149151
final ComboBoxItemData selectedComingVersion =
150152
(ComboBoxItemData) comingVersion.getSelectedItem();
151153

152-
if (selectedComingVersion != null) {
153-
uctRunConfiguration.setComingVersion(selectedComingVersion.getKey());
154-
} else {
154+
if (selectedComingVersion == null) {
155155
uctRunConfiguration.setComingVersion("");
156+
} else {
157+
uctRunConfiguration.setComingVersion(selectedComingVersion.getKey());
156158
}
157159

158160
final ComboBoxItemData selectedMinIssueLevel =
@@ -169,7 +171,7 @@ protected void applyEditorTo(final @NotNull UctRunConfiguration uctRunConfigurat
169171
}
170172

171173
uctRunConfiguration.setHasIgnoreCurrentVersionIssues(
172-
hasIgnoreCurrentVersionIssues.isSelected()
174+
ignoreCurrentVersionIssues.isSelected()
173175
);
174176
}
175177

@@ -184,26 +186,41 @@ protected void applyEditorTo(final @NotNull UctRunConfiguration uctRunConfigurat
184186
private void downloadUctAction() {
185187
ApplicationManager.getApplication().invokeAndWait(
186188
() -> {
187-
final DownloadUctCommand command = new DownloadUctCommand(project);
188-
command.execute();
189+
try {
190+
final DownloadUctCommand command = new DownloadUctCommand(project);
191+
command.execute();
192+
} catch (ExecutionException exception) {
193+
final Container parent = this.getComponent().getFocusCycleRootAncestor();
194+
195+
if (parent != null && parent.isVisible()) {
196+
parent.setVisible(false);
197+
JOptionPane.showMessageDialog(
198+
null,
199+
"Could not install the Upgrade Compatibility Tool "
200+
+ "for the current project",
201+
"The UCT installation Error",
202+
JOptionPane.ERROR_MESSAGE
203+
);
204+
}
205+
}
189206
}
190207
);
191208
ApplicationManager.getApplication().invokeAndWait(
192209
() -> {
193210
final Container parent = this.getComponent().getFocusCycleRootAncestor();
194211

195-
if (parent != null) {
212+
if (parent != null && parent.isVisible()) {
196213
parent.setVisible(false);
214+
JOptionPane.showMessageDialog(
215+
null,
216+
"Open UCT Run Configuration after project updates indexes for "
217+
+ "newly created files.\nThe UCT runnable will be "
218+
+ "filled automatically.",
219+
"The UCT is installed successfully",
220+
JOptionPane.INFORMATION_MESSAGE,
221+
MagentoIcons.PLUGIN_ICON_MEDIUM
222+
);
197223
}
198-
JOptionPane.showMessageDialog(
199-
null,
200-
"Open UCT Run Configuration after project updates indexes for newly "
201-
+ "created files.\nThe UCT runnable will be "
202-
+ "filled automatically.",
203-
"The UCT is installed successfully",
204-
JOptionPane.INFORMATION_MESSAGE,
205-
MagentoIcons.PLUGIN_ICON_MEDIUM
206-
);
207224
}
208225
);
209226
}
@@ -313,7 +330,7 @@ private void validateSettingsForm() {
313330
.addDocumentListener(new DocumentAdapter() {
314331
@SuppressWarnings("PMD.AccessorMethodGeneration")
315332
@Override
316-
protected void textChanged(@NotNull DocumentEvent event) {
333+
protected void textChanged(final @NotNull DocumentEvent event) {
317334
validateExecutablePathField();
318335
}
319336
});

src/com/magento/idea/magento2uct/execution/filters/UctPhpFileFilter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public UctPhpFileFilter(
3535
this.project = project;
3636
}
3737

38+
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
3839
@Override
3940
public @Nullable Result applyFilter(final @NotNull String line, final int entireLength) {
4041
if (!canContainUctPhpFileLink(line)) {
@@ -59,7 +60,7 @@ public UctPhpFileFilter(
5960
buildHyperLinkInfo(filePathCandidate)
6061
);
6162
} catch (IllegalStateException | IndexOutOfBoundsException exception) {
62-
// go to the next finding.
63+
continue;
6364
}
6465
}
6566
}

0 commit comments

Comments
 (0)