diff --git a/resources/uct/deprecation/indexes.v2.3.0.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.3.0.DEPRECATION.idc new file mode 100644 index 000000000..3c50f6294 Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.3.0.DEPRECATION.idc differ diff --git a/resources/uct/deprecation/indexes.v2.3.1.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.3.1.DEPRECATION.idc new file mode 100644 index 000000000..7210ae91a Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.3.1.DEPRECATION.idc differ diff --git a/resources/uct/deprecation/indexes.v2.3.2-p2.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.3.2-p2.DEPRECATION.idc new file mode 100644 index 000000000..4b1772c79 Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.3.2-p2.DEPRECATION.idc differ diff --git a/resources/uct/deprecation/indexes.v2.3.2.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.3.2.DEPRECATION.idc new file mode 100644 index 000000000..12e6fd3e5 Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.3.2.DEPRECATION.idc differ diff --git a/resources/uct/deprecation/indexes.v2.3.3-p1.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.3.3-p1.DEPRECATION.idc new file mode 100644 index 000000000..95edb3718 Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.3.3-p1.DEPRECATION.idc differ diff --git a/resources/uct/deprecation/indexes.v2.3.3.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.3.3.DEPRECATION.idc new file mode 100644 index 000000000..3b1559fdd Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.3.3.DEPRECATION.idc differ diff --git a/resources/uct/deprecation/indexes.v2.3.4.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.3.4.DEPRECATION.idc new file mode 100644 index 000000000..dbcd0b756 Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.3.4.DEPRECATION.idc differ diff --git a/resources/uct/deprecation/indexes.v2.3.5-p2.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.3.5-p2.DEPRECATION.idc new file mode 100644 index 000000000..e07dbdea5 Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.3.5-p2.DEPRECATION.idc differ diff --git a/resources/uct/deprecation/indexes.v2.3.5.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.3.5.DEPRECATION.idc new file mode 100644 index 000000000..9ab2b21f0 Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.3.5.DEPRECATION.idc differ diff --git a/resources/uct/deprecation/indexes.v2.3.6.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.3.6.DEPRECATION.idc new file mode 100644 index 000000000..62fd9d5e8 Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.3.6.DEPRECATION.idc differ diff --git a/resources/uct/deprecation/indexes.v2.3.7.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.3.7.DEPRECATION.idc new file mode 100644 index 000000000..a662bb315 Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.3.7.DEPRECATION.idc differ diff --git a/resources/uct/deprecation/indexes.v2.4.0.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.4.0.DEPRECATION.idc new file mode 100644 index 000000000..7cc82439d Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.4.0.DEPRECATION.idc differ diff --git a/resources/uct/deprecation/indexes.v2.4.1-p1.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.4.1-p1.DEPRECATION.idc new file mode 100644 index 000000000..f2b399f8e Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.4.1-p1.DEPRECATION.idc differ diff --git a/resources/uct/deprecation/indexes.v2.4.1.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.4.1.DEPRECATION.idc new file mode 100644 index 000000000..fafaded4e Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.4.1.DEPRECATION.idc differ diff --git a/resources/uct/deprecation/indexes.v2.4.2.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.4.2.DEPRECATION.idc new file mode 100644 index 000000000..1003786d3 Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.4.2.DEPRECATION.idc differ diff --git a/resources/uct/deprecation/indexes.v2.4.3.DEPRECATION.idc b/resources/uct/deprecation/indexes.v2.4.3.DEPRECATION.idc new file mode 100644 index 000000000..b7d119f7a Binary files /dev/null and b/resources/uct/deprecation/indexes.v2.4.3.DEPRECATION.idc differ diff --git a/src/com/magento/idea/magento2uct/actions/ReindexVersionedIndexesAction.java b/src/com/magento/idea/magento2uct/actions/ReindexVersionedIndexesAction.java index 23a26b363..ed5f9ab0e 100644 --- a/src/com/magento/idea/magento2uct/actions/ReindexVersionedIndexesAction.java +++ b/src/com/magento/idea/magento2uct/actions/ReindexVersionedIndexesAction.java @@ -13,16 +13,8 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; import com.magento.idea.magento2plugin.project.Settings; -import com.magento.idea.magento2uct.execution.scanner.ModuleFilesScanner; -import com.magento.idea.magento2uct.execution.scanner.ModuleScanner; -import com.magento.idea.magento2uct.execution.scanner.data.ComponentData; -import com.magento.idea.magento2uct.packages.IndexRegistry; -import com.magento.idea.magento2uct.versioning.IndexRepository; -import com.magento.idea.magento2uct.versioning.processors.DeprecationIndexProcessor; -import java.util.HashMap; -import java.util.Map; +import com.magento.idea.magento2uct.ui.ReindexDialog; import org.jetbrains.annotations.NotNull; public class ReindexVersionedIndexesAction extends AnAction { @@ -64,21 +56,7 @@ public void actionPerformed(final @NotNull AnActionEvent event) { if (directory == null) { return; } - final IndexRepository storage = - new IndexRepository<>(project.getBasePath(), IndexRegistry.DEPRECATION); - final Map deprecationData = new HashMap<>(); - - for (final ComponentData componentData : new ModuleScanner(directory)) { - for (final PsiFile psiFile : new ModuleFilesScanner(componentData)) { - deprecationData.putAll(new DeprecationIndexProcessor().process(psiFile)); - } - } - - if (!deprecationData.isEmpty()) { - storage.put(deprecationData, "2.3.0"); - } - - System.out.println(ACTION_NAME + " is run!!!!!!"); + ReindexDialog.open(project, directory); } /** diff --git a/src/com/magento/idea/magento2uct/actions/RunUpgradeCompatibilityToolAction.java b/src/com/magento/idea/magento2uct/actions/RunUpgradeCompatibilityToolAction.java index 139ea2113..48f45de53 100644 --- a/src/com/magento/idea/magento2uct/actions/RunUpgradeCompatibilityToolAction.java +++ b/src/com/magento/idea/magento2uct/actions/RunUpgradeCompatibilityToolAction.java @@ -8,7 +8,6 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.magento.idea.magento2plugin.project.Settings; import com.magento.idea.magento2uct.execution.RunAnalysisExecutor; @@ -19,7 +18,6 @@ public class RunUpgradeCompatibilityToolAction extends AnAction { public static final String ACTION_NAME = "Run The Upgrade Compatibility Tool"; public static final String ACTION_DESCRIPTION = "Magento 2 Upgrade Compatibility Tool"; - private static final Logger LOG = Logger.getInstance(RunUpgradeCompatibilityToolAction.class); /** * An action constructor. @@ -46,15 +44,11 @@ public void actionPerformed(final @NotNull AnActionEvent event) { if (project == null) { return; } - System.out.println("!!!...Action Performing Start...!!!"); - final RunAnalysisExecutor executor = new RunAnalysisExecutor( project, new DefaultAnalysisHandler(project) ); executor.run(); - - System.out.println("!!!...Action Performing End...!!!"); } /** diff --git a/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java b/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java index ef7097ec0..8d72a39bf 100644 --- a/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java +++ b/src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java @@ -33,6 +33,7 @@ public class GenerateUctReportCommand { * Command constructor. * * @param project Project + * @param output OutputWrapper */ public GenerateUctReportCommand( final @NotNull Project project, diff --git a/src/com/magento/idea/magento2uct/execution/ReindexUctCommand.java b/src/com/magento/idea/magento2uct/execution/ReindexUctCommand.java new file mode 100644 index 000000000..78aa28648 --- /dev/null +++ b/src/com/magento/idea/magento2uct/execution/ReindexUctCommand.java @@ -0,0 +1,105 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.execution; + +import com.intellij.execution.process.ProcessHandler; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2uct.execution.process.OutputWrapper; +import com.magento.idea.magento2uct.execution.scanner.ModuleFilesScanner; +import com.magento.idea.magento2uct.execution.scanner.ModuleScanner; +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 { + + private final Project project; + private final PsiDirectory directory; + private final OutputWrapper output; + private final ProcessHandler process; + + /** + * Command constructor. + * + * @param project Project + * @param directory PsiDirectory + * @param output OutputWrapper + */ + public ReindexUctCommand( + final @NotNull Project project, + final @NotNull PsiDirectory directory, + final @NotNull OutputWrapper output, + final @NotNull ProcessHandler process + ) { + this.project = project; + this.directory = directory; + this.output = output; + this.process = process; + } + + /** + * Execute command. + * + * @param version SupportedVersion + */ + public void execute(final @NotNull SupportedVersion version) { + if (project.getBasePath() == null) { + return; + } + output.write("Indexing process...\n\n"); + + final IndexRepository indexRepository = new IndexRepository<>( + project.getBasePath(), + IndexRegistry.DEPRECATION + ); + final Map deprecationData = new HashMap<>(); + + ApplicationManager.getApplication().executeOnPooledThread(() -> { + ApplicationManager.getApplication().runReadAction(() -> { + for (final ComponentData componentData : new ModuleScanner(directory)) { + 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 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 previousData = deprecationIndex.getIndexData(); + deprecationData.entrySet().removeAll(previousData.entrySet()); + + if (!deprecationData.isEmpty()) { + indexRepository.put(deprecationData, version.getVersion()); + } + } + + process.destroyProcess(); + }); + }); + } +} diff --git a/src/com/magento/idea/magento2uct/execution/process/ReindexHandler.java b/src/com/magento/idea/magento2uct/execution/process/ReindexHandler.java new file mode 100644 index 000000000..c61e3cf7c --- /dev/null +++ b/src/com/magento/idea/magento2uct/execution/process/ReindexHandler.java @@ -0,0 +1,83 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.execution.process; + +import com.intellij.execution.process.ProcessAdapter; +import com.intellij.execution.process.ProcessEvent; +import com.intellij.execution.process.ProcessHandler; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.magento.idea.magento2uct.execution.ReindexUctCommand; +import com.magento.idea.magento2uct.packages.SupportedVersion; +import java.io.OutputStream; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ReindexHandler extends ProcessHandler { + + private final Project project; + private final PsiDirectory directory; + + /** + * Default indexing handler constructor. + * + * @param project Project + * @param directory PsiDirectory + * @param version SupportedVersion + */ + public ReindexHandler( + final @NotNull Project project, + final @NotNull PsiDirectory directory, + final @NotNull SupportedVersion version + ) { + super(); + this.project = project; + this.directory = directory; + this.addProcessListener( + new ProcessAdapter() { + @Override + public void startNotified(final @NotNull ProcessEvent event) { + execute(version); + } + } + ); + } + + /** + * Run indexing process. + * + * @param version SupportedVersion + */ + private void execute(final @NotNull SupportedVersion version) { + final ReindexUctCommand command = new ReindexUctCommand( + project, + directory, + new OutputWrapper(this), + this + ); + command.execute(version); + } + + @Override + protected void destroyProcessImpl() { + notifyProcessTerminated(0); + } + + @Override + protected void detachProcessImpl() { + notifyProcessDetached(); + } + + @Override + public boolean detachIsDefault() { + return false; + } + + @Override + public @Nullable OutputStream getProcessInput() { + return null; + } +} diff --git a/src/com/magento/idea/magento2uct/inspections/php/deprecation/CallingDeprecatedMethod.java b/src/com/magento/idea/magento2uct/inspections/php/deprecation/CallingDeprecatedMethod.java index f6720e90e..faa18afdf 100644 --- a/src/com/magento/idea/magento2uct/inspections/php/deprecation/CallingDeprecatedMethod.java +++ b/src/com/magento/idea/magento2uct/inspections/php/deprecation/CallingDeprecatedMethod.java @@ -36,7 +36,7 @@ public void visitPhpMethodReference(final MethodReference reference) { } final String type = ((Method) resolvedElement).getFQN(); - if (VersionStateManager.getInstance().isDeprecated(type)) { + if (VersionStateManager.getInstance(reference.getProject()).isDeprecated(type)) { if (problemsHolder instanceof UctProblemsHolder) { ((UctProblemsHolder) problemsHolder).setReservedErrorCode( SupportedIssue.CALLING_DEPRECATED_METHOD.getCode() diff --git a/src/com/magento/idea/magento2uct/inspections/php/deprecation/ExtendingDeprecatedClass.java b/src/com/magento/idea/magento2uct/inspections/php/deprecation/ExtendingDeprecatedClass.java index 8f46a03a7..917a07d3c 100644 --- a/src/com/magento/idea/magento2uct/inspections/php/deprecation/ExtendingDeprecatedClass.java +++ b/src/com/magento/idea/magento2uct/inspections/php/deprecation/ExtendingDeprecatedClass.java @@ -38,7 +38,8 @@ public void visitPhpClass(final PhpClass clazz) { final String parentClassFqn = parentClass.getFQN(); while (parentClass != null) { - if (VersionStateManager.getInstance().isDeprecated(parentClass.getFQN())) { + if (VersionStateManager.getInstance(clazz.getProject()) + .isDeprecated(parentClass.getFQN())) { for (final ClassReference classReference : list.getReferenceElements()) { if (parentClassFqn.equals(classReference.getFQN())) { if (problemsHolder instanceof UctProblemsHolder) { diff --git a/src/com/magento/idea/magento2uct/inspections/php/deprecation/ImplementedDeprecatedInterface.java b/src/com/magento/idea/magento2uct/inspections/php/deprecation/ImplementedDeprecatedInterface.java index 01b204347..385e6bed8 100644 --- a/src/com/magento/idea/magento2uct/inspections/php/deprecation/ImplementedDeprecatedInterface.java +++ b/src/com/magento/idea/magento2uct/inspections/php/deprecation/ImplementedDeprecatedInterface.java @@ -41,8 +41,8 @@ public void visitPhpClass(final PhpClass clazz) { if (interfaceFqn == null || !(interfaceClass instanceof PhpClass)) { continue; } - final boolean isDeprecated - = VersionStateManager.getInstance().isDeprecated(interfaceFqn); + final boolean isDeprecated = VersionStateManager + .getInstance(clazz.getProject()).isDeprecated(interfaceFqn); Pair checkResult = null; if (isDeprecated || (checkResult = InheritedDeprecatedInterface @@ -112,7 +112,8 @@ private Pair checkImplements(final PhpClass clazz) { continue; } - if (VersionStateManager.getInstance().isDeprecated(interfaceFqn)) { + if (VersionStateManager.getInstance(clazz.getProject()) + .isDeprecated(interfaceFqn)) { return new Pair<>(true, interfaceFqn); } final Pair parentCheck = InheritedDeprecatedInterface diff --git a/src/com/magento/idea/magento2uct/inspections/php/deprecation/ImportingDeprecatedType.java b/src/com/magento/idea/magento2uct/inspections/php/deprecation/ImportingDeprecatedType.java index da97fdb94..8c96687bf 100644 --- a/src/com/magento/idea/magento2uct/inspections/php/deprecation/ImportingDeprecatedType.java +++ b/src/com/magento/idea/magento2uct/inspections/php/deprecation/ImportingDeprecatedType.java @@ -50,7 +50,8 @@ public void visitPhpUseList(final PhpUseList useList) { return; } for (final PhpUse use : useList.getDeclarations()) { - if (VersionStateManager.getInstance().isDeprecated(use.getFQN())) { + if (VersionStateManager.getInstance(useList.getProject()) + .isDeprecated(use.getFQN())) { final PhpReference phpReference = use.getTargetReference(); boolean isInterface = false; diff --git a/src/com/magento/idea/magento2uct/inspections/php/deprecation/InheritedDeprecatedInterface.java b/src/com/magento/idea/magento2uct/inspections/php/deprecation/InheritedDeprecatedInterface.java index 924c0f636..76c8e99f0 100644 --- a/src/com/magento/idea/magento2uct/inspections/php/deprecation/InheritedDeprecatedInterface.java +++ b/src/com/magento/idea/magento2uct/inspections/php/deprecation/InheritedDeprecatedInterface.java @@ -42,7 +42,8 @@ public void visitPhpClass(final PhpClass clazz) { } Pair parentCheckResult = null; - if (VersionStateManager.getInstance().isDeprecated(interfaceFqn) + if (VersionStateManager.getInstance(clazz.getProject()) + .isDeprecated(interfaceFqn) || (parentCheckResult = hasDeprecatedParent( (PhpClass) interfaceClass )).getFirst()) { @@ -85,7 +86,8 @@ public static Pair hasDeprecatedParent(final PhpClass interface continue; } - if (VersionStateManager.getInstance().isDeprecated(interfaceFqn)) { + if (VersionStateManager.getInstance(interfaceClass.getProject()) + .isDeprecated(interfaceFqn)) { return new Pair<>(true, interfaceFqn); } } diff --git a/src/com/magento/idea/magento2uct/inspections/php/deprecation/OverridingDeprecatedConstant.java b/src/com/magento/idea/magento2uct/inspections/php/deprecation/OverridingDeprecatedConstant.java index 7698898d3..a75bce19c 100644 --- a/src/com/magento/idea/magento2uct/inspections/php/deprecation/OverridingDeprecatedConstant.java +++ b/src/com/magento/idea/magento2uct/inspections/php/deprecation/OverridingDeprecatedConstant.java @@ -47,7 +47,8 @@ public void visitPhpField(final Field field) { for (final Field ownField : parentClass.getOwnFields()) { if (ownField instanceof ClassConstImpl && ownField.getName().equals(constant.getName()) - && VersionStateManager.getInstance().isDeprecated(ownField.getFQN()) + && VersionStateManager.getInstance(field.getProject()) + .isDeprecated(ownField.getFQN()) ) { if (problemsHolder instanceof UctProblemsHolder) { ((UctProblemsHolder) problemsHolder).setReservedErrorCode( diff --git a/src/com/magento/idea/magento2uct/inspections/php/deprecation/OverridingDeprecatedProperty.java b/src/com/magento/idea/magento2uct/inspections/php/deprecation/OverridingDeprecatedProperty.java index 94ce8f988..14cde4760 100644 --- a/src/com/magento/idea/magento2uct/inspections/php/deprecation/OverridingDeprecatedProperty.java +++ b/src/com/magento/idea/magento2uct/inspections/php/deprecation/OverridingDeprecatedProperty.java @@ -46,9 +46,10 @@ public void visitPhpField(final Field field) { for (final Field parentField : parentClass.getOwnFields()) { if (!(parentField instanceof ClassConstImpl) && parentField.getName().equals(field.getName()) - && VersionStateManager.getInstance().isDeprecated( - parentField.getFQN() - )) { + && VersionStateManager + .getInstance(field.getProject()) + .isDeprecated(parentField.getFQN()) + ) { if (problemsHolder instanceof UctProblemsHolder) { ((UctProblemsHolder) problemsHolder).setReservedErrorCode( SupportedIssue.OVERRIDING_DEPRECATED_PROPERTY.getCode() diff --git a/src/com/magento/idea/magento2uct/inspections/php/deprecation/UsingDeprecatedConstant.java b/src/com/magento/idea/magento2uct/inspections/php/deprecation/UsingDeprecatedConstant.java index a985849a7..ed45b090e 100644 --- a/src/com/magento/idea/magento2uct/inspections/php/deprecation/UsingDeprecatedConstant.java +++ b/src/com/magento/idea/magento2uct/inspections/php/deprecation/UsingDeprecatedConstant.java @@ -39,7 +39,8 @@ public void visitPhpClassConstantReference( } final String constantClass = ((ClassConstImpl) element).getFQN(); - if (!VersionStateManager.getInstance().isDeprecated(constantClass)) { + if (!VersionStateManager.getInstance(constantReference.getProject()) + .isDeprecated(constantClass)) { return; } final PhpClass containingClass = ((ClassConstImpl) element).getContainingClass(); diff --git a/src/com/magento/idea/magento2uct/inspections/php/deprecation/UsingDeprecatedProperty.java b/src/com/magento/idea/magento2uct/inspections/php/deprecation/UsingDeprecatedProperty.java index 4081066d5..b346d993c 100644 --- a/src/com/magento/idea/magento2uct/inspections/php/deprecation/UsingDeprecatedProperty.java +++ b/src/com/magento/idea/magento2uct/inspections/php/deprecation/UsingDeprecatedProperty.java @@ -39,7 +39,8 @@ public void visitPhpFieldReference(final FieldReference fieldReference) { } final Field field = (Field) element; - if (VersionStateManager.getInstance().isDeprecated(field.getFQN())) { + if (VersionStateManager.getInstance(fieldReference.getProject()) + .isDeprecated(field.getFQN())) { if (problemsHolder instanceof UctProblemsHolder) { ((UctProblemsHolder) problemsHolder).setReservedErrorCode( SupportedIssue.USING_DEPRECATED_PROPERTY.getCode() @@ -58,7 +59,8 @@ public void visitPhpFieldReference(final FieldReference fieldReference) { if (containingClass == null) { return; } - if (VersionStateManager.getInstance().isDeprecated(containingClass.getFQN())) { + if (VersionStateManager.getInstance(fieldReference.getProject()) + .isDeprecated(containingClass.getFQN())) { if (problemsHolder instanceof UctProblemsHolder) { ((UctProblemsHolder) problemsHolder).setReservedErrorCode( SupportedIssue.USING_DEPRECATED_PROPERTY.getCode() diff --git a/src/com/magento/idea/magento2uct/inspections/php/deprecation/UsingDeprecatedType.java b/src/com/magento/idea/magento2uct/inspections/php/deprecation/UsingDeprecatedType.java index 90a2d720e..c45e6ad61 100644 --- a/src/com/magento/idea/magento2uct/inspections/php/deprecation/UsingDeprecatedType.java +++ b/src/com/magento/idea/magento2uct/inspections/php/deprecation/UsingDeprecatedType.java @@ -84,7 +84,7 @@ public void visitPhpField(final Field field) { isInterface = true; } - if (VersionStateManager.getInstance().isDeprecated(fieldType)) { + if (VersionStateManager.getInstance(field.getProject()).isDeprecated(fieldType)) { registerProblem(problemsHolder, field, fieldType, isInterface); } } @@ -99,7 +99,8 @@ public void visitPhpClassReference(final ClassReference reference) { final PhpClass phpClass = (PhpClass) resolved; final boolean isInterface = phpClass.isInterface(); - if (VersionStateManager.getInstance().isDeprecated(phpClass.getFQN())) { + if (VersionStateManager.getInstance(reference.getProject()) + .isDeprecated(phpClass.getFQN())) { registerReferenceProblem( problemsHolder, reference, diff --git a/src/com/magento/idea/magento2uct/packages/IndexRegistry.java b/src/com/magento/idea/magento2uct/packages/IndexRegistry.java index c51f3f9d1..f940304d1 100644 --- a/src/com/magento/idea/magento2uct/packages/IndexRegistry.java +++ b/src/com/magento/idea/magento2uct/packages/IndexRegistry.java @@ -5,14 +5,17 @@ package com.magento.idea.magento2uct.packages; -import com.magento.idea.magento2uct.versioning.indexes.DeprecationStateIndex; +import com.magento.idea.magento2uct.versioning.indexes.data.DeprecationStateIndex; import java.util.Arrays; import java.util.List; import org.jetbrains.annotations.NotNull; public enum IndexRegistry { - DEPRECATION(DeprecationStateIndex.class, new String[]{"2.3.0"}); + DEPRECATION( + DeprecationStateIndex.class, + SupportedVersion.getSupportedVersions().toArray(new String[0]) + ); private final String key; private final Class type; diff --git a/src/com/magento/idea/magento2uct/packages/SupportedVersion.java b/src/com/magento/idea/magento2uct/packages/SupportedVersion.java index cdd152414..6acb9157e 100644 --- a/src/com/magento/idea/magento2uct/packages/SupportedVersion.java +++ b/src/com/magento/idea/magento2uct/packages/SupportedVersion.java @@ -7,6 +7,8 @@ import java.util.LinkedList; import java.util.List; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public enum SupportedVersion { @@ -50,6 +52,22 @@ public String getVersion() { return version; } + /** + * Get version ENUM by version code. + * + * @param versionCandidate String + * + * @return SupportedVersion + */ + public @Nullable static SupportedVersion getVersion(final @NotNull String versionCandidate) { + for (final SupportedVersion version : SupportedVersion.values()) { + if (version.getVersion().equals(versionCandidate)) { + return version; + } + } + return null; + } + /** * Get supported versions. * diff --git a/src/com/magento/idea/magento2uct/settings/UctSettingsService.java b/src/com/magento/idea/magento2uct/settings/UctSettingsService.java index 2a907c65b..ed936d612 100644 --- a/src/com/magento/idea/magento2uct/settings/UctSettingsService.java +++ b/src/com/magento/idea/magento2uct/settings/UctSettingsService.java @@ -6,12 +6,13 @@ package com.magento.idea.magento2uct.settings; import com.intellij.openapi.components.PersistentStateComponent; -import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.intellij.openapi.project.Project; import com.intellij.util.xmlb.XmlSerializerUtil; import com.intellij.util.xmlb.annotations.Property; +import com.magento.idea.magento2uct.packages.IssueSeverityLevel; +import com.magento.idea.magento2uct.packages.SupportedVersion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -44,11 +45,21 @@ public UctSettingsService(final String uctExecutablePath) { * @return UctSettingsService */ public @Nullable static UctSettingsService getInstance(final @NotNull Project project) { - return ServiceManager.getService(project, UctSettingsService.class); + return project.getService(UctSettingsService.class); + } + + @Override + public @Nullable UctSettingsService getState() { + return this; + } + + @Override + public void loadState(final @NotNull UctSettingsService state) { + XmlSerializerUtil.copyBean(state, this); } /** - * Get UCT executable path for the project. + * Get UCT executable path for the project (UCT Run Configuration). * * @return String */ @@ -60,7 +71,7 @@ public UctSettingsService(final String uctExecutablePath) { } /** - * Set UCT executable path. + * Set UCT executable path (UCT Run Configuration). * * @param uctExecutablePath String */ @@ -68,13 +79,48 @@ public void setUctExecutablePath(final String uctExecutablePath) { this.uctExecutablePath = uctExecutablePath; } - @Override - public @Nullable UctSettingsService getState() { - return this; + /** + * Get current version. + * + * @return SupportedVersion or null if current version is less than min supported version. + */ + public SupportedVersion getCurrentVersion() { + return SupportedVersion.V230; } - @Override - public void loadState(final @NotNull UctSettingsService state) { - XmlSerializerUtil.copyBean(state, this); + /** + * Get target supported version. + * + * @return SupportedVersion + */ + public SupportedVersion getTargetVersion() { + return SupportedVersion.V231; + } + + /** + * Get target module path (path to analyse). + * + * @return String + */ + public String getModulePath() { + return "test"; + } + + /** + * Get minimum issue severity level. + * + * @return IssueSeverityLevel + */ + public IssueSeverityLevel getMinIssueLevel() { + return IssueSeverityLevel.WARNING; + } + + /** + * Check if analysis should ignore current version compatibility problems. + * + * @return boolean + */ + public boolean shouldIgnoreCurrentVersion() { + return false; } } diff --git a/src/com/magento/idea/magento2uct/ui/ReindexDialog.form b/src/com/magento/idea/magento2uct/ui/ReindexDialog.form new file mode 100644 index 000000000..6f7d1a31d --- /dev/null +++ b/src/com/magento/idea/magento2uct/ui/ReindexDialog.form @@ -0,0 +1,61 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/com/magento/idea/magento2uct/ui/ReindexDialog.java b/src/com/magento/idea/magento2uct/ui/ReindexDialog.java new file mode 100644 index 000000000..e20da3008 --- /dev/null +++ b/src/com/magento/idea/magento2uct/ui/ReindexDialog.java @@ -0,0 +1,135 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.ui; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.ComboBox; +import com.intellij.psi.PsiDirectory; +import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; +import com.magento.idea.magento2plugin.actions.generation.dialog.AbstractDialog; +import com.magento.idea.magento2uct.actions.ReindexVersionedIndexesAction; +import com.magento.idea.magento2uct.execution.RunAnalysisExecutor; +import com.magento.idea.magento2uct.execution.process.ReindexHandler; +import com.magento.idea.magento2uct.packages.SupportedVersion; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.KeyStroke; +import org.jetbrains.annotations.NotNull; + +public class ReindexDialog extends AbstractDialog { + + private final Project project; + private final PsiDirectory directory; + + private JPanel contentPanel; + private JComboBox targetVersion; + private JLabel targetVersionLabel;//NOPMD + private JButton buttonOk; + private JButton buttonCancel; + + /** + * Reindexing dialog. + * + * @param project Project + * @param directory PsiDirectory + */ + public ReindexDialog( + final @NotNull Project project, + final @NotNull PsiDirectory directory + ) { + super(); + + this.project = project; + this.directory = directory; + + setContentPane(contentPanel); + setModal(true); + setTitle(ReindexVersionedIndexesAction.ACTION_NAME); + getRootPane().setDefaultButton(buttonOk); + + buttonOk.addActionListener(event -> onOK()); + buttonCancel.addActionListener(event -> onCancel()); + + // call onCancel() when cross is clicked + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(final WindowEvent event) { + onCancel(); + } + }); + + // call onCancel() on ESCAPE + contentPanel.registerKeyboardAction( + event -> onCancel(), + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT + ); + } + + /** + * Open reindexing dialog window. + * + * @param project Project + * @param directory PsiDirectory + */ + public static void open( + final @NotNull Project project, + final @NotNull PsiDirectory directory + ) { + final ReindexDialog dialog = new ReindexDialog( + project, + directory + ); + dialog.pack(); + dialog.centerDialog(dialog); + dialog.setVisible(true); + } + + /** + * Execute reindexing action. + */ + private void onOK() { + if (targetVersion.getSelectedItem() == null) { + return; + } + final SupportedVersion version = SupportedVersion.getVersion( + targetVersion.getSelectedItem().toString() + ); + if (version == null) { + return; + } + final RunAnalysisExecutor executor = new RunAnalysisExecutor( + project, + new ReindexHandler( + project, + directory, + version + ) + ); + executor.run(); + + this.setVisible(false); + } + + /** + * Create custom components and fill their entries. + */ + @SuppressWarnings({"PMD.UnusedPrivateMethod", "PMD.AvoidInstantiatingObjectsInLoops"}) + private void createUIComponents() { + targetVersion = new ComboBox<>(); + + for (final String version : SupportedVersion.getSupportedVersions()) { + targetVersion.addItem(new ComboBoxItemData(version, version)); + } + } +} diff --git a/src/com/magento/idea/magento2uct/versioning/Storage.java b/src/com/magento/idea/magento2uct/versioning/Storage.java deleted file mode 100644 index d13b8da86..000000000 --- a/src/com/magento/idea/magento2uct/versioning/Storage.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2uct.versioning; - -import java.io.IOException; -import java.util.Map; -import org.jetbrains.annotations.NotNull; - -public interface Storage { - - void put(final Map data, final String version); - - Map get(final @NotNull String resourceName) throws IOException, ClassNotFoundException; -} diff --git a/src/com/magento/idea/magento2uct/versioning/VersionStateManager.java b/src/com/magento/idea/magento2uct/versioning/VersionStateManager.java index 1d3ca9b0c..b0d87ae93 100644 --- a/src/com/magento/idea/magento2uct/versioning/VersionStateManager.java +++ b/src/com/magento/idea/magento2uct/versioning/VersionStateManager.java @@ -5,66 +5,85 @@ package com.magento.idea.magento2uct.versioning; -import com.jetbrains.php.lang.psi.elements.Field; -import com.jetbrains.php.lang.psi.elements.Method; -import com.jetbrains.php.lang.psi.elements.PhpClass; -import com.magento.idea.magento2uct.versioning.indexes.DeprecationStateIndex; +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2uct.packages.SupportedVersion; +import com.magento.idea.magento2uct.settings.UctSettingsService; +import com.magento.idea.magento2uct.versioning.indexes.data.DeprecationStateIndex; +import com.magento.idea.magento2uct.versioning.indexes.data.VersionStateIndex; +import java.util.LinkedList; +import java.util.List; import org.jetbrains.annotations.NotNull; public final class VersionStateManager { - private static final VersionStateManager INSTANCE = new VersionStateManager(); - private final DeprecationStateIndex deprecationStateIndex; - - public static VersionStateManager getInstance() { - return INSTANCE; - } + private final Project project; + private final UctSettingsService settingsService; - private VersionStateManager() { - deprecationStateIndex = new DeprecationStateIndex(); - } + private static VersionStateManager INSTANCE; + private final DeprecationStateIndex deprecationStateIndex; /** - * Check if PHP class is deprecated. + * Get instance of the version state manager. * - * @param phpClass PhpClass + * @param project Project * - * @return boolean + * @return VersionStateManager */ - public boolean isDeprecated(final @NotNull PhpClass phpClass) { - return deprecationStateIndex.has(phpClass); + public static VersionStateManager getInstance(final @NotNull Project project) { + if (INSTANCE == null) { + INSTANCE = new VersionStateManager(project); + } + return INSTANCE; } /** - * Check if PHP method is deprecated. - * - * @param method Method - * - * @return boolean + * Version state manager constructor. */ - public boolean isDeprecated(final @NotNull Method method) { - return deprecationStateIndex.has(method); + private VersionStateManager(final @NotNull Project project) { + this.project = project; + settingsService = UctSettingsService.getInstance(project); + deprecationStateIndex = new DeprecationStateIndex(); + compute(deprecationStateIndex); } /** - * Check if PHP field is deprecated. + * Check if specified FQN exists in the deprecation index. * - * @param field Field + * @param fqn String * * @return boolean */ - public boolean isDeprecated(final @NotNull Field field) { - return deprecationStateIndex.has(field); + public boolean isDeprecated(final @NotNull String fqn) { + return deprecationStateIndex.has(fqn); } /** - * Check if specified FQN exists in the deprecation index. - * - * @param fqn String + * Compute index data. * - * @return boolean + * @param index VersionStateIndex */ - public boolean isDeprecated(final @NotNull String fqn) { - return deprecationStateIndex.has(fqn); + private void compute(final VersionStateIndex index) { + final SupportedVersion currentVersion = settingsService.getCurrentVersion(); + final SupportedVersion targetVersion = settingsService.getTargetVersion(); + final boolean hasIgnoringFlag = settingsService.shouldIgnoreCurrentVersion(); + + if (targetVersion == null) { + return; + } + final List versionsToLoad = new LinkedList<>(); + + for (final SupportedVersion version : SupportedVersion.values()) { + if (version.compareTo(targetVersion) <= 0) { + if (hasIgnoringFlag) { + // If current version is NULL, it is less than minimum supported version. + if (currentVersion == null || version.compareTo(currentVersion) > 0) { + versionsToLoad.add(version); + } + } else { + versionsToLoad.add(version); + } + } + } + index.load(versionsToLoad); } } diff --git a/src/com/magento/idea/magento2uct/versioning/IndexRepository.java b/src/com/magento/idea/magento2uct/versioning/indexes/IndexRepository.java similarity index 78% rename from src/com/magento/idea/magento2uct/versioning/IndexRepository.java rename to src/com/magento/idea/magento2uct/versioning/indexes/IndexRepository.java index cb4883cb4..ebaaac178 100644 --- a/src/com/magento/idea/magento2uct/versioning/IndexRepository.java +++ b/src/com/magento/idea/magento2uct/versioning/indexes/IndexRepository.java @@ -3,10 +3,10 @@ * See COPYING.txt for license details. */ -package com.magento.idea.magento2uct.versioning; +package com.magento.idea.magento2uct.versioning.indexes; import com.magento.idea.magento2uct.packages.IndexRegistry; -import com.magento.idea.magento2uct.versioning.indexes.VersionStateIndex; +import com.magento.idea.magento2uct.versioning.indexes.data.VersionStateIndex; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.Map; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class IndexRepository implements Storage { @@ -29,10 +30,19 @@ public class IndexRepository implements Storage { private final String basePath; private final IndexRegistry index; + /** + * Index repository constructor. + */ public IndexRepository() { this("", null); } + /** + * Index repository constructor. + * + * @param basePath String + * @param index IndexRegistry + */ public IndexRepository( final @NotNull String basePath, final IndexRegistry index @@ -43,6 +53,11 @@ public IndexRepository( @Override public void put(final @NotNull Map data, final String version) { + if (basePath.isEmpty() || index == null) { + throw new IllegalArgumentException( + "Project bath path and index type are required params for storing indexes." + ); + } try { final Path path = Paths.get(basePath + DEFAULT_RELATIVE_PATH); @@ -54,7 +69,8 @@ public void put(final @NotNull Map data, final String version) { throw new IllegalArgumentException( String.format( "Specified version `%s` must be declared for the index `%s`", - version, index.getKey() + version, + index.getKey() ) ); } @@ -87,10 +103,13 @@ public void put(final @NotNull Map data, final String version) { } @Override - public Map get(final @NotNull String resourceName) + public @Nullable Map load(final @NotNull String resourceName) throws IOException, ClassNotFoundException { - InputStream inputStream = getClass().getResourceAsStream(resourceName); + final InputStream inputStream = getClass().getResourceAsStream(resourceName); + if (inputStream == null) { + return null; + } try (ObjectInputStream objectInputStream = new ObjectInputStream(inputStream)) { return (HashMap) objectInputStream.readObject(); } catch (ClassCastException exception) { diff --git a/src/com/magento/idea/magento2uct/versioning/indexes/Storage.java b/src/com/magento/idea/magento2uct/versioning/indexes/Storage.java new file mode 100644 index 000000000..ae6f91e8c --- /dev/null +++ b/src/com/magento/idea/magento2uct/versioning/indexes/Storage.java @@ -0,0 +1,30 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.versioning.indexes; + +import java.io.IOException; +import java.util.Map; +import org.jetbrains.annotations.NotNull; + +public interface Storage { + + /** + * Put index data to storage. + * + * @param data Map[K, V] + * @param version String + */ + void put(final Map data, final String version); + + /** + * Load index data from storage. + * + * @param resourceName String + * + * @return Map[K, V] + */ + Map load(final @NotNull String resourceName) throws IOException, ClassNotFoundException; +} diff --git a/src/com/magento/idea/magento2uct/versioning/indexes/VersionStateIndex.java b/src/com/magento/idea/magento2uct/versioning/indexes/VersionStateIndex.java deleted file mode 100644 index 75c8638bc..000000000 --- a/src/com/magento/idea/magento2uct/versioning/indexes/VersionStateIndex.java +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2uct.versioning.indexes; - -public interface VersionStateIndex { - - String FILE_NAME_PATTERN = "indexes.v%version.%key.idc"; -} diff --git a/src/com/magento/idea/magento2uct/versioning/indexes/DeprecationStateIndex.java b/src/com/magento/idea/magento2uct/versioning/indexes/data/DeprecationStateIndex.java similarity index 51% rename from src/com/magento/idea/magento2uct/versioning/indexes/DeprecationStateIndex.java rename to src/com/magento/idea/magento2uct/versioning/indexes/data/DeprecationStateIndex.java index 9f140468a..95aa47aa1 100644 --- a/src/com/magento/idea/magento2uct/versioning/indexes/DeprecationStateIndex.java +++ b/src/com/magento/idea/magento2uct/versioning/indexes/data/DeprecationStateIndex.java @@ -3,65 +3,34 @@ * See COPYING.txt for license details. */ -package com.magento.idea.magento2uct.versioning.indexes; +package com.magento.idea.magento2uct.versioning.indexes.data; import com.intellij.openapi.util.Pair; -import com.jetbrains.php.lang.psi.elements.Field; -import com.jetbrains.php.lang.psi.elements.Method; -import com.jetbrains.php.lang.psi.elements.PhpClass; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2uct.packages.IndexRegistry; -import com.magento.idea.magento2uct.versioning.IndexRepository; -import com.magento.idea.magento2uct.versioning.Storage; +import com.magento.idea.magento2uct.packages.SupportedVersion; +import com.magento.idea.magento2uct.versioning.indexes.IndexRepository; +import com.magento.idea.magento2uct.versioning.indexes.Storage; import java.io.IOException; +import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import org.jetbrains.annotations.NotNull; public class DeprecationStateIndex implements VersionStateIndex { + private static final String RESOURCE_PATH = File.separator + "uct" + + File.separator + "deprecation" + File.separator; + private final Map> versioningData; private String versionState; - public DeprecationStateIndex() { - versioningData = new LinkedHashMap<>(); - } - /** - * Check if PHP class exists in the deprecation index. - * - * @param phpClass PhpClass - * - * @return boolean + * Deprecation state index constructor. */ - public boolean has(final @NotNull PhpClass phpClass) { - return has(phpClass.getFQN()); - } - - /** - * Check if PHP method exists in the deprecation index. - * - * @param method Method - * - * @return boolean - */ - public boolean has(final @NotNull Method method) { - final String methodFQN = method.getFQN(); - - return has(methodFQN); - } - - /** - * Check if PHP field exists in the deprecation index. - * - * @param field Field - * - * @return boolean - */ - public boolean has(final @NotNull Field field) { - final String fieldFQN = field.getFQN(); - - return has(fieldFQN); + public DeprecationStateIndex() { + versioningData = new LinkedHashMap<>(); } /** @@ -83,19 +52,49 @@ public boolean has(final @NotNull String key) { } /** - * Put index for version. + * Get version state after lookup. * - * @param version String - * @param data Map + * @return String */ - public void putIndexData(final @NotNull String version, final Map data) { - versioningData.put(version, data); - } - public String getVersion() { return versionState; } + @Override + public void load(final @NotNull List versions) { + final Storage storage = new IndexRepository<>(); + final IndexRegistry registrationInfo = IndexRegistry.getRegistryInfoByClass( + DeprecationStateIndex.class + ); + assert registrationInfo != null; + + for (final SupportedVersion version : versions) { + final String indexName = VersionStateIndex.FILE_NAME_PATTERN + .replace("%version", version.getVersion()) + .replace("%key", registrationInfo.getKey()); + try { + putIndexData(version.getVersion(), storage.load(RESOURCE_PATH + indexName)); + } catch (IOException | ClassNotFoundException exception) { + // + } + } + } + + /** + * Get deprecation index data. + * + * @return Map[String, Boolean] + */ + public Map getIndexData() { + final Map data = new HashMap<>(); + + for (final Map.Entry> vData : versioningData.entrySet()) { + data.putAll(vData.getValue()); + } + + return data; + } + /** * Lookup if key is deprecated. * @@ -104,21 +103,12 @@ public String getVersion() { * @return Pair[String, Boolean] */ private Pair isDeprecatedLookup(final @NotNull String lookupKey) { - if (versioningData.isEmpty()) { - load(); - } for (final Map.Entry> versionIndexEntry : versioningData.entrySet()) { final String version = versionIndexEntry.getKey(); - for (final Map.Entry indexEntry - : versionIndexEntry.getValue().entrySet()) { - final String indexKey = indexEntry.getKey(); - final Boolean indexValue = indexEntry.getValue(); - - if (lookupKey.equals(indexKey)) { - return new Pair<>(version, indexValue); - } + if (versionIndexEntry.getValue().containsKey(lookupKey)) { + return new Pair<>(version, versionIndexEntry.getValue().get(lookupKey)); } } @@ -126,26 +116,14 @@ private Pair isDeprecatedLookup(final @NotNull String lookupKey } /** - * Load index from storage. + * Put index for version. + * + * @param version String + * @param data Map */ - private void load() { - final Storage storage = new IndexRepository<>(); - final IndexRegistry registrationInfo = - IndexRegistry.getRegistryInfoByClass(DeprecationStateIndex.class); - assert registrationInfo != null; - - for (final String version : registrationInfo.getVersions()) { - final String indexName = VersionStateIndex.FILE_NAME_PATTERN - .replace("%version", version) - .replace("%key", registrationInfo.getKey()); - try { - putIndexData( - version, - storage.get(File.separator + "uct" + File.separator + indexName) - ); - } catch (IOException | ClassNotFoundException exception) { - // - } + private void putIndexData(final @NotNull String version, final Map data) { + if (data != null) { + versioningData.put(version, data); } } } diff --git a/src/com/magento/idea/magento2uct/versioning/indexes/data/VersionStateIndex.java b/src/com/magento/idea/magento2uct/versioning/indexes/data/VersionStateIndex.java new file mode 100644 index 000000000..d349c6e39 --- /dev/null +++ b/src/com/magento/idea/magento2uct/versioning/indexes/data/VersionStateIndex.java @@ -0,0 +1,22 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.versioning.indexes.data; + +import com.magento.idea.magento2uct.packages.SupportedVersion; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +public interface VersionStateIndex { + + String FILE_NAME_PATTERN = "indexes.v%version.%key.idc"; + + /** + * Load index data for specified versions. + * + * @param versions List[SupportedVersion] + */ + void load(final @NotNull List versions); +}