Search in sources :

Example 6 with Problem

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

the class MigrationUtil method getProblemFromSelection.

public static Problem getProblemFromSelection(ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) selection;
        Object element = ss.getFirstElement();
        if (element instanceof Problem) {
            return (Problem) element;
        }
    }
    return null;
}
Also used : Problem(com.liferay.blade.api.Problem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 7 with Problem

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

the class MigratorComparator method compare.

@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    final Problem t1 = (Problem) e1;
    final Problem t2 = (Problem) e2;
    int flag = 0;
    switch(_columnIndex) {
        case 0:
            flag = (t1.getStatus() == Problem.STATUS_RESOLVED) ? 1 : -1;
            break;
        case 1:
            flag = t1.getLineNumber() >= t2.getLineNumber() ? 1 : -1;
            break;
        case 2:
            if (t1.getTitle().compareTo(t2.getTitle()) != 0) {
                flag = t1.getTitle().compareTo(t2.getTitle()) > 0 ? 1 : -1;
            }
            break;
        default:
            flag = 0;
    }
    if (_direction != _descending) {
        flag = -flag;
    }
    return flag;
}
Also used : Problem(com.liferay.blade.api.Problem)

Example 8 with Problem

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

the class ProblemAction method refreshTableViewer.

protected void refreshTableViewer() {
    FindBreakingChangesPage page = UpgradeView.getPage(Page.findbreackingchangesPageId, FindBreakingChangesPage.class);
    TableViewer problemsViewer = page.getProblemsViewer();
    UIUtil.async(new Runnable() {

        @Override
        public void run() {
            final Object selection = problemsViewer.getStructuredSelection().getFirstElement();
            List<Problem> problems = null;
            if (selection instanceof IFile) {
                IFile file = (IFile) selection;
                problems = MigrationUtil.getProblemsFromResource(file);
            } else if (selection instanceof Problem) {
                ISelection se = page.getTreeViewer().getSelection();
                if (se instanceof TreeSelection) {
                    problems = MigrationUtil.getCurrentProblemsFromTreeNode((TreeSelection) se);
                }
            }
            if (ListUtil.isNotEmpty(problems)) {
                problemsViewer.setInput(problems.toArray());
                problemsViewer.setSelection(new StructuredSelection(problems.get(0)));
            } else {
                problemsViewer.setInput(null);
            }
        }
    });
}
Also used : IFile(org.eclipse.core.resources.IFile) TreeSelection(org.eclipse.jface.viewers.TreeSelection) FindBreakingChangesPage(com.liferay.ide.project.ui.upgrade.animated.FindBreakingChangesPage) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) List(java.util.List) Problem(com.liferay.blade.api.Problem) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 9 with Problem

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

the class MigrateProjectHandler method findMigrationProblems.

public void findMigrationProblems(final IPath[] locations, final String[] projectName) {
    Job job = new WorkspaceJob("Finding migration problems...") {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
            IStatus retval = Status.OK_STATUS;
            final BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
            ProgressMonitor override = new ProgressMonitor() {

                @Override
                public void beginTask(String taskName, int totalWork) {
                    monitor.beginTask(taskName, totalWork);
                }

                @Override
                public void done() {
                    monitor.done();
                }

                @Override
                public boolean isCanceled() {
                    return monitor.isCanceled();
                }

                @Override
                public void setTaskName(String taskName) {
                    monitor.setTaskName(taskName);
                }

                @Override
                public void worked(int work) {
                    monitor.worked(work);
                }
            };
            try {
                final ServiceReference<Migration> sr = context.getServiceReference(Migration.class);
                final Migration m = context.getService(sr);
                List<Problem> allProblems = null;
                boolean singleFile = false;
                if ((locations.length == 1) && locations[0].toFile().exists() && locations[0].toFile().isFile()) {
                    singleFile = true;
                }
                MigrationProblemsContainer container = null;
                if (_combineExistedProblem == true) {
                    container = UpgradeAssistantSettingsUtil.getObjectFromStore(MigrationProblemsContainer.class);
                }
                List<MigrationProblems> migrationProblemsList = new ArrayList<>();
                if (container == null) {
                    container = new MigrationProblemsContainer();
                }
                if (container.getProblemsArray() != null) {
                    List<MigrationProblems> mpList = Arrays.asList(container.getProblemsArray());
                    for (MigrationProblems mp : mpList) {
                        migrationProblemsList.add(mp);
                    }
                }
                for (int j = 0; j < locations.length; j++) {
                    allProblems = new ArrayList<>();
                    if (!override.isCanceled() && _shouldSearch(locations[j].toFile())) {
                        List<Problem> problems = null;
                        if (singleFile) {
                            _clearFileMarkers(locations[j].toFile());
                            Set<File> files = new HashSet<>();
                            files.add(locations[j].toFile());
                            problems = m.findProblems(files, override);
                        } else {
                            problems = m.findProblems(locations[j].toFile(), override);
                        }
                        for (Problem problem : problems) {
                            if (_shouldAdd(problem)) {
                                allProblems.add(problem);
                            }
                        }
                    }
                    if (ListUtil.isNotEmpty(allProblems)) {
                        _addMarkers(allProblems);
                        MigrationProblems migrationProblems = new MigrationProblems();
                        FileProblems[] fileProblems = FileProblemsUtil.newFileProblemsListFrom(allProblems.toArray(new Problem[0]));
                        migrationProblems.setProblems(fileProblems);
                        migrationProblems.setType("Code Problems");
                        migrationProblems.setSuffix(projectName[j]);
                        int index = _isAlreadyExist(migrationProblemsList, projectName, j);
                        if (index != -1) {
                            if (singleFile) {
                                UpgradeProblems up = migrationProblemsList.get(index);
                                FileProblems[] problems = up.getProblems();
                                for (int n = 0; n < problems.length; n++) {
                                    FileProblems fp = problems[n];
                                    String problemFilePath = fp.getFile().getPath();
                                    String initProblemFilePath = locations[0].toFile().getPath();
                                    if (problemFilePath.equals(initProblemFilePath)) {
                                        problems[n] = fileProblems[0];
                                        break;
                                    }
                                }
                                migrationProblems.setProblems(problems);
                            }
                            migrationProblemsList.set(index, migrationProblems);
                        } else {
                            migrationProblemsList.add(migrationProblems);
                        }
                    } else {
                        int index = _isAlreadyExist(migrationProblemsList, projectName, j);
                        if (index != -1) {
                            if (singleFile) {
                                MigrationProblems mp = migrationProblemsList.get(index);
                                FileProblems[] fps = mp.getProblems();
                                List<FileProblems> fpList = Arrays.asList(fps);
                                List<FileProblems> newFPList = new ArrayList<>();
                                for (FileProblems fp : fpList) {
                                    String problemFilePath = fp.getFile().getPath();
                                    String initProblemFilePath = locations[0].toFile().getPath();
                                    if (!problemFilePath.equals(initProblemFilePath)) {
                                        newFPList.add(fp);
                                    }
                                }
                                mp.setProblems(newFPList.toArray(new FileProblems[0]));
                                migrationProblemsList.set(index, mp);
                            } else {
                                migrationProblemsList.remove(index);
                            }
                        }
                    }
                }
                if (ListUtil.isNotEmpty(migrationProblemsList)) {
                    container.setProblemsArray(migrationProblemsList.toArray(new MigrationProblems[0]));
                    UpgradeAssistantSettingsUtil.setObjectToStore(MigrationProblemsContainer.class, container);
                } else {
                    UpgradeAssistantSettingsUtil.setObjectToStore(MigrationProblemsContainer.class, null);
                }
                if (singleFile) {
                    refreshViewer(allProblems);
                } else {
                    allProblems.add(new Problem());
                    m.reportProblems(allProblems, Migration.DETAIL_LONG, "ide");
                }
            } catch (Exception e) {
                retval = ProjectUI.createErrorStatus("Error in migrate command", e);
            }
            return retval;
        }
    };
    try {
        ProjectUI.getProgressService().showInDialog(Display.getDefault().getActiveShell(), job);
    } catch (Exception e) {
    }
    job.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Migration(com.liferay.blade.api.Migration) ArrayList(java.util.ArrayList) MigrationProblems(com.liferay.ide.project.core.upgrade.MigrationProblems) MigrationProblemsContainer(com.liferay.ide.project.core.upgrade.MigrationProblemsContainer) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Job(org.eclipse.core.runtime.jobs.Job) HashSet(java.util.HashSet) UpgradeProblems(com.liferay.ide.project.core.upgrade.UpgradeProblems) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) ProgressMonitor(com.liferay.blade.api.ProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileProblems(com.liferay.ide.project.core.upgrade.FileProblems) Problem(com.liferay.blade.api.Problem) IFile(org.eclipse.core.resources.IFile) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 10 with Problem

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

the class MigrateProjectHandler method _addMarkers.

private void _addMarkers(List<Problem> problems) {
    IWorkspaceRoot ws = CoreUtil.getWorkspaceRoot();
    for (Problem problem : problems) {
        IResource workspaceResource = null;
        File file = problem.file;
        IResource[] containers = ws.findContainersForLocationURI(file.toURI());
        if (ListUtil.isNotEmpty(containers)) {
            for (IResource container : containers) {
                if (FileUtil.exists(container)) {
                    if (container.getType() == IResource.PROJECT) {
                        workspaceResource = container;
                        break;
                    } else {
                        IProject project = container.getProject();
                        if (CoreUtil.isLiferayProject(project)) {
                            workspaceResource = container;
                            break;
                        }
                    }
                }
            }
            if (workspaceResource == null) {
                final IFile[] files = ws.findFilesForLocationURI(file.toURI());
                for (IFile ifile : files) {
                    if (ifile.exists()) {
                        if (workspaceResource == null) {
                            if (CoreUtil.isLiferayProject(ifile.getProject())) {
                                workspaceResource = ifile;
                            }
                        } else {
                            if (ifile.getFullPath().segmentCount() < workspaceResource.getFullPath().segmentCount()) {
                                workspaceResource = ifile;
                            }
                        }
                    }
                }
            }
            if (workspaceResource == null) {
                for (IResource container : containers) {
                    if (workspaceResource == null) {
                        workspaceResource = container;
                    } else {
                        if (container.getLocation().segmentCount() < workspaceResource.getLocation().segmentCount()) {
                            workspaceResource = container;
                        }
                    }
                }
            }
        }
        if ((workspaceResource != null) && workspaceResource.exists()) {
            try {
                final IMarker marker = workspaceResource.createMarker(MigrationConstants.MARKER_TYPE);
                problem.setMarkerId(marker.getId());
                MigrationUtil.problemToMarker(problem, marker);
            } catch (CoreException ce) {
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) Problem(com.liferay.blade.api.Problem) IMarker(org.eclipse.core.resources.IMarker) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

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