Search in sources :

Example 1 with FacetedProjectWorkingCopy

use of org.eclipse.wst.common.project.facet.core.internal.FacetedProjectWorkingCopy in project liferay-ide by liferay.

the class SDKProjectConvertOperation method convertExistingProject.

protected IProject convertExistingProject(ProjectRecord record, IProgressMonitor monitor) throws CoreException {
    String projectName = record.getProjectName();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject project = workspace.getRoot().getProject(projectName);
    if (record.description == null) {
        // error case
        record.description = workspace.newProjectDescription(projectName);
        IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath());
        if (Platform.getLocation().isPrefixOf(locationPath)) {
            record.description.setLocation(null);
        } else {
            record.description.setLocation(locationPath);
        }
    } else {
        record.description.setName(projectName);
    }
    monitor.beginTask(Msgs.importingProject, 100);
    project.open(IResource.FORCE, CoreUtil.newSubMonitor(monitor, 70));
    IFacetedProject fProject = ProjectFacetsManager.create(project, true, monitor);
    FacetedProjectWorkingCopy fpwc = new FacetedProjectWorkingCopy(fProject);
    String sdkLocation = getDataModel().getStringProperty(SDK_LOCATION);
    IRuntime runtime = (IRuntime) model.getProperty(IFacetProjectCreationDataModelProperties.FACET_RUNTIME);
    String pluginType = ProjectUtil.guessPluginType(fpwc);
    SDKPluginFacetUtil.configureProjectAsRuntimeProject(fpwc, runtime, pluginType, sdkLocation, record);
    fpwc.commitChanges(monitor);
    monitor.done();
    return project;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace) FacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.internal.FacetedProjectWorkingCopy) IProject(org.eclipse.core.resources.IProject) IRuntime(org.eclipse.wst.common.project.facet.core.runtime.IRuntime)

Example 2 with FacetedProjectWorkingCopy

use of org.eclipse.wst.common.project.facet.core.internal.FacetedProjectWorkingCopy in project liferay-ide by liferay.

the class ProjectUtil method createExistingProject.

public static IProject createExistingProject(ProjectRecord record, IPath sdkLocation, IProgressMonitor monitor) throws CoreException {
    String projectName = record.getProjectName();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject project = workspace.getRoot().getProject(projectName);
    if (record.description == null) {
        // error case
        record.description = workspace.newProjectDescription(projectName);
        IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath());
        if (Platform.getLocation().isPrefixOf(locationPath)) {
            record.description.setLocation(null);
        } else {
            record.description.setLocation(locationPath);
        }
    } else {
        record.description.setName(projectName);
    }
    project.create(record.description, CoreUtil.newSubMonitor(monitor, 30));
    project.open(IResource.FORCE, CoreUtil.newSubMonitor(monitor, 70));
    if (project.getName().endsWith(ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)) {
        _fixExtProjectClasspathEntries(project);
    }
    IFacetedProject fProject = ProjectFacetsManager.create(project, true, monitor);
    FacetedProjectWorkingCopy fpwc = new FacetedProjectWorkingCopy(fProject);
    String pluginType = guessPluginType(fpwc);
    SDKPluginFacetUtil.configureProjectAsSDKProject(fpwc, pluginType, sdkLocation.toPortableString(), record);
    fpwc.commitChanges(monitor);
    IJavaProject javaProject = JavaCore.create(fProject.getProject());
    CoreUtil.getWorkspace().run(new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            List<IClasspathEntry> rawClasspaths = new ArrayList<>();
            IPath containerPath = null;
            for (IClasspathEntry entry : javaProject.getRawClasspath()) {
                String segment = entry.getPath().segment(0);
                if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && segment.equals(SDKClasspathContainer.ID)) {
                    containerPath = entry.getPath();
                    break;
                }
                if (!_isLiferayRuntimePluginClassPath(entry)) {
                    rawClasspaths.add(entry);
                }
            }
            if (containerPath != null) {
                ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(SDKClasspathContainer.ID);
                initializer.initialize(containerPath, javaProject);
            } else {
                javaProject.setRawClasspath(rawClasspaths.toArray(new IClasspathEntry[rawClasspaths.size()]), new NullProgressMonitor());
                javaProject.setRawClasspath(rawClasspaths.toArray(new IClasspathEntry[rawClasspaths.size()]), new NullProgressMonitor());
                IAccessRule[] accessRules = {};
                IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute(IClasspathDependencyConstants.CLASSPATH_COMPONENT_NON_DEPENDENCY, StringPool.EMPTY) };
                IPath cpePath = new Path(SDKClasspathContainer.ID);
                IClasspathEntry newEntry = JavaCore.newContainerEntry(cpePath, accessRules, attributes, false);
                IClasspathEntry[] entries = javaProject.getRawClasspath();
                for (IClasspathEntry entry : entries) {
                    if (entry.getPath().equals(cpePath)) {
                        return;
                    }
                }
                IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
                System.arraycopy(entries, 0, newEntries, 0, entries.length);
                newEntries[entries.length] = newEntry;
                javaProject.setRawClasspath(newEntries, monitor);
            }
            monitor.done();
            SDK sdk = SDKUtil.createSDKFromLocation(sdkLocation);
            SDKUtil.openAsProject(sdk);
        }
    }, monitor);
    return project;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) FacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.internal.FacetedProjectWorkingCopy) IFacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy) IProject(org.eclipse.core.resources.IProject) PluginClasspathContainerInitializer(com.liferay.ide.project.core.PluginClasspathContainerInitializer) ClasspathContainerInitializer(org.eclipse.jdt.core.ClasspathContainerInitializer) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) List(java.util.List) ArrayList(java.util.ArrayList) SDK(com.liferay.ide.sdk.core.SDK)

Example 3 with FacetedProjectWorkingCopy

use of org.eclipse.wst.common.project.facet.core.internal.FacetedProjectWorkingCopy in project liferay-ide by liferay.

the class ProjectUtil method createExistingProject.

public static IProject createExistingProject(ProjectRecord record, IRuntime runtime, String sdkLocation, IProgressMonitor monitor) throws CoreException {
    String projectName = record.getProjectName();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject project = workspace.getRoot().getProject(projectName);
    if (record.description == null) {
        // error case
        record.description = workspace.newProjectDescription(projectName);
        IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath());
        if (Platform.getLocation().isPrefixOf(locationPath)) {
            record.description.setLocation(null);
        } else {
            record.description.setLocation(locationPath);
        }
    } else {
        record.description.setName(projectName);
    }
    monitor.beginTask(Msgs.importingProject, 100);
    project.create(record.description, CoreUtil.newSubMonitor(monitor, 30));
    project.open(IResource.FORCE, CoreUtil.newSubMonitor(monitor, 70));
    if (project.getName().endsWith(ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)) {
        _fixExtProjectClasspathEntries(project);
    }
    IFacetedProject fProject = ProjectFacetsManager.create(project, true, monitor);
    FacetedProjectWorkingCopy fpwc = new FacetedProjectWorkingCopy(fProject);
    String pluginType = guessPluginType(fpwc);
    SDKPluginFacetUtil.configureProjectAsRuntimeProject(fpwc, runtime, pluginType, sdkLocation, record);
    fpwc.commitChanges(monitor);
    IJavaProject javaProject = JavaCore.create(fProject.getProject());
    CoreUtil.getWorkspace().run(new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            for (IClasspathEntry entry : javaProject.getRawClasspath()) {
                String segment = entry.getPath().segment(0);
                if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && segment.equals(PluginClasspathContainerInitializer.ID)) {
                    ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(PluginClasspathContainerInitializer.ID);
                    initializer.initialize(entry.getPath(), javaProject);
                    break;
                }
            }
            monitor.done();
        }
    }, monitor);
    return project;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) FacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.internal.FacetedProjectWorkingCopy) IFacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy) IProject(org.eclipse.core.resources.IProject) PluginClasspathContainerInitializer(com.liferay.ide.project.core.PluginClasspathContainerInitializer) ClasspathContainerInitializer(org.eclipse.jdt.core.ClasspathContainerInitializer) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace)

Aggregations

IProject (org.eclipse.core.resources.IProject)3 IWorkspace (org.eclipse.core.resources.IWorkspace)3 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 IFacetedProject (org.eclipse.wst.common.project.facet.core.IFacetedProject)3 FacetedProjectWorkingCopy (org.eclipse.wst.common.project.facet.core.internal.FacetedProjectWorkingCopy)3 PluginClasspathContainerInitializer (com.liferay.ide.project.core.PluginClasspathContainerInitializer)2 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ClasspathContainerInitializer (org.eclipse.jdt.core.ClasspathContainerInitializer)2 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 IFacetedProjectWorkingCopy (org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy)2 SDK (com.liferay.ide.sdk.core.SDK)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IRuntime (org.eclipse.wst.common.project.facet.core.runtime.IRuntime)1