use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class MVCPortletClassInPortletXML method correctProblems.
@Override
public int correctProblems(File file, List<Problem> problems) throws AutoMigrateException {
int corrected = 0;
IFile xmlFile = getXmlFile(file);
IDOMModel xmlModel = null;
if (xmlFile != null) {
try {
xmlModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(xmlFile);
List<IDOMElement> elementsToCorrect = new ArrayList<>();
for (Problem problem : problems) {
if (_KEY.equals(problem.autoCorrectContext)) {
IndexedRegion region = xmlModel.getIndexedRegion(problem.startOffset);
if (region instanceof IDOMElement) {
IDOMElement element = (IDOMElement) region;
elementsToCorrect.add(element);
}
}
}
for (IDOMElement element : elementsToCorrect) {
xmlModel.aboutToChangeModel();
_removeChildren(element);
Text textContent = element.getOwnerDocument().createTextNode("com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet");
element.appendChild(textContent);
xmlModel.changedModel();
corrected++;
}
xmlModel.save();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (xmlModel != null) {
xmlModel.releaseFromEdit();
}
}
}
IPath location = xmlFile.getLocation();
if ((corrected > 0) && !location.toFile().equals(file)) {
try (InputStream xmlFileContent = xmlFile.getContents()) {
Files.copy(xmlFileContent, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
throw new AutoMigrateException("Error writing corrected file.", e);
}
}
return corrected;
}
use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class PropertiesFileMigrator method analyze.
@Override
public List<Problem> analyze(File file) {
List<Problem> problems = new ArrayList<>();
PropertiesFileChecker propertiesFileChecker = new PropertiesFileChecker(file);
for (String key : properties) {
List<SearchResult> results = propertiesFileChecker.findProperties(key);
if (results != null) {
String sectionHtml = MarkdownParser.getSection("BREAKING_CHANGES.markdown", sectionKey);
for (SearchResult searchResult : results) {
problems.add(new Problem(problemTitle, problemSummary, problemType, problemTickets, file, searchResult.startLine, searchResult.startOffset, searchResult.endOffset, sectionHtml, searchResult.autoCorrectContext, Problem.STATUS_NOT_RESOLVED, Problem.DEFAULT_MARKER_ID, Problem.MARKER_ERROR));
}
}
}
return problems;
}
Aggregations