Search in sources :

Example 1 with ModuleFolder

use of org.eclipse.wst.server.core.util.ModuleFolder in project webtools.servertools by eclipse.

the class PublishUtilTestCase method getTestProject.

private static IProject getTestProject() throws CoreException {
    if (testProject == null) {
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("PublishTest");
        if (!project.exists())
            project.create(null);
        if (!project.isOpen())
            project.open(null);
        // Create a project with "A" and "B" files in the root of the
        // project and in "A" and "B" folders.  Create two module resource
        // arrays, one including all resources and one omitting the "B" files.
        // Prepare an array of IPaths for the "B" files to use in testing
        // preservation.
        testResources = new IModuleResource[4];
        testResources2 = new IModuleResource[3];
        preservePaths = new IPath[3];
        IFile rootFileA = project.getFile("rootFileA.txt");
        setFileContents(rootFileA, "rootFileA contents", true);
        testResources[0] = new ModuleFile(rootFileA, "rootFileA.txt", rootFileA.getProjectRelativePath());
        testResources2[0] = testResources[0];
        IFile rootFileB = project.getFile("rootFileB.txt");
        setFileContents(rootFileB, "rootFileB contents", true);
        testResources[1] = new ModuleFile(rootFileB, "rootFileB.txt", rootFileB.getProjectRelativePath());
        preservePaths[0] = rootFileB.getProjectRelativePath();
        IFolder folderA = project.getFolder("FolderA");
        if (!folderA.exists())
            folderA.create(true, true, null);
        ModuleFolder moduleFolder = new ModuleFolder(folderA, "FolderA", folderA.getProjectRelativePath());
        IModuleResource[] folderFiles = new IModuleResource[2];
        moduleFolder.setMembers(folderFiles);
        testResources[2] = moduleFolder;
        IFile folderAFileA = folderA.getFile("folderAFileA.txt");
        setFileContents(folderAFileA, "folderAFileA contents", true);
        folderFiles[0] = new ModuleFile(folderAFileA, "folderAFileA.txt", folderAFileA.getProjectRelativePath());
        IFile folderAFileB = folderA.getFile("folderAFileB.txt");
        setFileContents(folderAFileB, "folderAFileB contents", true);
        folderFiles[1] = new ModuleFile(folderAFileB, "folderAFileB.txt", folderAFileB.getProjectRelativePath());
        preservePaths[1] = folderAFileB.getProjectRelativePath();
        moduleFolder = new ModuleFolder(folderA, "FolderA", folderA.getProjectRelativePath());
        moduleFolder.setMembers(new IModuleResource[] { folderFiles[0] });
        testResources2[1] = moduleFolder;
        IFolder folderB = project.getFolder("FolderB");
        if (!folderB.exists())
            folderB.create(true, true, null);
        moduleFolder = new ModuleFolder(folderB, "FolderB", folderB.getProjectRelativePath());
        folderFiles = new IModuleResource[2];
        moduleFolder.setMembers(folderFiles);
        testResources[3] = moduleFolder;
        IFile folderBFileA = folderB.getFile("folderBFileA.txt");
        setFileContents(folderBFileA, "folderBFileA contents", true);
        folderFiles[0] = new ModuleFile(folderBFileA, "folderBFileA.txt", folderBFileA.getProjectRelativePath());
        IFile folderBFileB = folderB.getFile("folderBFileB.txt");
        setFileContents(folderBFileB, "folderBFileB contents", true);
        folderFiles[1] = new ModuleFile(folderBFileB, "folderBFileB.txt", folderBFileB.getProjectRelativePath());
        preservePaths[2] = folderBFileB.getProjectRelativePath();
        moduleFolder = new ModuleFolder(folderB, "FolderB", folderB.getProjectRelativePath());
        moduleFolder.setMembers(new IModuleResource[] { folderFiles[0] });
        testResources2[2] = moduleFolder;
        testProject = project;
    }
    return testProject;
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IFile(org.eclipse.core.resources.IFile) ModuleFile(org.eclipse.wst.server.core.util.ModuleFile) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder) IModuleFolder(org.eclipse.wst.server.core.model.IModuleFolder) ModuleFolder(org.eclipse.wst.server.core.util.ModuleFolder)

Example 2 with ModuleFolder

use of org.eclipse.wst.server.core.util.ModuleFolder in project webtools.sourceediting by eclipse.

the class ComponentDeployable method ensureParentExists.

protected ModuleFolder ensureParentExists(IPath path, IContainer cc) {
    ModuleFolder parent = (ModuleFolder) getExistingModuleResource(members, path);
    if (parent == null) {
        String folderName = path.lastSegment();
        IPath folderPath = Path.EMPTY;
        if (path.segmentCount() > 1)
            folderPath = path.removeLastSegments(1);
        parent = new ModuleFolder(cc, folderName, folderPath);
        if (path.segmentCount() > 1)
            addMembersToModuleFolder(ensureParentExists(path.removeLastSegments(1), cc), new IModuleResource[] { parent });
        else
            members.add(parent);
    }
    return parent;
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IPath(org.eclipse.core.runtime.IPath) ModuleFolder(org.eclipse.wst.server.core.util.ModuleFolder) IModuleFolder(org.eclipse.wst.server.core.model.IModuleFolder)

Example 3 with ModuleFolder

use of org.eclipse.wst.server.core.util.ModuleFolder in project webtools.sourceediting by eclipse.

the class ComponentDeployable method getMembers.

/**
 * Find the module resources for a given container and path. Inserts in the java containers
 * at a given path if not null.
 *
 * @param cont a container
 * @param path the current module relative path
 * @param javaPath the path where Java resources fit in the root
 * @param javaCont
 * @return a possibly-empty array of module resources
 * @throws CoreException
 */
protected IModuleResource[] getMembers(IContainer cont, IPath path, IPath javaPath, IContainer[] javaCont) throws CoreException {
    IResource[] 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 IContainer) {
            IContainer cc = (IContainer) res[j];
            IPath newPath = path.append(cc.getName()).makeRelative();
            // Retrieve already existing module folder if applicable
            ModuleFolder mf = (ModuleFolder) getExistingModuleResource(members, newPath);
            if (mf == null) {
                mf = new ModuleFolder(cc, cc.getName(), path);
                ModuleFolder parent = (ModuleFolder) getExistingModuleResource(members, path);
                if (path.isEmpty())
                    members.add(mf);
                else {
                    if (parent == null)
                        parent = ensureParentExists(path, cc);
                    addMembersToModuleFolder(parent, new IModuleResource[] { mf });
                }
            }
            IModuleResource[] mr = getMembers(cc, newPath, javaPath, javaCont);
            if (javaPath != null && newPath.isPrefixOf(javaPath))
                mr = handleJavaPath(path, javaPath, newPath, javaCont, mr, cc);
            addMembersToModuleFolder(mf, mr);
        } else {
            IFile f = (IFile) res[j];
            // Handle the default package case
            if (path.equals(javaPath)) {
                ModuleFolder mFolder = (ModuleFolder) getExistingModuleResource(members, javaPath);
                IModuleFile mFile = createModuleFile(f, javaPath);
                if (mFolder != null)
                    addMembersToModuleFolder(mFolder, new IModuleResource[] { mFile });
                else
                    list.add(mFile);
            } else {
                IModuleFile mf = createModuleFile(f, path);
                list.add(mf);
            }
        }
    }
    IModuleResource[] mr = new IModuleResource[list.size()];
    list.toArray(mr);
    return mr;
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) ArrayList(java.util.ArrayList) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) ModuleFolder(org.eclipse.wst.server.core.util.ModuleFolder) IModuleFolder(org.eclipse.wst.server.core.model.IModuleFolder)

Example 4 with ModuleFolder

use of org.eclipse.wst.server.core.util.ModuleFolder 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 5 with ModuleFolder

use of org.eclipse.wst.server.core.util.ModuleFolder 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)

Aggregations

IModuleFolder (org.eclipse.wst.server.core.model.IModuleFolder)7 IModuleResource (org.eclipse.wst.server.core.model.IModuleResource)7 ModuleFolder (org.eclipse.wst.server.core.util.ModuleFolder)7 IModuleFile (org.eclipse.wst.server.core.model.IModuleFile)5 IFile (org.eclipse.core.resources.IFile)4 IPath (org.eclipse.core.runtime.IPath)4 ModuleFile (org.eclipse.wst.server.core.util.ModuleFile)4 IContainer (org.eclipse.core.resources.IContainer)3 ArrayList (java.util.ArrayList)2 Path (org.eclipse.core.runtime.Path)2 File (java.io.File)1 IOException (java.io.IOException)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IVirtualComponent (org.eclipse.wst.common.componentcore.resources.IVirtualComponent)1 IVirtualContainer (org.eclipse.wst.common.componentcore.resources.IVirtualContainer)1 IVirtualResource (org.eclipse.wst.common.componentcore.resources.IVirtualResource)1