use of org.apache.maven.model.License in project asterixdb by apache.
the class LicenseMojo method gatherProjectDependencies.
private void gatherProjectDependencies(MavenProject project, Map<MavenProject, List<Pair<String, String>>> dependencyLicenseMap, Map<String, MavenProject> dependencyGavMap) throws ProjectBuildingException {
final Set dependencyArtifacts = project.getArtifacts();
if (dependencyArtifacts != null) {
for (Object depArtifactObj : dependencyArtifacts) {
final Artifact depArtifact = (Artifact) depArtifactObj;
if (!excludedScopes.contains(depArtifact.getScope())) {
MavenProject dep = resolveDependency(depArtifact);
dep.setArtifact(depArtifact);
dependencyGavMap.put(toGav(dep), dep);
List<Pair<String, String>> licenseUrls = new ArrayList<>();
for (Object license : dep.getLicenses()) {
final License license1 = (License) license;
String url = license1.getUrl() != null ? license1.getUrl() : (license1.getName() != null ? license1.getName() : "LICENSE_EMPTY_NAME_URL");
licenseUrls.add(new ImmutablePair<>(url, license1.getName()));
}
dependencyLicenseMap.put(dep, licenseUrls);
}
}
}
}
use of org.apache.maven.model.License 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.model.License 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.model.License in project maven-plugins by apache.
the class LicensesReport method canGenerateReport.
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
@Override
public boolean canGenerateReport() {
boolean result = super.canGenerateReport();
if (result && skipEmptyReport) {
result = !isEmpty(getProject().getModel().getLicenses());
}
if (!result) {
return false;
}
if (!offline) {
return true;
}
for (License license : project.getModel().getLicenses()) {
String url = license.getUrl();
URL licenseUrl = null;
try {
licenseUrl = getLicenseURL(project, url);
} catch (MalformedURLException e) {
getLog().error(e.getMessage());
} catch (IOException e) {
getLog().error(e.getMessage());
}
if (licenseUrl != null && licenseUrl.getProtocol().equals("file")) {
return true;
}
if (licenseUrl != null && (licenseUrl.getProtocol().equals("http") || licenseUrl.getProtocol().equals("https"))) {
linkOnly = true;
return true;
}
}
return false;
}
use of org.apache.maven.model.License in project maven-plugins by apache.
the class DoapUtilTest method testInterpolate.
/**
* Test method for:
* {@link DoapUtil#interpolate(String, MavenProject, org.apache.maven.settings.Settings)}
*
* @throws Exception if any
*/
public void testInterpolate() throws Exception {
License license = new License();
license.setName("licenseName");
license.setUrl("licenseUrl");
List<Developer> developers = new ArrayList<Developer>();
Developer developer1 = new Developer();
developer1.setId("id1");
developer1.setName("developerName1");
developers.add(developer1);
Developer developer2 = new Developer();
developer2.setId("id1");
developer2.setName("developerName2");
developers.add(developer2);
MavenProject project = new MavenProject();
project.setName("projectName");
project.setDescription("projectDescription");
project.setLicenses(Collections.singletonList(license));
project.setDevelopers(developers);
project.getProperties().put("myKey", "myValue");
assertEquals(DoapUtil.interpolate("${project.name}", project, null), "projectName");
assertEquals(DoapUtil.interpolate("my name is ${project.name}", project, null), "my name is projectName");
assertEquals(DoapUtil.interpolate("my name is ${project.invalid}", project, null), "my name is ${project.invalid}");
assertEquals(DoapUtil.interpolate("${pom.description}", project, null), "projectDescription");
assertNull(DoapUtil.interpolate("${project.licenses.name}", project, null));
assertEquals(DoapUtil.interpolate("${project.licenses[0].name}", project, null), "licenseName");
assertNull(DoapUtil.interpolate("${project.licenses[1].name}", project, null));
assertNotNull(DoapUtil.interpolate("${project.developers}", project, null));
assertEquals(DoapUtil.interpolate("${project.developers[0].name}", project, null), "developerName1");
assertEquals(DoapUtil.interpolate("${project.developers[1].name}", project, null), "developerName2");
assertEquals(DoapUtil.interpolate("${myKey}", project, null), "myValue");
}
Aggregations