Search in sources :

Example 1 with ListingResult

use of org.commonjava.maven.galley.model.ListingResult in project indy by Commonjava.

the class DefaultDownloadManager method list.

@Override
public List<StoreResource> list(final List<? extends ArtifactStore> stores, final String path) throws IndyWorkflowException {
    final String dir = PathUtils.dirname(path);
    final List<StoreResource> result = new ArrayList<>();
    try {
        final List<ListingResult> results = transfers.listAll(locationExpander.expand(new VirtualResource(LocationUtils.toLocations(stores), path)));
        for (final ListingResult lr : results) {
            if (lr != null && lr.getListing() != null) {
                for (final String file : lr.getListing()) {
                    result.add(new StoreResource((KeyedLocation) lr.getLocation(), dir, file));
                }
            }
        }
    } catch (final BadGatewayException e) {
        Location location = e.getLocation();
        KeyedLocation kl = (KeyedLocation) location;
        fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
        logger.warn("Bad gateway: " + e.getMessage(), e);
    } catch (final TransferTimeoutException e) {
        Location location = e.getLocation();
        KeyedLocation kl = (KeyedLocation) location;
        fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
        logger.warn("Timeout: " + e.getMessage(), e);
    } catch (final TransferLocationException e) {
        Location location = e.getLocation();
        KeyedLocation kl = (KeyedLocation) location;
        fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
        logger.warn("Location Error: " + e.getMessage(), e);
    } catch (final TransferException e) {
        logger.error(e.getMessage(), e);
        throw new IndyWorkflowException("Failed to list ALL paths: {} from: {}. Reason: {}", e, path, stores, e.getMessage());
    }
    return dedupeListing(result);
}
Also used : TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ArrayList(java.util.ArrayList) ListingResult(org.commonjava.maven.galley.model.ListingResult) StoreResource(org.commonjava.indy.content.StoreResource) TransferException(org.commonjava.maven.galley.TransferException) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) VirtualResource(org.commonjava.maven.galley.model.VirtualResource) BadGatewayException(org.commonjava.maven.galley.BadGatewayException) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) IndyStoreErrorEvent(org.commonjava.indy.change.event.IndyStoreErrorEvent) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location)

Example 2 with ListingResult

use of org.commonjava.maven.galley.model.ListingResult in project galley by Commonjava.

the class HttpListTest method simpleCentralListing_Missing.

@Test
public void simpleCentralListing_Missing() throws Exception {
    final String dir = "central-missing/";
    final String fname = dir + "index.html";
    final String listingFname = dir + ".listing.txt";
    final String url = fixture.formatUrl(fname);
    final SimpleHttpLocation location = new SimpleHttpLocation("test", url, true, true, true, true, null);
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, listingFname));
    final HttpListing listing = new HttpListing(url, new ConcreteResource(location, fname), fixture.getHttp());
    final ListingResult result = listing.call();
    assertThat(result, nullValue());
    assertThat(listing.getError(), nullValue());
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ListingResult(org.commonjava.maven.galley.model.ListingResult) Test(org.junit.Test)

Example 3 with ListingResult

use of org.commonjava.maven.galley.model.ListingResult in project galley by Commonjava.

the class HttpListTest method simpleNexusListing.

@Test
public void simpleNexusListing() throws Exception {
    final String dir = "nexus-switchyard/";
    final String fname = dir + "index.html";
    final String listingFname = dir + ".listing.txt";
    final String url = fixture.formatUrl(fname);
    final String body = getBody(fname);
    fixture.getServer().expect(url, 200, body);
    final SimpleHttpLocation location = new SimpleHttpLocation("test", url, true, true, true, true, null);
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, listingFname));
    final HttpListing listing = new HttpListing(url, new ConcreteResource(location, fname), fixture.getHttp());
    final ListingResult result = listing.call();
    assertThat(listing.getError(), nullValue());
    assertThat(result, notNullValue());
    assertThat(result.getListing(), notNullValue());
    assertTrue(Arrays.equals(nexusswitchyard, result.getListing()));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ListingResult(org.commonjava.maven.galley.model.ListingResult) Test(org.junit.Test)

Example 4 with ListingResult

use of org.commonjava.maven.galley.model.ListingResult in project galley by Commonjava.

the class HttpListTest method simpleCentralListing_WriteListingFile.

@Test
public void simpleCentralListing_WriteListingFile() throws Exception {
    final String dir = "central-btm/";
    final String fname = dir + "index.html";
    final String listingFname = dir + ".listing.txt";
    final String url = fixture.formatUrl(fname);
    final String body = getBody(fname);
    fixture.getServer().expect(url, 200, body);
    final SimpleHttpLocation location = new SimpleHttpLocation("test", url, true, true, true, true, null);
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, listingFname));
    final HttpListing listing = new HttpListing(url, new ConcreteResource(location, fname), fixture.getHttp());
    final ListingResult result = listing.call();
    assertThat(listing.getError(), nullValue());
    assertThat(result, notNullValue());
    assertThat(result.getListing(), notNullValue());
    assertTrue(Arrays.equals(centralbtm, result.getListing()));
    final List<String> lines = IOUtils.readLines(transfer.openInputStream());
    assertTrue("Listing file written incorrectly!", lines.equals(Arrays.asList(centralbtm)));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ListingResult(org.commonjava.maven.galley.model.ListingResult) Test(org.junit.Test)

Example 5 with ListingResult

use of org.commonjava.maven.galley.model.ListingResult in project galley by Commonjava.

the class ZipListing method call.

@Override
public ListingResult call() {
    final File src = getZipFile();
    if (src.isDirectory()) {
        return null;
    }
    final boolean isJar = isJarOperation();
    final TreeSet<String> filenames = new TreeSet<String>();
    ZipFile zf = null;
    try {
        if (isJar) {
            zf = new JarFile(src);
        } else {
            zf = new ZipFile(src);
        }
        final String path = getFullPath();
        final int pathLen = path.length();
        for (final ZipEntry entry : Collections.list(zf.entries())) {
            String name = entry.getName();
            if (name.startsWith(path)) {
                name = name.substring(pathLen);
                if (name.startsWith("/") && name.length() > 1) {
                    name = name.substring(1);
                    if (name.indexOf("/") < 0) {
                        filenames.add(name);
                    }
                }
            }
        }
    } catch (final IOException e) {
        error = new TransferException("Failed to get listing for: %s to: %s. Reason: %s", e, resource, e.getMessage());
    } finally {
        if (zf != null) {
            // noinspection EmptyCatchBlock
            try {
                zf.close();
            } catch (final IOException e) {
            }
        }
    }
    if (!filenames.isEmpty()) {
        return new ListingResult(resource, filenames.toArray(new String[filenames.size()]));
    }
    return null;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) ZipFile(java.util.zip.ZipFile) TreeSet(java.util.TreeSet) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) ListingResult(org.commonjava.maven.galley.model.ListingResult) JarFile(java.util.jar.JarFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

ListingResult (org.commonjava.maven.galley.model.ListingResult)21 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)12 TransferException (org.commonjava.maven.galley.TransferException)11 ArrayList (java.util.ArrayList)9 Transfer (org.commonjava.maven.galley.model.Transfer)8 StoreResource (org.commonjava.indy.content.StoreResource)7 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)7 SimpleHttpLocation (org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation)7 Test (org.junit.Test)7 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)5 VirtualResource (org.commonjava.maven.galley.model.VirtualResource)5 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)4 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)4 IOException (java.io.IOException)3 TransferTimeoutException (org.commonjava.maven.galley.TransferTimeoutException)3 Logger (org.slf4j.Logger)3 InputStream (java.io.InputStream)2 IndyStoreErrorEvent (org.commonjava.indy.change.event.IndyStoreErrorEvent)2 BadGatewayException (org.commonjava.maven.galley.BadGatewayException)2 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)2