Search in sources :

Example 11 with IFacetedProject

use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project mdw-designer by CenturyLinkCloud.

the class WorkflowProjectManager method loadWorkflowProjects.

private List<WorkflowProject> loadWorkflowProjects() {
    List<WorkflowProject> workflowProjects = new ArrayList<WorkflowProject>();
    List<IProject> javaSourceProjectsForEars = new ArrayList<IProject>();
    // local workflow projects (ear and cloud projects)
    for (IFacetedProject facetedProject : findWorkflowFacetedProjects()) {
        try {
            if (facetedProject.getProject().isOpen()) {
                boolean hasEarFacet = hasEarFacet(facetedProject.getProject());
                WorkflowProject wfProject = loadWorkflowProject(facetedProject.getProject());
                if (hasEarFacet) {
                    wfProject.setEarProjectName(facetedProject.getProject().getName());
                    javaSourceProjectsForEars.add(wfProject.getSourceProject());
                } else {
                    wfProject.setCloudProject(true);
                }
                workflowProjects.add(wfProject);
            }
        } catch (Exception ex) {
            PluginMessages.log(ex);
        }
    }
    // remote workflow projects
    workflowProjects.addAll(findRemoteWorkflowProjects(javaSourceProjectsForEars));
    Collections.sort(workflowProjects);
    for (WorkflowProject workflowProject : workflowProjects) workflowProject.initNoticeChecks();
    PluginMessages.log("WorkflowProjectManager loaded", IStatus.INFO);
    return workflowProjects;
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) ArrayList(java.util.ArrayList) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IProject(org.eclipse.core.resources.IProject) ResourceException(org.eclipse.core.internal.resources.ResourceException) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) DiscoveryException(com.centurylink.mdw.plugin.designer.DiscoveryException) XmlException(org.apache.xmlbeans.XmlException)

Example 12 with IFacetedProject

use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project mdw-designer by CenturyLinkCloud.

the class ProjectInflator method inflateCloudProject.

public void inflateCloudProject(final IRunnableContext container) {
    getProject().setCloudProject(true);
    // get a project handle
    final IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(workflowProject.getName());
    // get a project descriptor
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
    // create the new project operation
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            Repository newRepo = null;
            try {
                if (workflowProject.getPersistType() == PersistType.Git)
                    createGitRepository(monitor);
                CreateProjectOperation op = new CreateProjectOperation(description, "MDW Cloud Project");
                PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(shell));
            } catch (Exception ex) {
                throw new InvocationTargetException(ex);
            } finally {
                if (newRepo != null)
                    newRepo.close();
            }
        }
    };
    // run the new project creation operation
    try {
        container.run(false, false, op);
        ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(MdwPlugin.getShell());
        pmDialog.run(true, false, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Inflating Workflow Project", 250);
                monitor.worked(5);
                // configure as Java project
                ProjectConfigurator projConf = new ProjectConfigurator(getProject(), MdwPlugin.getSettings());
                projConf.setJava(new SubProgressMonitor(monitor, 3));
                ProjectUpdater updater = new ProjectUpdater(getProject(), MdwPlugin.getSettings());
                // bootstrap
                updater.updateMappingFiles(new SubProgressMonitor(monitor, 3));
                // versions
                // of
                // the
                // property
                // files
                updater.updateFrameworkJars(new SubProgressMonitor(monitor, 150));
                updater.updateWebProjectJars(new SubProgressMonitor(monitor, 50));
                try {
                    if (getProject().isOsgi())
                        projConf.addJavaProjectSourceFolder(getProject().getOsgiSettings().getSourceDir(), new SubProgressMonitor(monitor, 3));
                    else if (!getProject().isWar())
                        projConf.addJavaProjectSourceFolder("src", monitor);
                    projConf.setJavaBuildOutputPath("build/classes", new SubProgressMonitor(monitor, 5));
                    projConf.addFrameworkJarsToClasspath(monitor);
                    // add the workflow facet
                    // already
                    getProject().setSkipFacetPostInstallUpdates(true);
                    // did
                    // framework
                    // updates
                    IFacetedProject facetedProject = ProjectFacetsManager.create(getProject().getSourceProject(), true, new SubProgressMonitor(monitor, 3));
                    IProjectFacetVersion javaFacetVersion = ProjectFacetsManager.getProjectFacet("java").getDefaultVersion();
                    if (Float.parseFloat(javaFacetVersion.getVersionString()) < 1.6)
                        javaFacetVersion = ProjectFacetsManager.getProjectFacet("java").getVersion("1.6");
                    if (workflowProject.isCloudOnly())
                        javaFacetVersion = ProjectFacetsManager.getProjectFacet("java").getVersion("1.7");
                    facetedProject.installProjectFacet(javaFacetVersion, null, new SubProgressMonitor(monitor, 3));
                    IProjectFacetVersion mdwFacet = ProjectFacetsManager.getProjectFacet("mdw.workflow").getDefaultVersion();
                    facetedProject.installProjectFacet(mdwFacet, getProject(), new SubProgressMonitor(monitor, 3));
                    if (workflowProject.isOsgi()) {
                        IProjectFacet utilFacet = ProjectFacetsManager.getProjectFacet("jst.utility");
                        IProjectFacetVersion facetVer = utilFacet.getDefaultVersion();
                        IActionDefinition def = facetVer.getActionDefinition(null, IFacetedProject.Action.Type.INSTALL);
                        Object cfg = def.createConfigObject();
                        facetedProject.installProjectFacet(ProjectFacetsManager.getProjectFacet("jst.utility").getDefaultVersion(), cfg, new SubProgressMonitor(monitor, 3));
                    } else if (workflowProject.isWar()) {
                        // add the facet to the xml file
                        IFile facetsFile = workflowProject.getSourceProject().getFile(".settings/org.eclipse.wst.common.project.facet.core.xml");
                        if (facetsFile.exists()) {
                            String content = new String(PluginUtil.readFile(facetsFile));
                            int insert = content.indexOf("</faceted-project>");
                            content = content.substring(0, insert) + "  <installed facet=\"jst.web\" version=\"3.0\"/>\n" + content.substring(insert);
                            PluginUtil.writeFile(facetsFile, content, new SubProgressMonitor(monitor, 3));
                        }
                    }
                    final ProjectConfigurator configurator = new ProjectConfigurator(getProject(), MdwPlugin.getSettings());
                    if (!workflowProject.isOsgi() && !workflowProject.isWar()) {
                        MdwPlugin.getDisplay().syncExec(new Runnable() {

                            public void run() {
                                try {
                                    configurator.createFrameworkSourceCodeAssociations(MdwPlugin.getShell(), new NullProgressMonitor());
                                } catch (CoreException ex) {
                                    PluginMessages.log(ex);
                                }
                            }
                        });
                    }
                    if (workflowProject.isOsgi()) {
                        generateOsgiArtifacts(new SubProgressMonitor(monitor, 10));
                        configurator.configureOsgiProject(shell, new SubProgressMonitor(monitor, 5));
                    } else if (workflowProject.isWar()) {
                        generateWarCloudArtifacts(new SubProgressMonitor(monitor, 10));
                        // force
                        configurator.addMavenNature(new SubProgressMonitor(monitor, 5));
                    // maven
                    // refresh
                    }
                } catch (Exception ex) {
                    throw new InvocationTargetException(ex);
                }
            }
        });
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Create Cloud Project", workflowProject);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IFile(org.eclipse.core.resources.IFile) MdwProgressMonitorDialog(com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) IActionDefinition(org.eclipse.wst.common.project.facet.core.IActionDefinition) MdwProgressMonitorDialog(com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IProject(org.eclipse.core.resources.IProject) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) VcsRepository(com.centurylink.mdw.plugin.project.model.VcsRepository) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) CreateProjectOperation(org.eclipse.ui.ide.undo.CreateProjectOperation)

Example 13 with IFacetedProject

use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project webtools.sourceediting by eclipse.

the class FacetModuleCoreSupportDelegate method isWebProject.

/**
 * @param project
 * @return
 * @throws CoreException
 */
static boolean isWebProject(IProject project) {
    boolean is = false;
    try {
        IFacetedProject faceted = ProjectFacetsManager.create(project);
        if (ProjectFacetsManager.isProjectFacetDefined(JST_WEB_MODULE)) {
            IProjectFacet facet = ProjectFacetsManager.getProjectFacet(JST_WEB_MODULE);
            is = is || (faceted != null && faceted.hasProjectFacet(facet));
        }
        if (!is && ProjectFacetsManager.isProjectFacetDefined(WST_WEB_MODULE)) {
            IProjectFacet facet = ProjectFacetsManager.getProjectFacet(WST_WEB_MODULE);
            is = is || (faceted != null && faceted.hasProjectFacet(facet));
        }
        if (!is && ProjectFacetsManager.isProjectFacetDefined(JST_WEBFRAGMENT_MODULE)) {
            IProjectFacet facet = ProjectFacetsManager.getProjectFacet(JST_WEBFRAGMENT_MODULE);
            is = is || (faceted != null && faceted.hasProjectFacet(facet));
        }
    } catch (CoreException e) {
        Logger.logException(e);
    }
    return is;
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) CoreException(org.eclipse.core.runtime.CoreException) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet)

Example 14 with IFacetedProject

use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project webtools.sourceediting by eclipse.

the class FacetModuleCoreSupportDelegate method isDynamicWebProject.

/**
 * @param project
 * @return
 * @throws CoreException
 */
static boolean isDynamicWebProject(IProject project) {
    if (project == null)
        return false;
    try {
        if (ProjectFacetsManager.isProjectFacetDefined(JST_WEB_MODULE)) {
            IFacetedProject faceted = ProjectFacetsManager.create(project);
            IProjectFacet webModuleFacet = ProjectFacetsManager.getProjectFacet(JST_WEB_MODULE);
            if (faceted != null && faceted.hasProjectFacet(webModuleFacet)) {
                return true;
            }
        }
    } catch (CoreException e) {
        Logger.logException(e);
    }
    return false;
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) CoreException(org.eclipse.core.runtime.CoreException) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet)

Example 15 with IFacetedProject

use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project webtools.sourceediting by eclipse.

the class StaticWebDeployableFactory method isValidModule.

/**
 * Returns true if the project represents a deployable project of this type.
 *
 * @param project
 *            org.eclipse.core.resources.IProject
 * @return boolean
 */
protected boolean isValidModule(IProject project) {
    try {
        IFacetedProject facetedProject = ProjectFacetsManager.create(project);
        if (facetedProject == null)
            return false;
        IProjectFacet webFacet = ProjectFacetsManager.getProjectFacet(IModuleConstants.WST_WEB_MODULE);
        return facetedProject.hasProjectFacet(webFacet);
    } catch (Exception e) {
        return false;
    }
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

IFacetedProject (org.eclipse.wst.common.project.facet.core.IFacetedProject)32 CoreException (org.eclipse.core.runtime.CoreException)20 IProjectFacet (org.eclipse.wst.common.project.facet.core.IProjectFacet)17 IProject (org.eclipse.core.resources.IProject)16 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IStatus (org.eclipse.core.runtime.IStatus)6 IProjectFacetVersion (org.eclipse.wst.common.project.facet.core.IProjectFacetVersion)5 IRuntime (org.eclipse.wst.server.core.IRuntime)5 IWorkspace (org.eclipse.core.resources.IWorkspace)4 IPath (org.eclipse.core.runtime.IPath)4 IFile (org.eclipse.core.resources.IFile)3 Path (org.eclipse.core.runtime.Path)3 IFacetedProjectWorkingCopy (org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy)3 FacetedProjectWorkingCopy (org.eclipse.wst.common.project.facet.core.internal.FacetedProjectWorkingCopy)3 PluginClasspathContainerInitializer (com.liferay.ide.project.core.PluginClasspathContainerInitializer)2 IPluginPublisher (com.liferay.ide.server.core.IPluginPublisher)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Status (org.eclipse.core.runtime.Status)2