Search in sources :

Example 51 with Status

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

the class NewModuleFragmentFilesOpMethods method execute.

public static final Status execute(NewModuleFragmentFilesOp op, ProgressMonitor pm) {
    IProgressMonitor monitor = ProgressMonitorBridge.create(pm);
    monitor.beginTask("Copy files (this process may take several minutes)", 100);
    String projectName = op.getProjectName().content();
    IProject project = CoreUtil.getProject(projectName);
    Status retval = null;
    try {
        String hostBundleName = op.getHostOsgiBundle().content();
        IPath projectCoreLocation = ProjectCore.getDefault().getStateLocation();
        IPath tempJarDir = LiferayCore.GLOBAL_USER_DIR.append(hostBundleName);
        if (FileUtil.notExists(tempJarDir)) {
            IRuntime runtime = ServerUtil.getRuntime(op.getLiferayRuntimeName().content());
            String hostOsgiJar = hostBundleName + ".jar";
            ServerUtil.getModuleFileFrom70Server(runtime, hostOsgiJar, projectCoreLocation);
            IPath tempJarFile = projectCoreLocation.append(hostOsgiJar);
            try {
                ZipUtil.unzip(tempJarFile.toFile(), tempJarDir.toFile());
            } catch (IOException ioe) {
                throw new CoreException(ProjectCore.createErrorStatus(ioe));
            }
        }
        ElementList<OverrideFilePath> files = op.getOverrideFiles();
        for (OverrideFilePath file : files) {
            File fragmentFile = tempJarDir.append(file.getValue().content()).toFile();
            if (FileUtil.exists(fragmentFile)) {
                File folder = null;
                if (fragmentFile.getName().equals("portlet.properties")) {
                    IPath path = project.getLocation().append("src/main/java");
                    folder = path.toFile();
                    FileUtil.copyFileToDir(fragmentFile, "portlet-ext.properties", folder);
                } else if (fragmentFile.getName().contains("default.xml")) {
                    String parent = fragmentFile.getPath();
                    parent = parent.replaceAll("\\\\", "/");
                    String metaInfResources = "resource-actions";
                    parent = parent.substring(parent.indexOf(metaInfResources) + metaInfResources.length());
                    IPath resources = project.getLocation().append("src/main/resources/resource-actions");
                    folder = resources.toFile();
                    folder.mkdirs();
                    FileUtil.copyFileToDir(fragmentFile, "default-ext.xml", folder);
                    try {
                        File ext = new File(project.getLocation().append("src/main/resources") + "/portlet-ext.properties");
                        ext.createNewFile();
                        String extFileContent = "resource.actions.configs=resource-actions/default.xml," + "resource-actions/default-ext.xml";
                        FileUtil.writeFile(ext, extFileContent, null);
                    } catch (Exception e) {
                        throw new CoreException(ProjectCore.createErrorStatus(e));
                    }
                } else {
                    String parent = fragmentFile.getParentFile().getPath();
                    parent = parent.replaceAll("\\\\", "/");
                    String metaInfResources = "META-INF/resources";
                    parent = parent.substring(parent.indexOf(metaInfResources) + metaInfResources.length());
                    IPath resources = project.getLocation().append("src/main/resources/META-INF/resources");
                    folder = resources.toFile();
                    folder.mkdirs();
                    if (!parent.equals("resources") && !parent.equals("")) {
                        folder = resources.append(parent).toFile();
                        folder.mkdirs();
                    }
                    FileUtil.copyFileToDir(fragmentFile, folder);
                }
            }
        }
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
        retval = Status.createOkStatus();
    } catch (Exception e) {
        String msg = "Error copy files.";
        ProjectCore.logError(msg, e);
        return Status.createErrorStatus(msg + " Please see Eclipse error log for more details.", e);
    }
    return retval;
}
Also used : Status(org.eclipse.sapphire.modeling.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) File(java.io.File) IProject(org.eclipse.core.resources.IProject) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 52 with Status

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

the class NewModuleFragmentOpMethods method execute.

public static final Status execute(NewModuleFragmentOp op, ProgressMonitor pm) {
    IProgressMonitor monitor = ProgressMonitorBridge.create(pm);
    monitor.beginTask("Creating Liferay module fragment project (this process may take several minutes)", 100);
    Status retval = null;
    try {
        NewLiferayProjectProvider<BaseModuleOp> projectProvider = op.getProjectProvider().content(true);
        IStatus status = projectProvider.createNewProject(op, monitor);
        retval = StatusBridge.create(status);
        if (retval.ok()) {
            _updateBuildPrefs(op);
        }
    } catch (Exception e) {
        String msg = "Error creating Liferay module fragment project.";
        ProjectCore.logError(msg, e);
        return Status.createErrorStatus(msg + " Please see Eclipse error log for more details.", e);
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.sapphire.modeling.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) BaseModuleOp(com.liferay.ide.project.core.modules.BaseModuleOp) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException)

Example 53 with Status

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

the class ImportLiferayModuleProjectOpMethods method execute.

public static final Status execute(ImportLiferayModuleProjectOp op, ProgressMonitor pm) {
    IProgressMonitor monitor = ProgressMonitorBridge.create(pm);
    monitor.beginTask("Importing Module project...", 100);
    Path path = op.getLocation().content();
    String location = path.toOSString();
    ILiferayProjectImporter importer = LiferayCore.getImporter(op.getBuildType().content());
    Status retval = Status.createOkStatus();
    try {
        importer.importProjects(location, monitor);
    } catch (CoreException ce) {
        retval = Status.createErrorStatus(ce);
    }
    return retval;
}
Also used : Path(org.eclipse.sapphire.modeling.Path) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.sapphire.modeling.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILiferayProjectImporter(com.liferay.ide.core.ILiferayProjectImporter) CoreException(org.eclipse.core.runtime.CoreException)

Example 54 with Status

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

the class ImportModuleProjectLocationValidationService method compute.

@Override
protected Status compute() {
    ImportLiferayModuleProjectOp op = _op();
    Path path = op.getLocation().content();
    if ((path == null) || path.isEmpty()) {
        return Status.createOkStatus();
    }
    String location = path.toOSString();
    Status retval = StatusBridge.create(ProjectImportUtil.validatePath(location));
    if (!retval.ok()) {
        return retval;
    }
    if (LiferayWorkspaceUtil.isValidWorkspaceLocation(location)) {
        return Status.createErrorStatus("Can't import Liferay Workspace, please use Import Liferay Workspace Project wizard.");
    }
    retval = StatusBridge.create(ImportLiferayModuleProjectOpMethods.getBuildType(location));
    if (retval.severity() == Status.Severity.ERROR) {
        return retval;
    }
    String projectName = path.lastSegment();
    if (FileUtil.exists(CoreUtil.getProject(projectName))) {
        return Status.createErrorStatus("A project with that name already exists.");
    }
    return retval;
}
Also used : Path(org.eclipse.sapphire.modeling.Path) Status(org.eclipse.sapphire.modeling.Status)

Example 55 with Status

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

the class JavaPackageNameValidationService method compute.

@Override
protected Status compute() {
    Status retval = Status.createOkStatus();
    NewLiferayComponentOp op = _op();
    String projectName = op.getProjectName().text(false);
    if (projectName != null) {
        IJavaProject javaproject = JavaCore.create(CoreUtil.getProject(op.getProjectName().text(false)));
        if (CoreUtil.getSourceFolders(javaproject).size() == 0) {
            retval = Status.createErrorStatus("Unable to find any source folders.");
            return retval;
        }
    }
    JavaPackageName packageName = op.getPackageName().content(true);
    if (packageName != null) {
        IStatus status = JavaConventions.validatePackageName(packageName.toString(), CompilerOptions.VERSION_1_7, CompilerOptions.VERSION_1_7);
        int packageNameStatus = status.getSeverity();
        if (packageNameStatus == IStatus.ERROR) {
            retval = Status.createErrorStatus("Invalid package name");
        }
    }
    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)

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