use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class FindBreakingChangesPage method _createColumns.
private void _createColumns(final TableViewer problemsViewer) {
final String[] titles = { "Resolved", "Line", "Problem" };
TableViewerColumn col0 = _createTableViewerColumn(titles[0], problemsViewer);
col0.getColumn().pack();
col0.setEditingSupport(new EditingSupport(problemsViewer) {
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected CellEditor getCellEditor(Object element) {
return new CheckboxCellEditor(problemsViewer.getTable());
}
@Override
protected Object getValue(Object element) {
return ((Problem) element).getStatus() == Problem.STATUS_RESOLVED;
}
@Override
protected void setValue(Object element, Object value) {
if (value == Boolean.TRUE) {
new MarkDoneAction().run((Problem) element, problemsViewer);
} else {
new MarkUndoneAction().run((Problem) element, problemsViewer);
}
}
});
col0.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
Problem p = (Problem) element;
if (p.getStatus() == Problem.STATUS_RESOLVED) {
return _imageChecked;
} else {
return _imageUnchecked;
}
}
@Override
public String getText(Object element) {
return null;
}
});
TableViewerColumn col1 = _createTableViewerColumn(titles[1], problemsViewer);
col1.getColumn().pack();
col1.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Problem p = (Problem) element;
return p.lineNumber > -1 ? (p.lineNumber + "") : "";
}
});
TableViewerColumn col2 = _createTableViewerColumn(titles[2], problemsViewer);
col2.getColumn().pack();
col2.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Problem p = (Problem) element;
return p.title;
}
@Override
public void update(ViewerCell cell) {
super.update(cell);
Table table = problemsViewer.getTable();
table.getColumn(2).pack();
}
});
TableColumnLayout tableLayout = new TableColumnLayout();
TableColumn column0 = col0.getColumn();
TableColumn column1 = col1.getColumn();
TableColumn column2 = col2.getColumn();
tableLayout.setColumnData(column0, new ColumnWeightData(50, column0.getWidth()));
tableLayout.setColumnData(column1, new ColumnWeightData(50, column1.getWidth()));
tableLayout.setColumnData(column2, new ColumnWeightData(100, column2.getWidth()));
Table table = problemsViewer.getTable();
table.getParent().setLayout(tableLayout);
}
use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class ProjectMigrationService method reportProblems.
@Override
public void reportProblems(List<Problem> problems, int detail, String format, Object... args) {
Reporter reporter = null;
try {
Collection<ServiceReference<Reporter>> references = _context.getServiceReferences(Reporter.class, "(format=" + format + ")");
if (ListUtil.isNotEmpty(references)) {
reporter = _context.getService(references.iterator().next());
} else {
ServiceReference<Reporter> sr = _context.getServiceReference(Reporter.class);
reporter = _context.getService(sr);
}
} catch (InvalidSyntaxException ise) {
ise.printStackTrace();
}
OutputStream fos = null;
try {
if (ListUtil.isNotEmpty(args)) {
if (args[0] instanceof File) {
File outputFile = (File) args[0];
outputFile.getParentFile().mkdirs();
outputFile.createNewFile();
fos = Files.newOutputStream(outputFile.toPath());
} else if (args[0] instanceof OutputStream) {
fos = (OutputStream) args[0];
}
}
if (ListUtil.isNotEmpty(problems)) {
reporter.beginReporting(detail, fos);
for (Problem problem : problems) {
reporter.report(problem);
}
reporter.endReporting();
}
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class ProjectMigrationService method analyzeFile.
protected FileVisitResult analyzeFile(File file, final List<Problem> problems, ProgressMonitor monitor) {
Path path = file.toPath();
String fileName = path.getFileName().toString();
String extension = fileName.substring(fileName.lastIndexOf('.') + 1);
monitor.setTaskName("Analyzing file " + _count + "/" + _total + " " + fileName);
ServiceReference<FileMigrator>[] fileMigrators = _fileMigratorTracker.getServiceReferences();
if (ListUtil.isNotEmpty(fileMigrators)) {
Stream<ServiceReference<FileMigrator>> serviceStream = Arrays.asList(fileMigrators).stream();
List<ServiceReference<FileMigrator>> fileMigratorList = serviceStream.filter(predicate -> {
String fileExtensionString = (String) predicate.getProperty("file.extensions");
List<String> extensionList = Arrays.asList(fileExtensionString.split(","));
return extensionList.contains(extension);
}).collect(Collectors.toList());
if (ListUtil.isNotEmpty(fileMigratorList)) {
try {
Stream<ServiceReference<FileMigrator>> migratorStream = fileMigratorList.stream();
migratorStream.map(_context::getService).parallel().forEach(fm -> {
List<Problem> fileProlbems = fm.analyze(file);
if (ListUtil.isNotEmpty(fileProlbems)) {
problems.addAll(fileProlbems);
}
});
} catch (Exception e) {
}
}
_count++;
}
return FileVisitResult.CONTINUE;
}
use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class AbstractFileMigrator method analyze.
@Override
public List<Problem> analyze(File file) {
List<Problem> problems = new ArrayList<>();
String fileExtension = new Path(file.getAbsolutePath()).getFileExtension();
List<SearchResult> searchResults = searchFile(file, createFileChecker(type, file, fileExtension));
if (ListUtil.isNotEmpty(searchResults)) {
String sectionHtml = MarkdownParser.getSection("BREAKING_CHANGES.markdown", sectionKey);
if ((sectionHtml != null) && sectionHtml.equals("#legacy")) {
sectionHtml = problemSummary;
}
for (SearchResult searchResult : searchResults) {
if (searchResult != null) {
problems.add(new Problem(problemTitle, problemSummary, fileExtension, problemTickets, file, searchResult.startLine, searchResult.startOffset, searchResult.endOffset, sectionHtml, searchResult.autoCorrectContext, Problem.STATUS_NOT_RESOLVED, Problem.DEFAULT_MARKER_ID, Problem.MARKER_ERROR));
}
}
}
return problems;
}
use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class JSPTagMigrator method correctProblems.
@Override
public int correctProblems(File file, List<Problem> problems) throws AutoMigrateException {
int corrected = 0;
List<Integer> autoCorrectTagOffsets = new ArrayList<>();
Stream<Problem> stream = problems.stream();
Class<? extends JSPTagMigrator> class1 = getClass();
String autoCorrectContext = "jsptag:" + class1.getName();
stream.filter(p -> p.autoCorrectContext.equals(autoCorrectContext)).map(p -> p.getStartOffset()).sorted();
for (Problem problem : problems) {
if ((problem.autoCorrectContext != null) && problem.autoCorrectContext.equals("jsptag:" + class1.getName())) {
autoCorrectTagOffsets.add(problem.getStartOffset());
}
}
Collections.sort(autoCorrectTagOffsets, new Comparator<Integer>() {
@Override
public int compare(Integer i1, Integer i2) {
return i2.compareTo(i1);
}
});
IFile jspFile = getJSPFile(file);
if (ListUtil.isNotEmpty(autoCorrectTagOffsets)) {
IDOMModel domModel = null;
try {
domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(jspFile);
List<IDOMElement> elementsToCorrect = new ArrayList<>();
for (int startOffset : autoCorrectTagOffsets) {
IndexedRegion region = domModel.getIndexedRegion(startOffset);
if (region instanceof IDOMElement) {
IDOMElement element = (IDOMElement) region;
elementsToCorrect.add(element);
}
}
for (IDOMElement element : elementsToCorrect) {
domModel.aboutToChangeModel();
if (_newAttrValues.length == 1) {
element.setAttribute(_attrNames[0], _newAttrValues[0]);
corrected++;
} else if (_newAttrNames.length == 1) {
String value = element.getAttribute(_attrNames[0]);
element.removeAttribute(_attrNames[0]);
element.setAttribute(_newAttrNames[0], value);
corrected++;
} else if (ListUtil.isNotEmpty(_newTagNames)) {
String tagName = element.getTagName();
NamedNodeMap attributes = element.getAttributes();
NodeList childNodes = element.getChildNodes();
String nodeValue = element.getNodeValue();
String newTagName = "";
for (int i = 0; i < _tagNames.length; i++) {
if (_tagNames[i].equals(tagName)) {
newTagName = _newTagNames[i];
break;
}
}
if (newTagName.equals("")) {
continue;
}
Element newNode = element.getOwnerDocument().createElement(newTagName);
if (nodeValue != null) {
newNode.setNodeValue(nodeValue);
}
for (int i = 0; i < attributes.getLength(); i++) {
Node attribute = attributes.item(i);
newNode.setAttribute(attribute.getNodeName(), attribute.getNodeValue());
}
for (int i = 0; i < childNodes.getLength(); i++) {
Node childNode = childNodes.item(i);
newNode.appendChild(childNode.cloneNode(true));
}
element.getParentNode().replaceChild(newNode, element);
corrected++;
}
domModel.changedModel();
domModel.save();
}
} catch (Exception e) {
throw new AutoMigrateException("Unable to auto-correct", e);
} finally {
if (domModel != null) {
domModel.releaseFromEdit();
}
}
IPath location = jspFile.getLocation();
if ((corrected > 0) && !location.toFile().equals(file)) {
try (InputStream jspFileContent = jspFile.getContents()) {
Files.copy(jspFileContent, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
throw new AutoMigrateException("Error writing corrected file.", e);
}
}
}
return corrected;
}
Aggregations