use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class ProjectMigrationService method findProblems.
@Override
public List<Problem> findProblems(Set<File> files, ProgressMonitor monitor) {
List<Problem> problems = Collections.synchronizedList(new ArrayList<Problem>());
monitor.beginTask("Analyzing files", -1);
_total = files.size();
for (File file : files) {
_count++;
if (monitor.isCanceled()) {
return Collections.emptyList();
}
analyzeFile(file, problems, monitor);
}
_updateListeners(problems);
monitor.done();
_count = 0;
_total = 0;
return problems;
}
use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class ImportStatementMigrator method correctProblems.
@Override
public int correctProblems(File file, List<Problem> problems) throws AutoMigrateException {
int problemsFixed = 0;
List<String> importsToRewrite = new ArrayList<>();
for (Problem problem : problems) {
boolean problemFound = false;
if (problem.autoCorrectContext instanceof String) {
String importData = problem.autoCorrectContext;
if ((importData != null) && importData.startsWith(_PREFIX)) {
String importValue = importData.substring(_PREFIX.length());
if (_importFixes.containsKey(importValue)) {
importsToRewrite.add(problem.getLineNumber() + "," + importValue);
problemFound = true;
}
}
}
if (problemFound) {
problemsFixed++;
}
}
if (ListUtil.isNotEmpty(importsToRewrite)) {
try (InputStream inputStream = Files.newInputStream(file.toPath())) {
String[] lines = _readLines(inputStream);
String[] editedLines = new String[lines.length];
System.arraycopy(lines, 0, editedLines, 0, lines.length);
for (String importData : importsToRewrite) {
String[] importMap = importData.split(",");
int lineNumber = Integer.parseInt(importMap[0]);
String importName = importMap[1];
editedLines[lineNumber - 1] = editedLines[lineNumber - 1].replaceAll(importName, _importFixes.get(importName));
}
StringBuilder sb = new StringBuilder();
for (String editedLine : editedLines) {
sb.append(editedLine);
sb.append(System.getProperty("line.separator"));
}
FileWriter writer = new FileWriter(file);
writer.write(sb.toString());
writer.close();
_clearCache(file);
return problemsFixed;
} catch (IOException ioe) {
throw new AutoMigrateException("Unable to auto-correct", ioe);
}
}
return 0;
}
use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class LiferayVersionsProperties method correctProblems.
@Override
public int correctProblems(File file, List<Problem> problems) throws AutoMigrateException {
try {
String contents = new String(Files.readAllBytes(file.toPath()));
JavaFile javaFile = context.getBundleContext().getService(context.getBundleContext().getServiceReference(JavaFile.class));
IFile propertiesFile = javaFile.getIFile(file);
int problemsFixed = 0;
for (Problem problem : problems) {
if (problem.autoCorrectContext instanceof String) {
String propertyData = problem.autoCorrectContext;
if ((propertyData != null) && propertyData.startsWith(_PREFIX)) {
String propertyValue = propertyData.substring(_PREFIX.length());
contents = contents.replaceAll(propertyValue + ".*", propertyValue + "=7.0.0+");
problemsFixed++;
}
}
}
try (ByteArrayInputStream bos = new ByteArrayInputStream(contents.getBytes())) {
propertiesFile.setContents(bos, IResource.FORCE, null);
}
return problemsFixed;
} catch (CoreException | IOException e) {
}
return 0;
}
use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class LiferayVersionsProperties method analyze.
@Override
public List<Problem> analyze(File file) {
List<Problem> problems = new ArrayList<>();
if (file.getName().equals("liferay-plugin-package.properties")) {
PropertiesFileChecker propertiesFileChecker = new PropertiesFileChecker(file);
List<KeyInfo> keys = propertiesFileChecker.getInfos("liferay-versions");
if (ListUtil.isNotEmpty(keys)) {
String versions = keys.get(0).value;
if (!versions.matches(".*7\\.[0-9]\\.[0-9].*")) {
List<SearchResult> results = propertiesFileChecker.findProperties("liferay-versions");
if (results != null) {
String sectionHtml = problemSummary;
for (SearchResult searchResult : results) {
searchResult.autoCorrectContext = _PREFIX + "liferay-versions";
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;
}
use of com.liferay.blade.api.Problem in project liferay-ide by liferay.
the class MigrationUtil method markerToProblem.
public static Problem markerToProblem(IMarker marker) {
final String title = marker.getAttribute(IMarker.MESSAGE, "");
final String summary = marker.getAttribute("migrationProblem.summary", "");
final String type = marker.getAttribute("migrationProblem.type", "");
final String ticket = marker.getAttribute("migrationProblem.ticket", "");
final int lineNumber = marker.getAttribute(IMarker.LINE_NUMBER, 0);
final int startOffset = marker.getAttribute(IMarker.CHAR_START, 0);
final int endOffset = marker.getAttribute(IMarker.CHAR_END, 0);
final String html = marker.getAttribute("migrationProblem.html", "");
final String autoCorrectContext = marker.getAttribute("migrationProblem.autoCorrectContext", "");
final int status = marker.getAttribute("migrationProblem.status", 0);
final long markerId = marker.getId();
final int markerType = marker.getAttribute(IMarker.SEVERITY, 2);
final File file = new File(marker.getResource().getLocationURI());
return new Problem(UUID.randomUUID().toString(), title, summary, type, ticket, file, lineNumber, startOffset, endOffset, html, autoCorrectContext, status, markerId, markerType);
}
Aggregations