Search in sources :

Example 21 with Path

use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.

the class ProjectNameValidationService 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);
        }
    }
    String currentProjectName = op.getProjectName().content();
    if (currentProjectName != null) {
        IStatus nameStatus = CoreUtil.getWorkspace().validateName(currentProjectName, IResource.PROJECT);
        if (!nameStatus.isOK()) {
            retval = StatusBridge.create(nameStatus);
        } else if (_isInvalidProjectName(op)) {
            Boolean projectImported = op.getImportProjectStatus().content();
            if (projectImported == false) {
                retval = Status.createErrorStatus("A project with that name already exists.");
            }
        } else if (_isAntProject(op) && _isSuffixOnly(currentProjectName)) {
            retval = Status.createErrorStatus("A project name cannot only be a type suffix.");
        } else if (!_hasValidDisplayName(currentProjectName)) {
            retval = Status.createErrorStatus("The project name is invalid.");
        } else if (_isMavenProject(op) && !_isValidMavenProjectName(currentProjectName)) {
            retval = Status.createErrorStatus("The project name is invalid for a maven project");
        } else {
            Path currentProjectLocation = op.getLocation().content(true);
            if ((currentProjectName != null) && (currentProjectLocation != null)) {
                String currentPath = currentProjectLocation.toOSString();
                IPath osPath = org.eclipse.core.runtime.Path.fromOSString(currentPath);
                IStatus projectStatus = provider.validateProjectLocation(currentProjectName, osPath);
                if (!projectStatus.isOK()) {
                    retval = StatusBridge.create(projectStatus);
                }
            }
        }
    }
    op.getSdkLocation().refresh();
    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 22 with Path

use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.

the class ModuleFragmentProjectArtifactVersionDefaultValueService method compute.

@Override
protected String compute() {
    String data = null;
    NewModuleFragmentOp op = _op();
    Path location = op.getLocation().content();
    if (location != null) {
        String parentProjectLocation = location.toOSString();
        IPath parentProjectOsPath = org.eclipse.core.runtime.Path.fromOSString(parentProjectLocation);
        String projectName = op.getProjectName().content();
        data = NewModuleFragmentOpMethods.getMavenParentPomVersion(op, projectName, parentProjectOsPath);
    }
    if (data == null) {
        data = "1.0.0-SNAPSHOT";
    }
    return data;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) IPath(org.eclipse.core.runtime.IPath)

Example 23 with Path

use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.

the class WorkspaceLocationValidationService method compute.

@Override
protected Status compute() {
    Status retval = Status.createOkStatus();
    /*
		 * 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.
		 *
		 * 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.
		 */
    Path currentProjectLocation = _op().getLocation().content(true);
    boolean useDefaultLocation = _op().getUseDefaultLocation().content(true);
    if (!useDefaultLocation) {
        if (currentProjectLocation != null) {
            String currentPath = currentProjectLocation.toOSString();
            File osPathFile = Path.fromOSString(currentPath).toFile();
            if (!osPathFile.isAbsolute()) {
                return Status.createErrorStatus("\"" + currentPath + "\" is not an absolute path.");
            }
            if (!_canCreate(osPathFile)) {
                return Status.createErrorStatus("Cannot create project content at \"" + currentPath + "\".");
            }
        } else {
            return Status.createErrorStatus("Location must be specified.");
        }
    }
    return retval;
}
Also used : Status(org.eclipse.sapphire.modeling.Status) Path(org.eclipse.sapphire.modeling.Path) File(java.io.File)

Example 24 with Path

use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.

the class LocationListener method handleTypedEvent.

@Override
protected void handleTypedEvent(ValuePropertyContentEvent event) {
    NewLiferayPluginProjectOp op = op(event);
    boolean useDefaultLocation = op.getUseDefaultLocation().content(true);
    if (useDefaultLocation) {
        return;
    }
    String afterValue = event.after();
    String beforeValue = event.before();
    if ((beforeValue == null) && (afterValue != null)) {
        NewLiferayPluginProjectOpMethods.updateLocation(op, new Path(afterValue));
    }
}
Also used : Path(org.eclipse.sapphire.modeling.Path) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)

Example 25 with Path

use of org.eclipse.sapphire.modeling.Path 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)

Aggregations

Path (org.eclipse.sapphire.modeling.Path)71 IPath (org.eclipse.core.runtime.IPath)37 IStatus (org.eclipse.core.runtime.IStatus)18 Status (org.eclipse.sapphire.modeling.Status)18 IProject (org.eclipse.core.resources.IProject)17 SDK (com.liferay.ide.sdk.core.SDK)16 CoreException (org.eclipse.core.runtime.CoreException)16 IFile (org.eclipse.core.resources.IFile)12 File (java.io.File)9 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)8 ArrayList (java.util.ArrayList)8 IFolder (org.eclipse.core.resources.IFolder)8 Hook (com.liferay.ide.hook.core.model.Hook)6 Element (org.eclipse.sapphire.Element)6 CustomJspDir (com.liferay.ide.hook.core.model.CustomJspDir)5 IWebProject (com.liferay.ide.core.IWebProject)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)3 ValueProperty (org.eclipse.sapphire.ValueProperty)3 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)2