Search in sources :

Example 1 with ProjectVersionRef

use of org.commonjava.atlas.maven.ident.ref.ProjectVersionRef in project indy by Commonjava.

the class KojiUtils method isVersionSignatureAllowedWithPath.

public boolean isVersionSignatureAllowedWithPath(String path) {
    final ArtifactPathInfo pathInfo = ArtifactPathInfo.parse(path);
    // skip those files without standard GAV format path
    if (pathInfo == null) {
        return true;
    }
    ProjectVersionRef versionRef = pathInfo.getProjectId();
    return isVersionSignatureAllowedWithVersion(versionRef.getVersionStringRaw());
}
Also used : ProjectVersionRef(org.commonjava.atlas.maven.ident.ref.ProjectVersionRef) ArtifactPathInfo(org.commonjava.atlas.maven.ident.util.ArtifactPathInfo)

Example 2 with ProjectVersionRef

use of org.commonjava.atlas.maven.ident.ref.ProjectVersionRef in project indy by Commonjava.

the class ImpliedRepositoryDetector method addImpliedRepositories.

private void addImpliedRepositories(final ImplicationsJob job) {
    job.implied = new ArrayList<>();
    logger.debug("Retrieving repository/pluginRepository declarations from:\n  {}", new JoinString("\n  ", job.pomView.getDocRefStack()));
    final List<List<RepositoryView>> repoLists = Arrays.asList(job.pomView.getNonProfileRepositories(), job.pomView.getAllPluginRepositories());
    final ImpliedRepositoryCreator creator = createRepoCreator();
    if (creator == null) {
        logger.error("Cannot proceed without a valid ImpliedRepositoryCreator instance. Aborting detection.");
        return;
    }
    for (final List<RepositoryView> repos : repoLists) {
        if (repos == null || repos.isEmpty()) {
            continue;
        }
        for (final RepositoryView repo : repos) {
            final ProjectVersionRef gav = job.pathInfo.getProjectId();
            try {
                if (config.isBlacklisted(repo.getUrl())) {
                    logger.debug("Discarding blacklisted repository: {}", repo);
                    continue;
                } else if (!config.isIncludeSnapshotRepos() && !repo.isReleasesEnabled()) {
                    logger.debug("Discarding snapshot repository: {}", repo);
                    continue;
                }
            } catch (final MalformedURLException e) {
                logger.error(String.format("Cannot add implied remote repo: %s from: %s (transfer: %s). Failed to check if repository is blacklisted.", repo.getUrl(), gav, job.transfer), e);
            }
            logger.debug("Detected POM-declared repository: {}", repo);
            List<RemoteRepository> rrs = null;
            try {
                rrs = storeManager.query().getRemoteRepositoryByUrl(MAVEN_PKG_KEY, repo.getUrl());
            } catch (IndyDataException e) {
                logger.error(String.format("Cannot lookup remote repositories by URL: %s. Reason: %s", e.getMessage()), e);
            }
            final RemoteRepository ref = creator.createFrom(gav, repo, LoggerFactory.getLogger(creator.getClass()));
            if (ref == null) {
                logger.warn("ImpliedRepositoryCreator didn't create anything for repo: {}, specified in: {}. Skipping.", repo.getId(), gav);
                continue;
            }
            if (rrs != null && !rrs.isEmpty()) {
                rrs = rrs.stream().filter(rr -> rr.isAllowReleases() == ref.isAllowReleases()).filter(rr -> rr.isAllowSnapshots() == ref.isAllowSnapshots()).filter(rr -> (isEmpty(rr.getPathMaskPatterns()) && isEmpty(ref.getPathMaskPatterns())) || rr.getPathMaskPatterns().equals(ref.getPathMaskPatterns())).collect(Collectors.toList());
            }
            if (rrs == null || rrs.isEmpty()) {
                logger.debug("Creating new RemoteRepository for: {}", repo);
                final RemoteRepository rr = ref.copyOf();
                rr.setMetadata(METADATA_ORIGIN, IMPLIED_REPO_ORIGIN);
                try {
                    rr.setMetadata(IMPLIED_BY_STORES, mapper.writeValueAsString(new ImpliedRepoMetadataManager.ImpliedRemotesWrapper(Collections.singletonList(job.store.getKey()))));
                } catch (JsonProcessingException e) {
                    logger.error("Failed to set {}", IMPLIED_BY_STORES);
                    continue;
                }
                if (!remoteValidator.isValid(rr)) {
                    logger.warn("Implied repository to: {} is invalid! Repository created was: {}", repo.getUrl(), rr);
                    continue;
                }
                final String changelog = String.format("Adding remote repository: %s (url: %s, name: %s), which is implied by the POM: %s (at: %s/%s)", repo.getId(), repo.getUrl(), repo.getName(), gav, job.transfer.getLocation().getUri(), job.transfer.getPath());
                final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, changelog);
                try {
                    final boolean result = storeManager.storeArtifactStore(rr, summary, true, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, IMPLIED_REPOS_DETECTION).set(IMPLIED_BY_POM_TRANSFER, job.transfer));
                    logger.debug("Stored new RemoteRepository: {}. (successful? {})", rr, result);
                    job.implied.add(rr);
                } catch (final IndyDataException e) {
                    logger.error(String.format("Cannot add implied remote repo: %s from: %s (transfer: %s). Failed to store new remote repository.", repo.getUrl(), gav, job.transfer), e);
                }
            } else {
                logger.debug("Found existing RemoteRepositories: {}", rrs);
                for (final RemoteRepository rr : rrs) {
                    rr.setMetadata(METADATA_ORIGIN, IMPLIED_REPO_ORIGIN);
                    try {
                        metadataManager.updateImpliedBy(rr, job.store);
                    } catch (ImpliedReposException e) {
                        logger.error("Failed to set {}", IMPLIED_BY_STORES);
                        continue;
                    }
                    final String changelog = String.format("Updating the existing remote repository: %s (url: %s, name: %s), which is implied by the POM: %s (at: %s/%s)", repo.getId(), repo.getUrl(), repo.getName(), gav, job.transfer.getLocation().getUri(), job.transfer.getPath());
                    final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, changelog);
                    try {
                        final boolean result = storeManager.storeArtifactStore(rr, summary, false, false, null);
                        logger.debug("Updated the RemoteRepository: {}. (successful? {})", rr, result);
                        job.implied.add(rr);
                    } catch (final IndyDataException e) {
                        logger.error(String.format("Cannot add implied remote repo: %s from: %s (transfer: %s). Failed to update the remote repository.", repo.getUrl(), gav, job.transfer), e);
                    }
                }
            }
        }
    }
}
Also used : Arrays(java.util.Arrays) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) LoggerFactory(org.slf4j.LoggerFactory) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StringUtils(org.apache.commons.lang3.StringUtils) WeftManaged(org.commonjava.cdi.util.weft.WeftManaged) FileStorageEvent(org.commonjava.maven.galley.event.FileStorageEvent) MavenPomReader(org.commonjava.maven.galley.maven.parse.MavenPomReader) Observes(javax.enterprise.event.Observes) ArtifactStoreValidator(org.commonjava.indy.data.ArtifactStoreValidator) CoreEventManagerConstants(org.commonjava.indy.change.event.CoreEventManagerConstants) ImpliedReposException(org.commonjava.indy.implrepo.ImpliedReposException) StoreKey(org.commonjava.indy.model.core.StoreKey) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) ArtifactPathInfo(org.commonjava.atlas.maven.ident.util.ArtifactPathInfo) IndyGroovyException(org.commonjava.indy.subsys.template.IndyGroovyException) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) Collection(java.util.Collection) IMPLIED_REPO_ORIGIN(org.commonjava.indy.implrepo.data.ImpliedReposStoreDataManagerDecorator.IMPLIED_REPO_ORIGIN) METADATA_ORIGIN(org.commonjava.indy.model.core.ArtifactStore.METADATA_ORIGIN) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) ProjectVersionRef(org.commonjava.atlas.maven.ident.ref.ProjectVersionRef) IMPLIED_BY_STORES(org.commonjava.indy.implrepo.data.ImpliedRepoMetadataManager.IMPLIED_BY_STORES) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) Group(org.commonjava.indy.model.core.Group) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Transfer(org.commonjava.maven.galley.model.Transfer) RepositoryView(org.commonjava.maven.galley.maven.model.view.RepositoryView) ImpliedRepoConfig(org.commonjava.indy.implrepo.conf.ImpliedRepoConfig) ExecutorConfig(org.commonjava.cdi.util.weft.ExecutorConfig) IMPLIED_STORES(org.commonjava.indy.implrepo.data.ImpliedRepoMetadataManager.IMPLIED_STORES) Location(org.commonjava.maven.galley.model.Location) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) MalformedURLException(java.net.MalformedURLException) Executor(java.util.concurrent.Executor) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ScriptEngine(org.commonjava.indy.subsys.template.ScriptEngine) ImpliedRepoMetadataManager(org.commonjava.indy.implrepo.data.ImpliedRepoMetadataManager) Collections(java.util.Collections) StoreDataManager(org.commonjava.indy.data.StoreDataManager) MalformedURLException(java.net.MalformedURLException) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) RepositoryView(org.commonjava.maven.galley.maven.model.view.RepositoryView) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) ProjectVersionRef(org.commonjava.atlas.maven.ident.ref.ProjectVersionRef) List(java.util.List) ArrayList(java.util.ArrayList) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ImpliedReposException(org.commonjava.indy.implrepo.ImpliedReposException)

Example 3 with ProjectVersionRef

use of org.commonjava.atlas.maven.ident.ref.ProjectVersionRef in project indy by Commonjava.

the class AbstractHttproxFunctionalTest method loadPom.

protected PomRef loadPom(final String name, final Map<String, String> substitutions) {
    try {
        final InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(name.endsWith(".pom") ? name : name + ".pom");
        String pom = IOUtils.toString(stream);
        IOUtils.closeQuietly(stream);
        for (final Map.Entry<String, String> entry : substitutions.entrySet()) {
            pom = pom.replace("@" + entry.getKey() + "@", entry.getValue());
        }
        final PomPeek peek = new PomPeek(pom, false);
        final ProjectVersionRef gav = peek.getKey();
        final String path = String.format("%s/%s/%s/%s-%s.pom", gav.getGroupId().replace('.', '/'), gav.getArtifactId(), gav.getVersionString(), gav.getArtifactId(), gav.getVersionString());
        return new PomRef(pom, path);
    } catch (final Exception e) {
        e.printStackTrace();
        fail("Failed to read POM from: " + name);
    }
    return null;
}
Also used : InputStream(java.io.InputStream) ProjectVersionRef(org.commonjava.atlas.maven.ident.ref.ProjectVersionRef) PomPeek(org.commonjava.maven.galley.maven.parse.PomPeek) Map(java.util.Map) IOException(java.io.IOException)

Example 4 with ProjectVersionRef

use of org.commonjava.atlas.maven.ident.ref.ProjectVersionRef in project indy by Commonjava.

the class HttpProxyTest method loadPom.

protected PomRef loadPom(final String name, final Map<String, String> substitutions) {
    try {
        final String resource = name.endsWith(".pom") ? name : name + ".pom";
        logger.info("Loading POM: {}", resource);
        final InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
        String pom = IOUtils.toString(stream);
        IOUtils.closeQuietly(stream);
        for (final Map.Entry<String, String> entry : substitutions.entrySet()) {
            pom = pom.replace("@" + entry.getKey() + "@", entry.getValue());
        }
        final PomPeek peek = new PomPeek(pom, false);
        final ProjectVersionRef gav = peek.getKey();
        final String path = String.format("%s/%s/%s/%s-%s.pom", gav.getGroupId().replace('.', '/'), gav.getArtifactId(), gav.getVersionString(), gav.getArtifactId(), gav.getVersionString());
        return new PomRef(pom, path);
    } catch (final Exception e) {
        e.printStackTrace();
        fail("Failed to read POM from: " + name);
    }
    return null;
}
Also used : InputStream(java.io.InputStream) ProjectVersionRef(org.commonjava.atlas.maven.ident.ref.ProjectVersionRef) PomPeek(org.commonjava.maven.galley.maven.parse.PomPeek) Map(java.util.Map)

Example 5 with ProjectVersionRef

use of org.commonjava.atlas.maven.ident.ref.ProjectVersionRef in project indy by Commonjava.

the class AbstractSkimFunctionalTest method loadPom.

protected PomRef loadPom(final String name, final Map<String, String> substitutions) {
    try {
        final InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(name + ".pom");
        String pom = IOUtils.toString(stream);
        IOUtils.closeQuietly(stream);
        for (final Map.Entry<String, String> entry : substitutions.entrySet()) {
            pom = pom.replace("@" + entry.getKey() + "@", entry.getValue());
        }
        final PomPeek peek = new PomPeek(pom, false);
        final ProjectVersionRef gav = peek.getKey();
        final String path = String.format("%s/%s/%s/%s-%s.pom", gav.getGroupId().replace('.', '/'), gav.getArtifactId(), gav.getVersionString(), gav.getArtifactId(), gav.getVersionString());
        return new PomRef(pom, path);
    } catch (final Exception e) {
        e.printStackTrace();
        fail("Failed to read POM from: " + name);
    }
    return null;
}
Also used : InputStream(java.io.InputStream) ProjectVersionRef(org.commonjava.atlas.maven.ident.ref.ProjectVersionRef) PomPeek(org.commonjava.maven.galley.maven.parse.PomPeek) Map(java.util.Map) IOException(java.io.IOException)

Aggregations

ProjectVersionRef (org.commonjava.atlas.maven.ident.ref.ProjectVersionRef)5 InputStream (java.io.InputStream)3 Map (java.util.Map)3 PomPeek (org.commonjava.maven.galley.maven.parse.PomPeek)3 IOException (java.io.IOException)2 ArtifactPathInfo (org.commonjava.atlas.maven.ident.util.ArtifactPathInfo)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Set (java.util.Set)1 Executor (java.util.concurrent.Executor)1 ExecutorService (java.util.concurrent.ExecutorService)1 Collectors (java.util.stream.Collectors)1 Observes (javax.enterprise.event.Observes)1 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang3.StringUtils)1