Search in sources :

Example 1 with ILiferayProjectImporter

use of com.liferay.ide.core.ILiferayProjectImporter in project liferay-ide by liferay.

the class NewMavenJSFModuleProjectProvider method createNewProject.

@Override
public IStatus createNewProject(NewLiferayJSFModuleProjectOp op, IProgressMonitor monitor) throws CoreException {
    IStatus retval = null;
    IPath projectLocation = createArchetypeProject(op, monitor);
    IPath buildGradle = projectLocation.append("build.gradle");
    if (FileUtil.exists(buildGradle)) {
        buildGradle.toFile().delete();
    }
    ILiferayProjectImporter importer = LiferayCore.getImporter("maven");
    IStatus canImport = importer.canImport(projectLocation.toOSString());
    if (canImport.getCode() != Status.ERROR) {
        importer.importProjects(projectLocation.toOSString(), monitor);
    }
    retval = Status.OK_STATUS;
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) ILiferayProjectImporter(com.liferay.ide.core.ILiferayProjectImporter)

Example 2 with ILiferayProjectImporter

use of com.liferay.ide.core.ILiferayProjectImporter in project liferay-ide by liferay.

the class LiferayMavenLegacyProjectUpdaterTests method testUpgrade.

@Test
public void testUpgrade() throws Exception {
    IProject project = CoreUtil.getProject("testMavenProjects");
    if (project != null && project.exists()) {
        project.delete(true, true, new NullProgressMonitor());
    }
    final URL projectZipUrl = Platform.getBundle("com.liferay.ide.maven.core.tests").getEntry("projects/testMavenProjects.zip");
    final File projectZipFile = new File(FileLocator.toFileURL(projectZipUrl).getFile());
    IPath stateLocation = LiferayMavenCore.getDefault().getStateLocation();
    File targetFolder = new File(stateLocation.toFile(), "testMavenProjects");
    if (targetFolder.exists()) {
        targetFolder.delete();
    }
    ZipUtil.unzip(projectZipFile, stateLocation.toFile());
    assertTrue(targetFolder.exists());
    ILiferayProjectImporter importer = LiferayCore.getImporter("maven");
    importer.importProjects(targetFolder.getAbsolutePath(), new NullProgressMonitor());
    LiferayMavenLegacyProjectUpdater updater = new LiferayMavenLegacyProjectUpdater();
    // portlet project
    IProject ppProject = CoreUtil.getProject("testpp");
    assertTrue(updater.isNeedUpgrade(ppProject));
    updater.upgradePomFile(ppProject, null);
    assertFalse(updater.isNeedUpgrade(ppProject));
    assertTrue(containString(ppProject, "com.liferay.css.builder"));
    makeSureNoLegacyElememnts(ppProject);
    // service builder parent project
    IProject testsbProject = CoreUtil.getProject("testsb");
    assertTrue(updater.isNeedUpgrade(testsbProject));
    updater.upgradePomFile(testsbProject, null);
    assertFalse(updater.isNeedUpgrade(testsbProject));
    makeSureNoLegacyElememnts(testsbProject);
    // service builder -portlet subproject
    IProject testsbPortletProject = CoreUtil.getProject("testsb-portlet");
    assertTrue(updater.isNeedUpgrade(testsbPortletProject));
    updater.upgradePomFile(testsbPortletProject, null);
    assertFalse(updater.isNeedUpgrade(testsbPortletProject));
    assertTrue(containString(testsbPortletProject, "com.liferay.css.builder"));
    assertTrue(containString(testsbPortletProject, "com.liferay.portal.tools.service.builder"));
    assertTrue(containString(testsbPortletProject, "biz.aQute.bnd.annotation"));
    makeSureNoLegacyElememnts(testsbPortletProject);
    // // service builder -service subproject
    IProject testsbPortletServiceProject = CoreUtil.getProject("testsb-portlet-service");
    assertTrue(updater.isNeedUpgrade(testsbPortletServiceProject));
    updater.upgradePomFile(testsbPortletServiceProject, null);
    assertFalse(updater.isNeedUpgrade(testsbPortletServiceProject));
    assertTrue(containString(testsbPortletServiceProject, "biz.aQute.bnd.annotation"));
    makeSureNoLegacyElememnts(testsbPortletServiceProject);
    // theme project
    IProject testthemeProject = CoreUtil.getProject("testtheme");
    assertTrue(updater.isNeedUpgrade(testthemeProject));
    updater.upgradePomFile(testthemeProject, null);
    assertFalse(updater.isNeedUpgrade(testthemeProject));
    assertTrue(containString(testthemeProject, "com.liferay.portal.tools.theme.builder.outputDir"));
    assertTrue(containString(testthemeProject, "project.build.sourceEncoding"));
    assertTrue(containString(testthemeProject, "maven-war-plugin"));
    assertTrue(containString(testthemeProject, "maven-dependency-plugin"));
    assertTrue(containString(testthemeProject, "com.liferay.css.builder"));
    assertTrue(containString(testthemeProject, "com.liferay.portal.tools.theme.builder"));
    makeSureNoLegacyElememnts(testthemeProject);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) LiferayMavenLegacyProjectUpdater(com.liferay.ide.maven.core.LiferayMavenLegacyProjectUpdater) IPath(org.eclipse.core.runtime.IPath) ILiferayProjectImporter(com.liferay.ide.core.ILiferayProjectImporter) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject) URL(java.net.URL) Test(org.junit.Test)

Example 3 with ILiferayProjectImporter

use of com.liferay.ide.core.ILiferayProjectImporter in project liferay-ide by liferay.

the class NewLiferayWorkspaceOpTests method testNewLiferayWorkspaceOp.

@Test
public void testNewLiferayWorkspaceOp() throws Exception {
    ILiferayProjectImporter importer = LiferayCore.getImporter("gradle");
    File eclipseWorkspaceLocation = CoreUtil.getWorkspaceRoot().getLocation().toFile();
    URL projectZipUrl = Platform.getBundle("com.liferay.ide.project.core.tests").getEntry("projects/existingProject.zip");
    final File projectZipFile = new File(FileLocator.toFileURL(projectZipUrl).getFile());
    ZipUtil.unzip(projectZipFile, eclipseWorkspaceLocation);
    File projectFolder = new File(eclipseWorkspaceLocation, "existingProject");
    waitForBuildAndValidation();
    importer.importProjects(projectFolder.getAbsolutePath(), new NullProgressMonitor());
    NewLiferayWorkspaceOp op = NewLiferayWorkspaceOp.TYPE.instantiate();
    op.setWorkspaceName("existingProject");
    String message = op.validation().message();
    assertNotNull(message);
    assertEquals("A project with that name(ignore case) already exists.", message);
    op.setWorkspaceName("ExistingProject");
    message = op.validation().message();
    assertTrue(message.equals("A project with that name(ignore case) already exists."));
    String projectName = "test-liferay-workspace";
    IPath workspaceLocation = CoreUtil.getWorkspaceRoot().getLocation();
    op.setWorkspaceName(projectName);
    op.setUseDefaultLocation(false);
    op.setLocation(workspaceLocation.toPortableString());
    op.execute(new ProgressMonitor());
    String wsLocation = workspaceLocation.append(projectName).toPortableString();
    File wsFile = new File(wsLocation);
    assertTrue(wsFile.exists());
    assertTrue(LiferayWorkspaceUtil.isValidWorkspaceLocation(wsLocation));
    File propertiesFile = new File(wsFile, "gradle.properties");
    Properties prop = PropertiesUtil.loadProperties(propertiesFile);
    prop.setProperty(LiferayWorkspaceUtil.LIFERAY_WORKSPACE_WARS_DIR, "wars,wars2");
    PropertiesUtil.saveProperties(prop, propertiesFile);
    NewLiferayModuleProjectOp moduleProjectOp = NewLiferayModuleProjectOp.TYPE.instantiate();
    moduleProjectOp.setProjectName("testThemeWarDefault");
    moduleProjectOp.setProjectTemplateName("theme");
    moduleProjectOp.execute(new ProgressMonitor());
    waitForBuildAndValidation();
    assertTrue(CoreUtil.getProject("testThemeWarDefault").exists());
    moduleProjectOp = NewLiferayModuleProjectOp.TYPE.instantiate();
    moduleProjectOp.setProjectName("testThemeWarNotDefault");
    moduleProjectOp.setProjectTemplateName("theme");
    moduleProjectOp.setUseDefaultLocation(false);
    moduleProjectOp.setLocation(wsLocation + "/wars");
    moduleProjectOp.execute(new ProgressMonitor());
    waitForBuildAndValidation();
    assertTrue(CoreUtil.getProject("testThemeWarNotDefault").exists());
    moduleProjectOp = NewLiferayModuleProjectOp.TYPE.instantiate();
    moduleProjectOp.setProjectName("testThemeWar2");
    moduleProjectOp.setProjectTemplateName("theme");
    moduleProjectOp.setUseDefaultLocation(false);
    moduleProjectOp.setLocation(wsLocation + "/wars2");
    moduleProjectOp.execute(new ProgressMonitor());
    waitForBuildAndValidation();
    assertTrue(CoreUtil.getProject("testThemeWar2").exists());
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProgressMonitor(org.eclipse.sapphire.modeling.ProgressMonitor) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) NewLiferayWorkspaceOp(com.liferay.ide.project.core.workspace.NewLiferayWorkspaceOp) ILiferayProjectImporter(com.liferay.ide.core.ILiferayProjectImporter) IPath(org.eclipse.core.runtime.IPath) NewLiferayModuleProjectOp(com.liferay.ide.project.core.modules.NewLiferayModuleProjectOp) Properties(java.util.Properties) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 4 with ILiferayProjectImporter

use of com.liferay.ide.core.ILiferayProjectImporter in project liferay-ide by liferay.

the class InitConfigureProjectPage method importProject.

protected void importProject() throws CoreException {
    String layout = dataModel.getLayout().content();
    IPath location = PathBridge.create(dataModel.getSdkLocation().content());
    if (_isAlreadyImported(location)) {
        Stream.of(CoreUtil.getAllProjects()).forEach(this::_checkProjectType);
        dataModel.setImportFinished(true);
        return;
    }
    try {
        IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
        progressService.run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
                try {
                    String newPath = "";
                    _backup(monitor);
                    _clearExistingProjects(location, monitor);
                    _deleteEclipseConfigFiles(location.toFile());
                    if (_isMavenProject(location.toPortableString())) {
                        ILiferayProjectImporter importer = LiferayCore.getImporter("maven");
                        List<IProject> projects = importer.importProjects(location.toPortableString(), monitor);
                        for (IProject project : projects) {
                            _checkProjectType(project);
                        }
                    } else {
                        if (layout.equals("Upgrade to Liferay Workspace")) {
                            _createLiferayWorkspace(location, monitor);
                            _removeIvyPrivateSetting(location.append("plugins-sdk"));
                            newPath = _renameProjectFolder(location);
                            IPath sdkLocation = new Path(newPath).append("plugins-sdk");
                            _deleteSDKLegacyProjects(sdkLocation);
                            ILiferayProjectImporter importer = LiferayCore.getImporter("gradle");
                            importer.importProjects(newPath, monitor);
                            if (dataModel.getDownloadBundle().content()) {
                                _createInitBundle(monitor);
                            }
                            _importSDKProject(sdkLocation, monitor);
                            dataModel.setConvertLiferayWorkspace(true);
                        } else {
                            _deleteEclipseConfigFiles(location.toFile());
                            _copyNewSDK(location, monitor);
                            _removeIvyPrivateSetting(location);
                            _deleteSDKLegacyProjects(location);
                            String serverName = dataModel.getLiferay70ServerName().content();
                            IServer server = ServerUtil.getServer(serverName);
                            newPath = _renameProjectFolder(location);
                            SDK sdk = SDKUtil.createSDKFromLocation(new Path(newPath));
                            sdk.addOrUpdateServerProperties(ServerUtil.getLiferayRuntime(server).getLiferayHome());
                            SDKUtil.openAsProject(sdk, monitor);
                            _importSDKProject(sdk.getLocation(), monitor);
                        }
                    }
                    dataModel.setImportFinished(true);
                } catch (Exception e) {
                    ProjectUI.logError(e);
                    throw new InvocationTargetException(e, e.getMessage());
                }
            }
        });
    } catch (Exception e) {
        ProjectUI.logError(e);
        throw new CoreException(StatusBridge.create(Status.createErrorStatus(e.getMessage(), e)));
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IServer(org.eclipse.wst.server.core.IServer) IPath(org.eclipse.core.runtime.IPath) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) BladeCLIException(com.liferay.ide.project.core.modules.BladeCLIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILiferayProjectImporter(com.liferay.ide.core.ILiferayProjectImporter) CoreException(org.eclipse.core.runtime.CoreException) IProgressService(org.eclipse.ui.progress.IProgressService) ArrayList(java.util.ArrayList) List(java.util.List) SDK(com.liferay.ide.sdk.core.SDK)

Example 5 with ILiferayProjectImporter

use of com.liferay.ide.core.ILiferayProjectImporter in project liferay-ide by liferay.

the class ImportLiferayModuleProjectOpMethods method execute.

public static final Status execute(ImportLiferayModuleProjectOp op, ProgressMonitor pm) {
    IProgressMonitor monitor = ProgressMonitorBridge.create(pm);
    monitor.beginTask("Importing Module project...", 100);
    Path path = op.getLocation().content();
    String location = path.toOSString();
    ILiferayProjectImporter importer = LiferayCore.getImporter(op.getBuildType().content());
    Status retval = Status.createOkStatus();
    try {
        importer.importProjects(location, monitor);
    } catch (CoreException ce) {
        retval = Status.createErrorStatus(ce);
    }
    return retval;
}
Also used : Path(org.eclipse.sapphire.modeling.Path) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.sapphire.modeling.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILiferayProjectImporter(com.liferay.ide.core.ILiferayProjectImporter) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

ILiferayProjectImporter (com.liferay.ide.core.ILiferayProjectImporter)9 IPath (org.eclipse.core.runtime.IPath)6 File (java.io.File)5 IStatus (org.eclipse.core.runtime.IStatus)5 CoreException (org.eclipse.core.runtime.CoreException)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 URL (java.net.URL)3 IProject (org.eclipse.core.resources.IProject)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 Test (org.junit.Test)2 LiferayMavenLegacyProjectUpdater (com.liferay.ide.maven.core.LiferayMavenLegacyProjectUpdater)1 BladeCLIException (com.liferay.ide.project.core.modules.BladeCLIException)1 NewLiferayModuleProjectOp (com.liferay.ide.project.core.modules.NewLiferayModuleProjectOp)1 NewLiferayWorkspaceOp (com.liferay.ide.project.core.workspace.NewLiferayWorkspaceOp)1 SDK (com.liferay.ide.sdk.core.SDK)1 IOException (java.io.IOException)1 List (java.util.List)1