Search in sources :

Example 21 with SDK

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

the class SDKProjectConvertDataModelProvider method getDefaultProperty.

@Override
public Object getDefaultProperty(String propertyName) {
    if (SDK_LOCATION.equals(propertyName)) {
        IPath rawLocation = _project.getRawLocation();
        if (rawLocation == null) {
            URI absoluteUri = _project.getLocationURI();
            rawLocation = new Path(absoluteUri.getPath());
        }
        return rawLocation.removeLastSegments(2).toOSString();
    } else if (SDK_VERSION.equals(propertyName)) {
        // see if we have a sdk location and extract the version
        String sdkLoc = getStringProperty(SDK_LOCATION);
        try {
            boolean validSDKLocation = SDKUtil.isValidSDKLocation(sdkLoc);
            if (validSDKLocation) {
                SDK sdk = SDKUtil.createSDKFromLocation(new Path(sdkLoc));
                if (sdk != null) {
                    String sdkVersionValue = sdk.getVersion();
                    Version v = new Version(sdkVersionValue);
                    return v.toString();
                }
            } else {
                return StringPool.EMPTY;
            }
        } catch (Exception e) {
        }
    } else if (SELECTED_PROJECTS.equals(propertyName)) {
        return new ProjectRecord[] { new ProjectRecord(_project) };
    }
    return super.getDefaultProperty(propertyName);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) Version(org.osgi.framework.Version) SDK(com.liferay.ide.sdk.core.SDK) URI(java.net.URI)

Example 22 with SDK

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

the class LocationValidationService method compute.

@Override
protected Status compute() {
    Status retval = Status.createOkStatus();
    NewLiferayPluginProjectOp op = _op();
    NewLiferayProjectProvider<NewLiferayPluginProjectOp> provider = op.getProjectProvider().content();
    if (provider.getShortName().equals("ant")) {
        SDK sdk = null;
        try {
            sdk = SDKUtil.getWorkspaceSDK();
            if (sdk != null) {
                IStatus sdkStatus = sdk.validate();
                if (!sdkStatus.isOK()) {
                    retval = Status.createErrorStatus(sdkStatus.getChildren()[0].getMessage());
                }
            }
        } catch (CoreException ce) {
            retval = Status.createErrorStatus(ce);
        }
    }
    Path currentProjectLocation = op.getLocation().content(true);
    String currentProjectName = op.getProjectName().content();
    /*
		 * Location won't be validated if the UseDefaultLocation has an error.
		 * Get the validation of the property might not work as excepted,
		 * let's use call the validation service manually.
		 */
    Value<Boolean> useDefalutLocationValue = op.getUseDefaultLocation();
    Status status = useDefalutLocationValue.service(UseDefaultLocationValidationService.class).validation();
    if (!useDefalutLocationValue.content(true) && status.ok() && (currentProjectName != null)) {
        /*
			 * IDE-1150, instead of using annotation "@Required",use this service to
			 * validate the custom project location must be specified, let the wizard
			 * display the error of project name when project name and location are both
			 * null.
			 */
        if (currentProjectLocation == null) {
            return Status.createErrorStatus("Location must be specified.");
        }
        String currentPath = currentProjectLocation.toOSString();
        if (!org.eclipse.core.runtime.Path.EMPTY.isValidPath(currentPath)) {
            return Status.createErrorStatus("\"" + currentPath + "\" is not a valid path.");
        }
        IPath osPath = org.eclipse.core.runtime.Path.fromOSString(currentPath);
        if (!osPath.toFile().isAbsolute()) {
            return Status.createErrorStatus("\"" + currentPath + "\" is not an absolute path.");
        }
        if (FileUtil.notExists(osPath) && !_canCreate(osPath.toFile())) {
            retval = Status.createErrorStatus("Cannot create project content at \"" + currentPath + "\"");
        }
        IStatus locationStatus = provider.validateProjectLocation(currentProjectName, osPath);
        if (!locationStatus.isOK()) {
            retval = Status.createErrorStatus(locationStatus.getMessage());
        }
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.sapphire.modeling.Status) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IPath(org.eclipse.core.runtime.IPath) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) SDK(com.liferay.ide.sdk.core.SDK)

Example 23 with SDK

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

the class NewLiferayPluginProjectOpMethods method supportsTypePlugin.

public static boolean supportsTypePlugin(NewLiferayPluginProjectOp op, String type) {
    boolean retval = false;
    NewLiferayProjectProvider<NewLiferayPluginProjectOp> provider = op.getProjectProvider().content(true);
    if (provider.getShortName().equals("maven") && (type.equals("web") || type.equals("theme"))) {
        return true;
    } else {
        SDK sdk = null;
        try {
            sdk = SDKUtil.getWorkspaceSDK();
        } catch (CoreException ce) {
        }
        if (sdk == null) {
            Path sdkLocation = op.getSdkLocation().content();
            if (sdkLocation != null) {
                sdk = SDKUtil.createSDKFromLocation(PathBridge.create(sdkLocation));
            }
        }
        if (sdk == null) {
            return true;
        }
        Version version = new Version(sdk.getVersion());
        boolean greaterThan700 = false;
        if (CoreUtil.compareVersions(version, ILiferayConstants.V700) >= 0) {
            greaterThan700 = true;
        }
        if ((greaterThan700 && "web".equals(type)) || ("theme".equals(type))) {
            retval = true;
        }
        if (greaterThan700 && "ext".equals(type)) {
            IPath extFolder = sdk.getLocation().append("ext");
            File buildXml = extFolder.append("build.xml").toFile();
            if (FileUtil.exists(extFolder) && FileUtil.exists(buildXml)) {
                return true;
            }
        } else if (!greaterThan700 && "ext".equals(type)) {
            return true;
        }
    }
    return retval;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) CoreException(org.eclipse.core.runtime.CoreException) IPath(org.eclipse.core.runtime.IPath) Version(org.osgi.framework.Version) SDK(com.liferay.ide.sdk.core.SDK) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 24 with SDK

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

the class NewLiferayPluginProjectOpMethods method updateLocation.

public static void updateLocation(NewLiferayPluginProjectOp op) {
    String currentProjectName = op.getProjectName().content();
    if (currentProjectName == null) {
        return;
    }
    boolean useDefaultLocation = op.getUseDefaultLocation().content(true);
    NewLiferayProjectProvider<NewLiferayPluginProjectOp> provider = op.getProjectProvider().content(true);
    String providerShortName = provider.getShortName();
    if (useDefaultLocation) {
        Path newLocationBase = null;
        if (providerShortName.equals("ant")) {
            SDK sdk = null;
            try {
                sdk = SDKUtil.getWorkspaceSDK();
                if (sdk != null) {
                    IStatus sdkStatus = sdk.validate();
                    if (!sdkStatus.isOK()) {
                        sdk = null;
                    }
                }
            } catch (CoreException ce) {
            }
            if (sdk == null) {
                if (op.getSdkLocation() != null) {
                    Path sdkPath = op.getSdkLocation().content();
                    if (sdkPath != null) {
                        IPath sdkLocation = PathBridge.create(sdkPath);
                        sdk = SDKUtil.createSDKFromLocation(sdkLocation);
                    }
                }
            }
            if (sdk != null) {
                Path sdkLocation = PathBridge.create(sdk.getLocation());
                switch(op.getPluginType().content(true)) {
                    case portlet:
                    case servicebuilder:
                        newLocationBase = sdkLocation.append("portlets");
                        break;
                    case ext:
                        newLocationBase = sdkLocation.append("ext");
                        break;
                    case hook:
                        newLocationBase = sdkLocation.append("hooks");
                        break;
                    case layouttpl:
                        newLocationBase = sdkLocation.append("layouttpl");
                        break;
                    case theme:
                        newLocationBase = sdkLocation.append("themes");
                        break;
                    case web:
                        newLocationBase = sdkLocation.append("webs");
                        break;
                }
            } else {
                return;
            }
        } else {
            newLocationBase = PathBridge.create(CoreUtil.getWorkspaceRoot().getLocation());
        }
        if (newLocationBase != null) {
            updateLocation(op, newLocationBase);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IPath(org.eclipse.core.runtime.IPath) SDK(com.liferay.ide.sdk.core.SDK)

Example 25 with SDK

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

the class ParentSDKProjectImportOpMethods method execute.

public static final Status execute(ParentSDKProjectImportOp op, ProgressMonitor pm) {
    IProgressMonitor monitor = ProgressMonitorBridge.create(pm);
    monitor.beginTask("Importing Liferay parent sdk project...", 100);
    Status retval = Status.createOkStatus();
    Path sdkLocation = op.getSdkLocation().content();
    if ((sdkLocation == null) || sdkLocation.isEmpty()) {
        return Status.createErrorStatus("SDK folder cannot be empty");
    }
    SDK sdk = SDKUtil.createSDKFromLocation(PathBridge.create(sdkLocation));
    try {
        SDKUtil.openAsProject(sdk, monitor);
    } catch (CoreException ce) {
        retval = StatusBridge.create(ProjectCore.createErrorStatus(ce));
    }
    return retval;
}
Also used : Status(org.eclipse.sapphire.modeling.Status) Path(org.eclipse.sapphire.modeling.Path) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) SDK(com.liferay.ide.sdk.core.SDK)

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