Search in sources :

Example 41 with Metadata

use of org.apache.maven.artifact.repository.metadata.Metadata in project fabric8 by jboss-fuse.

the class AetherResolutionSupport method getOrCreateMetadata.

private Metadata getOrCreateMetadata(File repository, String groupId, String artifactId, String version, String repoId) throws IOException {
    File metadata;
    if (version == null) {
        metadata = new File(repository, String.format("%s/%s/maven-metadata%s.xml", groupId.replaceAll("\\.", "/"), artifactId, repoId == null ? "" : "-" + repoId));
    } else {
        metadata = new File(repository, String.format("%s/%s/%s/maven-metadata%s.xml", groupId.replaceAll("\\.", "/"), artifactId, version, repoId == null ? "" : "-" + repoId));
    }
    Metadata md;
    if (metadata.isFile()) {
        try {
            md = new MetadataXpp3Reader().read(new FileReader(metadata));
        } catch (XmlPullParserException e) {
            throw new IOException(e.getMessage(), e);
        }
    } else {
        md = new Metadata();
        md.setGroupId(groupId);
        md.setArtifactId(artifactId);
        if (version != null) {
            md.setVersion(version);
        }
        md.setVersioning(new Versioning());
    }
    return md;
}
Also used : Versioning(org.apache.maven.artifact.repository.metadata.Versioning) MetadataXpp3Reader(org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) File(java.io.File)

Example 42 with Metadata

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

the class LegacyToDefaultConverter method updateMetadata.

private void updateMetadata(RepositoryMetadata artifactMetadata, ArtifactRepository targetRepository, Metadata newMetadata, FileTransaction transaction) throws ArtifactConversionException {
    Path file = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(artifactMetadata));
    Metadata metadata;
    boolean changed;
    if (Files.exists(file)) {
        metadata = readMetadata(file);
        changed = metadata.merge(newMetadata);
    } else {
        changed = true;
        metadata = newMetadata;
    }
    if (changed) {
        try (StringWriter writer = new StringWriter()) {
            MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer();
            mappingWriter.write(writer, metadata);
            transaction.createFile(writer.toString(), file, digesters);
        } catch (IOException e) {
            throw new ArtifactConversionException(Messages.getString("error.writing.target.metadata"), // $NON-NLS-1$
            e);
        }
    }
}
Also used : Path(java.nio.file.Path) MetadataXpp3Writer(org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer) StringWriter(java.io.StringWriter) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata) RepositoryMetadata(org.apache.maven.artifact.repository.metadata.RepositoryMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) IOException(java.io.IOException)

Example 43 with Metadata

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

the class KojiMavenMetadataProvider method handleExpired.

private void handleExpired(ProjectRef key) {
    Logger logger = LoggerFactory.getLogger(getClass());
    if (!kojiConfig.isEnabled()) {
        logger.debug("Koji add-on is disabled.");
        return;
    }
    logger.info("Koji metadata expired for GA: {}", key);
    try {
        Set<Group> affected = storeDataManager.query().getAll(s -> group == s.getType() && kojiConfig.isEnabledFor(s)).stream().map(s -> (Group) s).collect(Collectors.toSet());
        if (storeDataManager instanceof AbstractStoreDataManager) {
            affected = ((AbstractStoreDataManager) storeDataManager).filterAffectedGroups(affected);
        }
        if (!affected.isEmpty()) {
            logger.info("Triggering metadata cleanup from Koji metadata expiration, for GA: {} in groups: {}", key, affected);
            String path = ArtifactPathUtils.formatMetadataPath(key, METADATA_NAME);
            clearPaths(affected, path);
        }
    } catch (IndyDataException ex) {
        logger.error("Failed to clear group metadata for expired Koji metadata: " + key, ex);
    } catch (TransferException ex) {
        logger.error("Failed to format metadata path for: " + key, ex);
    }
}
Also used : Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) KojiTagInfo(com.redhat.red.build.koji.model.xmlrpc.KojiTagInfo) BasicCacheHandle(org.commonjava.indy.subsys.infinispan.BasicCacheHandle) Cache(org.infinispan.Cache) RemoteCache(org.infinispan.client.hotrod.RemoteCache) WeftExecutorService(org.commonjava.cdi.util.weft.WeftExecutorService) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) WeftManaged(org.commonjava.cdi.util.weft.WeftManaged) CacheProducer(org.commonjava.indy.subsys.infinispan.CacheProducer) Map(java.util.Map) KojiArchiveInfo(com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo) StoreKey(org.commonjava.indy.model.core.StoreKey) StoreType.group(org.commonjava.indy.model.core.StoreType.group) GroupMergeHelper(org.commonjava.indy.core.content.group.GroupMergeHelper) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Listener(org.infinispan.notifications.Listener) ClientListener(org.infinispan.client.hotrod.annotation.ClientListener) TimeZone(java.util.TimeZone) KojiClient(com.redhat.red.build.koji.KojiClient) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) CacheEntryExpired(org.infinispan.notifications.cachelistener.annotation.CacheEntryExpired) Collectors(java.util.stream.Collectors) List(java.util.List) InvalidVersionSpecificationException(org.commonjava.atlas.maven.ident.version.InvalidVersionSpecificationException) KojiBuildInfo(com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) PostConstruct(javax.annotation.PostConstruct) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Pattern(java.util.regex.Pattern) KojiBuildArchiveCollection(com.redhat.red.build.koji.model.xmlrpc.KojiBuildArchiveCollection) DirectContentAccess(org.commonjava.indy.content.DirectContentAccess) IndyDataException(org.commonjava.indy.data.IndyDataException) PoolUtils.detectOverloadVoid(org.commonjava.indy.core.ctl.PoolUtils.detectOverloadVoid) IndyKojiConfig(org.commonjava.indy.koji.conf.IndyKojiConfig) Locker(org.commonjava.cdi.util.weft.Locker) MavenMetadataProvider(org.commonjava.indy.pkg.maven.content.group.MavenMetadataProvider) SimpleDateFormat(java.text.SimpleDateFormat) SimpleProjectRef(org.commonjava.atlas.maven.ident.ref.SimpleProjectRef) Callable(java.util.concurrent.Callable) AtomicReference(java.util.concurrent.atomic.AtomicReference) VersionUtils(org.commonjava.atlas.maven.ident.util.VersionUtils) Group(org.commonjava.indy.model.core.Group) ConcurrentHashSet(org.infinispan.commons.util.concurrent.ConcurrentHashSet) ArrayList(java.util.ArrayList) InvalidRefException(org.commonjava.atlas.maven.ident.ref.InvalidRefException) AbstractStoreDataManager(org.commonjava.indy.db.common.AbstractStoreDataManager) ClientCacheEntryExpired(org.infinispan.client.hotrod.annotation.ClientCacheEntryExpired) Inject(javax.inject.Inject) Transfer(org.commonjava.maven.galley.model.Transfer) MetadataCacheManager(org.commonjava.indy.pkg.maven.content.MetadataCacheManager) CacheEntryExpiredEvent(org.infinispan.notifications.cachelistener.event.CacheEntryExpiredEvent) Calendar(java.util.Calendar) Measure(org.commonjava.o11yphant.metrics.annotation.Measure) ExecutorConfig(org.commonjava.cdi.util.weft.ExecutorConfig) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) KojiMavenVersionMetadataLocks(org.commonjava.indy.koji.inject.KojiMavenVersionMetadataLocks) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService) KojiClientException(com.redhat.red.build.koji.KojiClientException) ArtifactPathUtils(org.commonjava.maven.galley.maven.util.ArtifactPathUtils) METADATA_NAME(org.commonjava.indy.pkg.maven.content.group.MavenMetadataMerger.METADATA_NAME) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) LocationUtils(org.commonjava.indy.util.LocationUtils) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ProjectRef(org.commonjava.atlas.maven.ident.ref.ProjectRef) IOException(java.io.IOException) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) CacheHandle(org.commonjava.indy.subsys.infinispan.CacheHandle) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) KojiBuildState(com.redhat.red.build.koji.model.xmlrpc.KojiBuildState) ClientCacheEntryExpiredEvent(org.infinispan.client.hotrod.event.ClientCacheEntryExpiredEvent) KojiMavenVersionMetadataCache(org.commonjava.indy.koji.inject.KojiMavenVersionMetadataCache) SingleVersion(org.commonjava.atlas.maven.ident.version.SingleVersion) Collections(java.util.Collections) StoreDataManager(org.commonjava.indy.data.StoreDataManager) TransferException(org.commonjava.maven.galley.TransferException) IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) TransferException(org.commonjava.maven.galley.TransferException) AbstractStoreDataManager(org.commonjava.indy.db.common.AbstractStoreDataManager) Logger(org.slf4j.Logger)

Example 44 with Metadata

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

the class KojiMavenMetadataProvider method executeKojiMetadataLookup.

@Measure
private Metadata executeKojiMetadataLookup(ProjectRef ga, String path) throws KojiClientException, IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    // short-term caches to help improve performance a bit by avoiding xml-rpc calls.
    List<KojiArchiveInfo> archives = kojiContentProvider.listArchivesMatching(ga, null);
    Map<Integer, KojiBuildArchiveCollection> seenBuildArchives = new ConcurrentHashMap<>();
    Set<Integer> seenBuilds = new ConcurrentHashSet<>();
    DrainingExecutorCompletionService<SingleVersion> svc = new DrainingExecutorCompletionService<>(kojiMDService);
    detectOverloadVoid(() -> {
        for (KojiArchiveInfo archive : archives) {
            svc.submit(archiveScanner(path, ga, archive, seenBuilds, seenBuildArchives));
        }
    });
    Set<SingleVersion> versions = new ConcurrentHashSet<>();
    try {
        svc.drain(v -> {
            if (v != null) {
                versions.add(v);
            }
        });
    } catch (InterruptedException | ExecutionException e) {
        logger.warn("Failed to scan for Koji metadata related to: " + ga, e);
    }
    if (versions.isEmpty()) {
        logger.debug("No versions found in Koji builds for metadata: {}", path);
        return null;
    }
    List<SingleVersion> sortedVersions = new ArrayList<>(versions);
    Collections.sort(sortedVersions);
    Metadata md = new Metadata();
    md.setGroupId(ga.getGroupId());
    md.setArtifactId(ga.getArtifactId());
    Versioning versioning = new Versioning();
    versioning.setRelease(sortedVersions.get(versions.size() - 1).renderStandard());
    versioning.setLatest(sortedVersions.get(versions.size() - 1).renderStandard());
    versioning.setVersions(sortedVersions.stream().map(SingleVersion::renderStandard).collect(Collectors.toList()));
    Date lastUpdated = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime();
    versioning.setLastUpdated(new SimpleDateFormat(LAST_UPDATED_FORMAT).format(lastUpdated));
    md.setVersioning(versioning);
    return md;
}
Also used : ArrayList(java.util.ArrayList) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) Logger(org.slf4j.Logger) KojiArchiveInfo(com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo) Date(java.util.Date) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) KojiBuildArchiveCollection(com.redhat.red.build.koji.model.xmlrpc.KojiBuildArchiveCollection) ConcurrentHashSet(org.infinispan.commons.util.concurrent.ConcurrentHashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SingleVersion(org.commonjava.atlas.maven.ident.version.SingleVersion) ExecutionException(java.util.concurrent.ExecutionException) SimpleDateFormat(java.text.SimpleDateFormat) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 45 with Metadata

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

the class KojiMavenMetadataProviderTest method retrieveVersionMetadata.

@Test
public void retrieveVersionMetadata() throws Exception {
    initKojiClient("simple-metadata-generate", false);
    Metadata metadata = provider.getMetadata(new StoreKey(MAVEN_PKG_KEY, group, "public"), "commons-io/commons-io/maven-metadata.xml");
    assertThat(metadata, notNullValue());
    StringWriter sw = new StringWriter();
    new MetadataXpp3Writer().write(sw, metadata);
    System.out.println(sw.toString());
    Versioning versioning = metadata.getVersioning();
    assertThat(versioning, notNullValue());
    assertThat(versioning.getLatest(), equalTo("2.4.0.redhat-1"));
    assertThat(versioning.getRelease(), equalTo("2.4.0.redhat-1"));
    List<String> versions = versioning.getVersions();
    assertThat(versions, notNullValue());
    assertThat(versions.size(), equalTo(2));
    int idx = 0;
    assertThat(versions.get(idx), equalTo("2.1-redhat-1"));
    idx++;
    assertThat(versions.get(idx), equalTo("2.4.0.redhat-1"));
}
Also used : Versioning(org.apache.maven.artifact.repository.metadata.Versioning) MetadataXpp3Writer(org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer) StringWriter(java.io.StringWriter) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

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