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

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

Introduction

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

Prototype

@Deprecated
    boolean isBlacklisted();

Source Link

Usage

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

License:Apache License

/**
 * ???/*from   w  w w. ja v  a  2 s  .co  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.org.maven.plugin.dws.utils.RepositoryUtils.java

License:Apache License

/**
 * @param repo not null//from   www. ja va2s. c om
 * @param artifact not null
 * @return <code>true</code> if the artifact exists in the given repo, <code>false</code> otherwise or if
 * the repo is blacklisted.
 */
public boolean dependencyExistsInRepo(ArtifactRepository repo, Artifact artifact) {
    if (repo.isBlacklisted()) {
        if (log.isDebugEnabled()) {
            log.debug("The repo '" + repo.getId() + "' is black listed - Ignored it");
        }
        return false;
    }

    String id = repo.getId();
    Repository repository = new Repository(id, repo.getUrl());

    Wagon wagon;
    try {
        wagon = wagonManager.getWagon(repository);
    } catch (UnsupportedProtocolException e) {
        log.error("Unsupported protocol: '" + repo.getProtocol() + "'", e);
        return false;
    } catch (WagonConfigurationException e) {
        log.error("Unsupported protocol: '" + repo.getProtocol() + "'", e);
        return false;
    }

    if (log.isDebugEnabled()) {
        Debug debug = new Debug();

        wagon.addSessionListener(debug);
        wagon.addTransferListener(debug);
    }

    try {
        AuthenticationInfo auth = wagonManager.getAuthenticationInfo(repo.getId());

        ProxyInfo proxyInfo = getProxyInfo();
        if (proxyInfo != null) {
            wagon.connect(repository, auth, proxyInfo);
        } else {
            wagon.connect(repository, auth);
        }

        return wagon.resourceExists(
                StringUtils.replace(getDependencyUrlFromRepository(artifact, repo), repo.getUrl(), ""));
    } catch (ConnectionException e) {
        if (log.isDebugEnabled()) {
            log.error("Unable to connect to: " + repo.getUrl(), e);
        } else {
            log.error("Unable to connect to: " + repo.getUrl());
        }
        return false;
    } catch (AuthenticationException e) {
        if (log.isDebugEnabled()) {
            log.error("Unable to connect to: " + repo.getUrl(), e);
        } else {
            log.error("Unable to connect to: " + repo.getUrl());
        }
        return false;
    } catch (TransferFailedException e) {
        if (log.isDebugEnabled()) {
            log.error("Unable to determine if resource " + artifact + " exists in " + repo.getUrl(), e);
        } else {
            log.error("Unable to determine if resource " + artifact + " exists in " + repo.getUrl());
        }
        return false;
    } catch (AuthorizationException e) {
        if (log.isDebugEnabled()) {
            log.error("Unable to connect to: " + repo.getUrl(), e);
        } else {
            log.error("Unable to connect to: " + repo.getUrl());
        }
        return false;
    } catch (AbstractMethodError e) {
        log.error("Wagon " + wagon.getClass().getName() + " does not support the resourceExists method");
        return false;
    } finally {
        try {
            wagon.disconnect();
        } catch (ConnectionException e) {
            if (log.isDebugEnabled()) {
                log.error("Error disconnecting wagon - ignored", e);
            } else {
                log.error("Error disconnecting wagon - ignored");
            }
        }
    }
}

From source file:org.org.maven.plugin.dws.utils.RepositoryUtils.java

License:Apache License

/**
 * @param artifact not null// w w  w . j a va 2s  .c om
 * @param repo not null
 * @return the artifact url in the given repo for the given artifact. If it is a snapshot artifact, the version
 * will be the timestamp and the build number from the metadata. Could return null if the repo is blacklisted.
 */
public String getDependencyUrlFromRepository(Artifact artifact, ArtifactRepository repo) {
    if (repo.isBlacklisted()) {
        return null;
    }

    Artifact copyArtifact = ArtifactUtils.copyArtifact(artifact);
    // Try to get the last artifact repo name depending the snapshot version
    if ((artifact.isSnapshot() && repo.getSnapshots().isEnabled())) {
        if (artifact.getBaseVersion().equals(artifact.getVersion())) {
            // Try to resolve it if not already done
            if (artifact.getMetadataList() == null || artifact.getMetadataList().isEmpty()) {
                try {
                    resolve(artifact);
                } catch (ArtifactResolutionException e) {
                    log.error("Artifact: " + artifact.getId() + " could not be resolved.");
                } catch (ArtifactNotFoundException e) {
                    log.error("Artifact: " + artifact.getId() + " was not found.");
                }
            }

            for (Iterator it = artifact.getMetadataList().iterator(); it.hasNext();) {
                ArtifactMetadata m = (ArtifactMetadata) it.next();

                if (m instanceof SnapshotArtifactRepositoryMetadata) {
                    SnapshotArtifactRepositoryMetadata snapshotMetadata = (SnapshotArtifactRepositoryMetadata) m;

                    // Removed not found log
                    int oldThreshold = loggerManager.getThreshold();
                    loggerManager.setThreshold(RepositoryMetadataManager.class.getName(),
                            Logger.LEVEL_DISABLED);
                    try {
                        repositoryMetadataManager.resolveAlways(snapshotMetadata, localRepository, repo);
                    } catch (RepositoryMetadataResolutionException e) {
                        loggerManager.setThreshold(RepositoryMetadataManager.class.getName(), oldThreshold);
                        if (log.isDebugEnabled()) {
                            log.error("Unable to connect to: " + repo.getUrl(), e);
                        } else {
                            log.error("Unable to connect to: " + repo.getUrl());
                        }
                        return repo.getUrl() + "/" + repo.pathOf(copyArtifact);
                    } finally {
                        loggerManager.setThreshold(RepositoryMetadataManager.class.getName(), oldThreshold);
                    }

                    Metadata metadata = snapshotMetadata.getMetadata();
                    if (metadata.getVersioning() == null || metadata.getVersioning().getSnapshot() == null
                            || metadata.getVersioning().getSnapshot().isLocalCopy()
                            || metadata.getVersioning().getSnapshot().getTimestamp() == null) {
                        continue;
                    }

                    // create the version according SnapshotTransformation
                    String version = StringUtils.replace(copyArtifact.getVersion(), Artifact.SNAPSHOT_VERSION,
                            metadata.getVersioning().getSnapshot().getTimestamp()) + "-"
                            + metadata.getVersioning().getSnapshot().getBuildNumber();
                    copyArtifact.setVersion(version);
                }
            }
        }
    }

    return repo.getUrl() + "/" + repo.pathOf(copyArtifact);
}