Search in sources :

Example 1 with Status

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

the class NewLiferayComponentValidationService method compute.

@Override
protected Status compute() {
    Status retval = Status.createOkStatus();
    NewLiferayComponentOp op = _op();
    String className = op.getComponentClassName().content(true);
    if (!CoreUtil.isNullOrEmpty(className)) {
        IStatus status = JavaConventions.validateJavaTypeName(className, CompilerOptions.VERSION_1_7, CompilerOptions.VERSION_1_7);
        int classNameStatus = status.getSeverity();
        if (className.indexOf('.') != -1) {
            classNameStatus = IStatus.ERROR;
        }
        if (classNameStatus == IStatus.ERROR) {
            retval = Status.createErrorStatus("Invalid class name");
        }
    }
    String projectName = op.getProjectName().content(true);
    if (projectName != null) {
        IProject project = CoreUtil.getProject(projectName);
        if (project != null) {
            try {
                JavaPackageName pack = op.getPackageName().content(true);
                if (pack != null) {
                    String packageName = pack.toString();
                    IJavaProject javaProject = JavaCore.create(project);
                    IType type = javaProject.findType(packageName + "." + className);
                    if (type != null) {
                        retval = Status.createErrorStatus(packageName + "." + className + " already exists.");
                    }
                }
            } catch (Exception e) {
                ProjectCore.logError("Checking component class name failed.", e);
            }
        }
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.sapphire.modeling.Status) JavaPackageName(org.eclipse.sapphire.java.JavaPackageName) IStatus(org.eclipse.core.runtime.IStatus) IJavaProject(org.eclipse.jdt.core.IJavaProject) IProject(org.eclipse.core.resources.IProject) IType(org.eclipse.jdt.core.IType)

Example 2 with Status

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

the class SDKImportLocationValidationService method compute.

@Override
protected Status compute() {
    Status retval = Status.createOkStatus();
    SDKProjectsImportOp op = _op();
    Path currentProjectLocation = op.getSdkLocation().content(true);
    if ((currentProjectLocation != null) && !currentProjectLocation.isEmpty()) {
        String currentPath = currentProjectLocation.toOSString();
        retval = StatusBridge.create(ProjectImportUtil.validateSDKPath(currentPath));
    }
    return retval;
}
Also used : Status(org.eclipse.sapphire.modeling.Status) Path(org.eclipse.sapphire.modeling.Path) SDKProjectsImportOp(com.liferay.ide.project.core.model.SDKProjectsImportOp)

Example 3 with Status

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

the class SDKImportValidationService method compute.

@Override
protected Status compute() {
    Status retval = Status.createOkStatus();
    ParentSDKProjectImportOp op = _op();
    try {
        SDK sdk = SDKUtil.getWorkspaceSDK();
        if (sdk != null) {
            return StatusBridge.create(ProjectCore.createErrorStatus(" This workspace already has another sdk."));
        }
        Path currentProjectLocation = op.getSdkLocation().content(true);
        if ((currentProjectLocation != null) && !currentProjectLocation.isEmpty()) {
            sdk = SDKUtil.createSDKFromLocation(PathBridge.create(currentProjectLocation));
            if (sdk != null) {
                IStatus sdkStatus = sdk.validate(true);
                if (!sdkStatus.isOK()) {
                    retval = StatusBridge.create(ProjectCore.createWarningStatus(sdkStatus.getChildren()[0].getMessage()));
                }
            } else {
                retval = StatusBridge.create(ProjectCore.createErrorStatus("This parent sdk project path is invalid."));
            }
        }
    } catch (CoreException ce) {
    }
    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) CoreException(org.eclipse.core.runtime.CoreException) ParentSDKProjectImportOp(com.liferay.ide.project.core.model.ParentSDKProjectImportOp) SDK(com.liferay.ide.sdk.core.SDK)

Example 4 with Status

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

the class UseDefaultLocationValidationService method compute.

@Override
protected Status compute() {
    Status retval = Status.createOkStatus();
    NewLiferayPluginProjectOp op = _op();
    NewLiferayProjectProvider<NewLiferayPluginProjectOp> provider = op.getProjectProvider().content();
    if ((op.getProjectName().content() != null) && "ant".equals(provider.getShortName()) && !op.getUseDefaultLocation().content() && !NewLiferayPluginProjectOpMethods.canUseCustomLocation(op)) {
        retval = Status.createErrorStatus("The specified SDK version is not allowed to use custom location.");
    }
    return retval;
}
Also used : Status(org.eclipse.sapphire.modeling.Status) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)

Example 5 with Status

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

the class AbstractProjectLocationValidationService method compute.

@Override
protected Status compute() {
    BaseModuleOp op = op();
    Status retval = Status.createOkStatus();
    String currentProjectName = op.getProjectName().content();
    Path currentProjectLocation = op.getLocation().content();
    Boolean userDefaultLocation = op.getUseDefaultLocation().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.
		 */
    if (userDefaultLocation) {
        return retval;
    }
    /*
		 * 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 (currentProjectName == null) {
        return retval;
    }
    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.");
    } else {
        IPath osPath = org.eclipse.core.runtime.Path.fromOSString(currentPath);
        if (!osPath.toFile().isAbsolute()) {
            retval = Status.createErrorStatus("\"" + currentPath + "\" is not an absolute path.");
        } else {
            if (FileUtil.notExists(osPath)) {
                if (!_canCreate(osPath.toFile())) {
                    retval = Status.createErrorStatus("Cannot create project content at \"" + currentPath + "\"");
                }
            }
            NewLiferayProjectProvider<BaseModuleOp> provider = op.getProjectProvider().content();
            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) IPath(org.eclipse.core.runtime.IPath)

Aggregations

Status (org.eclipse.sapphire.modeling.Status)83 IProject (org.eclipse.core.resources.IProject)33 Test (org.junit.Test)31 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)29 IStatus (org.eclipse.core.runtime.IStatus)25 Path (org.eclipse.sapphire.modeling.Path)18 CoreException (org.eclipse.core.runtime.CoreException)15 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)15 NewLiferayJSFModuleProjectOp (com.liferay.ide.project.core.jsf.NewLiferayJSFModuleProjectOp)14 IFile (org.eclipse.core.resources.IFile)12 IPath (org.eclipse.core.runtime.IPath)11 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)10 NewLiferayModuleProjectOp (com.liferay.ide.project.core.modules.NewLiferayModuleProjectOp)9 SDK (com.liferay.ide.sdk.core.SDK)9 File (java.io.File)6 NewLiferayComponentOp (com.liferay.ide.project.core.modules.NewLiferayComponentOp)5 IRuntime (org.eclipse.wst.server.core.IRuntime)5 PropertyKey (com.liferay.ide.project.core.modules.PropertyKey)3 NewModuleFragmentOp (com.liferay.ide.project.core.modules.fragment.NewModuleFragmentOp)3 ArrayList (java.util.ArrayList)3