Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added resources/uct/existence/indexes.EXISTENCE.idc
Binary file not shown.
46 changes: 10 additions & 36 deletions src/com/magento/idea/magento2uct/execution/ReindexUctCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@
import com.magento.idea.magento2uct.execution.scanner.data.ComponentData;
import com.magento.idea.magento2uct.packages.IndexRegistry;
import com.magento.idea.magento2uct.packages.SupportedVersion;
import com.magento.idea.magento2uct.versioning.indexes.IndexRepository;
import com.magento.idea.magento2uct.versioning.indexes.data.DeprecationStateIndex;
import com.magento.idea.magento2uct.versioning.processors.DeprecationIndexProcessor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.NotNull;

public class ReindexUctCommand {
Expand Down Expand Up @@ -66,52 +59,33 @@ public void processTerminated(final @NotNull ProcessEvent event) {
* Execute command.
*
* @param version SupportedVersion
* @param index IndexRegistry
*/
@SuppressWarnings({"PMD.CognitiveComplexity", "PMD.AvoidInstantiatingObjectsInLoops"})
public void execute(final @NotNull SupportedVersion version) {
@SuppressWarnings({"PMD.AvoidInstantiatingObjectsInLoops"})
public void execute(
final @NotNull SupportedVersion version,
final @NotNull IndexRegistry index
) {
if (project.getBasePath() == null) {
return;
}
output.write("Indexing process...\n\n");

final IndexRepository<String, Boolean> indexRepository = new IndexRepository<>(
project.getBasePath(),
IndexRegistry.DEPRECATION
);
final Map<String, Boolean> deprecationData = new HashMap<>();

ApplicationManager.getApplication().executeOnPooledThread(() -> {
ApplicationManager.getApplication().runReadAction(() -> {
index.getProcessor().clearData();

for (final ComponentData componentData : new ModuleScanner(directory)) {
if (process.isProcessTerminated()) {
return;
}
output.print(output.wrapInfo(componentData.getName()).concat("\n"));

for (final PsiFile psiFile : new ModuleFilesScanner(componentData)) {
deprecationData.putAll(
new DeprecationIndexProcessor().process(psiFile)
);
}
}

if (!deprecationData.isEmpty()) {
final List<SupportedVersion> previousVersions = new ArrayList<>();

for (final SupportedVersion supportedVersion : SupportedVersion.values()) {
if (supportedVersion.compareTo(version) < 0) {
previousVersions.add(supportedVersion);
}
}
final DeprecationStateIndex deprecationIndex = new DeprecationStateIndex();
deprecationIndex.load(previousVersions);
final Map<String, Boolean> previousData = deprecationIndex.getIndexData();
deprecationData.entrySet().removeAll(previousData.entrySet());

if (!deprecationData.isEmpty()) {
indexRepository.put(deprecationData, version.getVersion());
index.getProcessor().process(psiFile);
}
}
index.getProcessor().save(project.getBasePath(), version);

process.destroyProcess();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDirectory;
import com.magento.idea.magento2uct.execution.ReindexUctCommand;
import com.magento.idea.magento2uct.packages.IndexRegistry;
import com.magento.idea.magento2uct.packages.SupportedVersion;
import java.io.OutputStream;
import org.jetbrains.annotations.NotNull;
Expand All @@ -27,11 +28,13 @@ public class ReindexHandler extends ProcessHandler {
* @param project Project
* @param directory PsiDirectory
* @param version SupportedVersion
* @param index IndexRegistry
*/
public ReindexHandler(
final @NotNull Project project,
final @NotNull PsiDirectory directory,
final @NotNull SupportedVersion version
final @NotNull SupportedVersion version,
final @NotNull IndexRegistry index
) {
super();
this.project = project;
Expand All @@ -40,7 +43,7 @@ public ReindexHandler(
new ProcessAdapter() {
@Override
public void startNotified(final @NotNull ProcessEvent event) {
ReindexHandler.this.execute(version);
ReindexHandler.this.execute(version, index);
}
}
);
Expand All @@ -50,15 +53,19 @@ public void startNotified(final @NotNull ProcessEvent event) {
* Run indexing process.
*
* @param version SupportedVersion
* @param index IndexRegistry
*/
public void execute(final @NotNull SupportedVersion version) {
public void execute(
final @NotNull SupportedVersion version,
final @NotNull IndexRegistry index
) {
final ReindexUctCommand command = new ReindexUctCommand(
project,
directory,
new OutputWrapper(this),
this
);
command.execute(version);
command.execute(version, index);
}

@Override
Expand Down
58 changes: 57 additions & 1 deletion src/com/magento/idea/magento2uct/packages/IndexRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
package com.magento.idea.magento2uct.packages;

import com.magento.idea.magento2uct.versioning.indexes.data.DeprecationStateIndex;
import com.magento.idea.magento2uct.versioning.indexes.data.ExistenceStateIndex;
import com.magento.idea.magento2uct.versioning.processors.DeprecationIndexProcessor;
import com.magento.idea.magento2uct.versioning.processors.ExistenceIndexProcessor;
import com.magento.idea.magento2uct.versioning.processors.IndexProcessor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.jetbrains.annotations.NotNull;
Expand All @@ -14,15 +19,27 @@ public enum IndexRegistry {

DEPRECATION(
DeprecationStateIndex.class,
new DeprecationIndexProcessor(),
SupportedVersion.getSupportedVersions().toArray(new String[0])
),
EXISTENCE(
ExistenceStateIndex.class,
new ExistenceIndexProcessor(),
SupportedVersion.getSupportedVersions().toArray(new String[0])
);

private final String key;
private final Class<?> type;
private final IndexProcessor processor;
private final String[] versions;

IndexRegistry(final Class<?> type, final String... versions) {
IndexRegistry(
final Class<?> type,
final IndexProcessor processor,
final String... versions
) {
this.type = type;
this.processor = processor;
this.versions = Arrays.copyOf(versions, versions.length);
key = this.toString();
}
Expand All @@ -45,6 +62,15 @@ public Class<?> getType() {
return type;
}

/**
* Get index processor.
*
* @return IndexProcessor
*/
public IndexProcessor getProcessor() {
return processor;
}

/**
* Get registered versions.
*
Expand All @@ -70,4 +96,34 @@ public static IndexRegistry getRegistryInfoByClass(final @NotNull Class<?> index

return null;
}

/**
* Get registry record by index key.
*
* @param key String
*
* @return IndexRegistry
*/
public static IndexRegistry getRegistryInfoByKey(final @NotNull String key) {
try {
return IndexRegistry.valueOf(key);
} catch (IllegalArgumentException exception) {
return null;
}
}

/**
* Get list of available indexes names.
*
* @return List[String]
*/
public static List<String> getIndexList() {
final List<String> list = new ArrayList<>();

for (final IndexRegistry index : IndexRegistry.values()) {
list.add(index.getKey());
}

return list;
}
}
24 changes: 19 additions & 5 deletions src/com/magento/idea/magento2uct/ui/ReindexDialog.form
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
</constraints>
<properties>
<enabled value="true"/>
<preferredSize width="350" height="100"/>
<preferredSize width="380" height="130"/>
</properties>
<border type="none"/>
<children>
<grid id="42064" layout-manager="GridLayoutManager" row-count="3" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="42064" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<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"/>
Expand All @@ -35,25 +35,39 @@
</component>
<component id="d3633" class="javax.swing.JButton" binding="buttonCancel">
<constraints>
<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"/>
<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"/>
</constraints>
<properties>
<text value="Cancel"/>
</properties>
</component>
<vspacer id="f8358">
<constraints>
<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"/>
<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"/>
</constraints>
</vspacer>
<component id="a4465" class="javax.swing.JButton" binding="buttonOk">
<constraints>
<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"/>
<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"/>
</constraints>
<properties>
<text value="Reindex"/>
</properties>
</component>
<component id="e5ded" class="javax.swing.JComboBox" binding="targetIndex" custom-create="true">
<constraints>
<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"/>
</constraints>
<properties/>
</component>
<component id="ba4f8" class="javax.swing.JLabel" binding="targetIndexLabel">
<constraints>
<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"/>
</constraints>
<properties>
<text value="Target Index"/>
</properties>
</component>
</children>
</grid>
</children>
Expand Down
18 changes: 15 additions & 3 deletions src/com/magento/idea/magento2uct/ui/ReindexDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.magento.idea.magento2uct.actions.ReindexVersionedIndexesAction;
import com.magento.idea.magento2uct.execution.DefaultExecutor;
import com.magento.idea.magento2uct.execution.process.ReindexHandler;
import com.magento.idea.magento2uct.packages.IndexRegistry;
import com.magento.idea.magento2uct.packages.SupportedVersion;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
Expand All @@ -32,9 +33,11 @@ public class ReindexDialog extends AbstractDialog {

private JPanel contentPanel;
private JComboBox<ComboBoxItemData> targetVersion;
private JComboBox<ComboBoxItemData> targetIndex;
private JButton buttonOk;
private JButton buttonCancel;
private JLabel targetVersionLabel;//NOPMD
private JLabel targetIndexLabel;//NOPMD

/**
* Reindexing dialog.
Expand Down Expand Up @@ -99,21 +102,25 @@ public static void open(
* Execute reindexing action.
*/
private void onOK() {
if (targetVersion.getSelectedItem() == null) {
if (targetVersion.getSelectedItem() == null || targetIndex.getSelectedItem() == null) {
return;
}
final SupportedVersion version = SupportedVersion.getVersion(
targetVersion.getSelectedItem().toString()
);
if (version == null) {
final IndexRegistry index = IndexRegistry.getRegistryInfoByKey(
targetIndex.getSelectedItem().toString()
);
if (version == null || index == null) {
return;
}
final DefaultExecutor executor = new DefaultExecutor(
project,
new ReindexHandler(
project,
directory,
version
version,
index
)
);
executor.run();
Expand All @@ -131,5 +138,10 @@ private void createUIComponents() {
for (final String version : SupportedVersion.getSupportedVersions()) {
targetVersion.addItem(new ComboBoxItemData(version, version));
}
targetIndex = new ComboBox<>();

for (final String key : IndexRegistry.getIndexList()) {
targetIndex.addItem(new ComboBoxItemData(key, key));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ private VersionStateManager(final @NotNull Project project) {
*
* @return boolean
*/
private boolean isValidFor(
@SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
private synchronized boolean isValidFor(
final Boolean isSetIgnoreFlag,
final SupportedVersion currentVersion,
final SupportedVersion targetVersion
Expand Down
30 changes: 0 additions & 30 deletions src/com/magento/idea/magento2uct/versioning/indexes/Storage.java

This file was deleted.

Loading