Skip to content

Commit 01db38f

Browse files
authored
Merge pull request #743 from bohdan-harniuk/uct-api-coverage-index
UCT-703: Added API coverage index, indexed Magento 2.3.0-2.4.3
2 parents a1769b2 + 7e73359 commit 01db38f

File tree

11 files changed

+455
-14
lines changed

11 files changed

+455
-14
lines changed
2.81 MB
Binary file not shown.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
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;
910
import com.magento.idea.magento2uct.versioning.indexes.data.ExistenceStateIndex;
11+
import com.magento.idea.magento2uct.versioning.processors.ApiCoverageIndexProcessor;
1012
import com.magento.idea.magento2uct.versioning.processors.DeprecationIndexProcessor;
1113
import com.magento.idea.magento2uct.versioning.processors.ExistenceIndexProcessor;
1214
import com.magento.idea.magento2uct.versioning.processors.IndexProcessor;
@@ -26,6 +28,11 @@ public enum IndexRegistry {
2628
ExistenceStateIndex.class,
2729
new ExistenceIndexProcessor(),
2830
SupportedVersion.getSupportedVersions().toArray(new String[0])
31+
),
32+
API_COVERAGE(
33+
ApiCoverageStateIndex.class,
34+
new ApiCoverageIndexProcessor(),
35+
SupportedVersion.getSupportedVersions().toArray(new String[0])
2936
);
3037

3138
private final String key;

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</constraints>
88
<properties>
99
<enabled value="true"/>
10-
<preferredSize width="380" height="130"/>
10+
<preferredSize width="380" height="180"/>
1111
</properties>
1212
<border type="none"/>
1313
<children>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ private void createUIComponents() {
139139
targetVersion.addItem(new ComboBoxItemData(version, version));
140140
}
141141
targetIndex = new ComboBox<>();
142+
targetIndex.addItem(new ComboBoxItemData("", " --- Choose Target Index --- "));
142143

143144
for (final String key : IndexRegistry.getIndexList()) {
144145
targetIndex.addItem(new ComboBoxItemData(key, key));
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2uct.versioning.indexes.data;
7+
8+
import com.intellij.openapi.util.Pair;
9+
import com.magento.idea.magento2uct.packages.IndexRegistry;
10+
import com.magento.idea.magento2uct.packages.SupportedVersion;
11+
import com.magento.idea.magento2uct.versioning.indexes.storage.FileLoader;
12+
import com.magento.idea.magento2uct.versioning.indexes.storage.IndexLoader;
13+
import com.magento.idea.magento2uct.versioning.indexes.storage.ResourceLoader;
14+
import com.magento.idea.magento2uct.versioning.processors.util.VersioningDataOperationsUtil;
15+
import java.io.IOException;
16+
import java.util.ArrayList;
17+
import java.util.Collections;
18+
import java.util.HashMap;
19+
import java.util.LinkedHashMap;
20+
import java.util.List;
21+
import java.util.Map;
22+
import org.jetbrains.annotations.NotNull;
23+
24+
public class ApiCoverageStateIndex implements VersionStateIndex {
25+
26+
private static final String RESOURCE_DIR = "api";
27+
28+
private final Map<String, Map<String, Boolean>> data;
29+
private final Map<String, String> changelog = new HashMap<>();//NOPMD
30+
private String projectBasePath;
31+
private String version;//NOPMD
32+
33+
public ApiCoverageStateIndex() {
34+
data = new LinkedHashMap<>();
35+
}
36+
37+
/**
38+
* Set project base path.
39+
*
40+
* @param projectBasePath String
41+
*/
42+
public void setProjectBasePath(final @NotNull String projectBasePath) {
43+
this.projectBasePath = projectBasePath;
44+
}
45+
46+
/**
47+
* Get version state after lookup.
48+
*
49+
* @return String
50+
*/
51+
public String getVersion() {
52+
return version;
53+
}
54+
55+
/**
56+
* Get API coverage index data.
57+
*
58+
* @return Map[String, Boolean]
59+
*/
60+
public Map<String, Boolean> getIndexData() {
61+
final Pair<Map<String, Boolean>, Map<String, String>> gatheredData =
62+
VersioningDataOperationsUtil.unionVersionDataWithChangelog(
63+
data,
64+
new ArrayList<>(Collections.singletonList(
65+
SupportedVersion.V230.getVersion()
66+
)),
67+
true
68+
);
69+
70+
return gatheredData.getFirst();
71+
}
72+
73+
@Override
74+
public void load(final @NotNull List<SupportedVersion> versions) {
75+
final IndexLoader<String, Map<String, Boolean>> loader = new ResourceLoader<>(RESOURCE_DIR);
76+
processLoading(versions, loader);
77+
}
78+
79+
@Override
80+
public void loadFromFile(final @NotNull List<SupportedVersion> versions) {
81+
if (projectBasePath == null) {
82+
throw new IllegalArgumentException(
83+
"Project base path is mandatory for loading index data from the file."
84+
);
85+
}
86+
final IndexLoader<String, Map<String, Boolean>> loader = new FileLoader<>(projectBasePath);
87+
processLoading(versions, loader);
88+
}
89+
90+
/**
91+
* Process index loading.
92+
*
93+
* @param versions List[SupportedVersion]
94+
* @param loader IndexLoader
95+
*/
96+
private void processLoading(
97+
final @NotNull List<SupportedVersion> versions,
98+
final IndexLoader<String, Map<String, Boolean>> loader
99+
) {
100+
final IndexRegistry apiIndexInfo = IndexRegistry.getRegistryInfoByClass(
101+
ApiCoverageStateIndex.class
102+
);
103+
assert apiIndexInfo != null;
104+
105+
final String apiIndexesFileName = VersionStateIndex.SINGLE_FILE_NAME_PATTERN
106+
.replace("%key", apiIndexInfo.getKey());
107+
108+
try {
109+
final Map<String, Map<String, Boolean>> loadedData = loader.load(apiIndexesFileName);
110+
111+
if (loadedData == null) {
112+
return;
113+
}
114+
115+
for (final Map.Entry<String, Map<String, Boolean>> loadedEntry
116+
: loadedData.entrySet()) {
117+
final SupportedVersion loadedVersion = SupportedVersion.getVersion(
118+
loadedEntry.getKey()
119+
);
120+
121+
if (loadedVersion == null || !versions.contains(loadedVersion)) {
122+
continue;
123+
}
124+
putIndexData(loadedVersion.getVersion(), loadedEntry.getValue());
125+
}
126+
} catch (IOException | ClassNotFoundException exception) { //NOPMD
127+
// Just go for the next version.
128+
}
129+
}
130+
131+
/**
132+
* Put index for version.
133+
*
134+
* @param version String
135+
* @param indexData Map
136+
*/
137+
private void putIndexData(
138+
final @NotNull String version,
139+
final Map<String, Boolean> indexData
140+
) {
141+
if (indexData != null) {
142+
data.put(version, indexData);
143+
}
144+
}
145+
}

src/com/magento/idea/magento2uct/versioning/indexes/data/DeprecationStateIndex.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package com.magento.idea.magento2uct.versioning.indexes.data;
77

88
import com.intellij.openapi.util.Pair;
9-
import com.magento.idea.magento2plugin.magento.packages.File;
109
import com.magento.idea.magento2uct.packages.IndexRegistry;
1110
import com.magento.idea.magento2uct.packages.SupportedVersion;
1211
import com.magento.idea.magento2uct.versioning.indexes.storage.FileLoader;
@@ -21,8 +20,7 @@
2120

2221
public class DeprecationStateIndex implements VersionStateIndex {
2322

24-
private static final String RESOURCE_PATH = File.separator + "uct"
25-
+ File.separator + "deprecation" + File.separator;
23+
private static final String RESOURCE_DIR = "deprecation";
2624

2725
private final Map<String, Map<String, Boolean>> versioningData;
2826
private String projectBasePath;
@@ -73,7 +71,7 @@ public String getVersion() {
7371

7472
@Override
7573
public void load(final @NotNull List<SupportedVersion> versions) {
76-
final IndexLoader<String, Boolean> loader = new ResourceLoader<>();
74+
final IndexLoader<String, Boolean> loader = new ResourceLoader<>(RESOURCE_DIR);
7775
processLoading(versions, loader);
7876
}
7977

@@ -123,7 +121,7 @@ private void processLoading(
123121
.replace("%version", version.getVersion())
124122
.replace("%key", registrationInfo.getKey());
125123
try {
126-
putIndexData(version.getVersion(), loader.load(RESOURCE_PATH + indexName));
124+
putIndexData(version.getVersion(), loader.load(indexName));
127125
} catch (IOException | ClassNotFoundException exception) { //NOPMD
128126
// Just go for the next version.
129127
}

src/com/magento/idea/magento2uct/versioning/indexes/data/ExistenceStateIndex.java

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

66
package com.magento.idea.magento2uct.versioning.indexes.data;
77

8-
import com.magento.idea.magento2plugin.magento.packages.File;
98
import com.magento.idea.magento2uct.packages.IndexRegistry;
109
import com.magento.idea.magento2uct.packages.SupportedVersion;
1110
import com.magento.idea.magento2uct.versioning.indexes.storage.FileLoader;
@@ -21,8 +20,7 @@
2120

2221
public class ExistenceStateIndex implements VersionStateIndex {
2322

24-
private static final String RESOURCE_PATH = File.separator + "uct"
25-
+ File.separator + "existence" + File.separator;
23+
private static final String RESOURCE_DIR = "existence";
2624

2725
private final Map<String, Map<String, Boolean>> data;
2826
private String projectBasePath;
@@ -81,7 +79,7 @@ public Map<String, Boolean> getIndexData() {
8179

8280
@Override
8381
public void load(final @NotNull List<SupportedVersion> versions) {
84-
final IndexLoader<String, Map<String, Boolean>> loader = new ResourceLoader<>();
82+
final IndexLoader<String, Map<String, Boolean>> loader = new ResourceLoader<>(RESOURCE_DIR);
8583
processLoading(versions, loader);
8684
}
8785

@@ -115,9 +113,7 @@ private void processLoading(
115113
.replace("%key", registrationInfo.getKey());
116114

117115
try {
118-
final Map<String, Map<String, Boolean>> loadedData = loader.load(
119-
RESOURCE_PATH + indexesFileName
120-
);
116+
final Map<String, Map<String, Boolean>> loadedData = loader.load(indexesFileName);
121117

122118
if (loadedData == null) {
123119
return;

src/com/magento/idea/magento2uct/versioning/indexes/storage/ResourceLoader.java

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

66
package com.magento.idea.magento2uct.versioning.indexes.storage;
77

8+
import com.magento.idea.magento2plugin.magento.packages.File;
89
import java.io.IOException;
910
import java.io.InputStream;
1011
import java.io.ObjectInputStream;
@@ -15,12 +16,26 @@
1516

1617
public class ResourceLoader<K, V> implements IndexLoader<K, V> {
1718

19+
private static final String BASE_PATH = File.separator + "uct";
20+
21+
private final String resourcePath;
22+
23+
/**
24+
* Resource loader constructor.
25+
*
26+
* @param baseDir String
27+
*/
28+
public ResourceLoader(final @NotNull String baseDir) {
29+
resourcePath = BASE_PATH + File.separator + baseDir + File.separator;
30+
}
31+
1832
@Override
1933
public @Nullable Map<K, V> load(final @NotNull String resourceName)
2034
throws IOException, ClassNotFoundException {
2135
ObjectInputStream objectInputStream = null;
36+
final String path = resourcePath + resourceName;
2237

23-
try (InputStream inputStream = getClass().getResourceAsStream(resourceName)) { // NOPMD
38+
try (InputStream inputStream = getClass().getResourceAsStream(path)) { // NOPMD
2439
if (inputStream == null) {
2540
return null;
2641
}

0 commit comments

Comments
 (0)