Search in sources :

Example 6 with IModuleFile

use of org.eclipse.wst.server.core.model.IModuleFile in project webtools.servertools by eclipse.

the class PublishHelper method copy.

private IStatus[] copy(IModuleResource resource, IPath path, IProgressMonitor monitor) {
    if (monitor.isCanceled()) {
        return new IStatus[0];
    }
    String name = resource.getName();
    if (Trace.PUBLISHING) {
        Trace.trace(Trace.STRING_PUBLISHING, "Copying: " + name + " to " + path.toString());
    }
    List<IStatus> status = new ArrayList<IStatus>(2);
    if (resource instanceof IModuleFolder) {
        IModuleFolder folder = (IModuleFolder) resource;
        IStatus[] stat = publishFull(folder.members(), path, monitor);
        addArrayToList(status, stat);
    } else {
        IModuleFile mf = (IModuleFile) resource;
        path = path.append(mf.getModuleRelativePath()).append(name);
        File f = path.toFile().getParentFile();
        if (f.exists()) {
            try {
                copyFile(mf, path);
            } catch (CoreException ce) {
                status.add(ce.getStatus());
            }
        } else {
            // Create the parent directory.
            if (f.mkdirs()) {
                try {
                    copyFile(mf, path);
                } catch (CoreException ce) {
                    status.add(ce.getStatus());
                }
            } else {
                if (Trace.PUBLISHING) {
                    Trace.trace(Trace.STRING_PUBLISHING, "Failed to create the directory: " + f.getAbsolutePath());
                }
                status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorMkdir, f.getAbsolutePath()), null));
            }
        }
    }
    IStatus[] stat = new IStatus[status.size()];
    status.toArray(stat);
    return stat;
}
Also used : IModuleFolder(org.eclipse.wst.server.core.model.IModuleFolder) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) ArrayList(java.util.ArrayList) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) IFile(org.eclipse.core.resources.IFile)

Example 7 with IModuleFile

use of org.eclipse.wst.server.core.model.IModuleFile in project webtools.servertools by eclipse.

the class PublishHelper method copyFile.

private void copyFile(IModuleFile mf, IPath path) throws CoreException {
    if (Trace.PUBLISHING) {
        Trace.trace(Trace.STRING_PUBLISHING, "Copying: " + mf.getName() + " to " + path.toString());
    }
    if (!isCopyFile(mf, path)) {
        return;
    }
    IFile file = (IFile) mf.getAdapter(IFile.class);
    if (file != null)
        copyFile(file.getContents(), path, file.getLocalTimeStamp(), mf);
    else {
        File file2 = (File) mf.getAdapter(File.class);
        InputStream in = null;
        try {
            in = new FileInputStream(file2);
        } catch (IOException e) {
            throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorReading, file2.getAbsolutePath()), e));
        }
        copyFile(in, path, file2.lastModified(), mf);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) IFile(org.eclipse.core.resources.IFile)

Example 8 with IModuleFile

use of org.eclipse.wst.server.core.model.IModuleFile in project webtools.servertools by eclipse.

the class PublishHelper method publishDelta.

/**
 * Handle a delta publish.
 *
 * @param delta a module resource delta
 * @param path the path to publish to
 * @param monitor a progress monitor, or <code>null</code> if progress
 *    reporting and cancellation are not desired
 * @return a possibly-empty array of error and warning status
 */
public IStatus[] publishDelta(IModuleResourceDelta delta, IPath path, IProgressMonitor monitor) {
    List<IStatus> status = new ArrayList<IStatus>(2);
    IModuleResource resource = delta.getModuleResource();
    int kind2 = delta.getKind();
    if (resource instanceof IModuleFile) {
        IModuleFile file = (IModuleFile) resource;
        try {
            if (kind2 == IModuleResourceDelta.REMOVED)
                deleteFile(path, file);
            else {
                IPath path2 = path.append(file.getModuleRelativePath()).append(file.getName());
                File f = path2.toFile().getParentFile();
                if (!f.exists())
                    f.mkdirs();
                copyFile(file, path2);
            }
        } catch (CoreException ce) {
            status.add(ce.getStatus());
        }
        IStatus[] stat = new IStatus[status.size()];
        status.toArray(stat);
        return stat;
    }
    if (kind2 == IModuleResourceDelta.ADDED) {
        IPath path2 = path.append(resource.getModuleRelativePath()).append(resource.getName());
        File file = path2.toFile();
        if (!file.exists() && !file.mkdirs()) {
            status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorMkdir, path2), null));
            IStatus[] stat = new IStatus[status.size()];
            status.toArray(stat);
            return stat;
        }
    }
    IModuleResourceDelta[] childDeltas = delta.getAffectedChildren();
    int size = childDeltas.length;
    for (int i = 0; i < size; i++) {
        IStatus[] stat = publishDelta(childDeltas[i], path, monitor);
        addArrayToList(status, stat);
    }
    if (kind2 == IModuleResourceDelta.REMOVED) {
        IPath path2 = path.append(resource.getModuleRelativePath()).append(resource.getName());
        File file = path2.toFile();
        if (file.exists() && !file.delete()) {
            status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, path2), null));
        }
    }
    IStatus[] stat = new IStatus[status.size()];
    status.toArray(stat);
    return stat;
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) ArrayList(java.util.ArrayList) IModuleResourceDelta(org.eclipse.wst.server.core.model.IModuleResourceDelta) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) IFile(org.eclipse.core.resources.IFile)

Example 9 with IModuleFile

use of org.eclipse.wst.server.core.model.IModuleFile in project webtools.servertools by eclipse.

the class PublishHelper method addZipEntries.

private static void addZipEntries(ZipOutputStream zout, IModuleResource[] resources) throws Exception {
    if (resources == null)
        return;
    int size = resources.length;
    for (int i = 0; i < size; i++) {
        if (resources[i] instanceof IModuleFolder) {
            IModuleFolder mf = (IModuleFolder) resources[i];
            IModuleResource[] res = mf.members();
            IPath path = mf.getModuleRelativePath().append(mf.getName());
            String entryPath = path.toPortableString();
            if (!entryPath.endsWith("/"))
                entryPath += '/';
            ZipEntry ze = new ZipEntry(entryPath);
            long ts = 0;
            IContainer folder = (IContainer) mf.getAdapter(IContainer.class);
            if (folder != null)
                ts = folder.getLocalTimeStamp();
            if (ts != IResource.NULL_STAMP && ts != 0)
                ze.setTime(ts);
            zout.putNextEntry(ze);
            zout.closeEntry();
            addZipEntries(zout, res);
            continue;
        }
        IModuleFile mf = (IModuleFile) resources[i];
        IPath path = mf.getModuleRelativePath().append(mf.getName());
        ZipEntry ze = new ZipEntry(path.toPortableString());
        InputStream in = null;
        long ts = 0;
        IFile file = (IFile) mf.getAdapter(IFile.class);
        if (file != null) {
            ts = file.getLocalTimeStamp();
            in = file.getContents();
        } else {
            File file2 = (File) mf.getAdapter(File.class);
            ts = file2.lastModified();
            in = new FileInputStream(file2);
        }
        if (ts != IResource.NULL_STAMP && ts != 0)
            ze.setTime(ts);
        zout.putNextEntry(ze);
        try {
            int n = 0;
            while (n > -1) {
                n = in.read(buf);
                if (n > 0)
                    zout.write(buf, 0, n);
            }
        } finally {
            in.close();
        }
        zout.closeEntry();
    }
}
Also used : IModuleFolder(org.eclipse.wst.server.core.model.IModuleFolder) IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IFile(org.eclipse.core.resources.IFile) ZipEntry(java.util.zip.ZipEntry) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) IContainer(org.eclipse.core.resources.IContainer) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) IFile(org.eclipse.core.resources.IFile)

Example 10 with IModuleFile

use of org.eclipse.wst.server.core.model.IModuleFile in project webtools.servertools by eclipse.

the class ModulePublishInfo method saveResource.

protected void saveResource(DataOutput out, IModuleResource[] resources2) throws IOException {
    if (resources2 == null)
        return;
    int size = resources2.length;
    out.writeInt(size);
    for (int i = 0; i < size; i++) {
        if (resources2[i] instanceof IModuleFile) {
            IModuleFile file = (IModuleFile) resources2[i];
            out.writeByte(0);
            out.writeUTF(file.getName());
            out.writeLong(file.getModificationStamp());
        } else {
            IModuleFolder folder = (IModuleFolder) resources2[i];
            out.writeByte(1);
            out.writeUTF(folder.getName());
            IModuleResource[] resources3 = folder.members();
            saveResource(out, resources3);
        }
    }
}
Also used : IModuleFolder(org.eclipse.wst.server.core.model.IModuleFolder) IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile)

Aggregations

IModuleFile (org.eclipse.wst.server.core.model.IModuleFile)10 IFile (org.eclipse.core.resources.IFile)9 IModuleFolder (org.eclipse.wst.server.core.model.IModuleFolder)7 IModuleResource (org.eclipse.wst.server.core.model.IModuleResource)7 ArrayList (java.util.ArrayList)5 IContainer (org.eclipse.core.resources.IContainer)4 IPath (org.eclipse.core.runtime.IPath)3 ModuleFolder (org.eclipse.wst.server.core.util.ModuleFolder)3 Path (org.eclipse.core.runtime.Path)2 File (java.io.File)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)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 IModuleResourceDelta (org.eclipse.wst.server.core.model.IModuleResourceDelta)1 ModuleFile (org.eclipse.wst.server.core.util.ModuleFile)1