use of org.commonjava.atlas.maven.ident.util.ArtifactPathInfo in project indy by Commonjava.
the class KojiContentManagerDecorator method findKojiBuildAnd.
@Measure
private <T> T findKojiBuildAnd(ArtifactStore store, String path, EventMetadata eventMetadata, T defValue, KojiBuildAction<T> action) throws IndyWorkflowException {
if (!config.getEnabled()) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Koji content-manager decorator is disabled.");
logger.debug("When koji addon is disenabled , path:{},config instance is {}", path, config.toString());
return defValue;
}
if (!config.isEnabledFor(store)) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Koji content-manager decorator not enabled for: {}.", store.getKey());
logger.debug("When the group is disenabled , path:{},config instance is {}", path, config.toString());
return defValue;
}
logger.debug("When the koji is enabled , path:{},config instance is {}", path, config.toString());
// TODO: This won't work for maven-metadata.xml files! We need to hit a POM or jar or something first.
// FIXME: This won't work for NPM!
ArtifactPathInfo pathInfo = ArtifactPathInfo.parse(path);
if (pathInfo != null) {
ArtifactRef artifactRef = pathInfo.getArtifact();
logger.info("Searching for Koji build: {}", artifactRef);
return proxyKojiBuild(store.getKey(), artifactRef, path, eventMetadata, defValue, action);
} else {
logger.info("Path is not a maven artifact reference: {}", path);
}
return defValue;
}
use of org.commonjava.atlas.maven.ident.util.ArtifactPathInfo 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.atlas.maven.ident.util.ArtifactPathInfo 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;
}
Aggregations