use of org.commonjava.indy.content.StoreResource in project indy by Commonjava.
the class MavenMetadataGenerator method generateDirectoryContent.
@Override
public List<StoreResource> generateDirectoryContent(final ArtifactStore store, final String path, final List<StoreResource> existing, final EventMetadata eventMetadata) throws IndyWorkflowException {
final StoreResource mdResource = new StoreResource(LocationUtils.toLocation(store), Paths.get(path, MavenMetadataMerger.METADATA_NAME).toString());
if (existing.contains(mdResource)) {
return null;
}
int pathElementsCount = StringUtils.strip(path, "/").split("/").length;
// if there is a possibility we are listing an artifactId
if (pathElementsCount >= 2) {
// regardless, we will need this first level of listings. What we do with it will depend on the logic below...
final List<StoreResource> firstLevelFiles = fileManager.listRaw(store, path, eventMetadata);
ArtifactPathInfo samplePomInfo = null;
for (final StoreResource topResource : firstLevelFiles) {
final String topPath = topResource.getPath();
if (topPath.endsWith(".pom")) {
samplePomInfo = ArtifactPathInfo.parse(topPath);
break;
}
}
// if this dir does not contain a pom check if a subdir contain a pom
if (samplePomInfo == null) {
List<String> firstLevelDirs = firstLevelFiles.stream().map(ConcreteResource::getPath).filter((subpath) -> subpath.endsWith("/")).collect(Collectors.toList());
final Map<String, List<StoreResource>> secondLevelMap = fileManager.listRaw(store, firstLevelDirs, eventMetadata);
nextTopResource: for (final String topPath : firstLevelDirs) {
final List<StoreResource> secondLevelListing = secondLevelMap.get(topPath);
for (final StoreResource fileResource : secondLevelListing) {
if (fileResource.getPath().endsWith(".pom")) {
samplePomInfo = ArtifactPathInfo.parse(fileResource.getPath());
break nextTopResource;
}
}
}
}
// We won't worry about this for now.
if (samplePomInfo != null) {
final List<StoreResource> result = new ArrayList<>();
result.add(mdResource);
result.add(new StoreResource(LocationUtils.toLocation(store), Paths.get(path, MavenMetadataMerger.METADATA_MD5_NAME).toString()));
result.add(new StoreResource(LocationUtils.toLocation(store), Paths.get(path, MavenMetadataMerger.METADATA_SHA_NAME).toString()));
return result;
}
}
return null;
}
use of org.commonjava.indy.content.StoreResource in project indy by Commonjava.
the class MavenMetadataGenerator method generateFileContent.
@Override
@Measure
public Transfer generateFileContent(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
// metadata merging is something else...don't handle it here.
if (StoreType.group == store.getKey().getType()) {
return null;
}
if (!canProcess(path)) {
return null;
}
boolean generated;
// TODO: Generation of plugin metadata files (groupId-level) is harder, and requires cracking open the jar file
// This is because that's the only place the plugin prefix can be reliably retrieved from.
// regardless, we will need this first level of listings. What we do with it will depend on the logic below...
final String parentPath = Paths.get(path).getParent().toString();
List<StoreResource> firstLevel;
try {
firstLevel = fileManager.listRaw(store, parentPath);
} catch (final IndyWorkflowException e) {
logger.error(String.format("SKIP: Failed to generate maven-metadata.xml from listing of directory contents for: %s under path: %s", store, parentPath), e);
return null;
}
String toGenPath = path;
if (!path.endsWith(MavenMetadataMerger.METADATA_NAME)) {
toGenPath = normalize(normalize(parentPath(toGenPath)), MavenMetadataMerger.METADATA_NAME);
}
ArtifactPathInfo snapshotPomInfo = null;
if (parentPath.endsWith(LOCAL_SNAPSHOT_VERSION_PART)) {
// If we're in a version directory, first-level listing should include a .pom file
for (final StoreResource resource : firstLevel) {
if (resource.getPath().endsWith(".pom")) {
snapshotPomInfo = ArtifactPathInfo.parse(resource.getPath());
break;
}
}
}
if (snapshotPomInfo != null) {
logger.debug("Generating maven-metadata.xml for snapshots, store: {}", store.getKey());
generated = writeSnapshotMetadata(snapshotPomInfo, firstLevel, store, toGenPath, eventMetadata);
} else {
logger.debug("Generating maven-metadata.xml for releases, store: {}", store.getKey());
generated = writeVersionMetadata(firstLevel, store, toGenPath, eventMetadata);
}
logger.debug("[Result] Generating maven-metadata.xml for store: {}, result: {}", store.getKey(), generated);
return generated ? fileManager.getTransfer(store, path) : null;
}
use of org.commonjava.indy.content.StoreResource in project indy by Commonjava.
the class DefaultContentManager method list.
@Override
@Measure
public List<StoreResource> list(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
final EventMetadata metadata = setAllowRemoteDownloading(eventMetadata);
List<StoreResource> listed;
if (group == store.getKey().getType()) {
List<ArtifactStore> members = getOrderedConcreteStoresAndFilter((Group) store, path);
listed = new ArrayList<>();
contentGeneratorManager.generateGroupDirectoryContentAnd((Group) store, members, path, eventMetadata, listed::addAll);
for (final ArtifactStore member : members) {
List<StoreResource> storeListing = null;
try {
storeListing = list(member, path, metadata);
} catch (IndyWorkflowException e) {
e.filterLocationErrors();
}
if (storeListing != null) {
listed.addAll(storeListing);
}
}
} else {
listed = downloadManager.list(store, path, metadata);
contentGeneratorManager.generateDirectoryContentAnd(store, path, listed, metadata, listed::addAll);
}
return dedupeListing(listed);
}
use of org.commonjava.indy.content.StoreResource in project indy by Commonjava.
the class DefaultDownloadManager method list.
@Override
@Measure
public List<StoreResource> list(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
final List<StoreResource> result = new ArrayList<>();
if (store.getKey().getType() == StoreType.group) {
try {
final List<ListingResult> results = transfers.listAll(locationExpander.expand(new VirtualResource(LocationUtils.toLocations(store), path)), eventMetadata);
for (final ListingResult lr : results) {
if (lr != null && lr.getListing() != null) {
for (final String file : lr.getListing()) {
result.add(new StoreResource((KeyedLocation) lr.getLocation(), path, file));
}
}
}
} catch (final TransferLocationException e) {
fireIndyStoreErrorEvent(e);
logger.warn("Location Error: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to list ALL paths: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
} catch (final TransferException e) {
logger.error(e.getMessage(), e);
throw new IndyWorkflowException("Failed to list ALL paths: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
}
} else {
if (!PathMaskChecker.checkListingMask(store, path)) {
// if list not permitted for the path, return empty list
return result;
}
final KeyedLocation loc = LocationUtils.toLocation(store);
final StoreResource res = new StoreResource(loc, path);
if (store instanceof RemoteRepository) {
try {
final ListingResult lr = transfers.list(res, eventMetadata);
if (lr != null && lr.getListing() != null) {
for (final String file : lr.getListing()) {
result.add(new StoreResource(loc, path, file));
}
}
} catch (final TransferLocationException e) {
fireIndyStoreErrorEvent(e);
logger.warn("Location Error: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to list path: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
} catch (final TransferException e) {
logger.error(e.getMessage(), e);
throw new IndyWorkflowException("Failed to list path: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
}
} else {
try {
final ListingResult listing = transfers.list(res, eventMetadata);
if (listing != null && listing.getListing() != null) {
for (final String child : listing.getListing()) {
result.add(new StoreResource(loc, path, child));
}
}
} catch (final TransferLocationException e) {
fireIndyStoreErrorEvent(e);
logger.warn("Timeout / bad gateway: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to list path: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
} catch (final TransferException e) {
logger.error(e.getMessage(), e);
throw new IndyWorkflowException("Failed to list path: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
}
}
}
return dedupeListing(result);
}
Aggregations