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);
}
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());
}
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()));
}
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)));
}
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;
}
Aggregations