Search in sources :

Example 41 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.

the class DeployMojoTest method testAltReleaseDeploymentRepository.

public void testAltReleaseDeploymentRepository() throws Exception {
    DeployMojo mojo = spy(new DeployMojo());
    ArtifactRepository repository = mock(ArtifactRepository.class);
    when(mojo.createDeploymentArtifactRepository("altReleaseDeploymentRepository", "http://localhost")).thenReturn(repository);
    project.setVersion("1.0");
    ProjectDeployerRequest pdr = new ProjectDeployerRequest().setProject(project).setAltReleaseDeploymentRepository("altReleaseDeploymentRepository::http://localhost");
    assertEquals(repository, mojo.getDeploymentRepository(pdr));
}
Also used : ProjectDeployerRequest(org.apache.maven.shared.project.deploy.ProjectDeployerRequest) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Example 42 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.

the class DoapMojo method writeReleases.

/**
 * Write all DOAP releases.
 *
 * @param writer  not null
 * @param project the Maven project, not null
 * @throws MojoExecutionException if any
 * @see <a href="http://usefulinc.com/ns/doap#release">http://usefulinc.com/ns/doap#release</a>
 * @see <a href="http://usefulinc.com/ns/doap#Version">http://usefulinc.com/ns/doap#Version</a>
 */
private void writeReleases(XMLWriter writer, MavenProject project) throws MojoExecutionException {
    Artifact artifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), null, project.getPackaging());
    RepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact);
    for (ArtifactRepository repo : remoteRepositories) {
        if (repo.isBlacklisted()) {
            continue;
        }
        if (repo.getSnapshots().isEnabled()) {
            continue;
        }
        if (repo.getReleases().isEnabled()) {
            try {
                repositoryMetadataManager.resolveAlways(metadata, localRepository, repo);
                break;
            } catch (RepositoryMetadataResolutionException e) {
                throw new MojoExecutionException(metadata.extendedToString() + " could not be retrieved from repositories due to an error: " + e.getMessage(), e);
            }
        }
    }
    if (metadata.getMetadata().getVersioning() == null) {
        messages.getWarnMessages().add("No versioning was found for " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ". Ignored DOAP <release/> tag.");
        return;
    }
    List<String> versions = metadata.getMetadata().getVersioning().getVersions();
    // Recent releases in first
    Collections.reverse(versions);
    boolean addComment = false;
    int i = 0;
    for (String version : versions) {
        if (!addComment) {
            DoapUtil.writeComment(writer, "Project releases.");
            addComment = true;
        }
        DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "release");
        DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "Version");
        DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "name");
        if (version.equals(metadata.getMetadata().getVersioning().getRelease())) {
            writer.writeText("Latest stable release");
        } else {
            writer.writeText(project.getName() + " - " + version);
        }
        // name
        writer.endElement();
        DoapUtil.writeElement(writer, doapOptions.getXmlnsPrefix(), "revision", version);
        // list all file release from all remote repos
        for (ArtifactRepository repo : remoteRepositories) {
            Artifact artifactRelease = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), version, null, project.getPackaging());
            if (artifactRelease == null) {
                continue;
            }
            String fileRelease = repo.getUrl() + "/" + repo.pathOf(artifactRelease);
            try {
                DoapUtil.fetchURL(settings, new URL(fileRelease));
            } catch (IOException e) {
                getLog().debug("IOException :" + e.getMessage());
                continue;
            }
            DoapUtil.writeElement(writer, doapOptions.getXmlnsPrefix(), "file-release", fileRelease);
            Date releaseDate = null;
            try {
                releaseDate = REPOSITORY_DATE_FORMAT.parse(metadata.getMetadata().getVersioning().getLastUpdated());
            } catch (ParseException e) {
                getLog().error("Unable to parse date '" + metadata.getMetadata().getVersioning().getLastUpdated() + "'");
                continue;
            }
            // See MDOAP-11
            if (i == 0) {
                DoapUtil.writeElement(writer, doapOptions.getXmlnsPrefix(), "created", DOAP_DATE_FORMAT.format(releaseDate));
            }
        }
        // Version
        writer.endElement();
        // release
        writer.endElement();
        i++;
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) IOException(java.io.IOException) DoapArtifact(org.apache.maven.plugin.doap.options.DoapArtifact) Artifact(org.apache.maven.artifact.Artifact) URL(java.net.URL) Date(java.util.Date) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata) RepositoryMetadata(org.apache.maven.artifact.repository.metadata.RepositoryMetadata) ParseException(java.text.ParseException) RepositoryMetadataResolutionException(org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata)

Example 43 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.

the class RepositoryUtils method dependencyExistsInRepo.

/**
 * @param repo not null
 * @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;
    }
    if (UNKNOWN_HOSTS.contains(repo.getUrl())) {
        if (log.isDebugEnabled()) {
            log.debug("The repo url '" + repo.getUrl() + "' is unknown - Ignored it");
        }
        return false;
    }
    repo = wagonManager.getMirrorRepository(repo);
    String id = repo.getId();
    Repository repository = new Repository(id, repo.getUrl());
    Wagon wagon;
    try {
        wagon = wagonManager.getWagon(repository);
    } catch (UnsupportedProtocolException e) {
        logError("Unsupported protocol: '" + repo.getProtocol() + "'", e);
        return false;
    } catch (WagonConfigurationException e) {
        logError("Unsupported protocol: '" + repo.getProtocol() + "'", e);
        return false;
    }
    wagon.setTimeout(1000);
    if (log.isDebugEnabled()) {
        Debug debug = new Debug();
        wagon.addSessionListener(debug);
        wagon.addTransferListener(debug);
    }
    try {
        // FIXME when upgrading to maven 3.x : this must be changed.
        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) {
        logError("Unable to connect to: " + repo.getUrl(), e);
        return false;
    } catch (AuthenticationException e) {
        logError("Unable to connect to: " + repo.getUrl(), e);
        return false;
    } catch (TransferFailedException e) {
        if (e.getCause() instanceof UnknownHostException) {
            log.error("Unknown host " + e.getCause().getMessage() + " - ignored it");
            UNKNOWN_HOSTS.add(repo.getUrl());
        } else {
            logError("Unable to determine if resource " + artifact + " exists in " + repo.getUrl(), e);
        }
        return false;
    } catch (AuthorizationException e) {
        logError("Unable to connect to: " + repo.getUrl(), e);
        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) {
            logError("Error disconnecting wagon - ignored", e);
        }
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) AuthorizationException(org.apache.maven.wagon.authorization.AuthorizationException) WagonConfigurationException(org.apache.maven.artifact.manager.WagonConfigurationException) UnsupportedProtocolException(org.apache.maven.wagon.UnsupportedProtocolException) Wagon(org.apache.maven.wagon.Wagon) AuthenticationInfo(org.apache.maven.wagon.authentication.AuthenticationInfo) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) Repository(org.apache.maven.wagon.repository.Repository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) TransferFailedException(org.apache.maven.wagon.TransferFailedException) Debug(org.apache.maven.wagon.observers.Debug) ConnectionException(org.apache.maven.wagon.ConnectionException)

Example 44 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.

the class DependenciesRenderer method printRepositories.

private void printRepositories(Map<String, ArtifactRepository> repoMap, List<String> repoUrlBlackListed) {
    // i18n
    String repoid = getI18nString("repo.locations.column.repoid");
    String url = getI18nString("repo.locations.column.url");
    String release = getI18nString("repo.locations.column.release");
    String snapshot = getI18nString("repo.locations.column.snapshot");
    String blacklisted = getI18nString("repo.locations.column.blacklisted");
    String releaseEnabled = getI18nString("repo.locations.cell.release.enabled");
    String releaseDisabled = getI18nString("repo.locations.cell.release.disabled");
    String snapshotEnabled = getI18nString("repo.locations.cell.snapshot.enabled");
    String snapshotDisabled = getI18nString("repo.locations.cell.snapshot.disabled");
    String blacklistedEnabled = getI18nString("repo.locations.cell.blacklisted.enabled");
    String blacklistedDisabled = getI18nString("repo.locations.cell.blacklisted.disabled");
    // Table header
    String[] tableHeader;
    int[] justificationRepo;
    if (repoUrlBlackListed.isEmpty()) {
        tableHeader = new String[] { repoid, url, release, snapshot };
        justificationRepo = new int[] { Sink.JUSTIFY_LEFT, Sink.JUSTIFY_LEFT, Sink.JUSTIFY_CENTER, Sink.JUSTIFY_CENTER };
    } else {
        tableHeader = new String[] { repoid, url, release, snapshot, blacklisted };
        justificationRepo = new int[] { Sink.JUSTIFY_LEFT, Sink.JUSTIFY_LEFT, Sink.JUSTIFY_CENTER, Sink.JUSTIFY_CENTER, Sink.JUSTIFY_CENTER };
    }
    startTable(justificationRepo, false);
    tableHeader(tableHeader);
    for (ArtifactRepository repo : repoMap.values()) {
        List<ArtifactRepository> mirroredRepos = getMirroredRepositories(repo);
        sink.tableRow();
        sink.tableCell();
        boolean addLineBreak = false;
        for (ArtifactRepository r : mirroredRepos) {
            if (addLineBreak) {
                sink.lineBreak();
            }
            addLineBreak = true;
            sink.text(r.getId());
        }
        sink.tableCell_();
        sink.tableCell();
        addLineBreak = false;
        for (ArtifactRepository r : mirroredRepos) {
            if (addLineBreak) {
                sink.lineBreak();
            }
            addLineBreak = true;
            if (repo.isBlacklisted()) {
                sink.text(r.getUrl());
            } else {
                sink.link(r.getUrl());
                sink.text(r.getUrl());
                sink.link_();
            }
        }
        sink.tableCell_();
        ArtifactRepositoryPolicy releasePolicy = repo.getReleases();
        tableCell(releasePolicy.isEnabled() ? releaseEnabled : releaseDisabled);
        ArtifactRepositoryPolicy snapshotPolicy = repo.getSnapshots();
        tableCell(snapshotPolicy.isEnabled() ? snapshotEnabled : snapshotDisabled);
        if (!repoUrlBlackListed.isEmpty()) {
            tableCell(repoUrlBlackListed.contains(repo.getUrl()) ? blacklistedEnabled : blacklistedDisabled);
        }
        sink.tableRow_();
    }
    endTable();
}
Also used : ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Example 45 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.

the class DependenciesRenderer method printArtifactsLocations.

private void printArtifactsLocations(Map<String, ArtifactRepository> repoMap, List<String> repoUrlBlackListed, List<Artifact> alldeps) {
    // i18n
    String artifact = getI18nString("repo.locations.column.artifact");
    sink.paragraph();
    sink.text(getI18nString("repo.locations.artifact.breakdown"));
    sink.paragraph_();
    List<String> repoIdList = new ArrayList<String>();
    // removed blacklisted repo
    for (Map.Entry<String, ArtifactRepository> entry : repoMap.entrySet()) {
        String repokey = entry.getKey();
        ArtifactRepository repo = entry.getValue();
        if (!(repo.isBlacklisted() || repoUrlBlackListed.contains(repo.getUrl()))) {
            repoIdList.add(repokey);
        }
    }
    String[] tableHeader = new String[repoIdList.size() + 1];
    int[] justificationRepo = new int[repoIdList.size() + 1];
    tableHeader[0] = artifact;
    justificationRepo[0] = Sink.JUSTIFY_LEFT;
    int idnum = 1;
    for (String id : repoIdList) {
        tableHeader[idnum] = id;
        justificationRepo[idnum] = Sink.JUSTIFY_CENTER;
        idnum++;
    }
    Map<String, Integer> totalByRepo = new HashMap<String, Integer>();
    TotalCell totaldeps = new TotalCell(DEFAULT_DECIMAL_FORMAT);
    startTable(justificationRepo, false);
    tableHeader(tableHeader);
    for (Artifact dependency : alldeps) {
        totaldeps.incrementTotal(dependency.getScope());
        sink.tableRow();
        tableCell(dependency.getId());
        if (Artifact.SCOPE_SYSTEM.equals(dependency.getScope())) {
            for (@SuppressWarnings("unused") String repoId : repoIdList) {
                tableCell("-");
            }
        } else {
            for (String repokey : repoIdList) {
                ArtifactRepository repo = repoMap.get(repokey);
                String depUrl = repoUtils.getDependencyUrlFromRepository(dependency, repo);
                Integer old = totalByRepo.get(repokey);
                if (old == null) {
                    old = 0;
                    totalByRepo.put(repokey, old);
                }
                boolean dependencyExists = false;
                // check snapshots in snapshots repository only and releases in release repositories...
                if ((dependency.isSnapshot() && repo.getSnapshots().isEnabled()) || (!dependency.isSnapshot() && repo.getReleases().isEnabled())) {
                    dependencyExists = repoUtils.dependencyExistsInRepo(repo, dependency);
                }
                if (dependencyExists) {
                    sink.tableCell();
                    if (StringUtils.isNotEmpty(depUrl)) {
                        sink.link(depUrl);
                    } else {
                        sink.text(depUrl);
                    }
                    sink.figure();
                    sink.figureCaption();
                    // TODO Translate me!
                    sink.text("Found at " + repo.getUrl());
                    sink.figureCaption_();
                    sink.figureGraphics("images/icon_success_sml.gif");
                    sink.figure_();
                    sink.link_();
                    sink.tableCell_();
                    totalByRepo.put(repokey, old.intValue() + 1);
                } else {
                    tableCell("-");
                }
            }
        }
        sink.tableRow_();
    }
    // Total row
    // reused key
    tableHeader[0] = getI18nString("file.details.total");
    tableHeader(tableHeader);
    String[] totalRow = new String[repoIdList.size() + 1];
    totalRow[0] = totaldeps.toString();
    idnum = 1;
    for (String repokey : repoIdList) {
        Integer deps = totalByRepo.get(repokey);
        totalRow[idnum++] = deps != null ? deps.toString() : "0";
    }
    tableRow(totalRow);
    endTable();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)108 File (java.io.File)46 Artifact (org.apache.maven.artifact.Artifact)26 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)26 ArrayList (java.util.ArrayList)23 MavenProject (org.apache.maven.project.MavenProject)20 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)17 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)15 IOException (java.io.IOException)13 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)13 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)11 Properties (java.util.Properties)10 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)9 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)9 Model (org.apache.maven.model.Model)9 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)8 MojoFailureException (org.apache.maven.plugin.MojoFailureException)8 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)8 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)8 MavenProjectResourcesStub (org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub)7