Example usage for org.apache.maven.artifact.repository ArtifactRepository getReleases

List of usage examples for org.apache.maven.artifact.repository ArtifactRepository getReleases

Introduction

In this page you can find the example usage for org.apache.maven.artifact.repository ArtifactRepository getReleases.

Prototype

ArtifactRepositoryPolicy getReleases();

Source Link

Usage

From source file:com.rebaze.maven.support.AetherUtils.java

License:Open Source License

public static RemoteRepository toRepo(ArtifactRepository repo) {
    RemoteRepository result = null;//from w w w .  ja  v  a2s. c  o  m
    if (repo != null) {
        RemoteRepository.Builder builder = new RemoteRepository.Builder(repo.getId(), getLayout(repo),
                repo.getUrl());
        builder.setSnapshotPolicy(toPolicy(repo.getSnapshots()));
        builder.setReleasePolicy(toPolicy(repo.getReleases()));
        builder.setAuthentication(toAuthentication(repo.getAuthentication()));
        builder.setProxy(toProxy(repo.getProxy()));
        builder.setMirroredRepositories(toRepos(repo.getMirroredRepositories()));
        result = builder.build();
    }
    return result;
}

From source file:com.unibet.maven.DependencyMetadataGenerateMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    Artifact artifact = project.getArtifact();
    List<ArtifactVersion> versions = new ArrayList<>(1);
    try {//w w  w  .  ja  va2  s  .  com
        versions.add(artifact.getSelectedVersion());
    } catch (OverConstrainedVersionException e) {
        throw new MojoFailureException("Failed getting selected version for artifact " + artifact, e);
    }

    if (applyOnPreviousVersions) {
        // Enable both releases and snapshot repositories and always update the metadata
        for (ArtifactRepository repository : remoteRepositories) {
            repository.getReleases().setUpdatePolicy(UPDATE_POLICY_ALWAYS);
            repository.getReleases().setEnabled(true);
            repository.getSnapshots().setUpdatePolicy(UPDATE_POLICY_ALWAYS);
            repository.getSnapshots().setEnabled(true);
        }
        versions.addAll(getLowerVersions(artifact));
    }

    for (ArtifactVersion version : versions) {
        Artifact metadataArtifact = artifactFactory.createArtifactWithClassifier(artifact.getGroupId(),
                artifact.getArtifactId(), version.toString(), METADATA_ARTIFACT_TYPE,
                METADATA_ARTIFACT_CLASSIFIER);
        try {
            logger.debug("Resolving metadata artifact {} in {} and {}", metadataArtifact, remoteRepositories,
                    logger);
            resolver.resolve(metadataArtifact, remoteRepositories, localRepository);
            logger.info("Metadata artifact {} already exists. Skipping...", metadataArtifact);
        } catch (ArtifactResolutionException e) {
            throw new MojoExecutionException("Failed resolving metadata artifact " + metadataArtifact, e);
        } catch (ArtifactNotFoundException e) {
            logger.debug("Metadata artifact {} not found", metadataArtifact);

            String filename = project.getArtifactId() + "-" + version.toString() + "-"
                    + METADATA_ARTIFACT_CLASSIFIER + "." + METADATA_ARTIFACT_TYPE;
            File artifactFile = new File(project.getBuild().getDirectory() + File.separator + filename);

            Metadata metadata = new Metadata();
            metadata.formatVersion = this.formatVersion;
            metadata.message = this.message;
            metadata.fail = this.fail;

            new File(project.getBuild().getDirectory()).mkdirs();
            try {
                OBJECT_MAPPER.writeValue(artifactFile, metadata);
            } catch (IOException ioe) {
                throw new MojoFailureException("Failed creating metadata artifact file " + artifactFile, ioe);
            }
            project.addAttachedArtifact(metadataArtifact);
            logger.info("Metadata artifact generated: {}", artifactFile);
        }
    }
}

From source file:nl.pieni.maven.dependency_analyzer.repository.remote.RemoteRepositorySearcher.java

License:Apache License

/**
 * Can this repo be used/*from   w  ww.  ja va 2s  . c om*/
 * @param repository the repo
 * @param allowSnapshots snapshots allowed
 * @return true when valid
 */
private boolean useableRepository(final ArtifactRepository repository, final boolean allowSnapshots) {
    boolean snapshots = repository.getSnapshots().isEnabled() || allowSnapshots;
    return repository.getReleases().isEnabled() && snapshots;
}

From source file:org.apache.marmotta.maven.plugins.repochecker.RepositoryCheckerMojo.java

License:Apache License

private Result lookupArtifact(Artifact artifact, ArtifactRepository rep, DefaultHttpClient client) {

    if (artifact.isSnapshot() && !rep.getSnapshots().isEnabled()) {
        return Result.NOT_FOUND;
    }/*from w w w .  j av  a2 s  . c  o m*/
    if (artifact.isRelease() && !rep.getReleases().isEnabled()) {
        return Result.NOT_FOUND;
    }

    try {
        final String baseUrl = rep.getUrl().replaceAll("/$", "") + "/";

        if (client.execute(new HttpHead(baseUrl + buildRelUrl(artifact)), fileExistsHandler)) {
            return Result.FOUND;
        }
        if (artifact.isSnapshot()) {
            // now check for a timestamp version
            final String fName = client.execute(new HttpGet(baseUrl + buildArtifactDir(artifact) + META_XML),
                    createTimestampHandler(artifact));
            if (fName != null && client.execute(new HttpHead(baseUrl + buildArtifactDir(artifact) + fName),
                    fileExistsHandler)) {
                return Result.FOUND;
            } else {
                return Result.NOT_FOUND;
            }
        } else {
            return Result.NOT_FOUND;
        }
    } catch (IOException e) {
        return Result.ERROR;
    }
}

From source file:org.ck.maven.plugins.pom.versions.service.version.PomVersionRepositoryMetadataManager.java

License:Apache License

/**
 * ???/*from ww  w .  j  a  v a2s. c  o m*/
 * metadata ???
 * remoteRepositories maven
 * localRepository maven
 */
public void resolve(RepositoryMetadata metadata, List remoteRepositories, ArtifactRepository localRepository)
        throws RepositoryMetadataResolutionException {
    this.getLogger().debug("use " + this.getClass().getName());
    boolean alreadyResolved = alreadyResolved(metadata);
    if (!alreadyResolved) {
        for (Iterator i = remoteRepositories.iterator(); i.hasNext();) {
            ArtifactRepository repository = (ArtifactRepository) i.next();

            ArtifactRepositoryPolicy policy = metadata.isSnapshot() ? repository.getSnapshots()
                    : repository.getReleases();

            if (!policy.isEnabled()) {
                getLogger().debug("Skipping disabled repository " + repository.getId());
            } else if (repository.isBlacklisted()) {
                getLogger().debug("Skipping blacklisted repository " + repository.getId());
            } else {
                File file = new File(localRepository.getBasedir(),
                        localRepository.pathOfLocalRepositoryMetadata(metadata, repository));

                boolean checkForUpdates = !file.exists()
                        || policy.checkOutOfDate(new Date(file.lastModified()));

                if (checkForUpdates) {
                    if (wagonManager.isOnline()) {
                        getLogger()
                                .debug(metadata.getKey() + ": checking for updates from " + repository.getId());

                        boolean storeMetadata = false;
                        try {
                            wagonManager.getArtifactMetadata(metadata, repository, file,
                                    policy.getChecksumPolicy());
                            storeMetadata = true;
                        } catch (ResourceDoesNotExistException e) {
                            getLogger().debug(
                                    metadata + " could not be found on repository: " + repository.getId());

                            // delete the local copy so the old details aren't used.
                            if (file.exists()) {
                                file.delete();
                            }
                            storeMetadata = true;
                        } catch (TransferFailedException e) {
                            getLogger().warn(metadata + " could not be retrieved from repository: "
                                    + repository.getId() + " due to an error: " + e.getMessage());
                            getLogger().debug("Exception", e);

                            getLogger().info("Repository '" + repository.getId() + "' will be blacklisted");
                            repository.setBlacklisted(true);

                            // TODO: [jc; 08-Nov-2005] revisit this for 2.1
                            // suppressing logging to avoid logging this error twice.
                        }
                        if (storeMetadata) {
                            // touch file so that this is not checked again until interval has passed
                            if (file.exists()) {
                                file.setLastModified(System.currentTimeMillis());
                            } else {
                                //??
                                // this ensures that files are not continuously checked when they don't exist remotely

                                // TODO: [jdcasey] If this happens as a result of ResourceDoesNotExistException, what effect will it have on subsequent runs?
                                // Will the updateInterval come into play cleanly, or will this plug up the works??
                                try {
                                    metadata.storeInLocalRepository(localRepository, repository);
                                } catch (RepositoryMetadataStoreException e) {
                                    throw new RepositoryMetadataResolutionException(
                                            "Unable to store local copy of metadata: " + e.getMessage(), e);
                                }
                            }
                        }
                    } else {
                        getLogger().debug("System is offline. Cannot resolve metadata:\n"
                                + metadata.extendedToString() + "\n\n");
                    }
                }
            }
        }

        // TODO: [jdcasey] what happens here when the system is offline, or there is a TransferFailedException
        // ...and no metadata file is written?
        cachedMetadata.add(metadata.getKey());
    }

    try {
        mergeMetadata(metadata, remoteRepositories, localRepository);
    } catch (RepositoryMetadataStoreException e) {
        throw new RepositoryMetadataResolutionException(
                "Unable to store local copy of metadata: " + e.getMessage(), e);
    } catch (RepositoryMetadataReadException e) {
        throw new RepositoryMetadataResolutionException(
                "Unable to read local copy of metadata: " + e.getMessage(), e);
    }
}

From source file:org.ck.maven.plugins.pom.versions.service.version.PomVersionRepositoryMetadataManager.java

License:Apache License

private void mergeMetadata(RepositoryMetadata metadata, List remoteRepositories,
        ArtifactRepository localRepository)
        throws RepositoryMetadataStoreException, RepositoryMetadataReadException {
    // TODO: currently this is first wins, but really we should take the latest by comparing either the
    // snapshot timestamp, or some other timestamp later encoded into the metadata.
    // TODO: this needs to be repeated here so the merging doesn't interfere with the written metadata
    //  - we'd be much better having a pristine input, and an ongoing metadata for merging instead

    Map previousMetadata = new HashMap();
    ArtifactRepository selected = null;//from   www  .  j  a  v a2  s  .  co  m
    for (Iterator i = remoteRepositories.iterator(); i.hasNext();) {
        ArtifactRepository repository = (ArtifactRepository) i.next();

        ArtifactRepositoryPolicy policy = metadata.isSnapshot() ? repository.getSnapshots()
                : repository.getReleases();

        if (policy.isEnabled() && loadMetadata(metadata, repository, localRepository, previousMetadata)) {
            metadata.setRepository(repository);
            selected = repository;
        }
    }
    //        if ( loadMetadata( metadata, localRepository, localRepository, previousMetadata ) )
    //        {
    //            metadata.setRepository( null );
    //            selected = localRepository;
    //        }

    updateSnapshotMetadata(metadata, previousMetadata, selected, localRepository);
}

From source file:org.commonjava.maven.ext.io.resolver.MavenLocationExpander.java

License:Apache License

private void addRequestRepositoriesTo(final Set<Location> locs,
        final List<ArtifactRepository> artifactRepositories, final Settings settings,
        final MirrorSelector mirrorSelector) throws MalformedURLException {
    if (artifactRepositories != null) {
        for (final ArtifactRepository repo : artifactRepositories) {
            // TODO: Authentication via memory password manager.
            String id = repo.getId();
            String url = repo.getUrl();

            if (url.startsWith("file:")) {
                locs.add(new SimpleLocation(id, url));
            } else {
                final List<Mirror> mirrors = settings.getMirrors();
                if (mirrors != null) {
                    final Mirror mirror = mirrorSelector == null ? null
                            : mirrorSelector.getMirror(repo, mirrors);
                    if (mirror != null) {
                        id = mirror.getId();
                        url = mirror.getUrl();
                    }//from  w  ww  .j  a va 2 s . com
                }

                final ArtifactRepositoryPolicy releases = repo.getReleases();
                final ArtifactRepositoryPolicy snapshots = repo.getSnapshots();

                SimpleHttpLocation addition = new SimpleHttpLocation(id, url,
                        snapshots != null && snapshots.isEnabled(), releases == null || releases.isEnabled(),
                        true, false, null);

                addition.setAttribute(Location.CONNECTION_TIMEOUT_SECONDS, 60);

                locs.add(addition);
            }
        }
    }
}

From source file:org.commonjava.maven.ext.manip.resolver.MavenLocationExpander.java

License:Open Source License

private void addRequestRepositoriesTo(final Set<Location> locs,
        final List<ArtifactRepository> artifactRepositories, final Settings settings,
        final MirrorSelector mirrorSelector) throws MalformedURLException {
    if (artifactRepositories != null) {
        for (final ArtifactRepository repo : artifactRepositories) {
            // TODO: Authentication via memory password manager.
            String id = repo.getId();
            String url = repo.getUrl();

            if (url.startsWith("file:")) {
                locs.add(new SimpleLocation(id, url));
            } else {
                final List<Mirror> mirrors = settings.getMirrors();
                if (mirrors != null) {
                    final Mirror mirror = mirrorSelector == null ? null
                            : mirrorSelector.getMirror(repo, mirrors);
                    if (mirror != null) {
                        id = mirror.getId();
                        url = mirror.getUrl();
                    }/*from   w ww  .j  ava 2 s.c  om*/
                }

                final ArtifactRepositoryPolicy releases = repo.getReleases();
                final ArtifactRepositoryPolicy snapshots = repo.getSnapshots();

                SimpleHttpLocation addition = new SimpleHttpLocation(id, url,
                        snapshots == null ? false : snapshots.isEnabled(),
                        releases == null ? true : releases.isEnabled(), true, false, null);

                addition.setAttribute(Location.CONNECTION_TIMEOUT_SECONDS, 60);

                locs.add(addition);
            }
        }
    }
}

From source file:org.commonjava.maven.plugins.betterdep.impl.MavenLocationExpander.java

License:Open Source License

public MavenLocationExpander(final List<Location> customLocations,
        final List<ArtifactRepository> artifactRepositories, final ArtifactRepository localRepository)
        throws MalformedURLException, URISyntaxException {
    final Set<Location> locs = new LinkedHashSet<Location>();
    final Set<URI> uris = new HashSet<URI>();

    if (localRepository != null) {
        locs.add(new SimpleLocation(new File(localRepository.getBasedir()).toURI().toString()));
    }/*w  w w  .j av a2  s  .co  m*/

    if (customLocations != null) {
        locs.addAll(customLocations);
    }

    for (final ArtifactRepository repo : artifactRepositories) {
        // TODO: Authentication via memory password manager.
        final String url = repo.getUrl();
        uris.add(new URI(url));

        if (url.startsWith("file:")) {
            locs.add(new SimpleLocation(url));
        } else {
            final ArtifactRepositoryPolicy releases = repo.getReleases();
            final ArtifactRepositoryPolicy snapshots = repo.getSnapshots();
            locs.add(new SimpleHttpLocation(url, url, snapshots != null && snapshots.isEnabled(),
                    releases == null || releases.isEnabled(), true, false, null));
        }
    }

    this.locationUris = new ArrayList<URI>(uris);
    this.locations = new ArrayList<Location>(locs);
}

From source file:org.duguo.maven.plugins.proxy.RepoAutoMojo.java

License:Apache License

protected List<Repository> convertArtifactToWagonRepos(List<ArtifactRepository> remoteArtifactRepositories) {
    List<Repository> wagonRepos = new ArrayList<Repository>();
    for (ArtifactRepository artifactRepository : remoteArtifactRepositories) {
        if (artifactRepository.getReleases().isEnabled()) {
            addWagonOnlyIfSupportedProtocol(wagonRepos, artifactRepository.getId(),
                    artifactRepository.getUrl());
        }//from   w w w . j  av a2  s.  co m
    }
    return wagonRepos;
}