Skip to content

Commit 2c0ce1f

Browse files
committed
Merge branch '4.2.0-develop' of github.com:magento/magento2-phpstorm-plugin into incorrect-display-of-magento-2-version
2 parents c6253a9 + 01db38f commit 2c0ce1f

25 files changed

+1161
-158
lines changed
2.81 MB
Binary file not shown.
15.5 MB
Binary file not shown.

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

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@
1818
import com.magento.idea.magento2uct.execution.scanner.data.ComponentData;
1919
import com.magento.idea.magento2uct.packages.IndexRegistry;
2020
import com.magento.idea.magento2uct.packages.SupportedVersion;
21-
import com.magento.idea.magento2uct.versioning.indexes.IndexRepository;
22-
import com.magento.idea.magento2uct.versioning.indexes.data.DeprecationStateIndex;
23-
import com.magento.idea.magento2uct.versioning.processors.DeprecationIndexProcessor;
24-
import java.util.ArrayList;
25-
import java.util.HashMap;
26-
import java.util.List;
27-
import java.util.Map;
2821
import org.jetbrains.annotations.NotNull;
2922

3023
public class ReindexUctCommand {
@@ -66,52 +59,33 @@ public void processTerminated(final @NotNull ProcessEvent event) {
6659
* Execute command.
6760
*
6861
* @param version SupportedVersion
62+
* @param index IndexRegistry
6963
*/
70-
@SuppressWarnings({"PMD.CognitiveComplexity", "PMD.AvoidInstantiatingObjectsInLoops"})
71-
public void execute(final @NotNull SupportedVersion version) {
64+
@SuppressWarnings({"PMD.AvoidInstantiatingObjectsInLoops"})
65+
public void execute(
66+
final @NotNull SupportedVersion version,
67+
final @NotNull IndexRegistry index
68+
) {
7269
if (project.getBasePath() == null) {
7370
return;
7471
}
7572
output.write("Indexing process...\n\n");
7673

77-
final IndexRepository<String, Boolean> indexRepository = new IndexRepository<>(
78-
project.getBasePath(),
79-
IndexRegistry.DEPRECATION
80-
);
81-
final Map<String, Boolean> deprecationData = new HashMap<>();
82-
8374
ApplicationManager.getApplication().executeOnPooledThread(() -> {
8475
ApplicationManager.getApplication().runReadAction(() -> {
76+
index.getProcessor().clearData();
77+
8578
for (final ComponentData componentData : new ModuleScanner(directory)) {
8679
if (process.isProcessTerminated()) {
8780
return;
8881
}
8982
output.print(output.wrapInfo(componentData.getName()).concat("\n"));
9083

9184
for (final PsiFile psiFile : new ModuleFilesScanner(componentData)) {
92-
deprecationData.putAll(
93-
new DeprecationIndexProcessor().process(psiFile)
94-
);
95-
}
96-
}
97-
98-
if (!deprecationData.isEmpty()) {
99-
final List<SupportedVersion> previousVersions = new ArrayList<>();
100-
101-
for (final SupportedVersion supportedVersion : SupportedVersion.values()) {
102-
if (supportedVersion.compareTo(version) < 0) {
103-
previousVersions.add(supportedVersion);
104-
}
105-
}
106-
final DeprecationStateIndex deprecationIndex = new DeprecationStateIndex();
107-
deprecationIndex.load(previousVersions);
108-
final Map<String, Boolean> previousData = deprecationIndex.getIndexData();
109-
deprecationData.entrySet().removeAll(previousData.entrySet());
110-
111-
if (!deprecationData.isEmpty()) {
112-
indexRepository.put(deprecationData, version.getVersion());
85+
index.getProcessor().process(psiFile);
11386
}
11487
}
88+
index.getProcessor().save(project.getBasePath(), version);
11589

11690
process.destroyProcess();
11791
});

src/com/magento/idea/magento2uct/execution/process/ReindexHandler.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.intellij.openapi.project.Project;
1212
import com.intellij.psi.PsiDirectory;
1313
import com.magento.idea.magento2uct.execution.ReindexUctCommand;
14+
import com.magento.idea.magento2uct.packages.IndexRegistry;
1415
import com.magento.idea.magento2uct.packages.SupportedVersion;
1516
import java.io.OutputStream;
1617
import org.jetbrains.annotations.NotNull;
@@ -27,11 +28,13 @@ public class ReindexHandler extends ProcessHandler {
2728
* @param project Project
2829
* @param directory PsiDirectory
2930
* @param version SupportedVersion
31+
* @param index IndexRegistry
3032
*/
3133
public ReindexHandler(
3234
final @NotNull Project project,
3335
final @NotNull PsiDirectory directory,
34-
final @NotNull SupportedVersion version
36+
final @NotNull SupportedVersion version,
37+
final @NotNull IndexRegistry index
3538
) {
3639
super();
3740
this.project = project;
@@ -40,7 +43,7 @@ public ReindexHandler(
4043
new ProcessAdapter() {
4144
@Override
4245
public void startNotified(final @NotNull ProcessEvent event) {
43-
ReindexHandler.this.execute(version);
46+
ReindexHandler.this.execute(version, index);
4447
}
4548
}
4649
);
@@ -50,15 +53,19 @@ public void startNotified(final @NotNull ProcessEvent event) {
5053
* Run indexing process.
5154
*
5255
* @param version SupportedVersion
56+
* @param index IndexRegistry
5357
*/
54-
public void execute(final @NotNull SupportedVersion version) {
58+
public void execute(
59+
final @NotNull SupportedVersion version,
60+
final @NotNull IndexRegistry index
61+
) {
5562
final ReindexUctCommand command = new ReindexUctCommand(
5663
project,
5764
directory,
5865
new OutputWrapper(this),
5966
this
6067
);
61-
command.execute(version);
68+
command.execute(version, index);
6269
}
6370

6471
@Override

src/com/magento/idea/magento2uct/packages/IndexRegistry.java

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55

66
package com.magento.idea.magento2uct.packages;
77

8+
import com.magento.idea.magento2uct.versioning.indexes.data.ApiCoverageStateIndex;
89
import com.magento.idea.magento2uct.versioning.indexes.data.DeprecationStateIndex;
10+
import com.magento.idea.magento2uct.versioning.indexes.data.ExistenceStateIndex;
11+
import com.magento.idea.magento2uct.versioning.processors.ApiCoverageIndexProcessor;
12+
import com.magento.idea.magento2uct.versioning.processors.DeprecationIndexProcessor;
13+
import com.magento.idea.magento2uct.versioning.processors.ExistenceIndexProcessor;
14+
import com.magento.idea.magento2uct.versioning.processors.IndexProcessor;
15+
import java.util.ArrayList;
916
import java.util.Arrays;
1017
import java.util.List;
1118
import org.jetbrains.annotations.NotNull;
@@ -14,15 +21,32 @@ public enum IndexRegistry {
1421

1522
DEPRECATION(
1623
DeprecationStateIndex.class,
24+
new DeprecationIndexProcessor(),
25+
SupportedVersion.getSupportedVersions().toArray(new String[0])
26+
),
27+
EXISTENCE(
28+
ExistenceStateIndex.class,
29+
new ExistenceIndexProcessor(),
30+
SupportedVersion.getSupportedVersions().toArray(new String[0])
31+
),
32+
API_COVERAGE(
33+
ApiCoverageStateIndex.class,
34+
new ApiCoverageIndexProcessor(),
1735
SupportedVersion.getSupportedVersions().toArray(new String[0])
1836
);
1937

2038
private final String key;
2139
private final Class<?> type;
40+
private final IndexProcessor processor;
2241
private final String[] versions;
2342

24-
IndexRegistry(final Class<?> type, final String... versions) {
43+
IndexRegistry(
44+
final Class<?> type,
45+
final IndexProcessor processor,
46+
final String... versions
47+
) {
2548
this.type = type;
49+
this.processor = processor;
2650
this.versions = Arrays.copyOf(versions, versions.length);
2751
key = this.toString();
2852
}
@@ -45,6 +69,15 @@ public Class<?> getType() {
4569
return type;
4670
}
4771

72+
/**
73+
* Get index processor.
74+
*
75+
* @return IndexProcessor
76+
*/
77+
public IndexProcessor getProcessor() {
78+
return processor;
79+
}
80+
4881
/**
4982
* Get registered versions.
5083
*
@@ -70,4 +103,34 @@ public static IndexRegistry getRegistryInfoByClass(final @NotNull Class<?> index
70103

71104
return null;
72105
}
106+
107+
/**
108+
* Get registry record by index key.
109+
*
110+
* @param key String
111+
*
112+
* @return IndexRegistry
113+
*/
114+
public static IndexRegistry getRegistryInfoByKey(final @NotNull String key) {
115+
try {
116+
return IndexRegistry.valueOf(key);
117+
} catch (IllegalArgumentException exception) {
118+
return null;
119+
}
120+
}
121+
122+
/**
123+
* Get list of available indexes names.
124+
*
125+
* @return List[String]
126+
*/
127+
public static List<String> getIndexList() {
128+
final List<String> list = new ArrayList<>();
129+
130+
for (final IndexRegistry index : IndexRegistry.values()) {
131+
list.add(index.getKey());
132+
}
133+
134+
return list;
135+
}
73136
}

src/com/magento/idea/magento2uct/packages/SupportedVersion.java

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

66
package com.magento.idea.magento2uct.packages;
77

8+
import java.util.ArrayList;
89
import java.util.LinkedList;
910
import java.util.List;
1011
import org.jetbrains.annotations.NotNull;
@@ -82,4 +83,23 @@ public static List<String> getSupportedVersions() {
8283

8384
return versions;
8485
}
86+
87+
/**
88+
* Get previous versions.
89+
*
90+
* @param version SupportedVersion
91+
*
92+
* @return List[SupportedVersion]
93+
*/
94+
public static List<SupportedVersion> getPriorVersions(final SupportedVersion version) {
95+
final List<SupportedVersion> previousVersions = new ArrayList<>();
96+
97+
for (final SupportedVersion supportedVersion : SupportedVersion.values()) {
98+
if (supportedVersion.compareTo(version) < 0) {
99+
previousVersions.add(supportedVersion);
100+
}
101+
}
102+
103+
return previousVersions;
104+
}
85105
}

src/com/magento/idea/magento2uct/ui/ReindexDialog.form

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
</constraints>
88
<properties>
99
<enabled value="true"/>
10-
<preferredSize width="350" height="100"/>
10+
<preferredSize width="380" height="180"/>
1111
</properties>
1212
<border type="none"/>
1313
<children>
14-
<grid id="42064" layout-manager="GridLayoutManager" row-count="3" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
14+
<grid id="42064" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
1515
<margin top="0" left="0" bottom="0" right="0"/>
1616
<constraints>
1717
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -35,25 +35,39 @@
3535
</component>
3636
<component id="d3633" class="javax.swing.JButton" binding="buttonCancel">
3737
<constraints>
38-
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
38+
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
3939
</constraints>
4040
<properties>
4141
<text value="Cancel"/>
4242
</properties>
4343
</component>
4444
<vspacer id="f8358">
4545
<constraints>
46-
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
46+
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
4747
</constraints>
4848
</vspacer>
4949
<component id="a4465" class="javax.swing.JButton" binding="buttonOk">
5050
<constraints>
51-
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
51+
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
5252
</constraints>
5353
<properties>
5454
<text value="Reindex"/>
5555
</properties>
5656
</component>
57+
<component id="e5ded" class="javax.swing.JComboBox" binding="targetIndex" custom-create="true">
58+
<constraints>
59+
<grid row="1" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
60+
</constraints>
61+
<properties/>
62+
</component>
63+
<component id="ba4f8" class="javax.swing.JLabel" binding="targetIndexLabel">
64+
<constraints>
65+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
66+
</constraints>
67+
<properties>
68+
<text value="Target Index"/>
69+
</properties>
70+
</component>
5771
</children>
5872
</grid>
5973
</children>

src/com/magento/idea/magento2uct/ui/ReindexDialog.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.magento.idea.magento2uct.actions.ReindexVersionedIndexesAction;
1414
import com.magento.idea.magento2uct.execution.DefaultExecutor;
1515
import com.magento.idea.magento2uct.execution.process.ReindexHandler;
16+
import com.magento.idea.magento2uct.packages.IndexRegistry;
1617
import com.magento.idea.magento2uct.packages.SupportedVersion;
1718
import java.awt.event.KeyEvent;
1819
import java.awt.event.WindowAdapter;
@@ -32,9 +33,11 @@ public class ReindexDialog extends AbstractDialog {
3233

3334
private JPanel contentPanel;
3435
private JComboBox<ComboBoxItemData> targetVersion;
36+
private JComboBox<ComboBoxItemData> targetIndex;
3537
private JButton buttonOk;
3638
private JButton buttonCancel;
3739
private JLabel targetVersionLabel;//NOPMD
40+
private JLabel targetIndexLabel;//NOPMD
3841

3942
/**
4043
* Reindexing dialog.
@@ -99,21 +102,25 @@ public static void open(
99102
* Execute reindexing action.
100103
*/
101104
private void onOK() {
102-
if (targetVersion.getSelectedItem() == null) {
105+
if (targetVersion.getSelectedItem() == null || targetIndex.getSelectedItem() == null) {
103106
return;
104107
}
105108
final SupportedVersion version = SupportedVersion.getVersion(
106109
targetVersion.getSelectedItem().toString()
107110
);
108-
if (version == null) {
111+
final IndexRegistry index = IndexRegistry.getRegistryInfoByKey(
112+
targetIndex.getSelectedItem().toString()
113+
);
114+
if (version == null || index == null) {
109115
return;
110116
}
111117
final DefaultExecutor executor = new DefaultExecutor(
112118
project,
113119
new ReindexHandler(
114120
project,
115121
directory,
116-
version
122+
version,
123+
index
117124
)
118125
);
119126
executor.run();
@@ -131,5 +138,11 @@ private void createUIComponents() {
131138
for (final String version : SupportedVersion.getSupportedVersions()) {
132139
targetVersion.addItem(new ComboBoxItemData(version, version));
133140
}
141+
targetIndex = new ComboBox<>();
142+
targetIndex.addItem(new ComboBoxItemData("", " --- Choose Target Index --- "));
143+
144+
for (final String key : IndexRegistry.getIndexList()) {
145+
targetIndex.addItem(new ComboBoxItemData(key, key));
146+
}
134147
}
135148
}

src/com/magento/idea/magento2uct/versioning/VersionStateManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ private VersionStateManager(final @NotNull Project project) {
7878
*
7979
* @return boolean
8080
*/
81-
private boolean isValidFor(
81+
@SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
82+
private synchronized boolean isValidFor(
8283
final Boolean isSetIgnoreFlag,
8384
final SupportedVersion currentVersion,
8485
final SupportedVersion targetVersion

0 commit comments

Comments
 (0)