Skip to content

Commit a1769b2

Browse files
authored
Merge pull request #740 from bohdan-harniuk/uct-existence-index
[UCT] Developed Existence index
2 parents e26567d + de15743 commit a1769b2

20 files changed

+717
-155
lines changed
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: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
package com.magento.idea.magento2uct.packages;
77

88
import com.magento.idea.magento2uct.versioning.indexes.data.DeprecationStateIndex;
9+
import com.magento.idea.magento2uct.versioning.indexes.data.ExistenceStateIndex;
10+
import com.magento.idea.magento2uct.versioning.processors.DeprecationIndexProcessor;
11+
import com.magento.idea.magento2uct.versioning.processors.ExistenceIndexProcessor;
12+
import com.magento.idea.magento2uct.versioning.processors.IndexProcessor;
13+
import java.util.ArrayList;
914
import java.util.Arrays;
1015
import java.util.List;
1116
import org.jetbrains.annotations.NotNull;
@@ -14,15 +19,27 @@ public enum IndexRegistry {
1419

1520
DEPRECATION(
1621
DeprecationStateIndex.class,
22+
new DeprecationIndexProcessor(),
23+
SupportedVersion.getSupportedVersions().toArray(new String[0])
24+
),
25+
EXISTENCE(
26+
ExistenceStateIndex.class,
27+
new ExistenceIndexProcessor(),
1728
SupportedVersion.getSupportedVersions().toArray(new String[0])
1829
);
1930

2031
private final String key;
2132
private final Class<?> type;
33+
private final IndexProcessor processor;
2234
private final String[] versions;
2335

24-
IndexRegistry(final Class<?> type, final String... versions) {
36+
IndexRegistry(
37+
final Class<?> type,
38+
final IndexProcessor processor,
39+
final String... versions
40+
) {
2541
this.type = type;
42+
this.processor = processor;
2643
this.versions = Arrays.copyOf(versions, versions.length);
2744
key = this.toString();
2845
}
@@ -45,6 +62,15 @@ public Class<?> getType() {
4562
return type;
4663
}
4764

65+
/**
66+
* Get index processor.
67+
*
68+
* @return IndexProcessor
69+
*/
70+
public IndexProcessor getProcessor() {
71+
return processor;
72+
}
73+
4874
/**
4975
* Get registered versions.
5076
*
@@ -70,4 +96,34 @@ public static IndexRegistry getRegistryInfoByClass(final @NotNull Class<?> index
7096

7197
return null;
7298
}
99+
100+
/**
101+
* Get registry record by index key.
102+
*
103+
* @param key String
104+
*
105+
* @return IndexRegistry
106+
*/
107+
public static IndexRegistry getRegistryInfoByKey(final @NotNull String key) {
108+
try {
109+
return IndexRegistry.valueOf(key);
110+
} catch (IllegalArgumentException exception) {
111+
return null;
112+
}
113+
}
114+
115+
/**
116+
* Get list of available indexes names.
117+
*
118+
* @return List[String]
119+
*/
120+
public static List<String> getIndexList() {
121+
final List<String> list = new ArrayList<>();
122+
123+
for (final IndexRegistry index : IndexRegistry.values()) {
124+
list.add(index.getKey());
125+
}
126+
127+
return list;
128+
}
73129
}

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="130"/>
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: 15 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,10 @@ private void createUIComponents() {
131138
for (final String version : SupportedVersion.getSupportedVersions()) {
132139
targetVersion.addItem(new ComboBoxItemData(version, version));
133140
}
141+
targetIndex = new ComboBox<>();
142+
143+
for (final String key : IndexRegistry.getIndexList()) {
144+
targetIndex.addItem(new ComboBoxItemData(key, key));
145+
}
134146
}
135147
}

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

src/com/magento/idea/magento2uct/versioning/indexes/Storage.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)