Search in sources :

Example 1 with MigrationProblemsContainer

use of com.liferay.ide.project.core.upgrade.MigrationProblemsContainer 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 2 with MigrationProblemsContainer

use of com.liferay.ide.project.core.upgrade.MigrationProblemsContainer in project liferay-ide by liferay.

the class MigrateProjectHandler method refreshViewer.

protected void refreshViewer(List<Problem> allProblems) {
    FindBreakingChangesPage page = UpgradeView.getPage(Page.findbreackingchangesPageId, FindBreakingChangesPage.class);
    TableViewer problemsViewer = page.get_problemsViewer();
    TreeViewer treeViewer = page.getTreeViewer();
    UIUtil.async(new Runnable() {

        @Override
        public void run() {
            problemsViewer.setInput(allProblems);
            Object currentTreeNode = treeViewer.getStructuredSelection().getFirstElement();
            String currentPath = null;
            if (currentTreeNode instanceof FileProblems) {
                FileProblems currentNode = (FileProblems) currentTreeNode;
                File currentFile = currentNode.getFile();
                currentPath = currentFile.getAbsolutePath();
            }
            MigrationContentProvider contentProvider = (MigrationContentProvider) treeViewer.getContentProvider();
            MigrationProblemsContainer mc = (MigrationProblemsContainer) contentProvider.getProblems().get(0);
            for (MigrationProblems project : mc.getProblemsArray()) {
                Iterator<FileProblems> fileProblemItertor = new LinkedList<>(Arrays.asList(project.getProblems())).iterator();
                while (fileProblemItertor.hasNext()) {
                    FileProblems fileProblem = fileProblemItertor.next();
                    File file = fileProblem.getFile();
                    String fileAbsolutePath = file.getAbsolutePath();
                    if (fileAbsolutePath.equals(currentPath)) {
                        List<Problem> problems = fileProblem.getProblems();
                        problems.clear();
                        problems.addAll(allProblems);
                        break;
                    }
                }
            }
        }
    });
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) FindBreakingChangesPage(com.liferay.ide.project.ui.upgrade.animated.FindBreakingChangesPage) MigrationProblems(com.liferay.ide.project.core.upgrade.MigrationProblems) MigrationProblemsContainer(com.liferay.ide.project.core.upgrade.MigrationProblemsContainer) LinkedList(java.util.LinkedList) FileProblems(com.liferay.ide.project.core.upgrade.FileProblems) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TableViewer(org.eclipse.jface.viewers.TableViewer) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 3 with MigrationProblemsContainer

use of com.liferay.ide.project.core.upgrade.MigrationProblemsContainer in project liferay-ide by liferay.

the class FindBreakingChangesPage method getInitialInput.

public List<ProblemsContainer> getInitialInput() {
    List<ProblemsContainer> problems = null;
    try {
        MigrationProblemsContainer container = UpgradeAssistantSettingsUtil.getObjectFromStore(MigrationProblemsContainer.class);
        if (container != null) {
            problems = new ArrayList<>();
            problems.add(container);
        }
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    _migrationContentProvider.setProblems(problems);
    return problems;
}
Also used : IOException(java.io.IOException) MigrationProblemsContainer(com.liferay.ide.project.core.upgrade.MigrationProblemsContainer) MigrationProblemsContainer(com.liferay.ide.project.core.upgrade.MigrationProblemsContainer) ProblemsContainer(com.liferay.ide.project.core.upgrade.ProblemsContainer)

Example 4 with MigrationProblemsContainer

use of com.liferay.ide.project.core.upgrade.MigrationProblemsContainer in project liferay-ide by liferay.

the class UpgradeView method _restartUpgradeTool.

private void _restartUpgradeTool() {
    boolean openNewLiferayProjectWizard = MessageDialog.openQuestion(UIUtil.getActiveShell(), "Restart code upgrade?", "All previous configuration files will be deleted. Do you want to restart the code upgrade tool?");
    if (openNewLiferayProjectWizard) {
        CustomJspConverter.clearConvertResults();
        try {
            MigrationProblemsContainer container = UpgradeAssistantSettingsUtil.getObjectFromStore(MigrationProblemsContainer.class);
            if (container != null) {
                UpgradeAssistantSettingsUtil.setObjectToStore(MigrationProblemsContainer.class, null);
            }
            BreakingChangeSelectedProject selectedProject = UpgradeAssistantSettingsUtil.getObjectFromStore(BreakingChangeSelectedProject.class);
            if (selectedProject != null) {
                UpgradeAssistantSettingsUtil.setObjectToStore(BreakingChangeSelectedProject.class, null);
            }
        } catch (IOException ioe) {
            ProjectUI.logError(ioe);
        }
        IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        IWorkbenchPage page = activeWorkbenchWindow.getActivePage();
        UpgradeView view = (UpgradeView) UIUtil.findView(UpgradeView.ID);
        CustomJspConverter.clearConvertResults();
        page.hideView(view);
        UpgradeSettingsUtil.resetStoreProperties();
        try {
            page.showView(UpgradeView.ID);
        } catch (PartInitException pie) {
            pie.printStackTrace();
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IOException(java.io.IOException) PartInitException(org.eclipse.ui.PartInitException) MigrationProblemsContainer(com.liferay.ide.project.core.upgrade.MigrationProblemsContainer) BreakingChangeSelectedProject(com.liferay.ide.project.core.upgrade.BreakingChangeSelectedProject)

Example 5 with MigrationProblemsContainer

use of com.liferay.ide.project.core.upgrade.MigrationProblemsContainer in project liferay-ide by liferay.

the class MigrationUtil method updateMigrationProblemToStore.

public static void updateMigrationProblemToStore(Problem problem) {
    File file = problem.getFile();
    try {
        MigrationProblemsContainer container = UpgradeAssistantSettingsUtil.getObjectFromStore(MigrationProblemsContainer.class);
        boolean found = false;
        for (MigrationProblems mp : container.getProblemsArray()) {
            for (FileProblems fileProblem : mp.getProblems()) {
                if (fileProblem.getFile().equals(file)) {
                    for (int i = 0; i < fileProblem.getProblems().size(); i++) {
                        Problem p = fileProblem.getProblems().get(i);
                        if (p.equals(problem)) {
                            fileProblem.getProblems().set(i, problem);
                            found = true;
                            break;
                        }
                    }
                }
                if (found) {
                    break;
                }
            }
            if (found) {
                break;
            }
        }
        UpgradeAssistantSettingsUtil.setObjectToStore(MigrationProblemsContainer.class, container);
    } catch (IOException ioe) {
    }
}
Also used : FileProblems(com.liferay.ide.project.core.upgrade.FileProblems) Problem(com.liferay.blade.api.Problem) IOException(java.io.IOException) MigrationProblems(com.liferay.ide.project.core.upgrade.MigrationProblems) IFile(org.eclipse.core.resources.IFile) File(java.io.File) MigrationProblemsContainer(com.liferay.ide.project.core.upgrade.MigrationProblemsContainer)

Aggregations

MigrationProblemsContainer (com.liferay.ide.project.core.upgrade.MigrationProblemsContainer)9 FileProblems (com.liferay.ide.project.core.upgrade.FileProblems)7 MigrationProblems (com.liferay.ide.project.core.upgrade.MigrationProblems)7 Problem (com.liferay.blade.api.Problem)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 File (java.io.File)3 HashSet (java.util.HashSet)3 IFile (org.eclipse.core.resources.IFile)3 FindBreakingChangesPage (com.liferay.ide.project.ui.upgrade.animated.FindBreakingChangesPage)2 List (java.util.List)2 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 Migration (com.liferay.blade.api.Migration)1 ProgressMonitor (com.liferay.blade.api.ProgressMonitor)1 BreakingChangeSelectedProject (com.liferay.ide.project.core.upgrade.BreakingChangeSelectedProject)1