Search in sources :

Example 6 with IVirtualComponent

use of org.eclipse.wst.common.componentcore.resources.IVirtualComponent in project liferay-ide by liferay.

the class LiferayMavenProjectTests method testNewLiferayHookProject.

@Test
public void testNewLiferayHookProject() throws Exception {
    NewLiferayPluginProjectOp op = NewLiferayPluginProjectOp.TYPE.instantiate();
    op.setProjectName("hookproject");
    op.setProjectProvider("maven");
    op.setPluginType(PluginType.hook);
    createTestBundleProfile(op);
    final IProject project = base.createProject(op);
    assertNotNull(project);
    String pomContents = CoreUtil.readStreamToString(project.getFile("pom.xml").getContents());
    assertTrue(pomContents.contains("<pluginType>hook</pluginType>"));
    assertTrue(pomContents.contains("<artifactId>liferay-maven-plugin</artifactId>"));
    assertTrue(pomContents.contains("<artifactId>portal-service</artifactId>"));
    waitForJobsToComplete();
    project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
    waitForJobsToComplete();
    IVirtualComponent projectComponent = ComponentCore.createComponent(project);
    assertEquals("hookproject-hook", projectComponent.getDeployedName());
}
Also used : NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 7 with IVirtualComponent

use of org.eclipse.wst.common.componentcore.resources.IVirtualComponent in project liferay-ide by liferay.

the class ProjectUtil method fixExtProjectSrcFolderLinks.

public static void fixExtProjectSrcFolderLinks(IProject extProject) throws JavaModelException {
    if (extProject == null) {
        return;
    }
    IJavaProject javaProject = JavaCore.create(extProject);
    if (javaProject == null) {
        return;
    }
    IVirtualComponent c = ComponentCore.createComponent(extProject, false);
    if (c == null) {
        return;
    }
    IVirtualFolder jsrc = c.getRootFolder().getFolder("/WEB-INF/classes");
    if (jsrc == null) {
        return;
    }
    IClasspathEntry[] cp = javaProject.getRawClasspath();
    for (int i = 0; i < cp.length; i++) {
        IClasspathEntry cpe = cp[i];
        if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath path = cpe.getPath().removeFirstSegments(1);
            if (path.segmentCount() > 0) {
                try {
                    IFolder srcFolder = CoreUtil.getWorkspaceRoot().getFolder(cpe.getPath());
                    IVirtualResource[] virtualResource = ComponentCore.createResources(srcFolder);
                    if (virtualResource.length == 0) {
                        jsrc.createLink(cpe.getPath().removeFirstSegments(1), 0, null);
                    }
                } catch (Exception e) {
                    ProjectCore.logError(e);
                }
            }
        }
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IVirtualFolder(org.eclipse.wst.common.componentcore.resources.IVirtualFolder) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) IVirtualResource(org.eclipse.wst.common.componentcore.resources.IVirtualResource) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) IOException(java.io.IOException) IFolder(org.eclipse.core.resources.IFolder)

Example 8 with IVirtualComponent

use of org.eclipse.wst.common.componentcore.resources.IVirtualComponent 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 9 with IVirtualComponent

use of org.eclipse.wst.common.componentcore.resources.IVirtualComponent in project liferay-ide by liferay.

the class LiferayMavenProjectConfigurator method configureDeployedName.

protected void configureDeployedName(IProject project, String deployedFileName) {
    // We need to remove the file extension from deployedFileName
    int extSeparatorPos = deployedFileName.lastIndexOf('.');
    String deployedName = extSeparatorPos > -1 ? deployedFileName.substring(0, extSeparatorPos) : deployedFileName;
    // From jerr's patch in MNGECLIPSE-965
    IVirtualComponent projectComponent = ComponentCore.createComponent(project);
    if ((projectComponent != null) && !deployedName.equals(projectComponent.getDeployedName())) {
        // MNGECLIPSE-2331 :
        // Seems
        // projectComponent.getDeployedName()
        // can be null
        StructureEdit moduleCore = null;
        try {
            moduleCore = StructureEdit.getStructureEditForWrite(project);
            if (moduleCore != null) {
                WorkbenchComponent component = moduleCore.getComponent();
                if (component != null) {
                    component.setName(deployedName);
                    moduleCore.saveIfNecessary(null);
                }
            }
        } finally {
            if (moduleCore != null) {
                moduleCore.dispose();
            }
        }
    }
}
Also used : WorkbenchComponent(org.eclipse.wst.common.componentcore.internal.WorkbenchComponent) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) StructureEdit(org.eclipse.wst.common.componentcore.internal.StructureEdit)

Example 10 with IVirtualComponent

use of org.eclipse.wst.common.componentcore.resources.IVirtualComponent in project webtools.servertools by eclipse.

the class ModuleTraverser method traverse.

/**
 * Scans the module using the specified visitor.
 *
 * @param module module to traverse
 * @param visitor visitor to handle resources
 * @param monitor a progress monitor
 * @throws CoreException
 */
public static void traverse(IModule module, IModuleVisitor visitor, IProgressMonitor monitor) throws CoreException {
    if (module == null || module.getModuleType() == null)
        return;
    String typeId = module.getModuleType().getId();
    IVirtualComponent component = ComponentCore.createComponent(module.getProject());
    if (component == null) {
        // can happen if project has been closed
        Trace.trace(Trace.WARNING, "Unable to create component for module " + module.getName());
        return;
    }
    if (EAR_MODULE.equals(typeId)) {
        traverseEarComponent(component, visitor, monitor);
    } else if (WEB_MODULE.equals(typeId)) {
        traverseWebComponent(component, visitor, monitor);
    }
}
Also used : IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent)

Aggregations

IVirtualComponent (org.eclipse.wst.common.componentcore.resources.IVirtualComponent)39 IPath (org.eclipse.core.runtime.IPath)24 IVirtualFolder (org.eclipse.wst.common.componentcore.resources.IVirtualFolder)12 IVirtualReference (org.eclipse.wst.common.componentcore.resources.IVirtualReference)11 IProject (org.eclipse.core.resources.IProject)9 ArrayList (java.util.ArrayList)8 IContainer (org.eclipse.core.resources.IContainer)7 IFile (org.eclipse.core.resources.IFile)6 IFolder (org.eclipse.core.resources.IFolder)6 Path (org.eclipse.core.runtime.Path)6 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)5 CoreException (org.eclipse.core.runtime.CoreException)5 IVirtualResource (org.eclipse.wst.common.componentcore.resources.IVirtualResource)5 Test (org.junit.Test)5 JavaModelException (org.eclipse.jdt.core.JavaModelException)4 List (java.util.List)3 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 IOException (java.io.IOException)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2