Search in sources :

Example 1 with Problem

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;
}
Also used : Problem(com.liferay.blade.api.Problem) File(java.io.File)

Example 2 with Problem

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;
}
Also used : AutoMigrateException(com.liferay.blade.api.AutoMigrateException) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) Problem(com.liferay.blade.api.Problem) IOException(java.io.IOException)

Example 3 with Problem

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) JavaFile(com.liferay.blade.api.JavaFile) Problem(com.liferay.blade.api.Problem) IOException(java.io.IOException)

Example 4 with Problem

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;
}
Also used : PropertiesFileChecker(com.liferay.blade.upgrade.liferay70.PropertiesFileChecker) KeyInfo(com.liferay.blade.upgrade.liferay70.PropertiesFileChecker.KeyInfo) ArrayList(java.util.ArrayList) Problem(com.liferay.blade.api.Problem) SearchResult(com.liferay.blade.api.SearchResult)

Example 5 with Problem

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);
}
Also used : Problem(com.liferay.blade.api.Problem) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

Problem (com.liferay.blade.api.Problem)92 Test (org.junit.Test)58 File (java.io.File)42 FileMigrator (com.liferay.blade.api.FileMigrator)31 Migration (com.liferay.blade.api.Migration)29 NullProgressMonitor (com.liferay.blade.util.NullProgressMonitor)26 ArrayList (java.util.ArrayList)16 FileProblems (com.liferay.ide.project.core.upgrade.FileProblems)9 IOException (java.io.IOException)9 ServiceReference (org.osgi.framework.ServiceReference)9 AutoMigrator (com.liferay.blade.api.AutoMigrator)8 IFile (org.eclipse.core.resources.IFile)8 List (java.util.List)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 AutoMigrateException (com.liferay.blade.api.AutoMigrateException)5 SearchResult (com.liferay.blade.api.SearchResult)5 MigrationProblems (com.liferay.ide.project.core.upgrade.MigrationProblems)5 MigrationProblemsContainer (com.liferay.ide.project.core.upgrade.MigrationProblemsContainer)5 HashSet (java.util.HashSet)5 CoreException (org.eclipse.core.runtime.CoreException)5