Search in sources :

Example 1 with ModuleFile

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

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

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

Example 4 with ModuleFile

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

the class ModulePublishInfo method loadResource.

/**
 * Used only for reading from WTP 1.x workspaces.
 */
protected IModuleResource[] loadResource(IMemento memento, IPath path) {
    if (memento == null)
        return EMPTY_MODULE_RESOURCE;
    List<IModuleResource> list = new ArrayList<IModuleResource>(10);
    // load files
    IMemento[] children = memento.getChildren(FILE);
    if (children != null) {
        int size = children.length;
        for (int i = 0; i < size; i++) {
            String name2 = children[i].getString(NAME);
            long stamp = Long.parseLong(children[i].getString(STAMP));
            ModuleFile file = new ModuleFile(name2, path, stamp);
            list.add(file);
        }
    }
    // load folders
    children = memento.getChildren(FOLDER);
    if (children != null) {
        int size = children.length;
        for (int i = 0; i < size; i++) {
            String name2 = children[i].getString(NAME);
            ModuleFolder folder = new ModuleFolder(null, name2, path);
            folder.setMembers(loadResource(children[i], path.append(name2)));
            list.add(folder);
        }
    }
    IModuleResource[] resources2 = new IModuleResource[list.size()];
    list.toArray(resources2);
    return resources2;
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) ModuleFile(org.eclipse.wst.server.core.util.ModuleFile) IModuleFolder(org.eclipse.wst.server.core.model.IModuleFolder) ModuleFolder(org.eclipse.wst.server.core.util.ModuleFolder)

Example 5 with ModuleFile

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

the class ModulePublishInfo method loadResource.

private IModuleResource[] loadResource(DataInput in, IPath path) throws IOException {
    int size = in.readInt();
    if (size > 1000000)
        throw new IOException("Folder capacity limit reached");
    IModuleResource[] resources2 = new IModuleResource[size];
    for (int i = 0; i < size; i++) {
        byte b = in.readByte();
        if (b == 0) {
            String name2 = in.readUTF();
            long stamp = in.readLong();
            resources2[i] = new ModuleFile(name2, path, stamp);
        } else if (b == 1) {
            String name2 = in.readUTF();
            ModuleFolder folder = new ModuleFolder(null, name2, path);
            folder.setMembers(loadResource(in, path.append(name2)));
            resources2[i] = folder;
        }
    }
    return resources2;
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) ModuleFile(org.eclipse.wst.server.core.util.ModuleFile) IOException(java.io.IOException) IModuleFolder(org.eclipse.wst.server.core.model.IModuleFolder) ModuleFolder(org.eclipse.wst.server.core.util.ModuleFolder)

Aggregations

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