use of com.liferay.blade.api.Migration 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();
}
use of com.liferay.blade.api.Migration 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.Migration 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.Migration 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());
}
use of com.liferay.blade.api.Migration in project liferay-ide by liferay.
the class CustomAUIValidatorsTagsTest 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/custom-aui-validators/"), new NullProgressMonitor());
assertEquals(9, problems.size());
boolean found = false;
for (Problem problem : problems) {
if (problem.file.getName().endsWith("CustomAUIValidatorsTest.jsp") && problem.lineNumber == 314 && problem.startOffset >= 11387 && problem.endOffset >= 11393) {
found = true;
}
}
if (!found) {
fail();
}
}
Aggregations