Search in sources :

Example 6 with AutoMigrator

use of com.liferay.blade.api.AutoMigrator 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)

Example 7 with AutoMigrator

use of com.liferay.blade.api.AutoMigrator 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 8 with AutoMigrator

use of com.liferay.blade.api.AutoMigrator 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

AutoMigrator (com.liferay.blade.api.AutoMigrator)8 ServiceReference (org.osgi.framework.ServiceReference)8 Problem (com.liferay.blade.api.Problem)7 File (java.io.File)5 Test (org.junit.Test)5 FileMigrator (com.liferay.blade.api.FileMigrator)4 AutoMigrateException (com.liferay.blade.api.AutoMigrateException)2 IMarker (org.eclipse.core.resources.IMarker)2 IProject (org.eclipse.core.resources.IProject)2 IResource (org.eclipse.core.resources.IResource)2 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 BundleContext (org.osgi.framework.BundleContext)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 Migration (com.liferay.blade.api.Migration)1 NullProgressMonitor (com.liferay.blade.util.NullProgressMonitor)1 CoreUtil (com.liferay.ide.core.util.CoreUtil)1 FileUtil (com.liferay.ide.core.util.FileUtil)1