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;
}
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>");
}
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();
}
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);
}
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);
}
}
Aggregations