Search in sources :

Example 6 with ILiferayProjectImporter

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

the class ImportLiferayModuleProjectOpMethods method getBuildType.

public static IStatus getBuildType(String location) {
    IStatus retval = null;
    ILiferayProjectImporter[] importers = LiferayCore.getImporters();
    for (ILiferayProjectImporter importer : importers) {
        IStatus status = importer.canImport(location);
        if (status == null) {
            retval = ProjectCore.createErrorStatus("Location is not recognized as a valid project type.");
        } else if (status.isOK()) {
            retval = StatusBridge.create(Status.createStatus(Severity.OK, importer.getBuildType()));
            break;
        } else if (status.getSeverity() == IStatus.ERROR) {
            retval = StatusBridge.create(Status.createStatus(Severity.ERROR, status.getMessage()));
            break;
        } else if (status.getSeverity() == IStatus.WARNING) {
            retval = StatusBridge.create(Status.createStatus(Severity.WARNING, status.getMessage()));
            break;
        }
    }
    if (retval == null) {
        retval = StatusBridge.create(Status.createStatus(Severity.ERROR, "No project importers found."));
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ILiferayProjectImporter(com.liferay.ide.core.ILiferayProjectImporter)

Example 7 with ILiferayProjectImporter

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

the class WorkspaceHelper method openDir.

@Override
public String openDir(String path) {
    String retval = null;
    File dir = new File(path);
    if (!dir.exists() || !dir.isDirectory()) {
        retval = "Directory doesn't exist or isn't a directory.";
    }
    File dotProject = new File(dir, ".project");
    if (dotProject.exists()) {
        retval = _importExistingProject(dir);
    } else {
        for (ILiferayProjectImporter importer : LiferayCore.getImporters()) {
            try {
                IStatus importStatus = importer.canImport(dir.getCanonicalPath());
                if ((importStatus != null) && importStatus.isOK()) {
                    UIUtil.async(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                new ProgressMonitorDialog(UIUtil.getActiveShell()).run(true, true, new IRunnableWithProgress() {

                                    @Override
                                    public void run(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
                                        try {
                                            importer.importProjects(path, monitor);
                                        } catch (CoreException ce) {
                                            LiferayUIPlugin.logError("Error opening project", ce);
                                        }
                                    }
                                });
                            } catch (InterruptedException | InvocationTargetException e) {
                            }
                        }
                    });
                    return retval;
                }
            } catch (Exception e) {
            }
        }
        retval = "Directory must have a .project file to open.";
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILiferayProjectImporter(com.liferay.ide.core.ILiferayProjectImporter) CoreException(org.eclipse.core.runtime.CoreException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) File(java.io.File) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 8 with ILiferayProjectImporter

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

the class NewLiferayJSFModuleProjectOpTests method importWorkspaceProject.

private void importWorkspaceProject(String name) throws Exception {
    final URL projectZipUrl = Platform.getBundle("com.liferay.ide.maven.core.tests").getEntry("projects/" + name + ".zip");
    final File projectZipFile = new File(FileLocator.toFileURL(projectZipUrl).getFile());
    IPath wordkspaceProjectLocation = CoreUtil.getWorkspaceRoot().getLocation();
    ZipUtil.unzip(projectZipFile, wordkspaceProjectLocation.toFile());
    final IPath projectFolder = wordkspaceProjectLocation.append(name);
    assertEquals(true, projectFolder.toFile().exists());
    ILiferayProjectImporter gradleImporter = LiferayCore.getImporter("gradle");
    gradleImporter.importProjects(projectFolder.toOSString(), new NullProgressMonitor());
    IProject workspaceProject = CoreUtil.getProject("testWorkspace");
    assertNotNull(workspaceProject);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) ILiferayProjectImporter(com.liferay.ide.core.ILiferayProjectImporter) File(java.io.File) URL(java.net.URL) IProject(org.eclipse.core.resources.IProject)

Example 9 with ILiferayProjectImporter

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

the class NewGradleJSFModuleProjectProvider method createNewProject.

@Override
public IStatus createNewProject(NewLiferayJSFModuleProjectOp op, IProgressMonitor monitor) throws CoreException {
    IStatus retval = Status.OK_STATUS;
    try {
        IPath projectLocation = createArchetypeProject(op, monitor);
        IPath buildGradlePath = projectLocation.append("build.gradle");
        if (FileUtil.exists(buildGradlePath)) {
            try {
                File workspaceDir = LiferayWorkspaceUtil.getWorkspaceDir(buildGradlePath.toFile());
                if (FileUtil.exists(workspaceDir)) {
                    boolean hasLiferayWorkspace = LiferayWorkspaceUtil.isValidWorkspaceLocation(workspaceDir.getAbsolutePath());
                    if (hasLiferayWorkspace) {
                        List<String> buildGradleContents = Files.readAllLines(Paths.get(buildGradlePath.toFile().toURI()), StandardCharsets.UTF_8);
                        List<String> modifyContents = new ArrayList<>();
                        for (String line : buildGradleContents) {
                            if (_PATTERN_LIFERAY_WAR_PLUGIN.matcher(line).matches()) {
                                continue;
                            }
                            modifyContents.add(line);
                        }
                        Files.write(buildGradlePath.toFile().toPath(), modifyContents, StandardCharsets.UTF_8);
                    }
                }
            } catch (Exception e) {
                ProjectCore.logError("Failed to check LiferayWorkspace project. ");
            }
        }
        IPath buildPom = projectLocation.append("pom.xml");
        if (FileUtil.exists(buildPom)) {
            buildPom.toFile().delete();
        }
        ILiferayProjectImporter importer = LiferayCore.getImporter("gradle");
        IStatus canImport = importer.canImport(projectLocation.toOSString());
        if (canImport.getCode() != Status.ERROR) {
            importer.importProjects(projectLocation.toOSString(), monitor);
        }
    } catch (Exception e) {
        throw new CoreException(LiferayCore.createErrorStatus(e));
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) ILiferayProjectImporter(com.liferay.ide.core.ILiferayProjectImporter) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) File(java.io.File) 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