use of com.liferay.ide.project.core.upgrade.BreakingChangeSelectedProject in project liferay-ide by liferay.
the class OpenJavaProjectSelectionDialogAction method getSelectionProjects.
protected ISelection getSelectionProjects() {
final BreakingChangeProjectDialog dialog = new BreakingChangeProjectDialog(_shell);
if (dialog.open() == Window.OK) {
final Object[] selectedProjects = dialog.getResult();
if (selectedProjects != null) {
List<IProject> projects = new ArrayList<>();
for (Object project : selectedProjects) {
if (project instanceof IJavaProject) {
IJavaProject p = (IJavaProject) project;
projects.add(p.getProject());
}
}
try {
BreakingChangeSelectedProject bkProject = new BreakingChangeSelectedProject();
projects.stream().forEach(project -> bkProject.addSimpleProject(new BreakingChangeSimpleProject(project.getName(), project.getLocation().toOSString())));
UpgradeAssistantSettingsUtil.setObjectToStore(BreakingChangeSelectedProject.class, bkProject);
} catch (IOException ioe) {
ProjectUI.logError(ioe);
}
return new StructuredSelection(projects.toArray(new IProject[0]));
}
}
return null;
}
use of com.liferay.ide.project.core.upgrade.BreakingChangeSelectedProject in project liferay-ide by liferay.
the class AutoCorrectAllAction method run.
public void run() {
final BundleContext context = FrameworkUtil.getBundle(AutoCorrectAction.class).getBundleContext();
WorkspaceJob job = new WorkspaceJob("Auto correcting all of migration problem.") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) {
IStatus retval = Status.OK_STATUS;
try {
if ((_problemsContainerList != null) && (_problemsContainerList.size() > 0)) {
for (ProblemsContainer problemsContainer : _problemsContainerList) {
for (UpgradeProblems upgradeProblems : problemsContainer.getProblemsArray()) {
FileProblems[] fileProblemsArray = upgradeProblems.getProblems();
for (FileProblems fileProblems : fileProblemsArray) {
List<Problem> problems = fileProblems.getProblems();
Set<String> fixed = new HashSet<>();
for (Problem problem : problems) {
if (problem.getStatus() == Problem.STATUS_IGNORE) {
continue;
}
final IResource file = MigrationUtil.getIResourceFromProblem(problem);
if (FileUtil.notExists(file)) {
continue;
}
String fixedKey = file.getLocation().toString() + "," + problem.autoCorrectContext;
if ((problem.autoCorrectContext == null) || fixed.contains(fixedKey)) {
continue;
}
String autoCorrectKey = null;
final int filterKeyIndex = problem.autoCorrectContext.indexOf(":");
if (filterKeyIndex > -1) {
autoCorrectKey = problem.autoCorrectContext.substring(0, filterKeyIndex);
} else {
autoCorrectKey = problem.autoCorrectContext;
}
final Collection<ServiceReference<AutoMigrator>> refs = context.getServiceReferences(AutoMigrator.class, "(auto.correct=" + autoCorrectKey + ")");
for (ServiceReference<AutoMigrator> ref : refs) {
final AutoMigrator autoMigrator = context.getService(ref);
int problemsCorrected = autoMigrator.correctProblems(problem.file, problems);
fixed.add(fixedKey);
if ((problemsCorrected > 0) && (file != null)) {
IMarker problemMarker = file.findMarker(problem.markerId);
if ((problemMarker != null) && problemMarker.exists()) {
problemMarker.delete();
}
}
}
file.refreshLocal(IResource.DEPTH_ONE, monitor);
}
}
}
}
}
UIUtil.sync(new Runnable() {
@Override
public void run() {
IViewPart view = UIUtil.findView(UpgradeView.ID);
try {
BreakingChangeSelectedProject selectedProject = UpgradeAssistantSettingsUtil.getObjectFromStore(BreakingChangeSelectedProject.class);
StructuredSelection projectSelection = null;
List<IProject> projects = new ArrayList<>();
if (selectedProject != null) {
List<BreakingChangeSimpleProject> selectedProjects = selectedProject.getSelectedProjects();
selectedProjects.stream().forEach(breakingProject -> projects.add(CoreUtil.getProject(breakingProject.getName())));
projectSelection = new StructuredSelection(projects.toArray(new IProject[0]));
}
new RunMigrationToolAction("Run Migration Tool", view.getViewSite().getShell(), projectSelection).run();
} catch (IOException ioe) {
ProjectUI.logError(ioe);
}
}
});
} catch (AutoMigrateException | CoreException | InvalidSyntaxException e) {
return retval = ProjectUI.createErrorStatus("Unable to auto correct problem", e);
}
return retval;
}
};
job.schedule();
}
use of com.liferay.ide.project.core.upgrade.BreakingChangeSelectedProject 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();
}
}
}
Aggregations