Search in sources :

Example 16 with FileMigrator

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

the class APITestBase method test2.

@Test
public void test2() throws Exception {
    FileMigrator fmigrator = context.getService(fileMigrators[0]);
    List<Problem> problems = fmigrator.analyze(getTestFile());
    problems = fmigrator.analyze(getTestFile());
    context.ungetService(fileMigrators[0]);
    assertNotNull(problems);
    assertEquals(getExpectedNumber(), problems.size());
}
Also used : FileMigrator(com.liferay.blade.api.FileMigrator) Problem(com.liferay.blade.api.Problem) Test(org.junit.Test)

Example 17 with FileMigrator

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

the class APITestBase method beforeTest.

@Before
public void beforeTest() throws Exception {
    Filter filter = context.createFilter("(implName=" + getImplClassName() + ")");
    ServiceTracker<FileMigrator, FileMigrator> fileMigratorTracker = new ServiceTracker<FileMigrator, FileMigrator>(context, filter, null);
    fileMigratorTracker.open();
    fileMigrators = fileMigratorTracker.getServiceReferences();
    assertNotNull(fileMigrators);
    assertEquals(1, fileMigrators.length);
}
Also used : Filter(org.osgi.framework.Filter) FileMigrator(com.liferay.blade.api.FileMigrator) ServiceTracker(org.osgi.util.tracker.ServiceTracker) Before(org.junit.Before)

Example 18 with FileMigrator

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

the class ContactNameExceptionImportAutoCorrectTest method autoCorrectProblems.

@Test
public void autoCorrectProblems() throws Exception {
    File tempFolder = Files.createTempDirectory("autocorrect").toFile();
    File testFile = new File(tempFolder, "ContactNameExceptionImport.java");
    tempFolder.deleteOnExit();
    File originalTestfile = new File("javatests/ContactNameExceptionImport.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("ContactNameExceptionImport")) {
            problems = migrator.analyze(testFile);
            break;
        }
    }
    assertEquals(3, problems.size());
    int problemsFixed = ((AutoMigrator) migrator).correctProblems(testFile, problems);
    assertEquals(3, 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 19 with FileMigrator

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

the class AssetTagPropertiesTest method assetTageProperties.

@Test
public void assetTageProperties() {
    FileMigrator fmigrator = context.getService(fileMigrators[0]);
    List<Problem> problems = fmigrator.analyze(testFile2);
    context.ungetService(fileMigrators[0]);
    assertNotNull(problems);
    assertEquals(4, problems.size());
}
Also used : FileMigrator(com.liferay.blade.api.FileMigrator) Problem(com.liferay.blade.api.Problem) Test(org.junit.Test)

Example 20 with FileMigrator

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

the class AutoCorrectJSPTagTestBase method autoCorrectProblems.

@Test
public void autoCorrectProblems() throws Exception {
    File tempFolder = Files.createTempDirectory("autocorrect").toFile();
    File testFile = new File(tempFolder, "test.jsp");
    tempFolder.deleteOnExit();
    Files.copy(getOriginalTestFile().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(getImplClassName())) {
            problems = migrator.analyze(testFile);
            break;
        }
    }
    assertEquals(getExpectedNumber(), problems.size());
    int problemsFixed = ((AutoMigrator) migrator).correctProblems(testFile, problems);
    assertEquals(getExpectedFixedNumber(), problemsFixed);
    File dest = new File(tempFolder, "Updated.jsp");
    assertTrue(testFile.renameTo(dest));
    problems = migrator.analyze(dest);
    assertEquals(0, problems.size());
    for (String checkPoint : getCheckPoints()) {
        int lineNumber = Integer.parseInt(checkPoint.split(",")[0]);
        String lineContent = checkPoint.split(",")[1];
        try {
            String[] lines = _readLines(Files.newInputStream(dest.toPath()));
            assertTrue(lines[lineNumber - 1].trim().equals(lineContent));
        } catch (Exception e) {
        }
    }
}
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