use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class AutoCorrectAction method runWithAutoCorrect.
public IStatus runWithAutoCorrect(final List<Problem> problems) {
final IResource file = MigrationUtil.getIResourceFromProblem(problems.get(0));
final BundleContext context = FrameworkUtil.getBundle(AutoCorrectAction.class).getBundleContext();
WorkspaceJob job = new WorkspaceJob("Auto correcting migration problem.") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) {
IStatus retval = Status.OK_STATUS;
try {
final Problem problem = problems.get(0);
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, Collections.singletonList(problem));
if (problemsCorrected > 0) {
IResource resource = MigrationUtil.getIResourceFromProblem(problem);
if (resource != null) {
IMarker problemMarker = resource.findMarker(problem.markerId);
if ((problemMarker != null) && problemMarker.exists()) {
problemMarker.delete();
}
}
}
}
file.refreshLocal(IResource.DEPTH_ONE, monitor);
MigrateProjectHandler migrateHandler = new MigrateProjectHandler();
Path path = new Path(problem.getFile().getPath());
String projectName = "";
IProject project = CoreUtil.getProject(problem.getFile());
if (project.exists() && (project != null)) {
projectName = project.getName();
}
for (Problem p : problems) {
new MarkDoneAction().run(p, _provider);
}
if (!projectName.equals("")) {
migrateHandler.findMigrationProblems(new Path[] { path }, new String[] { projectName });
}
} catch (AutoMigrateException | CoreException | InvalidSyntaxException e) {
return retval = ProjectUI.createErrorStatus("Unable to auto correct problem", e);
}
return retval;
}
};
job.schedule();
return Status.OK_STATUS;
}
use of com.liferay.blade.api.Problem 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.blade.api.Problem in project liferay-ide by liferay.
the class ProgressMonitorCancelTest method cancelableProgressMonitor.
@Test
public void cancelableProgressMonitor() throws Exception {
ServiceReference<Migration> sr = context.getServiceReference(Migration.class);
final Migration m = context.getService(sr);
final List<Problem> result = new ArrayList<>();
final CancelableProgressMonitor cancelable = new CancelableProgressMonitor();
final Thread t = new Thread() {
@Override
public void run() {
List<Problem> problems = m.findProblems(new File("projects"), cancelable);
result.addAll(problems);
}
};
t.start();
Thread.sleep(5000);
cancelable.canceled = true;
t.join();
final int expectedSize = 1324;
final int size = result.size();
assertTrue(size < expectedSize);
}
use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class RestoreEntryTagsTest method findProblems.
@Test
public void findProblems() throws Exception {
ServiceReference<Migration> sr = context.getServiceReference(Migration.class);
Migration m = context.getService(sr);
List<Problem> problems = m.findProblems(new File("jsptests/restore-entry/"), new NullProgressMonitor());
assertEquals(1, problems.size());
boolean found = false;
for (Problem problem : problems) {
if (problem.file.getName().endsWith("RestoreEntryTagsTest.jsp")) {
if (problem.lineNumber == 2 && problem.startOffset >= 12 && problem.endOffset >= 318) {
found = true;
}
}
}
if (!found) {
fail();
}
}
use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class TrashUndoTagsTest method findProblems.
@Test
public void findProblems() throws Exception {
ServiceReference<Migration> sr = context.getServiceReference(Migration.class);
Migration m = context.getService(sr);
List<Problem> problems = m.findProblems(new File("jsptests/liferay-ui-trash-undo/"), new NullProgressMonitor());
assertEquals(1, problems.size());
}
Aggregations