Search in sources :

Example 6 with ProjectBuildingException

use of org.apache.maven.project.ProjectBuildingException in project maven-plugins by apache.

the class AbstractJavadocMojo method getDependenciesLinks.

/**
     * Using Maven, a Javadoc link is given by <code>${project.url}/apidocs</code>.
     *
     * @return the detected Javadoc links using the Maven conventions for all dependencies defined in the current
     *         project or an empty list.
     * @see #detectLinks
     * @see #isValidJavadocLink(String)
     * @since 2.6
     */
private List<String> getDependenciesLinks() {
    if (!detectLinks) {
        return Collections.emptyList();
    }
    getLog().debug("Trying to add links for dependencies...");
    List<String> dependenciesLinks = new ArrayList<String>();
    final Set<Artifact> dependencies = project.getDependencyArtifacts();
    for (Artifact artifact : dependencies) {
        if (artifact.getFile() == null || !artifact.getFile().exists()) {
            continue;
        }
        try {
            MavenProject artifactProject = mavenProjectBuilder.build(artifact, session.getProjectBuildingRequest()).getProject();
            if (StringUtils.isNotEmpty(artifactProject.getUrl())) {
                String url = getJavadocLink(artifactProject);
                if (isValidJavadocLink(url, true)) {
                    getLog().debug("Added Javadoc link: " + url + " for " + artifactProject.getId());
                    dependenciesLinks.add(url);
                }
            }
        } catch (ProjectBuildingException e) {
            logError("ProjectBuildingException for " + artifact.toString() + ": " + e.getMessage(), e);
        }
    }
    return dependenciesLinks;
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) JavadocPathArtifact(org.apache.maven.plugin.javadoc.options.JavadocPathArtifact) Artifact(org.apache.maven.artifact.Artifact) DocletArtifact(org.apache.maven.plugin.javadoc.options.DocletArtifact) BootclasspathArtifact(org.apache.maven.plugin.javadoc.options.BootclasspathArtifact) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) TagletArtifact(org.apache.maven.plugin.javadoc.options.TagletArtifact)

Example 7 with ProjectBuildingException

use of org.apache.maven.project.ProjectBuildingException in project maven-plugins by apache.

the class DependenciesRenderer method printDescriptionsAndURLs.

private void printDescriptionsAndURLs(DependencyNode node, String uid) {
    Artifact artifact = node.getArtifact();
    String id = artifact.getId();
    String unknownLicenseMessage = getI18nString("graph.tables.unknown");
    sink.rawText("<div id=\"" + uid + "\" style=\"display:none\">");
    sink.table();
    if (!Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
        try {
            MavenProject artifactProject = repoUtils.getMavenProjectFromRepository(artifact);
            String artifactDescription = artifactProject.getDescription();
            String artifactUrl = artifactProject.getUrl();
            String artifactName = artifactProject.getName();
            @SuppressWarnings("unchecked") List<License> licenses = artifactProject.getLicenses();
            sink.tableRow();
            sink.tableHeaderCell();
            sink.text(artifactName);
            sink.tableHeaderCell_();
            sink.tableRow_();
            sink.tableRow();
            sink.tableCell();
            sink.paragraph();
            sink.bold();
            sink.text(getI18nString("column.description") + ": ");
            sink.bold_();
            if (StringUtils.isNotEmpty(artifactDescription)) {
                sink.text(artifactDescription);
            } else {
                sink.text(getI18nString("index", "nodescription"));
            }
            sink.paragraph_();
            if (StringUtils.isNotEmpty(artifactUrl)) {
                sink.paragraph();
                sink.bold();
                sink.text(getI18nString("column.url") + ": ");
                sink.bold_();
                if (ProjectInfoReportUtils.isArtifactUrlValid(artifactUrl)) {
                    sink.link(artifactUrl);
                    sink.text(artifactUrl);
                    sink.link_();
                } else {
                    sink.text(artifactUrl);
                }
                sink.paragraph_();
            }
            sink.paragraph();
            sink.bold();
            sink.text(getI18nString("licenses", "title") + ": ");
            sink.bold_();
            if (!licenses.isEmpty()) {
                for (Iterator<License> it = licenses.iterator(); it.hasNext(); ) {
                    License license = it.next();
                    String licenseName = license.getName();
                    if (StringUtils.isEmpty(licenseName)) {
                        licenseName = getI18nString("unnamed");
                    }
                    String licenseUrl = license.getUrl();
                    if (licenseUrl != null) {
                        sink.link(licenseUrl);
                    }
                    sink.text(licenseName);
                    if (licenseUrl != null) {
                        sink.link_();
                    }
                    if (it.hasNext()) {
                        sink.text(", ");
                    }
                    licenseMap.put(licenseName, artifactName);
                }
            } else {
                sink.text(getI18nString("licenses", "nolicense"));
                licenseMap.put(unknownLicenseMessage, artifactName);
            }
            sink.paragraph_();
        } catch (ProjectBuildingException e) {
            log.warn("Unable to create Maven project from repository for artifact " + artifact.getId(), e);
        }
    } else {
        sink.tableRow();
        sink.tableHeaderCell();
        sink.text(id);
        sink.tableHeaderCell_();
        sink.tableRow_();
        sink.tableRow();
        sink.tableCell();
        sink.paragraph();
        sink.bold();
        sink.text(getI18nString("column.description") + ": ");
        sink.bold_();
        sink.text(getI18nString("index", "nodescription"));
        sink.paragraph_();
        if (artifact.getFile() != null) {
            sink.paragraph();
            sink.bold();
            sink.text(getI18nString("column.url") + ": ");
            sink.bold_();
            sink.text(artifact.getFile().getAbsolutePath());
            sink.paragraph_();
        }
    }
    sink.tableCell_();
    sink.tableRow_();
    sink.table_();
    sink.rawText("</div>");
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MavenProject(org.apache.maven.project.MavenProject) License(org.apache.maven.model.License) Artifact(org.apache.maven.artifact.Artifact)

Example 8 with ProjectBuildingException

use of org.apache.maven.project.ProjectBuildingException in project maven-plugins by apache.

the class DependenciesRenderer method renderSectionDependencyRepositoryLocations.

@SuppressWarnings("unchecked")
private void renderSectionDependencyRepositoryLocations() {
    startSection(getI18nString("repo.locations.title"));
    // Collect Alphabetical Dependencies
    List<Artifact> alldeps = dependencies.getAllDependencies();
    Collections.sort(alldeps, getArtifactComparator());
    // Collect Repositories
    Map<String, ArtifactRepository> repoMap = new HashMap<String, ArtifactRepository>();
    populateRepositoryMap(repoMap, repoUtils.getRemoteArtifactRepositories());
    for (Artifact artifact : alldeps) {
        try {
            MavenProject artifactProject = repoUtils.getMavenProjectFromRepository(artifact);
            populateRepositoryMap(repoMap, artifactProject.getRemoteArtifactRepositories());
        } catch (ProjectBuildingException e) {
            log.warn("Unable to create Maven project from repository for artifact " + artifact.getId(), e);
        }
    }
    List<String> repoUrlBlackListed = new ArrayList<String>();
    blacklistRepositoryMap(repoMap, repoUrlBlackListed);
    // Render Repository List
    printRepositories(repoMap, repoUrlBlackListed);
    // Render Artifacts locations
    printArtifactsLocations(repoMap, repoUrlBlackListed, alldeps);
    endSection();
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MavenProject(org.apache.maven.project.MavenProject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact)

Example 9 with ProjectBuildingException

use of org.apache.maven.project.ProjectBuildingException in project maven-plugins by apache.

the class DependenciesRenderer method renderArtifactRow.

/**
     * @param artifact not null
     * @param withClassifier <code>true</code> to include the classifier column, <code>false</code> otherwise.
     * @param withOptional <code>true</code> to include the optional column, <code>false</code> otherwise.
     * @see #getDependencyTableHeader(boolean, boolean)
     */
private void renderArtifactRow(Artifact artifact, boolean withClassifier, boolean withOptional) {
    String isOptional = artifact.isOptional() ? getI18nString("column.isOptional") : getI18nString("column.isNotOptional");
    String url = ProjectInfoReportUtils.getArtifactUrl(artifactFactory, artifact, mavenProjectBuilder, remoteRepositories, localRepository);
    String artifactIdCell = ProjectInfoReportUtils.getArtifactIdCell(artifact.getArtifactId(), url);
    MavenProject artifactProject;
    StringBuilder sb = new StringBuilder();
    try {
        artifactProject = repoUtils.getMavenProjectFromRepository(artifact);
        @SuppressWarnings("unchecked") List<License> licenses = artifactProject.getLicenses();
        for (License license : licenses) {
            sb.append(ProjectInfoReportUtils.getArtifactIdCell(license.getName(), license.getUrl()));
        }
    } catch (ProjectBuildingException e) {
        log.warn("Unable to create Maven project from repository.", e);
    }
    String[] content;
    if (withClassifier) {
        content = new String[] { artifact.getGroupId(), artifactIdCell, artifact.getVersion(), artifact.getClassifier(), artifact.getType(), sb.toString(), isOptional };
    } else {
        content = new String[] { artifact.getGroupId(), artifactIdCell, artifact.getVersion(), artifact.getType(), sb.toString(), isOptional };
    }
    tableRow(withOptional, content);
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MavenProject(org.apache.maven.project.MavenProject) License(org.apache.maven.model.License)

Example 10 with ProjectBuildingException

use of org.apache.maven.project.ProjectBuildingException in project maven-plugins by apache.

the class InstallFileMojo method createMavenProject.

/**
     * Creates a Maven project in-memory from the user-supplied groupId, artifactId and version. When a classifier is
     * supplied, the packaging must be POM because the project with only have attachments. This project serves as basis
     * to attach the artifacts to install to.
     * 
     * @return The created Maven project, never <code>null</code>.
     * @throws MojoExecutionException When the model of the project could not be built.
     * @throws MojoFailureException When building the project failed.
     */
private MavenProject createMavenProject() throws MojoExecutionException, MojoFailureException {
    if (groupId == null || artifactId == null || version == null || packaging == null) {
        throw new MojoExecutionException("The artifact information is incomplete: 'groupId', 'artifactId', " + "'version' and 'packaging' are required.");
    }
    ModelSource modelSource = new StringModelSource("<project><modelVersion>4.0.0</modelVersion><groupId>" + groupId + "</groupId><artifactId>" + artifactId + "</artifactId><version>" + version + "</version><packaging>" + (classifier == null ? packaging : "pom") + "</packaging></project>");
    ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
    pbr.setProcessPlugins(false);
    try {
        return projectBuilder.build(modelSource, pbr).getProject();
    } catch (ProjectBuildingException e) {
        if (e.getCause() instanceof ModelBuildingException) {
            throw new MojoExecutionException("The artifact information is not valid:" + Os.LINE_SEP + e.getCause().getMessage());
        }
        throw new MojoFailureException("Unable to create the project.", e);
    }
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException) StringModelSource(org.apache.maven.model.building.StringModelSource) StringModelSource(org.apache.maven.model.building.StringModelSource) ModelSource(org.apache.maven.model.building.ModelSource) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Aggregations

ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)18 MavenProject (org.apache.maven.project.MavenProject)12 Artifact (org.apache.maven.artifact.Artifact)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 VersionRange (org.apache.maven.artifact.versioning.VersionRange)3 License (org.apache.maven.model.License)3 Model (org.apache.maven.model.Model)3 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)3 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)3 File (java.io.File)2 HashMap (java.util.HashMap)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 InvalidVersionSpecificationException (org.apache.maven.artifact.versioning.InvalidVersionSpecificationException)2 ModelBuildingException (org.apache.maven.model.building.ModelBuildingException)2 ModelSource (org.apache.maven.model.building.ModelSource)2 StringModelSource (org.apache.maven.model.building.StringModelSource)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 InvalidProjectModelException (org.apache.maven.project.InvalidProjectModelException)2