Search in sources :

Example 46 with Problem

use of com.liferay.blade.api.Problem in project liferay-ide by liferay.

the class MigrationUtil method getProblemsFromTreeNode.

@SuppressWarnings("rawtypes")
public static List<Problem> getProblemsFromTreeNode(ISelection selection) {
    List<Problem> allProblems = new ArrayList<>();
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) selection;
        Iterator iterator = ss.iterator();
        while (iterator.hasNext()) {
            Object element = iterator.next();
            if (element instanceof FileProblems) {
                FileProblems fp = (FileProblems) element;
                allProblems.addAll(fp.getProblems());
            } else if (element instanceof MigrationProblems) {
                MigrationProblems migrationProblems = (MigrationProblems) element;
                for (FileProblems fProblems : migrationProblems.getProblems()) {
                    allProblems.addAll(fProblems.getProblems());
                }
            } else if (element instanceof MigrationProblemsContainer) {
                MigrationProblemsContainer migrationProblemsContainer = (MigrationProblemsContainer) element;
                for (MigrationProblems migrationProblems : migrationProblemsContainer.getProblemsArray()) {
                    for (FileProblems fProblems : migrationProblems.getProblems()) {
                        allProblems.addAll(fProblems.getProblems());
                    }
                }
            }
        }
        // remove duplicate problem
        HashSet<Problem> hashSet = new HashSet<>(allProblems);
        allProblems.clear();
        allProblems.addAll(hashSet);
        return allProblems;
    }
    return allProblems;
}
Also used : FileProblems(com.liferay.ide.project.core.upgrade.FileProblems) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Problem(com.liferay.blade.api.Problem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) MigrationProblems(com.liferay.ide.project.core.upgrade.MigrationProblems) MigrationProblemsContainer(com.liferay.ide.project.core.upgrade.MigrationProblemsContainer) HashSet(java.util.HashSet)

Example 47 with Problem

use of com.liferay.blade.api.Problem in project liferay-ide by liferay.

the class MigrationUtil method getProblemsFromSelection.

public static List<Problem> getProblemsFromSelection(ISelection selection) {
    final List<Problem> problems = new ArrayList<>();
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) selection;
        Iterator<?> elements = ss.iterator();
        while (elements.hasNext()) {
            Object element = elements.next();
            if (element instanceof Problem) {
                problems.add((Problem) element);
            }
        }
    }
    return problems;
}
Also used : ArrayList(java.util.ArrayList) Problem(com.liferay.blade.api.Problem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 48 with Problem

use of com.liferay.blade.api.Problem in project liferay-ide by liferay.

the class IgnoreAlwaysAction method run.

@Override
public void run() {
    final Problem problem = MigrationUtil.getProblemFromSelection(getSelection());
    _storeIgnoredProblem(problem);
    new WorkspaceJob("Ignore all problems of this type") {

        public IStatus runInWorkspace(IProgressMonitor monitor) {
            IStatus retval = Status.OK_STATUS;
            try {
                FindBreakingChangesPage page = UpgradeView.getPage(Page.findbreackingchangesPageId, FindBreakingChangesPage.class);
                TreeViewer treeViewer = page.getTreeViewer();
                MigrationContentProvider contentProvider = (MigrationContentProvider) treeViewer.getContentProvider();
                final MigrationProblemsContainer mpContainer = (MigrationProblemsContainer) contentProvider.getProblems().get(0);
                final MigrationProblems[] projectProblem = mpContainer.getProblemsArray();
                for (MigrationProblems pProblem : projectProblem) {
                    FileProblems[] fProblems = pProblem.getProblems();
                    for (FileProblems fp : fProblems) {
                        List<Problem> problems = fp.getProblems();
                        Iterator<Problem> iterator = problems.iterator();
                        while (iterator.hasNext()) {
                            Problem p = iterator.next();
                            if (p.getTicket().equals(problem.getTicket())) {
                                new IgnoreAction().run(p, _provider);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                retval = ProjectUI.createErrorStatus("Unable to get file from problem");
            }
            return retval;
        }
    }.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) TreeViewer(org.eclipse.jface.viewers.TreeViewer) FindBreakingChangesPage(com.liferay.ide.project.ui.upgrade.animated.FindBreakingChangesPage) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) MigrationProblems(com.liferay.ide.project.core.upgrade.MigrationProblems) MigrationProblemsContainer(com.liferay.ide.project.core.upgrade.MigrationProblemsContainer) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileProblems(com.liferay.ide.project.core.upgrade.FileProblems) Iterator(java.util.Iterator) Problem(com.liferay.blade.api.Problem) List(java.util.List)

Example 49 with Problem

use of com.liferay.blade.api.Problem in project liferay-ide by liferay.

the class MigrationDecorator method decorate.

@Override
public void decorate(Object element, IDecoration decoration) {
    final List<Problem> problems = new ArrayList<>();
    final List<Problem> resolvedProblems = new ArrayList<>();
    final List<Problem> ignoreProblems = new ArrayList<>();
    if (element instanceof FileProblems) {
        final FileProblems fileProblems = (FileProblems) element;
        problems.addAll(fileProblems.getProblems());
        resolvedProblems.addAll(fileProblems.getProblems(Problem.STATUS_RESOLVED));
        ignoreProblems.addAll(fileProblems.getProblems(Problem.STATUS_IGNORE));
    } else if (element instanceof UpgradeProblems) {
        final UpgradeProblems upgradeProblems = (UpgradeProblems) element;
        for (FileProblems fileProblems : upgradeProblems.getProblems()) {
            problems.addAll(fileProblems.getProblems());
            resolvedProblems.addAll(fileProblems.getProblems(Problem.STATUS_RESOLVED));
            ignoreProblems.addAll(fileProblems.getProblems(Problem.STATUS_IGNORE));
        }
    } else if (element instanceof ProblemsContainer) {
        ProblemsContainer problemsContainer = (ProblemsContainer) element;
        for (UpgradeProblems upgradeProblems : problemsContainer.getProblemsArray()) {
            for (FileProblems fileProblems : upgradeProblems.getProblems()) {
                problems.addAll(fileProblems.getProblems());
                resolvedProblems.addAll(fileProblems.getProblems(Problem.STATUS_RESOLVED));
                ignoreProblems.addAll(fileProblems.getProblems(Problem.STATUS_IGNORE));
            }
        }
    }
    if (ListUtil.isNotEmpty(problems)) {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        sb.append(problems.size()).append(" total");
        if (ListUtil.isNotEmpty(resolvedProblems)) {
            sb.append(", ");
            sb.append(resolvedProblems.size());
            sb.append(" resolved");
        }
        if (ListUtil.isNotEmpty(ignoreProblems)) {
            sb.append(", ");
            sb.append(ignoreProblems.size());
            sb.append(" ignored");
        }
        sb.append("]");
        decoration.addSuffix(sb.toString());
    }
}
Also used : FileProblems(com.liferay.ide.project.core.upgrade.FileProblems) UpgradeProblems(com.liferay.ide.project.core.upgrade.UpgradeProblems) ArrayList(java.util.ArrayList) Problem(com.liferay.blade.api.Problem) ProblemsContainer(com.liferay.ide.project.core.upgrade.ProblemsContainer)

Example 50 with Problem

use of com.liferay.blade.api.Problem in project liferay-ide by liferay.

the class AutoCorrectAction method selectionChanged.

@Override
public void selectionChanged(IStructuredSelection selection) {
    if (selection.isEmpty()) {
        setEnabled(false);
    } else {
        boolean selectionCompatible = true;
        Iterator<?> items = selection.iterator();
        Object lastItem = null;
        while (items.hasNext()) {
            Object item = items.next();
            if (!(item instanceof Problem)) {
                selectionCompatible = false;
                break;
            }
            Problem problem = (Problem) item;
            if (problem.autoCorrectContext == null) {
                selectionCompatible = false;
                break;
            }
            if (lastItem != null) {
                String prCurrentKey = ((Problem) item).autoCorrectContext.substring(0, problem.autoCorrectContext.indexOf(":"));
                String prLastKey = ((Problem) lastItem).autoCorrectContext.substring(0, problem.autoCorrectContext.indexOf(":"));
                if (!(prCurrentKey.equals(prLastKey))) {
                    selectionCompatible = false;
                    break;
                }
            }
            lastItem = item;
        }
        Iterator<?> items2 = selection.iterator();
        List<String> autoCorrectContexts = new ArrayList<>();
        while (items2.hasNext()) {
            Object item = items2.next();
            if (item instanceof Problem && ((Problem) item).autoCorrectContext != null) {
                autoCorrectContexts.add(((Problem) item).autoCorrectContext);
            }
        }
        setEnabled(selectionCompatible);
        List<String> allAutoCorrectContexts = new ArrayList<>();
        if (_provider instanceof TableViewer) {
            TableViewer viewer = (TableViewer) _provider;
            Object obj = viewer.getInput();
            if (obj instanceof Object[]) {
                Object[] problems = (Object[]) obj;
                for (Object o : problems) {
                    if (o instanceof Problem && ((Problem) o).autoCorrectContext != null) {
                        allAutoCorrectContexts.add(((Problem) o).autoCorrectContext);
                    }
                }
            } else if (obj instanceof List<?>) {
                List<?> list = (List<?>) obj;
                for (Object p : list) {
                    if (p instanceof Problem) {
                        Problem problem = (Problem) p;
                        if (problem.autoCorrectContext != null) {
                            allAutoCorrectContexts.add(problem.autoCorrectContext);
                        }
                    }
                }
            }
        }
        setText("Correct automatically");
    }
}
Also used : ArrayList(java.util.ArrayList) Problem(com.liferay.blade.api.Problem) ArrayList(java.util.ArrayList) List(java.util.List) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

Problem (com.liferay.blade.api.Problem)92 Test (org.junit.Test)58 File (java.io.File)42 FileMigrator (com.liferay.blade.api.FileMigrator)31 Migration (com.liferay.blade.api.Migration)29 NullProgressMonitor (com.liferay.blade.util.NullProgressMonitor)26 ArrayList (java.util.ArrayList)16 FileProblems (com.liferay.ide.project.core.upgrade.FileProblems)9 IOException (java.io.IOException)9 ServiceReference (org.osgi.framework.ServiceReference)9 AutoMigrator (com.liferay.blade.api.AutoMigrator)8 IFile (org.eclipse.core.resources.IFile)8 List (java.util.List)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 AutoMigrateException (com.liferay.blade.api.AutoMigrateException)5 SearchResult (com.liferay.blade.api.SearchResult)5 MigrationProblems (com.liferay.ide.project.core.upgrade.MigrationProblems)5 MigrationProblemsContainer (com.liferay.ide.project.core.upgrade.MigrationProblemsContainer)5 HashSet (java.util.HashSet)5 CoreException (org.eclipse.core.runtime.CoreException)5