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 buck by facebook.
the class Pom method merge.
private Model merge(Model first, @Nullable Model second) {
if (second == null) {
return first;
}
Model model = first.clone();
//---- Values from ModelBase
List<String> modules = second.getModules();
if (modules != null) {
for (String module : modules) {
model.addModule(module);
}
}
DistributionManagement distributionManagement = second.getDistributionManagement();
if (distributionManagement != null) {
model.setDistributionManagement(distributionManagement);
}
Properties properties = second.getProperties();
if (properties != null) {
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
model.addProperty((String) entry.getKey(), (String) entry.getValue());
}
}
DependencyManagement dependencyManagement = second.getDependencyManagement();
if (dependencyManagement != null) {
model.setDependencyManagement(dependencyManagement);
}
List<Dependency> dependencies = second.getDependencies();
if (dependencies != null) {
for (Dependency dependency : dependencies) {
model.addDependency(dependency);
}
}
List<Repository> repositories = second.getRepositories();
if (repositories != null) {
for (Repository repository : repositories) {
model.addRepository(repository);
}
}
List<Repository> pluginRepositories = second.getPluginRepositories();
if (pluginRepositories != null) {
for (Repository pluginRepository : pluginRepositories) {
model.addPluginRepository(pluginRepository);
}
}
// Ignore reports, reporting, and locations
//----- From Model
Parent parent = second.getParent();
if (parent != null) {
model.setParent(parent);
}
Organization organization = second.getOrganization();
if (organization != null) {
model.setOrganization(organization);
}
List<License> licenses = second.getLicenses();
Set<String> currentLicenseUrls = new HashSet<>();
if (model.getLicenses() != null) {
for (License license : model.getLicenses()) {
currentLicenseUrls.add(license.getUrl());
}
}
if (licenses != null) {
for (License license : licenses) {
if (!currentLicenseUrls.contains(license.getUrl())) {
model.addLicense(license);
currentLicenseUrls.add(license.getUrl());
}
}
}
List<Developer> developers = second.getDevelopers();
Set<String> currentDevelopers = new HashSet<>();
if (model.getDevelopers() != null) {
for (Developer developer : model.getDevelopers()) {
currentDevelopers.add(developer.getName());
}
}
if (developers != null) {
for (Developer developer : developers) {
if (!currentDevelopers.contains(developer.getName())) {
model.addDeveloper(developer);
currentDevelopers.add(developer.getName());
}
}
}
List<Contributor> contributors = second.getContributors();
Set<String> currentContributors = new HashSet<>();
if (model.getContributors() != null) {
for (Contributor contributor : model.getContributors()) {
currentDevelopers.add(contributor.getName());
}
}
if (contributors != null) {
for (Contributor contributor : contributors) {
if (!currentContributors.contains(contributor.getName())) {
model.addContributor(contributor);
currentContributors.add(contributor.getName());
}
}
}
List<MailingList> mailingLists = second.getMailingLists();
if (mailingLists != null) {
for (MailingList mailingList : mailingLists) {
model.addMailingList(mailingList);
}
}
Prerequisites prerequisites = second.getPrerequisites();
if (prerequisites != null) {
model.setPrerequisites(prerequisites);
}
Scm scm = second.getScm();
if (scm != null) {
model.setScm(scm);
}
String url = second.getUrl();
if (url != null) {
model.setUrl(url);
}
String description = second.getDescription();
if (description != null) {
model.setDescription(description);
}
IssueManagement issueManagement = second.getIssueManagement();
if (issueManagement != null) {
model.setIssueManagement(issueManagement);
}
CiManagement ciManagement = second.getCiManagement();
if (ciManagement != null) {
model.setCiManagement(ciManagement);
}
Build build = second.getBuild();
if (build != null) {
model.setBuild(build);
}
List<Profile> profiles = second.getProfiles();
Set<String> currentProfileIds = new HashSet<>();
if (model.getProfiles() != null) {
for (Profile profile : model.getProfiles()) {
currentProfileIds.add(profile.getId());
}
}
if (profiles != null) {
for (Profile profile : profiles) {
if (!currentProfileIds.contains(profile.getId())) {
model.addProfile(profile);
currentProfileIds.add(profile.getId());
}
}
}
return model;
}
use of org.apache.maven.model.License in project maven-plugins by apache.
the class DependencyManagementRenderer method getDependencyRow.
@SuppressWarnings("unchecked")
private String[] getDependencyRow(Dependency dependency, boolean hasClassifier) {
Artifact artifact = artifactFactory.createProjectArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
StringBuilder licensesBuffer = new StringBuilder();
String url = null;
try {
VersionRange range = VersionRange.createFromVersionSpec(dependency.getVersion());
if (range.getRecommendedVersion() == null) {
// MPIR-216: no direct version but version range: need to choose one precise version
log.debug("Resolving range for DependencyManagement on " + artifact.getId());
List<ArtifactVersion> versions = artifactMetadataSource.retrieveAvailableVersions(artifact, localRepository, remoteRepositories);
// only use versions from range
for (Iterator<ArtifactVersion> iter = versions.iterator(); iter.hasNext(); ) {
if (!range.containsVersion(iter.next())) {
iter.remove();
}
}
// select latest, assuming pom information will be the most accurate
if (versions.size() > 0) {
ArtifactVersion maxArtifactVersion = Collections.max(versions);
artifact.setVersion(maxArtifactVersion.toString());
log.debug("DependencyManagement resolved: " + artifact.getId());
}
}
url = ProjectInfoReportUtils.getArtifactUrl(artifactFactory, artifact, mavenProjectBuilder, remoteRepositories, localRepository);
MavenProject artifactProject = repoUtils.getMavenProjectFromRepository(artifact);
List<License> licenses = artifactProject.getLicenses();
for (License license : licenses) {
String licenseCell = ProjectInfoReportUtils.getArtifactIdCell(license.getName(), license.getUrl());
if (licensesBuffer.length() > 0) {
licensesBuffer.append(", ");
}
licensesBuffer.append(licenseCell);
}
} catch (InvalidVersionSpecificationException e) {
log.warn("Unable to parse version for " + artifact.getId(), e);
} catch (ArtifactMetadataRetrievalException e) {
log.warn("Unable to retrieve versions for " + artifact.getId() + " from repository.", e);
} catch (ProjectBuildingException e) {
log.warn("Unable to create Maven project for " + artifact.getId() + " from repository.", e);
}
String artifactIdCell = ProjectInfoReportUtils.getArtifactIdCell(artifact.getArtifactId(), url);
if (hasClassifier) {
return new String[] { dependency.getGroupId(), artifactIdCell, dependency.getVersion(), dependency.getClassifier(), dependency.getType(), licensesBuffer.toString() };
}
return new String[] { dependency.getGroupId(), artifactIdCell, dependency.getVersion(), dependency.getType(), licensesBuffer.toString() };
}
Aggregations