Search in sources :

Example 36 with SDK

use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.

the class SDKUtilTests method singleWorkSpaceProject.

@Test
public void singleWorkSpaceProject() throws Exception {
    if (shouldSkipBundleTests())
        return;
    final File liferayPluginsSdkDirFile = getLiferayPluginsSdkDir().toFile();
    if (!liferayPluginsSdkDirFile.exists()) {
        final File liferayPluginsSdkZipFile = getLiferayPluginsSDKZip().toFile();
        assertEquals("Expected file to exist: " + liferayPluginsSdkZipFile.getAbsolutePath(), true, liferayPluginsSdkZipFile.exists());
        liferayPluginsSdkDirFile.mkdirs();
        final String liferayPluginsSdkZipFolder = getLiferayPluginsSdkZipFolder();
        if (CoreUtil.isNullOrEmpty(liferayPluginsSdkZipFolder)) {
            ZipUtil.unzip(liferayPluginsSdkZipFile, liferayPluginsSdkDirFile);
        } else {
            ZipUtil.unzip(liferayPluginsSdkZipFile, liferayPluginsSdkZipFolder, liferayPluginsSdkDirFile, new NullProgressMonitor());
        }
    }
    assertEquals(true, liferayPluginsSdkDirFile.exists());
    SDK sdk = SDKUtil.createSDKFromLocation(getLiferayPluginsSdkDir());
    SDKUtil.openAsProject(sdk);
    IProject project = SDKUtil.getWorkspaceSDKProject();
    assertNotNull(project);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SDK(com.liferay.ide.sdk.core.SDK) File(java.io.File) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 37 with SDK

use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.

the class LiferaySDKValidationTests method testSDKLocationValidation.

@Test
public void testSDKLocationValidation() throws Exception {
    if (shouldSkipBundleTests())
        return;
    NewLiferayPluginProjectOp op = newProjectOp("test-sdk");
    op.setProjectProvider("ant");
    op.execute(new ProgressMonitor());
    SDK sdk = SDKUtil.getWorkspaceSDK();
    IPath sdkLocation = sdk.getLocation();
    if (sdk != null) {
        CoreUtil.getWorkspaceRoot().getProject(sdk.getName()).delete(false, true, null);
    }
    CoreUtil.getWorkspaceRoot().getProject("test-sdk").delete(false, true, null);
    // set existed project name
    op.setSdkLocation(sdkLocation.toOSString());
    assertTrue(op.validation().message().contains("A project with that name already exists."));
    op = newProjectOp("test2-sdk");
    op.setSdkLocation("");
    assertEquals("This sdk location is empty.", op.validation().message());
    op.setSdkLocation(sdkLocation.getDevice() + "/");
    assertEquals("This sdk location is not correct.", op.validation().message());
    // sdk has no build.USERNAME.properties file
    sdkLocation.append("build." + System.getProperty("user.name") + ".properties").toFile().delete();
    IStatus validateStatus = sdk.validate(true);
    assertEquals(false, validateStatus.isOK());
}
Also used : ProgressMonitor(org.eclipse.sapphire.modeling.ProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) SDK(com.liferay.ide.sdk.core.SDK) Test(org.junit.Test)

Example 38 with SDK

use of com.liferay.ide.sdk.core.SDK 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 39 with SDK

use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.

the class ProjectLocationValidationService method compute.

@Override
protected Status compute() {
    Status retval = Status.createOkStatus();
    int countPossibleWorkspaceSDKProjects = SDKUtil.countPossibleWorkspaceSDKProjects();
    if (countPossibleWorkspaceSDKProjects > 1) {
        return StatusBridge.create(ProjectCore.createErrorStatus("This workspace has more than one SDK."));
    }
    Value<Path> sdkLocation = _op().getSdkLocation();
    final Path location = sdkLocation.content(true);
    if ((location == null) || location.isEmpty()) {
        return StatusBridge.create(ProjectCore.createErrorStatus("Liferay Plugins SDK or Maven location is empty."));
    }
    IStatus buildType = ImportLiferayModuleProjectOpMethods.getBuildType(location.removeFileExtension().toPortableString());
    SDK sdk = SDKUtil.createSDKFromLocation(PathBridge.create(location));
    if (sdk != null) {
        String version = sdk.getVersion();
        if (version != null) {
            Version sdkVersion = new Version(version);
            int result = sdkVersion.compareTo(new Version("6.1.0"));
            if (result < 0) {
                return StatusBridge.create(ProjectCore.createErrorStatus("This tool doesn't support 6.0.x."));
            }
        }
    } else if (!buildType.getMessage().equals("maven")) {
        return StatusBridge.create(ProjectCore.createErrorStatus("Plugins SDK or Maven location is not valid."));
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.sapphire.modeling.Status) Path(org.eclipse.sapphire.modeling.Path) IStatus(org.eclipse.core.runtime.IStatus) Version(org.osgi.framework.Version) SDK(com.liferay.ide.sdk.core.SDK)

Example 40 with SDK

use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.

the class SDKCommandHandler method executeSdkCommand.

protected IStatus executeSdkCommand(final IProject project) {
    IStatus retval = null;
    try {
        final IFile buildXmlFile = project.getFile("build.xml");
        if (buildXmlFile.exists()) {
            final IProject p = project;
            final IFile buildFile = buildXmlFile;
            new Job(p.getName() + " : " + getSDKCommand()) {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    try {
                        final SDK sdk = SDKUtil.getSDK(p);
                        sdk.runCommand(p, buildFile, getSDKCommand(), null, monitor);
                        p.refreshLocal(IResource.DEPTH_INFINITE, monitor);
                    } catch (Exception e) {
                        return ProjectUI.createErrorStatus("Error running SDK command " + getSDKCommand(), e);
                    }
                    return Status.OK_STATUS;
                }
            }.schedule();
        }
    } catch (Exception e) {
        retval = ProjectCore.createErrorStatus("Unable to execute sdk command", e);
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) SDK(com.liferay.ide.sdk.core.SDK) Job(org.eclipse.core.runtime.jobs.Job) IProject(org.eclipse.core.resources.IProject) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

SDK (com.liferay.ide.sdk.core.SDK)75 IPath (org.eclipse.core.runtime.IPath)41 CoreException (org.eclipse.core.runtime.CoreException)29 IStatus (org.eclipse.core.runtime.IStatus)26 IProject (org.eclipse.core.resources.IProject)24 Path (org.eclipse.sapphire.modeling.Path)16 File (java.io.File)15 IFile (org.eclipse.core.resources.IFile)14 Path (org.eclipse.core.runtime.Path)14 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)12 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11 Version (org.osgi.framework.Version)11 IOException (java.io.IOException)9 Status (org.eclipse.sapphire.modeling.Status)9 IFolder (org.eclipse.core.resources.IFolder)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 IWebProject (com.liferay.ide.core.IWebProject)4 IPortletFramework (com.liferay.ide.project.core.IPortletFramework)4 PluginType (com.liferay.ide.project.core.model.PluginType)4