Search in sources :

Example 1 with IVirtualComponent

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

the class IvyUtil method addIvyLibrary.

public static IvyClasspathContainer addIvyLibrary(IProject project, IProgressMonitor monitor) {
    final String projectName = project.getName();
    final IJavaProject javaProject = JavaCore.create(project);
    final IvyClasspathContainerConfiguration conf = new IvyClasspathContainerConfiguration(javaProject, ISDKConstants.IVY_XML_FILE, true);
    final ClasspathSetup classpathSetup = new ClasspathSetup();
    conf.setAdvancedProjectSpecific(false);
    conf.setClasspathSetup(classpathSetup);
    conf.setClassthProjectSpecific(false);
    conf.setConfs(Collections.singletonList("*"));
    conf.setMappingProjectSpecific(false);
    conf.setSettingsProjectSpecific(true);
    SDK sdk = SDKUtil.getSDK(project);
    final SettingsSetup settingsSetup = new SettingsSetup();
    IPath ivyFilePath = sdk.getLocation().append(ISDKConstants.IVY_SETTINGS_XML_FILE);
    if (ivyFilePath.toFile().exists()) {
        StringBuilder builder = new StringBuilder();
        builder.append("${");
        builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR);
        builder.append(":");
        builder.append(projectName);
        builder.append("}/");
        builder.append(ISDKConstants.IVY_SETTINGS_XML_FILE);
        settingsSetup.setIvySettingsPath(builder.toString());
    }
    StringBuilder builder = new StringBuilder();
    builder.append("${");
    builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR);
    builder.append(":");
    builder.append(projectName);
    builder.append("}/.ivy");
    settingsSetup.setIvyUserDir(builder.toString());
    conf.setIvySettingsSetup(settingsSetup);
    final IPath path = conf.getPath();
    final IClasspathAttribute[] atts = conf.getAttributes();
    final IClasspathEntry ivyEntry = JavaCore.newContainerEntry(path, null, atts, false);
    final IVirtualComponent virtualComponent = ComponentCore.createComponent(project);
    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        List<IClasspathEntry> newEntries = new ArrayList<>(Arrays.asList(entries));
        IPath runtimePath = getDefaultRuntimePath(virtualComponent, ivyEntry);
        // add the deployment assembly config to deploy ivy container to /WEB-INF/lib
        final IClasspathEntry cpeTagged = modifyDependencyPath(ivyEntry, runtimePath);
        newEntries.add(cpeTagged);
        entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]);
        javaProject.setRawClasspath(entries, javaProject.getOutputLocation(), monitor);
        IvyClasspathContainer ivycp = IvyClasspathContainerHelper.getContainer(path, javaProject);
        return ivycp;
    } catch (JavaModelException jme) {
        ProjectUI.logError("Unable to add Ivy library container", jme);
    }
    return null;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) ClasspathSetup(org.apache.ivyde.eclipse.cp.ClasspathSetup) IvyClasspathContainer(org.apache.ivyde.eclipse.cp.IvyClasspathContainer) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IJavaProject(org.eclipse.jdt.core.IJavaProject) SettingsSetup(org.apache.ivyde.eclipse.cp.SettingsSetup) IvyClasspathContainerConfiguration(org.apache.ivyde.eclipse.cp.IvyClasspathContainerConfiguration) SDK(com.liferay.ide.sdk.core.SDK) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent)

Example 2 with IVirtualComponent

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

the class PluginFacetInstall method configureDeploymentAssembly.

protected void configureDeploymentAssembly(String srcPath, String deployPath) {
    IVirtualComponent vProject = ComponentCore.createComponent(project);
    IVirtualFolder vProjectFolder = vProject.getRootFolder();
    IVirtualFolder deployFolder = vProjectFolder.getFolder(new Path(deployPath));
    try {
        deployFolder.createLink(new Path(srcPath), IResource.FORCE, null);
    } catch (CoreException ce) {
        ProjectCore.logError("Unable to create link", ce);
    }
    try {
        IPath outputLocation = JavaCore.create(project).getOutputLocation();
        vProject.setMetaProperty(IModuleConstants.PROJ_REL_JAVA_OUTPUT_PATH, outputLocation.toPortableString());
    } catch (JavaModelException jme) {
        ProjectCore.logError("Unable to set java-ouput-path", jme);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) IPath(org.eclipse.core.runtime.IPath) IVirtualFolder(org.eclipse.wst.common.componentcore.resources.IVirtualFolder) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent)

Example 3 with IVirtualComponent

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

the class ComponentUtil method getSources.

private static IPackageFragmentRoot[] getSources(IProject project) {
    IJavaProject jProject = JavaCore.create(project);
    if (jProject == null) {
        return new IPackageFragmentRoot[0];
    }
    List<IPackageFragmentRoot> list = new ArrayList<IPackageFragmentRoot>();
    IVirtualComponent vc = ComponentCore.createComponent(project);
    IPackageFragmentRoot[] roots;
    try {
        roots = jProject.getPackageFragmentRoots();
        for (int i = 0; i < roots.length; i++) {
            if (roots[i].getKind() != IPackageFragmentRoot.K_SOURCE) {
                continue;
            }
            IResource resource = roots[i].getResource();
            if (null != resource) {
                IVirtualResource[] vResources = ComponentCore.createResources(resource);
                boolean found = false;
                for (int j = 0; !found && j < vResources.length; j++) {
                    if (vResources[j].getComponent().equals(vc)) {
                        if (!list.contains(roots[i])) {
                            list.add(roots[i]);
                        }
                        found = true;
                    }
                }
            }
        }
        if (list.size() == 0) {
            for (IPackageFragmentRoot root : roots) {
                if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
                    if (!list.contains(root)) {
                        list.add(root);
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        LiferayServerCore.logError(e);
    }
    return list.toArray(new IPackageFragmentRoot[list.size()]);
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) ArrayList(java.util.ArrayList) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) IVirtualResource(org.eclipse.wst.common.componentcore.resources.IVirtualResource) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 4 with IVirtualComponent

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

the class LiferayMavenProjectTests method testNewLiferayPortletProject.

@Test
public void testNewLiferayPortletProject() throws Exception {
    if (shouldSkipBundleTests())
        return;
    NewLiferayPluginProjectOp op = NewLiferayPluginProjectOp.TYPE.instantiate();
    op.setProjectName("mvc");
    op.setProjectProvider("maven");
    op.setPortletFramework("mvc");
    createTestBundleProfile(op);
    final IProject project = base.createProject(op);
    assertNotNull(project);
    String pomContents = CoreUtil.readStreamToString(project.getFile("pom.xml").getContents());
    assertTrue(pomContents.contains("<liferay.version>"));
    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("mvc-portlet", 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 5 with IVirtualComponent

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

the class LiferayMavenProjectTests method testNewLiferayLayouttplProject.

@Test
public void testNewLiferayLayouttplProject() throws Exception {
    NewLiferayPluginProjectOp op = NewLiferayPluginProjectOp.TYPE.instantiate();
    op.setProjectName("template");
    op.setProjectProvider("maven");
    op.setPluginType(PluginType.layouttpl);
    createTestBundleProfile(op);
    final IProject project = base.createProject(op);
    assertNotNull(project);
    String pomContents = CoreUtil.readStreamToString(project.getFile("pom.xml").getContents());
    assertTrue(pomContents.contains("<pluginType>layouttpl</pluginType>"));
    assertTrue(pomContents.contains("<artifactId>liferay-maven-plugin</artifactId>"));
    waitForJobsToComplete();
    project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
    waitForJobsToComplete();
    IVirtualComponent projectComponent = ComponentCore.createComponent(project);
    assertEquals("template-layouttpl", 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)

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