Search in sources :

Example 26 with Metadata

use of org.apache.maven.artifact.repository.metadata.Metadata in project indy by Commonjava.

the class AbstractContentManagementTest method getRealLastUpdated.

protected String getRealLastUpdated(StoreKey key, String path) throws Exception {
    InputStream meta = client.content().get(key, path);
    Metadata merged = new MetadataXpp3Reader().read(meta);
    return merged.getVersioning().getLastUpdated();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MetadataXpp3Reader(org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader) Metadata(org.apache.maven.artifact.repository.metadata.Metadata)

Example 27 with Metadata

use of org.apache.maven.artifact.repository.metadata.Metadata in project indy by Commonjava.

the class KojiMavenMetadataProvider method getMetadata.

@Override
@Measure
public Metadata getMetadata(StoreKey targetKey, String path) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    if (group != targetKey.getType()) {
        logger.debug("Not a group. Cannot supplement with metadata from Koji builds");
        return null;
    }
    if (!kojiConfig.isEnabled()) {
        logger.debug("Koji add-on is disabled.");
        return null;
    }
    try {
        ArtifactStore target = storeDataManager.getArtifactStore(targetKey);
        if (!kojiConfig.isEnabledFor(target)) {
            logger.debug("Koji integration is not enabled for group: {}", targetKey);
            return null;
        }
    } catch (IndyDataException e) {
        logger.error("Failed to get metadata for path {} in store {}: {}", path, targetKey, e.getMessage());
    }
    File mdFile = new File(path);
    File artifactDir = mdFile.getParentFile();
    File groupDir = artifactDir == null ? null : artifactDir.getParentFile();
    if (artifactDir == null || groupDir == null) {
        logger.debug("Invalid groupId / artifactId directory structure: '{}' / '{}'", groupDir, artifactDir);
        return null;
    }
    String groupId = groupDir.getPath().replace(File.separatorChar, '.');
    String artifactId = artifactDir.getName();
    ProjectRef ref = null;
    try {
        ref = new SimpleProjectRef(groupId, artifactId);
    } catch (InvalidRefException e) {
        logger.warn("Not a valid Maven GA: {}:{}. Skipping Koji metadata retrieval.", groupId, artifactId);
    }
    if (ref == null) {
        logger.debug("Could not render a valid Maven GA for path: '{}'", path);
        return null;
    }
    ProjectRef ga = ref;
    AtomicReference<IndyWorkflowException> wfError = new AtomicReference<>();
    return versionMetadataLocks.lockAnd(ga, kojiConfig.getLockTimeoutSeconds(), k -> {
        Metadata metadata = versionMetadata.get(ga);
        if (metadata == null) {
            try {
                metadata = executeKojiMetadataLookup(ga, path);
            } catch (IndyWorkflowException e) {
                wfError.set(e);
                metadata = null;
            } catch (KojiClientException e) {
                // FIXME: Should this bubble up like IndyWorkflowException does in the case of overloaded threadpool?
                Throwable cause = e.getCause();
                logger.error(String.format("Failed to retrieve version metadata for: %s from Koji. Reason: %s", ga, e.getMessage()), e);
                if (cause instanceof RuntimeException) {
                    logger.error("Previous exception's nested cause was a RuntimeException variant:", cause);
                }
                metadata = null;
            }
            if (metadata != null) {
                Metadata md = metadata;
                // FIXME: Need a way to listen for cache expiration and re-request this?
                versionMetadata.execute((cache) -> cache.put(ga, md, kojiConfig.getMetadataTimeoutSeconds(), TimeUnit.SECONDS));
            } else {
                logger.debug("Returning null metadata result for unknown reason (path: '{}')", path);
            }
        }
        return metadata;
    }, (k, lock) -> {
        logger.error("Failed to acquire Koji GA version metadata lock on: '{}' in {} seconds.", ga, kojiConfig.getLockTimeoutSeconds());
        return false;
    });
}
Also used : InvalidRefException(org.commonjava.atlas.maven.ident.ref.InvalidRefException) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) AtomicReference(java.util.concurrent.atomic.AtomicReference) Logger(org.slf4j.Logger) IndyDataException(org.commonjava.indy.data.IndyDataException) SimpleProjectRef(org.commonjava.atlas.maven.ident.ref.SimpleProjectRef) KojiClientException(com.redhat.red.build.koji.KojiClientException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) SimpleProjectRef(org.commonjava.atlas.maven.ident.ref.SimpleProjectRef) ProjectRef(org.commonjava.atlas.maven.ident.ref.ProjectRef) File(java.io.File) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 28 with Metadata

use of org.apache.maven.artifact.repository.metadata.Metadata in project platformlayer by platformlayer.

the class MavenResolver method resolve.

public Path resolve(MavenReference reference) throws IOException {
    Path artifactPath = toPath(reference.groupId, reference.artifactId);
    if (reference.versionId == null) {
        reference.versionId = resolveVersion(artifactPath, reference);
    }
    if (reference.classifier == null) {
        reference.classifier = "jar";
    }
    Path versionedPath = artifactPath.resolve(reference.versionId);
    Path artifactMavenMetadataPath = versionedPath.resolve("maven-metadata.xml");
    log.info("Reading file: " + artifactMavenMetadataPath);
    String mavenMetadataXml = IoUtils.readAll(Files.newInputStream(artifactMavenMetadataPath));
    Metadata mavenMetadata = MavenXml.readMetadata(mavenMetadataXml);
    return pickSnapshot(versionedPath, reference, mavenMetadata);
}
Also used : Path(java.nio.file.Path) Metadata(org.apache.maven.artifact.repository.metadata.Metadata)

Example 29 with Metadata

use of org.apache.maven.artifact.repository.metadata.Metadata in project gradle by gradle.

the class MavenRemotePublisher method createSnapshotMetadata.

@Override
protected Metadata createSnapshotMetadata(MavenNormalizedPublication publication, String groupId, String artifactId, String version, ExternalResourceRepository repository, ExternalResourceName metadataResource) {
    Metadata metadata = new Metadata();
    metadata.setModelVersion("1.1.0");
    metadata.setGroupId(groupId);
    metadata.setArtifactId(artifactId);
    metadata.setVersion(version);
    String timestamp = createSnapshotTimestamp();
    Snapshot snapshot = new Snapshot();
    snapshot.setBuildNumber(getNextBuildNumber(repository, metadataResource));
    snapshot.setTimestamp(timestamp);
    Versioning versioning = new Versioning();
    versioning.setSnapshot(snapshot);
    versioning.setLastUpdated(snapshot.getTimestamp().replace(".", ""));
    String timestampVersion = version.replace("SNAPSHOT", snapshot.getTimestamp() + "-" + snapshot.getBuildNumber());
    for (MavenArtifact artifact : publication.getAllArtifacts()) {
        SnapshotVersion sv = new SnapshotVersion();
        sv.setClassifier(artifact.getClassifier());
        sv.setExtension(artifact.getExtension());
        sv.setVersion(timestampVersion);
        sv.setUpdated(versioning.getLastUpdated());
        versioning.getSnapshotVersions().add(sv);
    }
    metadata.setVersioning(versioning);
    return metadata;
}
Also used : Snapshot(org.apache.maven.artifact.repository.metadata.Snapshot) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) SnapshotVersion(org.apache.maven.artifact.repository.metadata.SnapshotVersion) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) MavenArtifact(org.gradle.api.publish.maven.MavenArtifact)

Example 30 with Metadata

use of org.apache.maven.artifact.repository.metadata.Metadata in project gradle by gradle.

the class MavenRemotePublisher method getNextBuildNumber.

private int getNextBuildNumber(ExternalResourceRepository repository, ExternalResourceName metadataResource) {
    ExternalResourceReadResult<Metadata> existing = readExistingMetadata(repository, metadataResource);
    if (existing != null) {
        Metadata recessive = existing.getResult();
        Versioning versioning = recessive.getVersioning();
        if (versioning != null) {
            Snapshot snapshot = versioning.getSnapshot();
            if (snapshot != null && snapshot.getBuildNumber() > 0) {
                return snapshot.getBuildNumber() + 1;
            }
        }
    }
    return 1;
}
Also used : Versioning(org.apache.maven.artifact.repository.metadata.Versioning) Snapshot(org.apache.maven.artifact.repository.metadata.Snapshot) Metadata(org.apache.maven.artifact.repository.metadata.Metadata)

Aggregations

Metadata (org.apache.maven.artifact.repository.metadata.Metadata)55 Versioning (org.apache.maven.artifact.repository.metadata.Versioning)31 Test (org.junit.Test)20 File (java.io.File)18 MetadataXpp3Reader (org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader)16 MetadataXpp3Writer (org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer)16 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)15 Transfer (org.commonjava.maven.galley.model.Transfer)13 SnapshotVersion (org.apache.maven.artifact.repository.metadata.SnapshotVersion)12 StoreKey (org.commonjava.indy.model.core.StoreKey)12 IOException (java.io.IOException)9 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)9 Group (org.commonjava.indy.model.core.Group)9 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)9 Snapshot (org.apache.maven.artifact.repository.metadata.Snapshot)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 MavenResolver (io.fabric8.maven.MavenResolver)6 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6