Skip to content

Commit f869620

Browse files
author
Vitaliy Boyko
committed
Merge remote-tracking branch 'origin/4.4.1-develop' into 5.0.0-pre-release
2 parents ce5e860 + f4e5b6b commit f869620

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

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

8+
import static com.magento.idea.magento2uct.execution.configurations.UctSettingsEditor.MAGENTO_VERSION_PATTERN;
9+
810
import com.intellij.execution.ExecutionException;
911
import com.intellij.execution.Executor;
1012
import com.intellij.execution.RunManager;
@@ -32,6 +34,7 @@
3234
import com.magento.idea.magento2uct.settings.UctSettingsService;
3335
import com.magento.idea.magento2uct.util.UctExecutableValidatorUtil;
3436
import com.magento.idea.magento2uct.util.module.UctModulePathValidatorUtil;
37+
import java.util.regex.Matcher;
3538
import org.jetbrains.annotations.NotNull;
3639
import org.jetbrains.annotations.Nullable;
3740

@@ -241,6 +244,11 @@ public boolean isNewlyCreated() {
241244
throw new ExecutionException("The coming/target version is not specified");
242245
}
243246

247+
final Matcher matcher = MAGENTO_VERSION_PATTERN.matcher(getComingVersion());
248+
if (!matcher.find()) {
249+
throw new ExecutionException("The coming/target version is not correct");
250+
}
251+
244252
if (getProjectRoot().isEmpty()) {
245253
throw new ExecutionException("The project root is not specified");
246254
}
@@ -255,14 +263,12 @@ public boolean isNewlyCreated() {
255263
commandSettingsBuilder.addArgument("--coming-version=" + getComingVersion());
256264
}
257265

258-
commandSettingsBuilder.addArgument(getProjectRoot());
259-
260266
final GeneralCommandLine commandLine =
261267
commandSettingsBuilder.createGeneralCommandLine();
262268

263269
if (!getModulePath().isEmpty()) {
264270
if (UctModulePathValidatorUtil.validate(getModulePath())) {
265-
commandLine.addParameter("--module-path=".concat(getModulePath()));
271+
commandLine.addParameter(getModulePath());
266272
} else {
267273
throw new ExecutionException("The path to analyse is not valid");
268274
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
<constraints>
2626
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
2727
</constraints>
28-
<properties/>
28+
<properties>
29+
<editable value="true"/>
30+
</properties>
2931
</component>
3032
<component id="f6c56" class="javax.swing.JLabel" binding="comingVersionLabel">
3133
<constraints>

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

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
import java.awt.Container;
3030
import java.net.URI;
3131
import java.net.URISyntaxException;
32+
import java.util.Objects;
33+
import java.util.regex.Matcher;
34+
import java.util.regex.Pattern;
3235
import javax.swing.JCheckBox;
3336
import javax.swing.JComboBox;
3437
import javax.swing.JComponent;
@@ -45,6 +48,10 @@ public class UctSettingsEditor extends SettingsEditor<UctRunConfiguration> {
4548
private static final String LEARN_MORE_URI =
4649
"https://docs.magento.com/user-guide/getting-started.html#product-editions";
4750
private static final String LEARN_MORE_TEXT = "Learn more. ";
51+
@SuppressWarnings("checkstyle:LineLength")
52+
private static final String MAGENTO_VERSION_REGEX = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$";
53+
public static final Pattern MAGENTO_VERSION_PATTERN
54+
= Pattern.compile(MAGENTO_VERSION_REGEX);
4855

4956
private final Project project;
5057
private String uctExecutablePath;
@@ -126,6 +133,14 @@ protected void resetEditorFrom(final @NotNull UctRunConfiguration uctRunConfigur
126133
if (!uctRunConfiguration.getComingVersion().isEmpty()) {
127134
final String storedComingVersion = uctRunConfiguration.getComingVersion();
128135
setSelectedValueByItsKey(comingVersion, storedComingVersion);
136+
137+
if (!Objects.requireNonNull(
138+
comingVersion.getSelectedItem()).toString().equals(storedComingVersion)) {
139+
final ComboBoxItemData customVersion
140+
= new ComboBoxItemData(storedComingVersion, storedComingVersion);
141+
comingVersion.addItem(customVersion);
142+
comingVersion.setSelectedItem(customVersion);
143+
}
129144
}
130145

131146
if (uctRunConfiguration.getMinIssueLevel() > 0) {
@@ -148,8 +163,8 @@ protected void applyEditorTo(final @NotNull UctRunConfiguration uctRunConfigurat
148163
uctRunConfiguration.setProjectRoot(projectRoot.getComponent().getText());
149164
uctRunConfiguration.setModulePath(modulePath.getComponent().getText());
150165

151-
final ComboBoxItemData selectedComingVersion =
152-
(ComboBoxItemData) comingVersion.getSelectedItem();
166+
final ComboBoxItemData selectedComingVersion
167+
= getCorrectedSelectedItem(comingVersion.getSelectedItem());
153168

154169
if (selectedComingVersion == null) {
155170
uctRunConfiguration.setComingVersion("");
@@ -299,7 +314,7 @@ private String getStoredUctExecutablePath(
299314
*/
300315
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
301316
private void initializeComboboxSources() {
302-
comingVersion.addItem(new ComboBoxItemData("", "Choose a target version"));
317+
comingVersion.setToolTipText("Choose a target version");
303318

304319
for (final String version : SupportedVersion.getSupportedVersions()) {
305320
comingVersion.addItem(new ComboBoxItemData(version, version));
@@ -339,7 +354,7 @@ protected void textChanged(final @NotNull DocumentEvent event) {
339354
});
340355

341356
comingVersion.addItemListener(event -> {
342-
final ComboBoxItemData selectedItem = (ComboBoxItemData) event.getItem();
357+
final ComboBoxItemData selectedItem = getCorrectedSelectedItem(event.getItem());
343358

344359
validateComingVersionField(selectedItem);
345360
});
@@ -366,13 +381,37 @@ private void validateExecutablePathField() {
366381
* @param selectedItem ComboBoxItemData
367382
*/
368383
private void validateComingVersionField(final ComboBoxItemData selectedItem) {
384+
final Matcher matcher = MAGENTO_VERSION_PATTERN.matcher(selectedItem.getText());
385+
369386
if (selectedItem != null && selectedItem.getKey().isEmpty()) {
370387
comingVersionError.setText("Please, specify target version");
388+
} else if (!matcher.find()) { // NOPMD
389+
comingVersionError.setText("Please, correct target version");
371390
} else {
372391
comingVersionError.setText("");
373392
}
374393
}
375394

395+
/**
396+
* Get existing item or select and convert custom version.
397+
*
398+
* @param selectedItem String|ComboBoxItemData
399+
* @return ComboBoxItemData
400+
*/
401+
private ComboBoxItemData getCorrectedSelectedItem(final Object selectedItem) {
402+
ComboBoxItemData selectedComingVersion;
403+
404+
if (selectedItem instanceof ComboBoxItemData) {
405+
selectedComingVersion = (ComboBoxItemData) selectedItem;
406+
} else {
407+
final String customSelectedVersion = selectedItem.toString();
408+
selectedComingVersion
409+
= new ComboBoxItemData(customSelectedVersion, customSelectedVersion);
410+
}
411+
412+
return selectedComingVersion;
413+
}
414+
376415
/**
377416
* Set selected combobox item by key.
378417
*

0 commit comments

Comments
 (0)