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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -64,21 +56,7 @@ public void actionPerformed(final @NotNull AnActionEvent event) {
if (directory == null) {
return;
}
final IndexRepository<String, Boolean> storage =
new IndexRepository<>(project.getBasePath(), IndexRegistry.DEPRECATION);
final Map<String, Boolean> 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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...!!!");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class GenerateUctReportCommand {
* Command constructor.
*
* @param project Project
* @param output OutputWrapper
*/
public GenerateUctReportCommand(
final @NotNull Project project,
Expand Down
105 changes: 105 additions & 0 deletions src/com/magento/idea/magento2uct/execution/ReindexUctCommand.java
Original file line number Diff line number Diff line change
@@ -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<String, Boolean> indexRepository = new IndexRepository<>(
project.getBasePath(),
IndexRegistry.DEPRECATION
);
final Map<String, Boolean> 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<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());
}
}

process.destroyProcess();
});
});
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean, String> checkResult = null;

if (isDeprecated || (checkResult = InheritedDeprecatedInterface
Expand Down Expand Up @@ -112,7 +112,8 @@ private Pair<Boolean, String> checkImplements(final PhpClass clazz) {
continue;
}

if (VersionStateManager.getInstance().isDeprecated(interfaceFqn)) {
if (VersionStateManager.getInstance(clazz.getProject())
.isDeprecated(interfaceFqn)) {
return new Pair<>(true, interfaceFqn);
}
final Pair<Boolean, String> parentCheck = InheritedDeprecatedInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public void visitPhpClass(final PhpClass clazz) {
}
Pair<Boolean, String> parentCheckResult = null;

if (VersionStateManager.getInstance().isDeprecated(interfaceFqn)
if (VersionStateManager.getInstance(clazz.getProject())
.isDeprecated(interfaceFqn)
|| (parentCheckResult = hasDeprecatedParent(
(PhpClass) interfaceClass
)).getFirst()) {
Expand Down Expand Up @@ -85,7 +86,8 @@ public static Pair<Boolean, String> hasDeprecatedParent(final PhpClass interface
continue;
}

if (VersionStateManager.getInstance().isDeprecated(interfaceFqn)) {
if (VersionStateManager.getInstance(interfaceClass.getProject())
.isDeprecated(interfaceFqn)) {
return new Pair<>(true, interfaceFqn);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Loading