Search in sources :

Example 21 with IModuleResource

use of org.eclipse.wst.server.core.model.IModuleResource in project sling by apache.

the class SlingContentModuleAdapterTest method projectMembersContainDotDirFoldersLast.

@Test
public void projectMembersContainDotDirFoldersLast() throws Exception {
    // create faceted project
    IProject contentProject = projectRule.getProject();
    ProjectAdapter project = new ProjectAdapter(contentProject);
    project.addNatures(JavaCore.NATURE_ID, "org.eclipse.wst.common.project.facet.core.nature");
    // install bundle facet
    project.installFacet("sling.content", "1.0");
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/testproject/_jcr_content/image/file"), new ByteArrayInputStream(new byte[0]));
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/testproject/_jcr_content/image/file.dir/.content.xml"), new ByteArrayInputStream(new byte[0]));
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/testproject/_jcr_content/image/file.dir/_jcr_content/_dam_thumbnails/_dam_thumbnail_319.png"), new ByteArrayInputStream(new byte[0]));
    IModule module = ServerUtil.getModule(contentProject);
    SlingContentModuleFactory moduleFactory = new SlingContentModuleFactory();
    ModuleDelegate moduleDelegate = moduleFactory.getModuleDelegate(module);
    IModuleResource[] members = moduleDelegate.members();
    int fileIdx = -1;
    int fileDirIdx = -1;
    for (int i = 0; i < members.length; i++) {
        String memberName = members[i].getModuleRelativePath().lastSegment();
        if (memberName == null) {
            continue;
        } else if (memberName.equals("file.dir")) {
            fileDirIdx = i;
        } else if (memberName.equals("file")) {
            fileIdx = i;
        }
    }
    Assert.assertTrue("file not sorted before file.dir ; file index = " + fileIdx + ", file.dir index = " + fileDirIdx, fileIdx < fileDirIdx);
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IModule(org.eclipse.wst.server.core.IModule) ByteArrayInputStream(java.io.ByteArrayInputStream) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) ModuleDelegate(org.eclipse.wst.server.core.model.ModuleDelegate) IProject(org.eclipse.core.resources.IProject) SlingContentModuleFactory(org.apache.sling.ide.eclipse.core.internal.SlingContentModuleFactory) Test(org.junit.Test)

Example 22 with IModuleResource

use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.sourceediting by eclipse.

the class ComponentDeployable method addUtilMember.

protected void addUtilMember(IVirtualComponent parent, IVirtualReference reference, IPath runtimePath) {
    IModuleFile mf = null;
    final String archiveName2 = reference.getArchiveName();
    final String archiveName = new Path(archiveName2).lastSegment();
    final IVirtualComponent virtualComp = reference.getReferencedComponent();
    IFile ifile = virtualComp.getAdapter(IFile.class);
    if (ifile != null) {
        // In Workspace
        String name = null != archiveName ? archiveName : ifile.getName();
        mf = new ModuleFile(ifile, name, runtimePath.makeRelative());
    } else {
        File extFile = virtualComp.getAdapter(File.class);
        String name = null != archiveName ? archiveName : extFile.getName();
        mf = new ModuleFile(extFile, name, runtimePath.makeRelative());
    }
    IModuleResource moduleParent = getExistingModuleResource(members, mf.getModuleRelativePath());
    if (moduleParent != null && moduleParent instanceof ModuleFolder) {
        addMembersToModuleFolder((ModuleFolder) moduleParent, new IModuleResource[] { mf });
    } else {
        if (mf.getModuleRelativePath().isEmpty()) {
            members.add(mf);
        } else {
            if (moduleParent == null) {
                moduleParent = ensureParentExists(mf.getModuleRelativePath(), (IContainer) parent.getRootFolder().getUnderlyingResource());
            }
            addMembersToModuleFolder((ModuleFolder) moduleParent, new IModuleResource[] { mf });
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IFile(org.eclipse.core.resources.IFile) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) ModuleFile(org.eclipse.wst.server.core.util.ModuleFile) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) IContainer(org.eclipse.core.resources.IContainer) ModuleFile(org.eclipse.wst.server.core.util.ModuleFile) IFile(org.eclipse.core.resources.IFile) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) File(java.io.File) ModuleFolder(org.eclipse.wst.server.core.util.ModuleFolder) IModuleFolder(org.eclipse.wst.server.core.model.IModuleFolder)

Example 23 with IModuleResource

use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.sourceediting by eclipse.

the class ComponentDeployable method members.

@Override
public IModuleResource[] members() throws CoreException {
    members.clear();
    IVirtualComponent vc = ComponentCore.createComponent(getProject());
    if (vc != null) {
        IVirtualFolder vFolder = vc.getRootFolder();
        IModuleResource[] mr = getMembers(vFolder, Path.EMPTY);
        int size = mr.length;
        for (int j = 0; j < size; j++) {
            members.add(mr[j]);
        }
        addUtilMembers(vc);
    }
    IModuleResource[] mr = new IModuleResource[members.size()];
    members.toArray(mr);
    return mr;
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IVirtualFolder(org.eclipse.wst.common.componentcore.resources.IVirtualFolder) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent)

Example 24 with IModuleResource

use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.sourceediting by eclipse.

the class ComponentDeployable method getMembers.

protected IModuleResource[] getMembers(IVirtualContainer cont, IPath path) throws CoreException {
    IVirtualResource[] res = cont.members();
    int size2 = res.length;
    List<IModuleFile> list = new ArrayList<IModuleFile>(size2);
    for (int j = 0; j < size2; j++) {
        if (res[j] instanceof IVirtualContainer) {
            IVirtualContainer cc = (IVirtualContainer) res[j];
            // Retrieve already existing module folder if applicable
            ModuleFolder mf = (ModuleFolder) getExistingModuleResource(members, path.append(new Path(cc.getName()).makeRelative()));
            if (mf == null) {
                mf = new ModuleFolder((IContainer) cc.getUnderlyingResource(), cc.getName(), path);
                ModuleFolder parent = (ModuleFolder) getExistingModuleResource(members, path);
                if (path.isEmpty())
                    members.add(mf);
                else {
                    if (parent == null)
                        parent = ensureParentExists(path, (IContainer) cc.getUnderlyingResource());
                    addMembersToModuleFolder(parent, new IModuleResource[] { mf });
                }
            }
            IModuleResource[] mr = getMembers(cc, path.append(cc.getName()));
            addMembersToModuleFolder(mf, mr);
        } else {
            IFile f = (IFile) res[j].getUnderlyingResource();
            IModuleFile mf = null;
            if (shouldAddComponentFile(f)) {
                mf = createModuleFile(f, path);
                list.add(mf);
            }
        }
    }
    IModuleResource[] mr = new IModuleResource[list.size()];
    list.toArray(mr);
    return mr;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IFile(org.eclipse.core.resources.IFile) IVirtualContainer(org.eclipse.wst.common.componentcore.resources.IVirtualContainer) ArrayList(java.util.ArrayList) IVirtualResource(org.eclipse.wst.common.componentcore.resources.IVirtualResource) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) IContainer(org.eclipse.core.resources.IContainer) ModuleFolder(org.eclipse.wst.server.core.util.ModuleFolder) IModuleFolder(org.eclipse.wst.server.core.model.IModuleFolder)

Example 25 with IModuleResource

use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.sourceediting by eclipse.

the class FlatComponentDeployable method LEGACY_binaryMembers.

protected IModuleResource[] LEGACY_binaryMembers() {
    IFile ifile = component.getAdapter(IFile.class);
    File file = component.getAdapter(File.class);
    ModuleFile mf = // $NON-NLS-1$
    ifile != null ? // $NON-NLS-1$
    new ModuleFile(ifile, ifile.getName(), new Path("")) : // $NON-NLS-1$
    new ModuleFile(file, file.getName(), new Path(""));
    return new IModuleResource[] { mf };
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IFile(org.eclipse.core.resources.IFile) ModuleFile(org.eclipse.wst.server.core.util.ModuleFile) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) IFlatFile(org.eclipse.wst.common.componentcore.internal.flat.IFlatFile) ModuleFile(org.eclipse.wst.server.core.util.ModuleFile) IFile(org.eclipse.core.resources.IFile) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) File(java.io.File)

Aggregations

IModuleResource (org.eclipse.wst.server.core.model.IModuleResource)45 IPath (org.eclipse.core.runtime.IPath)24 IModuleFolder (org.eclipse.wst.server.core.model.IModuleFolder)21 IFile (org.eclipse.core.resources.IFile)17 IStatus (org.eclipse.core.runtime.IStatus)17 IModule (org.eclipse.wst.server.core.IModule)12 File (java.io.File)11 IModuleFile (org.eclipse.wst.server.core.model.IModuleFile)10 ModuleFile (org.eclipse.wst.server.core.util.ModuleFile)9 IProject (org.eclipse.core.resources.IProject)8 CoreException (org.eclipse.core.runtime.CoreException)8 IModuleResourceDelta (org.eclipse.wst.server.core.model.IModuleResourceDelta)8 ArrayList (java.util.ArrayList)7 ModuleFolder (org.eclipse.wst.server.core.util.ModuleFolder)7 ModuleDelegate (org.eclipse.wst.server.core.model.ModuleDelegate)5 IContainer (org.eclipse.core.resources.IContainer)4 Path (org.eclipse.core.runtime.Path)4 Status (org.eclipse.core.runtime.Status)4 IOException (java.io.IOException)3 ProjectModule (org.eclipse.wst.server.core.util.ProjectModule)3