Example usage for org.apache.maven.artifact.repository ArtifactRepositoryPolicy isEnabled

List of usage examples for org.apache.maven.artifact.repository ArtifactRepositoryPolicy isEnabled

Introduction

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

Prototype

public boolean isEnabled() 

Source Link

Usage

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

License:Open Source License

private static RepositoryPolicy toPolicy(ArtifactRepositoryPolicy policy) {
    RepositoryPolicy result = null;/*w w w  .  j  ava  2s  .  c o m*/
    if (policy != null) {
        result = new RepositoryPolicy(policy.isEnabled(), policy.getUpdatePolicy(), policy.getChecksumPolicy());
    }
    return result;
}

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

License:Apache License

/**
 * ???/*from  w  w  w. j a  v  a2  s  .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  ww  w .ja va 2 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 w  w.j  a  v a2 s  . c  o  m
                }

                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.io.resolver.MavenLocationExpander.java

License:Apache License

private void addSettingsProfileRepositoriesTo(final Set<Location> locs, final Settings settings,
        final List<String> activeProfiles, final MirrorSelector mirrorSelector) throws MalformedURLException {
    if (settings != null) {
        final Map<String, Profile> profiles = settings.getProfilesAsMap();
        if (profiles != null && activeProfiles != null && !activeProfiles.isEmpty()) {
            final LinkedHashSet<String> active = new LinkedHashSet<>(activeProfiles);

            final List<String> settingsActiveProfiles = settings.getActiveProfiles();
            if (settingsActiveProfiles != null && !settingsActiveProfiles.isEmpty()) {
                active.addAll(settingsActiveProfiles);
            }//from  w  w  w  .j a  va2 s  .c o m

            for (final String profileId : active) {
                final Profile profile = profiles.get(profileId);
                if (profile != null) {
                    final List<Repository> repositories = profile.getRepositories();
                    if (repositories != null) {
                        final List<Mirror> mirrors = settings.getMirrors();
                        final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
                        for (final Repository repo : repositories) {
                            String id = repo.getId();
                            String url = repo.getUrl();

                            if (mirrors != null) {
                                final ArtifactRepositoryPolicy snapshots = convertPolicy(repo.getSnapshots());
                                final ArtifactRepositoryPolicy releases = convertPolicy(repo.getReleases());

                                final MavenArtifactRepository arepo = new MavenArtifactRepository(id, url,
                                        layout, snapshots, releases);

                                final Mirror mirror = mirrorSelector == null ? null
                                        : mirrorSelector.getMirror(arepo, mirrors);

                                if (mirror != null) {
                                    id = mirror.getId();
                                    url = mirror.getUrl();
                                }

                                SimpleHttpLocation addition = new SimpleHttpLocation(id, url,
                                        snapshots.isEnabled(), 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();
                    }//  w  ww . j  a  v  a 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.ext.manip.resolver.MavenLocationExpander.java

License:Open Source License

private void addSettingsProfileRepositoriesTo(final Set<Location> locs, final Settings settings,
        final List<String> activeProfiles, final MirrorSelector mirrorSelector) throws MalformedURLException {
    if (settings != null) {
        final Map<String, Profile> profiles = settings.getProfilesAsMap();
        if (profiles != null && activeProfiles != null && !activeProfiles.isEmpty()) {
            final LinkedHashSet<String> active = new LinkedHashSet<String>(activeProfiles);

            final List<String> settingsActiveProfiles = settings.getActiveProfiles();
            if (settingsActiveProfiles != null && !settingsActiveProfiles.isEmpty()) {
                active.addAll(settingsActiveProfiles);
            }// w ww.  j a v  a  2  s  .  c  o  m

            for (final String profileId : active) {
                final Profile profile = profiles.get(profileId);
                if (profile != null) {
                    final List<Repository> repositories = profile.getRepositories();
                    if (repositories != null) {
                        final List<Mirror> mirrors = settings.getMirrors();
                        final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
                        for (final Repository repo : repositories) {
                            String id = repo.getId();
                            String url = repo.getUrl();

                            if (mirrors != null) {
                                final ArtifactRepositoryPolicy snapshots = convertPolicy(repo.getSnapshots());
                                final ArtifactRepositoryPolicy releases = convertPolicy(repo.getReleases());

                                final MavenArtifactRepository arepo = new MavenArtifactRepository(id, url,
                                        layout, snapshots, releases);

                                final Mirror mirror = mirrorSelector == null ? null
                                        : mirrorSelector.getMirror(arepo, mirrors);

                                if (mirror != null) {
                                    id = mirror.getId();
                                    url = mirror.getUrl();
                                }

                                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 ww  .  ja  v  a  2s.  c  o  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.springframework.boot.loader.thin.DependencyResolver.java

License:Apache License

private RepositoryPolicy policy(ArtifactRepositoryPolicy input) {
    RepositoryPolicy policy = new RepositoryPolicy(input.isEnabled(), RepositoryPolicy.UPDATE_POLICY_DAILY,
            RepositoryPolicy.CHECKSUM_POLICY_WARN);
    return policy;
}

From source file:org.wildfly.swarm.plugin.maven.MavenArtifactResolvingHelper.java

License:Apache License

private RemoteRepository buildRemoteRepository(final String id, final String url, final Authentication auth,
        final ArtifactRepositoryPolicy releasesPolicy, final ArtifactRepositoryPolicy snapshotsPolicy) {
    RemoteRepository.Builder builder = new RemoteRepository.Builder(id, "default", url);
    if (auth != null && auth.getUsername() != null && auth.getPassword() != null) {
        builder.setAuthentication(new AuthenticationBuilder().addUsername(auth.getUsername())
                .addPassword(auth.getPassword()).build());
    }/*from w w w  .  j  a  va 2s . co m*/

    builder.setSnapshotPolicy(new RepositoryPolicy(snapshotsPolicy.isEnabled(),
            snapshotsPolicy.getUpdatePolicy(), snapshotsPolicy.getChecksumPolicy()));
    builder.setReleasePolicy(new RepositoryPolicy(releasesPolicy.isEnabled(), releasesPolicy.getUpdatePolicy(),
            releasesPolicy.getChecksumPolicy()));

    RemoteRepository repository = builder.build();

    final RemoteRepository mirror = session.getMirrorSelector().getMirror(repository);

    if (mirror != null) {
        final org.eclipse.aether.repository.Authentication mirrorAuth = session.getAuthenticationSelector()
                .getAuthentication(mirror);
        repository = mirrorAuth != null
                ? new RemoteRepository.Builder(mirror).setAuthentication(mirrorAuth).build()
                : mirror;
    }

    Proxy proxy = session.getProxySelector().getProxy(repository);

    if (proxy != null) {
        repository = new RemoteRepository.Builder(repository).setProxy(proxy).build();
    }

    return repository;
}