Search in sources :

Example 11 with FileMigrator

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

the class SocialNetworkingLegacyAPITest method testFull.

@Test
public void testFull() throws Exception {
    FileMigrator fmigrator = context.getService(fileMigrators[0]);
    List<Problem> problems = fmigrator.analyze(getTestFile());
    context.ungetService(fileMigrators[0]);
    assertNotNull(problems);
    assertEquals(2, problems.size());
    Problem problem = problems.get(0);
    assertEquals(20, problem.lineNumber);
    if (Util.isWindows()) {
        assertEquals(781, problem.startOffset);
        assertEquals(843, problem.endOffset);
    } else {
        assertEquals(762, problem.startOffset);
        assertEquals(824, problem.endOffset);
    }
    problem = problems.get(1);
    assertEquals(31, problem.lineNumber);
    if (Util.isWindows()) {
        assertEquals(1086, problem.startOffset);
        assertEquals(1149, problem.endOffset);
    } else {
        assertEquals(1056, problem.startOffset);
        assertEquals(1119, problem.endOffset);
    }
}
Also used : FileMigrator(com.liferay.blade.api.FileMigrator) Problem(com.liferay.blade.api.Problem) Test(org.junit.Test)

Example 12 with FileMigrator

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

the class MVCPortletClassInPortletXMLAutoCorrectTest method testAutoCorrectPortletXmlBoth.

@Test
public void testAutoCorrectPortletXmlBoth() throws Exception {
    assertNotNull(autoMigrator);
    FileMigrator fileMigrator = (FileMigrator) autoMigrator;
    File testfile = new File("target/test/MVCPortletClassInPortletXMLAutoCorrectTest/portlet.xml");
    if (testfile.exists()) {
        assertTrue(testfile.delete());
    }
    testfile.getParentFile().mkdirs();
    Files.copy(new File("projects/test-portlet/docroot/WEB-INF/portlet.xml").toPath(), testfile.toPath());
    List<Problem> problems = fileMigrator.analyze(testfile);
    assertEquals(2, problems.size());
    int corrected = autoMigrator.correctProblems(testfile, problems);
    assertEquals(2, corrected);
    problems = fileMigrator.analyze(testfile);
    assertEquals(0, problems.size());
}
Also used : FileMigrator(com.liferay.blade.api.FileMigrator) Problem(com.liferay.blade.api.Problem) File(java.io.File) Test(org.junit.Test)

Example 13 with FileMigrator

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

the class MVCPortletClassInPortletXMLAutoCorrectTest method testAutoCorrectPortletXmlSingle.

@Test
public void testAutoCorrectPortletXmlSingle() throws Exception {
    assertNotNull(autoMigrator);
    FileMigrator fileMigrator = (FileMigrator) autoMigrator;
    File testfile = new File("generated/test/MVCPortletClassInPortletXMLAutoCorrectTest/portlet.xml");
    if (testfile.exists()) {
        assertTrue(testfile.delete());
    }
    testfile.getParentFile().mkdirs();
    Files.copy(new File("projects/test-portlet/docroot/WEB-INF/portlet.xml").toPath(), testfile.toPath());
    List<Problem> problems = fileMigrator.analyze(testfile);
    assertEquals(2, problems.size());
    int corrected = autoMigrator.correctProblems(testfile, Collections.singletonList(problems.get(0)));
    assertEquals(1, corrected);
    problems = fileMigrator.analyze(testfile);
    assertEquals(1, problems.size());
    corrected = autoMigrator.correctProblems(testfile, Collections.singletonList(problems.get(0)));
    assertEquals(1, corrected);
    problems = fileMigrator.analyze(testfile);
    assertEquals(0, problems.size());
}
Also used : FileMigrator(com.liferay.blade.api.FileMigrator) Problem(com.liferay.blade.api.Problem) File(java.io.File) Test(org.junit.Test)

Example 14 with FileMigrator

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

the class PortalServiceImportsAutoCorrectTest method autoCorrectProblems.

@Test
public void autoCorrectProblems() throws Exception {
    File tempFolder = Files.createTempDirectory("autocorrect").toFile();
    File testFile = new File(tempFolder, "PortalServiceImports.java");
    tempFolder.deleteOnExit();
    File originalTestfile = new File("javatests/PortalServiceImports.java");
    Files.copy(originalTestfile.toPath(), testFile.toPath());
    List<Problem> problems = null;
    FileMigrator migrator = null;
    Collection<ServiceReference<FileMigrator>> mrefs = context.getServiceReferences(FileMigrator.class, null);
    for (ServiceReference<FileMigrator> mref : mrefs) {
        migrator = context.getService(mref);
        if (migrator.getClass().getName().contains("PortalServiceImports")) {
            problems = migrator.analyze(testFile);
            break;
        }
    }
    assertEquals(2, problems.size());
    int problemsFixed = ((AutoMigrator) migrator).correctProblems(testFile, problems);
    assertEquals(2, problemsFixed);
    File dest = new File(tempFolder, "Updated.java");
    assertTrue(testFile.renameTo(dest));
    problems = migrator.analyze(dest);
    assertEquals(0, problems.size());
}
Also used : FileMigrator(com.liferay.blade.api.FileMigrator) AutoMigrator(com.liferay.blade.api.AutoMigrator) Problem(com.liferay.blade.api.Problem) File(java.io.File) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 15 with FileMigrator

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

the class RenamePortalKernelImportAutoCorrectTest method autoCorrectProblems.

@Test
public void autoCorrectProblems() throws Exception {
    File tempFolder = Files.createTempDirectory("autocorrect").toFile();
    File testFile = new File(tempFolder, "TasksEntryLocalServiceImpl.java");
    tempFolder.deleteOnExit();
    File originalTestfile = new File("javatests/TasksEntryLocalServiceImpl.java");
    Files.copy(originalTestfile.toPath(), testFile.toPath());
    List<Problem> problems = null;
    FileMigrator migrator = null;
    Collection<ServiceReference<FileMigrator>> mrefs = context.getServiceReferences(FileMigrator.class, null);
    for (ServiceReference<FileMigrator> mref : mrefs) {
        migrator = context.getService(mref);
        if (migrator.getClass().getName().contains("RenamePortalKernelImport")) {
            problems = migrator.analyze(testFile);
            break;
        }
    }
    assertEquals(10, problems.size());
    int problemsFixed = ((AutoMigrator) migrator).correctProblems(testFile, problems);
    assertEquals(10, problemsFixed);
    File dest = new File(tempFolder, "Updated.java");
    assertTrue(testFile.renameTo(dest));
    problems = migrator.analyze(dest);
    assertEquals(0, problems.size());
}
Also used : FileMigrator(com.liferay.blade.api.FileMigrator) AutoMigrator(com.liferay.blade.api.AutoMigrator) Problem(com.liferay.blade.api.Problem) File(java.io.File) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

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