Search in sources :

Example 1 with MavenFacet

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();
    }
}
Also used : MavenPath(org.sonatype.nexus.repository.maven.MavenPath) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) Asset(org.sonatype.nexus.repository.storage.Asset) MavenFacet(org.sonatype.nexus.repository.maven.MavenFacet) OrientMavenFacet(org.sonatype.nexus.orient.maven.OrientMavenFacet)

Example 2 with MavenFacet

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();
}
Also used : MavenPath(org.sonatype.nexus.repository.maven.MavenPath) Coordinates(org.sonatype.nexus.repository.maven.MavenPath.Coordinates) VersionPolicy(org.sonatype.nexus.repository.maven.VersionPolicy) MavenFacet(org.sonatype.nexus.repository.maven.MavenFacet) Nonnull(javax.annotation.Nonnull)

Example 3 with MavenFacet

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);
        }
    }
}
Also used : Path(java.nio.file.Path) MavenPath(org.sonatype.nexus.repository.maven.MavenPath) Coordinates(org.sonatype.nexus.repository.maven.MavenPath.Coordinates) StorageFacet(org.sonatype.nexus.repository.storage.StorageFacet) VersionPolicy(org.sonatype.nexus.repository.maven.VersionPolicy) MavenFacet(org.sonatype.nexus.repository.maven.MavenFacet) Singleton(javax.inject.Singleton) AttributesMap(org.sonatype.nexus.common.collect.AttributesMap) Inject(javax.inject.Inject) UnitOfWork(org.sonatype.nexus.transaction.UnitOfWork) Repository(org.sonatype.nexus.repository.Repository) PartPayload(org.sonatype.nexus.repository.view.PartPayload) Maven2MavenPathParser(org.sonatype.nexus.repository.maven.internal.Maven2MavenPathParser) StreamPayload(org.sonatype.nexus.repository.view.payloads.StreamPayload) TempBlob(org.sonatype.nexus.repository.view.payloads.TempBlob) Map(java.util.Map) MavenUploadHandlerSupport(org.sonatype.nexus.repository.maven.MavenUploadHandlerSupport) Payload(org.sonatype.nexus.repository.view.Payload) UploadDefinitionExtension(org.sonatype.nexus.repository.rest.UploadDefinitionExtension) Named(javax.inject.Named) OrientMavenFacet(org.sonatype.nexus.orient.maven.OrientMavenFacet) Path(java.nio.file.Path) MavenPath(org.sonatype.nexus.repository.maven.MavenPath) Files(java.nio.file.Files) MavenPomGenerator(org.sonatype.nexus.repository.maven.internal.MavenPomGenerator) HashCode(com.google.common.hash.HashCode) DateTime(org.joda.time.DateTime) Set(java.util.Set) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) ContentPermissionChecker(org.sonatype.nexus.repository.security.ContentPermissionChecker) File(java.io.File) ImportFileConfiguration(org.sonatype.nexus.repository.importtask.ImportFileConfiguration) Content(org.sonatype.nexus.repository.view.Content) VersionPolicyValidator(org.sonatype.nexus.repository.maven.internal.VersionPolicyValidator) VariableResolverAdapter(org.sonatype.nexus.repository.security.VariableResolverAdapter) HashType(org.sonatype.nexus.repository.maven.MavenPath.HashType) Maven2Format(org.sonatype.nexus.repository.maven.internal.Maven2Format) HashAlgorithm(org.sonatype.nexus.common.hash.HashAlgorithm) ComponentUpload(org.sonatype.nexus.repository.upload.ComponentUpload) MavenHostedFacet(org.sonatype.nexus.repository.maven.MavenHostedFacet) UploadResponse(org.sonatype.nexus.repository.upload.UploadResponse) StreamPayload(org.sonatype.nexus.repository.view.payloads.StreamPayload) MavenPath(org.sonatype.nexus.repository.maven.MavenPath) AttributesMap(org.sonatype.nexus.common.collect.AttributesMap) OrientMavenFacet(org.sonatype.nexus.orient.maven.OrientMavenFacet) DateTime(org.joda.time.DateTime) FileInputStream(java.io.FileInputStream) HashCode(com.google.common.hash.HashCode) PartPayload(org.sonatype.nexus.repository.view.PartPayload) StreamPayload(org.sonatype.nexus.repository.view.payloads.StreamPayload) Payload(org.sonatype.nexus.repository.view.Payload) File(java.io.File) HashAlgorithm(org.sonatype.nexus.common.hash.HashAlgorithm)

Aggregations

MavenFacet (org.sonatype.nexus.repository.maven.MavenFacet)3 MavenPath (org.sonatype.nexus.repository.maven.MavenPath)3 OrientMavenFacet (org.sonatype.nexus.orient.maven.OrientMavenFacet)2 Coordinates (org.sonatype.nexus.repository.maven.MavenPath.Coordinates)2 VersionPolicy (org.sonatype.nexus.repository.maven.VersionPolicy)2 HashCode (com.google.common.hash.HashCode)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1 Inject (javax.inject.Inject)1 Named (javax.inject.Named)1 Singleton (javax.inject.Singleton)1 DateTime (org.joda.time.DateTime)1 AttributesMap (org.sonatype.nexus.common.collect.AttributesMap)1