Search in sources :

Example 31 with FileMigrator

use of com.liferay.blade.api.FileMigrator in project liferay-ide by liferay.

the class SocialNetworkingLegacyAPITest method testFull2.

@Test
public void testFull2() throws Exception {
    FileMigrator fmigrator = context.getService(fileMigrators[0]);
    List<Problem> problems = fmigrator.analyze(testFile2);
    context.ungetService(fileMigrators[0]);
    assertNotNull(problems);
    assertEquals(6, problems.size());
    Problem problem = problems.get(0);
    assertEquals(24, problem.lineNumber);
    if (Util.isWindows()) {
        assertEquals(1005, problem.startOffset);
        assertEquals(1070, problem.endOffset);
    } else {
        assertEquals(982, problem.startOffset);
        assertEquals(1047, problem.endOffset);
    }
    problem = problems.get(1);
    assertEquals(57, problem.lineNumber);
    if (Util.isWindows()) {
        assertEquals(1892, problem.startOffset);
        assertEquals(1955, problem.endOffset);
    } else {
        assertEquals(1836, problem.startOffset);
        assertEquals(1899, problem.endOffset);
    }
    problem = problems.get(2);
    assertEquals(128, problem.lineNumber);
    if (Util.isWindows()) {
        assertEquals(4271, problem.startOffset);
        assertEquals(4570, problem.endOffset);
    } else {
        assertEquals(4144, problem.startOffset);
        assertEquals(4439, problem.endOffset);
    }
    problem = problems.get(3);
    assertEquals(135, problem.lineNumber);
    if (Util.isWindows()) {
        assertEquals(4591, problem.startOffset);
        assertEquals(4914, problem.endOffset);
    } else {
        assertEquals(4457, problem.startOffset);
        assertEquals(4775, problem.endOffset);
    }
    problem = problems.get(4);
    assertEquals(25, problem.lineNumber);
    if (Util.isWindows()) {
        assertEquals(1080, problem.startOffset);
        assertEquals(1152, problem.endOffset);
    } else {
        assertEquals(1056, problem.startOffset);
        assertEquals(1128, problem.endOffset);
    }
    problem = problems.get(5);
    assertEquals(156, problem.lineNumber);
    if (Util.isWindows()) {
        assertEquals(5378, problem.startOffset);
        assertEquals(5504, problem.endOffset);
    } else {
        assertEquals(5223, problem.startOffset);
        assertEquals(5348, problem.endOffset);
    }
}
Also used : FileMigrator(com.liferay.blade.api.FileMigrator) Problem(com.liferay.blade.api.Problem) Test(org.junit.Test)

Example 32 with FileMigrator

use of com.liferay.blade.api.FileMigrator 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;
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) ProgressMonitor(com.liferay.blade.api.ProgressMonitor) Migration(com.liferay.blade.api.Migration) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) ListUtil(com.liferay.ide.core.util.ListUtil) Activate(org.osgi.service.component.annotations.Activate) MigrationListener(com.liferay.blade.api.MigrationListener) Path(java.nio.file.Path) ServiceReference(org.osgi.framework.ServiceReference) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) OutputStream(java.io.OutputStream) FileVisitor(java.nio.file.FileVisitor) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Files(java.nio.file.Files) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Collectors(java.util.stream.Collectors) FileMigrator(com.liferay.blade.api.FileMigrator) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) FileVisitResult(java.nio.file.FileVisitResult) Problem(com.liferay.blade.api.Problem) List(java.util.List) Stream(java.util.stream.Stream) Reporter(com.liferay.blade.api.Reporter) ServiceTracker(org.osgi.util.tracker.ServiceTracker) Collections(java.util.Collections) ArrayList(java.util.ArrayList) List(java.util.List) Problem(com.liferay.blade.api.Problem) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

FileMigrator (com.liferay.blade.api.FileMigrator)32 Problem (com.liferay.blade.api.Problem)31 Test (org.junit.Test)30 File (java.io.File)7 ServiceReference (org.osgi.framework.ServiceReference)5 AutoMigrator (com.liferay.blade.api.AutoMigrator)4 ServiceTracker (org.osgi.util.tracker.ServiceTracker)2 Migration (com.liferay.blade.api.Migration)1 MigrationListener (com.liferay.blade.api.MigrationListener)1 ProgressMonitor (com.liferay.blade.api.ProgressMonitor)1 Reporter (com.liferay.blade.api.Reporter)1 ListUtil (com.liferay.ide.core.util.ListUtil)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 FileVisitResult (java.nio.file.FileVisitResult)1 FileVisitor (java.nio.file.FileVisitor)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 SimpleFileVisitor (java.nio.file.SimpleFileVisitor)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1