use of org.sonatype.nexus.repository.maven.MavenPath in project nexus-public by sonatype.
the class MergingGroupHandler method doGetContent.
private Response doGetContent(@Nonnull final Context context, @Nonnull final DispatchedRepositories dispatched) throws Exception {
final MavenPath mavenPath = context.getAttributes().require(MavenPath.class);
final MavenGroupFacet groupFacet = context.getRepository().facet(MavenGroupFacet.class);
final Repository repository = context.getRepository();
final List<Repository> members = groupFacet.members();
log.trace("Incoming request for {} : {}", context.getRepository().getName(), mavenPath.getPath());
List<Repository> proxiesOrGroups = members.stream().filter(PROXY_OR_GROUP::apply).collect(toList());
Content content = maybeCooperate(repository, mavenPath, () -> {
try {
// Check members to prime
Map<Repository, Response> passThroughResponses = getAll(context, proxiesOrGroups, dispatched);
Optional<Content> cached = checkCache(groupFacet, mavenPath, repository);
if (cached.isPresent()) {
log.trace("Serving cached content {} : {}", repository.getName(), mavenPath.getPath());
return cached.get();
}
// this will fetch the remaining responses, thanks to the 'dispatched' tracking
Map<Repository, Response> remainingResponses = getAll(context, members, dispatched);
// merge the two sets of responses according to member order
LinkedHashMap<Repository, Response> responses = new LinkedHashMap<>();
for (Repository member : members) {
Response response = passThroughResponses.get(member);
if (response == null) {
response = remainingResponses.get(member);
}
if (response != null) {
responses.put(member, response);
}
}
// merge the individual responses and cache the result
Content mergedContent = groupFacet.mergeAndCache(mavenPath, responses);
if (mergedContent != null) {
log.trace("Responses merged {} : {}", context.getRepository().getName(), mavenPath.getPath());
}
return mergedContent;
} catch (Exception e) {
throw new IOException(e);
}
});
if (content != null) {
return HttpResponses.ok(content);
} else {
log.trace("Not found response to merge {} : {}", repository.getName(), mavenPath.getPath());
return HttpResponses.notFound();
}
}
use of org.sonatype.nexus.repository.maven.MavenPath in project nexus-public by sonatype.
the class AbstractMetadataRebuilder method getPathsByGav.
/**
* Collect all {@link MavenPath} for the provided GAbV.
*
* @param repository The repository associated with the provided GAbV (Maven2 format, Hosted type only).
* @param groupId scope the work to given groupId.
* @param artifactId scope the work to given artifactId (groupId must be given).
* @param baseVersion scope the work to given baseVersion (groupId and artifactId must ge given).
* @return list of all paths for the input coordinates
* @since 3.14
*/
protected List<MavenPath> getPathsByGav(final Repository repository, final String groupId, final String artifactId, final String baseVersion) {
checkNotNull(groupId);
checkNotNull(artifactId);
checkNotNull(baseVersion);
log.debug("Collecting MavenPaths for Maven2 hosted repository metadata: repository={}, g={}, a={}, bV={}", repository.getName(), groupId, artifactId, baseVersion);
List<MavenPath> paths = new ArrayList<>();
// Build path for specific GAV
paths.add(metadataPath(groupId, artifactId, baseVersion));
// Build path for the GA; will be rebuilt as necessary but may hold the last GAV in which case rebuild would ignore it
paths.add(metadataPath(groupId, artifactId, null));
// Check explicitly for whether or not we have Group level metadata that might need rebuilding, since this
// is potentially the most expensive possible path to take.
MavenPath groupPath = metadataPath(groupId, null, null);
if (exists(repository, groupPath)) {
paths.add(groupPath);
}
return paths;
}
use of org.sonatype.nexus.repository.maven.MavenPath in project nexus-public by sonatype.
the class OrientArchetypeCatalogHandler method handle.
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
MavenPath path = context.getAttributes().require(MavenPath.class);
Repository repository = context.getRepository();
String action = context.getRequest().getAction();
switch(action) {
case GET:
case HEAD:
return doGet(path, repository);
default:
return HttpResponses.methodNotAllowed(context.getRequest().getAction(), GET, HEAD);
}
}
use of org.sonatype.nexus.repository.maven.MavenPath in project nexus-public by sonatype.
the class OrientIndexGroupHandler method handle.
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
MavenPath mavenPath = context.getAttributes().require(MavenPath.class);
OrientMavenFacet mavenFacet = context.getRepository().facet(OrientMavenFacet.class);
Content content = mavenFacet.get(mavenPath);
if (content == null) {
return HttpResponses.notFound(mavenPath.getPath());
}
return HttpResponses.ok(content);
}
use of org.sonatype.nexus.repository.maven.MavenPath in project nexus-public by sonatype.
the class OrientMavenGroupFacet method on.
@Subscribe
@AllowConcurrentEvents
public void on(final AssetEvent event) {
// only make DB changes on the originating node, as orient will also replicate those for us
if (event.isLocal() && event.getComponentId() == null && member(event.getRepositoryName())) {
final String path = event.getAsset().name();
final MavenPath mavenPath = mavenFacet.getMavenPathParser().parsePath(path);
// only trigger eviction on main metadata artifact (which may go on to evict its hashes)
if (!mavenPath.isHash()) {
UnitOfWork.begin(getRepository().facet(StorageFacet.class).txSupplier());
try {
evictCache(mavenPath, event instanceof AssetDeletedEvent);
} finally {
UnitOfWork.end();
}
}
}
}
Aggregations