Search in sources :

Example 6 with IFacetedProject

use of org.eclipse.wst.common.project.facet.core.IFacetedProject 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 7 with IFacetedProject

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

the class LiferayMavenProjectConfigurator method configure.

@Override
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    monitor.beginTask(NLS.bind(Msgs.configuringLiferayProject, request.getProject()), 100);
    Plugin liferayMavenPlugin = MavenUtil.getPlugin(request.getMavenProjectFacade(), ILiferayMavenConstants.LIFERAY_MAVEN_PLUGIN_KEY, monitor);
    if (!_shouldConfigure(liferayMavenPlugin, request)) {
        monitor.done();
        return;
    }
    IProject project = request.getProject();
    IFile pomFile = project.getFile(IMavenConstants.POM_FILE_NAME);
    IFacetedProject facetedProject = ProjectFacetsManager.create(project, false, monitor);
    _removeLiferayMavenMarkers(project);
    monitor.worked(25);
    MavenProject mavenProject = request.getMavenProject();
    List<MavenProblemInfo> errors = _findLiferayMavenPluginProblems(request, monitor);
    if (ListUtil.isNotEmpty(errors)) {
        try {
            markerManager.addErrorMarkers(pomFile, ILiferayMavenConstants.LIFERAY_MAVEN_MARKER_CONFIGURATION_WARNING_ID, errors);
        } catch (CoreException ce) {
        // no need to log this error its just best effort
        }
    }
    monitor.worked(25);
    MavenProblemInfo installProblem = null;
    if (_shouldInstallNewLiferayFacet(facetedProject)) {
        installProblem = _installNewLiferayFacet(facetedProject, request, monitor);
    }
    if (_shouldAddLiferayNature(mavenProject, facetedProject)) {
        LiferayNature.addLiferayNature(project, monitor);
    }
    monitor.worked(25);
    if (installProblem != null) {
        this.markerManager.addMarker(pomFile, ILiferayMavenConstants.LIFERAY_MAVEN_MARKER_CONFIGURATION_WARNING_ID, installProblem.getMessage(), installProblem.getLocation().getLineNumber(), IMarker.SEVERITY_WARNING);
    } else {
        String pluginType = MavenUtil.getLiferayMavenPluginType(mavenProject);
        // IDE-817 we need to mak sure that on deployment it will have the correct
        // suffix for project name
        IVirtualComponent projectComponent = ComponentCore.createComponent(project);
        try {
            if (projectComponent != null) {
                String deployedName = projectComponent.getDeployedName();
                Matcher m = _versionPattern.matcher(deployedName);
                if (m.matches()) {
                    deployedName = m.group(1);
                    configureDeployedName(project, deployedName);
                }
                if (pluginType != null) {
                    String pluginTypeSuffix = "-" + pluginType;
                    String deployedFileName = project.getName() + pluginTypeSuffix;
                    if ((deployedName == null) || ((deployedName != null) && !deployedName.endsWith(pluginTypeSuffix))) {
                        configureDeployedName(project, deployedFileName);
                    }
                    String oldContextRoot = ComponentUtilities.getServerContextRoot(project);
                    if ((oldContextRoot == null) || ((oldContextRoot != null) && !oldContextRoot.endsWith(pluginTypeSuffix))) {
                        IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(LiferayMavenCore.PLUGIN_ID);
                        boolean setMavenPluginSuffix = prefs.getBoolean(LiferayMavenCore.PREF_ADD_MAVEN_PLUGIN_SUFFIX, false);
                        if (setMavenPluginSuffix) {
                            ComponentUtilities.setServerContextRoot(project, deployedFileName);
                        }
                    }
                }
            }
        } catch (Exception e) {
            LiferayMavenCore.logError("Unable to configure deployed name for project " + project.getName(), e);
        }
        if (ILiferayMavenConstants.THEME_PLUGIN_TYPE.equals(pluginType)) {
            IVirtualComponent component = ComponentCore.createComponent(project, true);
            if (component != null) {
                // make sure to update the main deployment folder
                WarPluginConfiguration config = new WarPluginConfiguration(mavenProject, project);
                String warSourceDirectory = config.getWarSourceDirectory();
                IFolder contentFolder = project.getFolder(warSourceDirectory);
                IPath warPath = _rootPath.append(contentFolder.getProjectRelativePath());
                IPath themeFolder = _rootPath.append(getThemeTargetFolder(mavenProject, project));
                // add a link to our m2e-liferay/theme-resources folder into deployment assembly
                WTPProjectsUtil.insertLinkBefore(project, themeFolder, warPath, _rootPath, monitor);
            }
        }
    }
    if ((project != null) && ProjectUtil.isHookProject(project)) {
        HookDescriptorHelper hookDescriptor = new HookDescriptorHelper(project);
        String customJSPFolder = hookDescriptor.getCustomJSPFolder(null);
        if (customJSPFolder != null) {
            IWebProject webproject = LiferayCore.create(IWebProject.class, project);
            if ((webproject != null) && (webproject.getDefaultDocrootFolder() != null)) {
                IFolder docFolder = webproject.getDefaultDocrootFolder();
                IPath newPath = Path.fromOSString(customJSPFolder);
                IPath pathValue = docFolder.getFullPath().append(newPath);
                boolean disableCustomJspValidation = LiferayMavenCore.getPreferenceBoolean(LiferayMavenCore.PREF_DISABLE_CUSTOM_JSP_VALIDATION);
                if (disableCustomJspValidation) {
                    HookUtil.configureJSPSyntaxValidationExclude(project, project.getFolder(pathValue.makeRelativeTo(project.getFullPath())), true);
                }
            }
        }
    }
    monitor.worked(25);
    monitor.done();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) Matcher(java.util.regex.Matcher) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IWebProject(com.liferay.ide.core.IWebProject) WarPluginConfiguration(org.eclipse.m2e.wtp.WarPluginConfiguration) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) MavenProblemInfo(org.eclipse.m2e.core.internal.markers.MavenProblemInfo) MavenProject(org.apache.maven.project.MavenProject) CoreException(org.eclipse.core.runtime.CoreException) HookDescriptorHelper(com.liferay.ide.hook.core.dd.HookDescriptorHelper) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) Plugin(org.apache.maven.model.Plugin) IFolder(org.eclipse.core.resources.IFolder)

Example 8 with IFacetedProject

use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project jbosstools-hibernate by jbosstools.

the class JPAProjectConfigurator method configure.

@Override
public void configure(IProject project, Set<IPath> ignoredDirectories, IProgressMonitor monitor) {
    try {
        IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor);
        // $NON-NLS-1$
        IProjectFacet JPA_FACET = ProjectFacetsManager.getProjectFacet("jpt.jpa");
        if (!facetedProject.hasProjectFacet(JPA_FACET)) {
            Set<Action> actions = new LinkedHashSet<>(2, 1);
            IProjectFacetVersion javaFv = JavaFacet.FACET.getVersion(JavaFacetUtil.getCompilerLevel(project));
            if (!facetedProject.hasProjectFacet(JavaFacet.FACET)) {
                actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, javaFv, null));
            } else if (!facetedProject.hasProjectFacet(javaFv)) {
                actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.VERSION_CHANGE, javaFv, null));
            }
            // $NON-NLS-1$
            RecursiveFileFinder finder = new RecursiveFileFinder("persistence.xml", ignoredDirectories);
            project.accept(finder);
            PersistenceXmlResourceProvider provider = PersistenceXmlResourceProvider.getXmlResourceProvider(finder.getFile());
            JptXmlResource jpaXmlResource = provider.getXmlResource();
            IProjectFacetVersion version = null;
            if (jpaXmlResource.getVersion() != null) {
                version = JpaProject.FACET.getVersion(jpaXmlResource.getVersion());
            }
            if (version == null) {
                version = JpaProject.FACET.getLatestVersion();
            }
            // use default
            JpaPlatform platform = null;
            // TODO improve platform detection
            LibraryInstallDelegate libraryDelegate = new LibraryInstallDelegate(facetedProject, version);
            // $NON-NLS-1$
            ILibraryProvider libraryProvider = LibraryProviderFramework.getProvider("jpa-no-op-library-provider");
            libraryDelegate.setLibraryProvider(libraryProvider);
            IDataModel dm = DataModelFactory.createDataModel(new JpaFacetInstallDataModelProvider());
            dm.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, version.getVersionString());
            dm.setProperty(JpaFacetDataModelProperties.PLATFORM, platform);
            dm.setProperty(JpaFacetInstallDataModelProperties.DISCOVER_ANNOTATED_CLASSES, true);
            dm.setProperty(JpaFacetInstallDataModelProperties.LIBRARY_PROVIDER_DELEGATE, libraryDelegate);
            actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, version, dm));
            facetedProject.modify(actions, monitor);
        }
    } catch (Exception ex) {
        HibernateJptUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, HibernateJptUIPlugin.PLUGIN_ID, ex.getMessage(), ex));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) Action(org.eclipse.wst.common.project.facet.core.IFacetedProject.Action) JptXmlResource(org.eclipse.jpt.common.core.resource.xml.JptXmlResource) RecursiveFileFinder(org.eclipse.ui.wizards.datatransfer.RecursiveFileFinder) IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) JpaFacetInstallDataModelProvider(org.eclipse.jpt.jpa.core.internal.facet.JpaFacetInstallDataModelProvider) LibraryInstallDelegate(org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate) ILibraryProvider(org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider) IDataModel(org.eclipse.wst.common.frameworks.datamodel.IDataModel) JpaPlatform(org.eclipse.jpt.jpa.core.JpaPlatform) CoreException(org.eclipse.core.runtime.CoreException) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) Action(org.eclipse.wst.common.project.facet.core.IFacetedProject.Action) PersistenceXmlResourceProvider(org.eclipse.jpt.jpa.core.internal.resource.persistence.PersistenceXmlResourceProvider)

Example 9 with IFacetedProject

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

the class FacetUtil method verifyFacets.

/**
 * Tests whether the facets on a project are supported by a given server. Returns
 * an OK status if the server's runtime supports the project's facets, and an
 * ERROR status (with message) if it doesn't.
 *
 * @param project a project
 * @param server a server
 * @return OK status if the server's runtime supports the project's facets, and an
 *    ERROR status (with message) if it doesn't
 */
public static final IStatus verifyFacets(IProject project, IServer server) {
    if (server == null)
        return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, Messages.errorNoRuntime, null);
    IRuntime runtime = server.getRuntime();
    if (runtime == null)
        return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, Messages.errorNoRuntime, null);
    org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime2 = getRuntime(runtime);
    if (// bug 150194 - what do we do if the facet runtime doesn't exist yet
    runtime2 == null)
        return Status.OK_STATUS;
    try {
        IFacetedProject facetedProject = ProjectFacetsManager.create(project);
        Iterator iterator = facetedProject.getProjectFacets().iterator();
        while (iterator.hasNext()) {
            IProjectFacetVersion facet = (IProjectFacetVersion) iterator.next();
            if (!runtime2.supports(facet))
                return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorFacet, facet.getProjectFacet().getLabel(), facet.getVersionString()), null);
        }
    } catch (CoreException ce) {
        return ce.getStatus();
    }
    return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) CoreException(org.eclipse.core.runtime.CoreException) IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) Iterator(java.util.Iterator) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 10 with IFacetedProject

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

the class FacetUtil method removeTargets.

/**
 * Removes the given runtime from the target of all projects.
 *
 * @param runtime a runtime
 * @param monitor a progress monitor, or <code>null</code> if progress
 *   reporting and cancellation are not desired
 * @throws CoreException if failed for any reason
 */
public static void removeTargets(IRuntime runtime, IProgressMonitor monitor) throws CoreException {
    try {
        org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime2 = getRuntime(runtime);
        IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
        if (projects != null) {
            for (IProject project : projects) {
                IFacetedProject facetedProject = ProjectFacetsManager.create(project);
                if (facetedProject != null) {
                    Set<org.eclipse.wst.common.project.facet.core.runtime.IRuntime> set = facetedProject.getTargetedRuntimes();
                    if (set != null && set.contains(runtime2))
                        facetedProject.removeTargetedRuntime(runtime2, monitor);
                }
            }
        }
    } catch (CoreException ce) {
        throw ce;
    } catch (Throwable t) {
        if (Trace.WARNING) {
            Trace.trace(Trace.STRING_WARNING, "Could not remove runtime target", t);
        }
    }
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IProject(org.eclipse.core.resources.IProject) IRuntime(org.eclipse.wst.server.core.IRuntime) 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