use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.
the class IndyPathGeneratorTest method testGetHashedPathUnification.
@Test
public void testGetHashedPathUnification() {
ConcreteResource resource = new StoreResource(location, "abc/xyz/license.html");
String pathWithoutSlash = pathGenerator.getPath(resource);
resource = new StoreResource(location, "/abc/xyz/license.html");
String pathWithSlash = pathGenerator.getPath(resource);
assertThat(pathWithoutSlash, is(pathWithSlash));
resource = new StoreResource(location, "//abc/xyz/license.html");
String pathWithDoubleSlash = pathGenerator.getPath(resource);
assertThat(pathWithoutSlash, is(pathWithDoubleSlash));
}
use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.
the class IndyPathGeneratorTest method testGetHashedRootBasedPathUnification.
@Test
public void testGetHashedRootBasedPathUnification() {
ConcreteResource resource = new StoreResource(location, "license.html");
String pathWithoutSlash = pathGenerator.getPath(resource);
resource = new StoreResource(location, "/license.html");
String pathWithSlash = pathGenerator.getPath(resource);
assertThat(pathWithoutSlash, is(pathWithSlash));
resource = new StoreResource(location, "//license.html");
String pathWithDoubleSlash = pathGenerator.getPath(resource);
assertThat(pathWithoutSlash, is(pathWithDoubleSlash));
}
use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.
the class HtmlContentListBuilder method buildContent.
@Override
public List<ConcreteResource> buildContent(final RemoteRepository repository, final boolean isRescan) {
if (repository.getPrefetchPriority() <= 0) {
logger.warn("The repository {} prefetch disabled, can not use html content listing", repository.getName());
return Collections.emptyList();
}
final Set<String> pathMasks = repository.getPathMaskPatterns();
boolean useDefault = true;
if (pathMasks != null && !pathMasks.isEmpty()) {
useDefault = pathMasks.stream().anyMatch(p -> PathMaskChecker.isRegexPattern(p));
}
if (useDefault) {
final String rootPath = "/";
final KeyedLocation loc = LocationUtils.toLocation(repository);
final StoreResource res = new StoreResource(loc, rootPath);
try {
// If this is a rescan prefetch, we need to clear the listing cache and re-fetch from external
if (isRescan) {
transferManager.delete(new StoreResource(loc, "/.listing.txt"));
}
final ListingResult lr = transferManager.list(res);
if (lr != null && lr.getListing() != null) {
String[] files = lr.getListing();
List<ConcreteResource> resources = new ArrayList<>(files.length);
for (final String file : lr.getListing()) {
resources.add(new StoreResource(loc, rootPath, file));
}
return resources;
}
} catch (TransferException e) {
logger.error(String.format("Can not get transfer for repository %s", repository), e);
}
} else {
// if all path mask patterns are plaintext, we will use these as the download list directly.
return pathMasks.stream().map(p -> new StoreResource(LocationUtils.toLocation(repository), p)).collect(Collectors.toList());
}
return Collections.emptyList();
}
use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.
the class PrefetchWorker method run.
@Override
public void run() {
if (resources == null || resources.isEmpty()) {
logger.trace("No resources for downloading");
return;
}
logger.trace("Start downloading: {}", resources);
final AtomicBoolean scheduled = new AtomicBoolean(false);
for (Map.Entry<RemoteRepository, List<RescanableResourceWrapper>> entry : resources.entrySet()) {
final RemoteRepository repo = entry.getKey();
final List<RescanableResourceWrapper> res = entry.getValue();
res.forEach(r -> {
try {
final String path = r.getResource().getPath();
if (path == null || path.equals("") || path.endsWith("/") || path.endsWith(LISTING_HTML_FILE)) {
// If this is a rescan prefetch, we need to clear the listing cache and re-fetch from external
if (r.isRescan()) {
transfers.delete(new ConcreteResource(r.getResource().getLocation(), path, ".listing.txt"));
}
final List<RescanablePath> dirPaths = buildPaths(r.getResource(), r.isRescan());
logger.trace("{} is folder, will use it to schedule new Resources {}", r, dirPaths);
frontier.scheduleRepo(repo, dirPaths);
scheduled.set(true);
} else {
// if repo has path masks, we need to check that first to only download path mask enabled artifacts.
if (PathMaskChecker.checkMask(repo, path)) {
// If this is a rescan prefetch, and artifact is metadata, we need to clear it and re-fetch from external
if (r.isRescan()) {
final SpecialPathInfo spi = specialPathManager.getSpecialPathInfo(r.getResource());
if (spi != null && spi.isMetadata()) {
transfers.delete(r.getResource());
}
}
logger.trace("{} is file", r);
transfers.retrieve(r.getResource());
} else {
logger.trace("Path {} in repo {} not available for path mask {}", path, repo, repo.getPathMaskPatterns());
}
}
} catch (TransferException e) {
logger.error("Download failed during prefetch because of transfer getting failed for {}, Reason: {}", r, e.getMessage());
}
});
}
if (scheduled.get()) {
prefetchManager.triggerWorkers();
}
}
use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.
the class PrefetchFrontier method get.
public Map<RemoteRepository, List<ConcreteResource>> get(final int size) {
return lockAnd(t -> {
Map<RemoteRepository, List<ConcreteResource>> resources = new HashMap<>(2);
int removedSize = 0;
for (RemoteRepository repo : repoQueue) {
List<RescanablePath> paths = resourceCache.get(repo);
if (paths != null && !paths.isEmpty()) {
List<ConcreteResource> res = new ArrayList<>(size);
for (RescanablePath path : paths) {
res.add(new StoreResource(LocationUtils.toLocation(repo), path.getPath()));
}
resources.put(repo, res);
if (removedSize >= size) {
return resources;
}
}
}
return resources;
});
}
Aggregations