use of org.sonatype.nexus.repository.maven.MavenFacet in project nexus-public by sonatype.
the class OrientMavenTestHelper method getLastDownloadedTime.
@Override
public DateTime getLastDownloadedTime(final Repository repository, final String assetPath) {
MavenFacet mavenFacet = repository.facet(MavenFacet.class);
MavenPath mavenPath = mavenFacet.getMavenPathParser().parsePath(assetPath);
try (StorageTx tx = repository.facet(StorageFacet.class).txSupplier().get()) {
tx.begin();
Asset asset = tx.findAssetWithProperty(P_NAME, mavenPath.getPath(), tx.findBucket(repository));
return asset.lastDownloaded();
}
}
use of org.sonatype.nexus.repository.maven.MavenFacet in project nexus-public by sonatype.
the class VersionPolicyHandler method handle.
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
final MavenPath path = context.getAttributes().require(MavenPath.class);
final MavenFacet mavenFacet = context.getRepository().facet(MavenFacet.class);
final VersionPolicy versionPolicy = mavenFacet.getVersionPolicy();
final Coordinates coordinates = path.getCoordinates();
if (coordinates != null && !versionPolicyValidator.validArtifactPath(versionPolicy, coordinates)) {
return createResponse(context, "Repository version policy: " + versionPolicy + " does not allow version: " + coordinates.getVersion());
}
if (!versionPolicyValidator.validMetadataPath(versionPolicy, path.main().getPath())) {
return createResponse(context, "Repository version policy: " + versionPolicy + " does not allow metadata in path: " + path.getPath());
}
return context.proceed();
}
use of org.sonatype.nexus.repository.maven.MavenFacet in project nexus-public by sonatype.
the class MavenUploadHandler method doPut.
@Override
protected Content doPut(ImportFileConfiguration configuration) throws IOException {
OrientMavenFacet mavenFacet = configuration.getRepository().facet(OrientMavenFacet.class);
MavenPath mavenPath = parser.parsePath(configuration.getAssetName());
File content = configuration.getFile();
Path contentPath = content.toPath();
if (configuration.isHardLinkingEnabled()) {
final AttributesMap contentAttributes = new AttributesMap();
contentAttributes.set(Content.CONTENT_LAST_MODIFIED, new DateTime(Files.getLastModifiedTime(contentPath).toMillis()));
byte[] bytes = Files.readAllBytes(contentPath);
Map<HashAlgorithm, HashCode> hashes = HashType.ALGORITHMS.stream().collect(Collectors.toMap(a -> a, a -> a.function().hashBytes(bytes)));
return mavenFacet.put(mavenPath, contentPath, configuration.getAssetName(), contentAttributes, hashes, Files.size(contentPath));
} else {
try (FileInputStream fis = new FileInputStream(content)) {
Payload payload = new StreamPayload(() -> fis, content.length(), Files.probeContentType(contentPath));
return doPut(configuration.getRepository(), mavenPath, payload);
}
}
}
Aggregations