Search in sources :

Example 91 with Problem

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) AutoMigrateException(com.liferay.blade.api.AutoMigrateException) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Text(org.w3c.dom.Text) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) AutoMigrateException(com.liferay.blade.api.AutoMigrateException) Problem(com.liferay.blade.api.Problem)

Example 92 with Problem

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

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