Search in sources :

Example 1 with ResourceCollectionInfo

use of net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo in project processdash by dtuma.

the class ResourceBridgeClient method getDiff.

private ResourceCollectionDiff getDiff() throws IOException {
    // start by initiating the HTTP connection to the server
    URLConnection conn = makeGetRequest(LIST_ACTION);
    conn.connect();
    // now, while the server is thinking, do our calculations locally.
    localCollection.validate();
    ResourceCollectionInfo localList = new ResourceListing(localCollection, ResourceFilterFactory.DEFAULT_FILTER);
    // finally, retrieve the list from the server and compare the two.
    serverVersion = conn.getHeaderField(VERSION_HEADER);
    ResourceCollectionInfo remoteList = XmlCollectionListing.parseListing(new BufferedInputStream(conn.getInputStream()));
    return new ResourceCollectionDiff(localList, remoteList);
}
Also used : ResourceCollectionInfo(net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo) ResourceListing(net.sourceforge.processdash.tool.bridge.ResourceListing) ResourceCollectionDiff(net.sourceforge.processdash.tool.bridge.report.ResourceCollectionDiff) BufferedInputStream(java.io.BufferedInputStream) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection)

Example 2 with ResourceCollectionInfo

use of net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo in project processdash by dtuma.

the class ResourceBridgeClient method uploadSingleFile.

/**
     * Save a single file to the server.
     * 
     * @param remoteUrl the url of the team server
     * @param resourceName the name of the resource to save the data as
     * @param data the data to save to the server
     * @return the checksum of the file, as written to the server
     * @throws IOException if an IO error occurs
     * @throws LockFailureException if the team server rejects the request
     *      because a lock is required.
     */
public static Long uploadSingleFile(URL remoteUrl, String resourceName, InputStream data) throws IOException, LockFailureException {
    byte[] response = doAnonymousPostRequest(remoteUrl, UPLOAD_ACTION, resourceName, data);
    ResourceCollectionInfo remoteList = XmlCollectionListing.parseListing(new ByteArrayInputStream(response));
    return remoteList.getChecksum(resourceName);
}
Also used : ResourceCollectionInfo(net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 3 with ResourceCollectionInfo

use of net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo in project processdash by dtuma.

the class BridgedWorkingDirectory method syncTimestampIsRecent.

private boolean syncTimestampIsRecent() {
    try {
        String timestamp = getMetadata(SYNC_TIMESTAMP);
        if (timestamp == null)
            return false;
        ResourceFilter filter = ResourceFilterFactory.getForRequest(Collections.singletonMap(ResourceFilterFactory.LAST_MOD_PARAM, timestamp));
        ResourceCollectionInfo changedFiles = new ResourceListing(client.localCollection, filter);
        return changedFiles.listResourceNames().isEmpty();
    } catch (Exception e) {
        return false;
    }
}
Also used : ResourceFilter(net.sourceforge.processdash.tool.bridge.ResourceFilter) ResourceCollectionInfo(net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo) ResourceListing(net.sourceforge.processdash.tool.bridge.ResourceListing) LockFailureException(net.sourceforge.processdash.util.lock.LockFailureException) LockUncertainException(net.sourceforge.processdash.util.lock.LockUncertainException) OfflineLockLostException(net.sourceforge.processdash.util.lock.OfflineLockLostException) IOException(java.io.IOException) AlreadyLockedException(net.sourceforge.processdash.util.lock.AlreadyLockedException)

Example 4 with ResourceCollectionInfo

use of net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo in project processdash by dtuma.

the class ResourceBridgeClient method downloadFiles.

private ResourceCollectionInfo downloadFiles(URLConnection conn) throws IOException {
    ResourceCollectionInfo info = null;
    InputStream response = new BufferedInputStream(conn.getInputStream());
    ZipInputStream zipIn = new ZipInputStream(response);
    ZipEntry e;
    while ((e = zipIn.getNextEntry()) != null) {
        String name = e.getName();
        long modTime = e.getTime();
        if (ResourceContentStream.MANIFEST_FILENAME.equals(name)) {
            InputStream infoIn = new ByteArrayInputStream(FileUtils.slurpContents(zipIn, false));
            info = XmlCollectionListing.parseListing(infoIn);
            continue;
        }
        OutputStream out = localCollection.getOutputStream(name, modTime);
        if (out == null)
            // a member of our collection. Discard it.
            continue;
        logger.fine("downloading resource " + name);
        FileUtils.copyFile(zipIn, out);
        out.close();
        zipIn.closeEntry();
    }
    zipIn.close();
    return info;
}
Also used : ResourceCollectionInfo(net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo) ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ZipOutputStream(java.util.zip.ZipOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) PipedOutputStream(java.io.PipedOutputStream)

Aggregations

ResourceCollectionInfo (net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo)4 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ResourceListing (net.sourceforge.processdash.tool.bridge.ResourceListing)2 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URLConnection (java.net.URLConnection)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 ResourceFilter (net.sourceforge.processdash.tool.bridge.ResourceFilter)1 ResourceCollectionDiff (net.sourceforge.processdash.tool.bridge.report.ResourceCollectionDiff)1 AlreadyLockedException (net.sourceforge.processdash.util.lock.AlreadyLockedException)1 LockFailureException (net.sourceforge.processdash.util.lock.LockFailureException)1 LockUncertainException (net.sourceforge.processdash.util.lock.LockUncertainException)1