use of org.apache.hyracks.maven.license.project.Project in project asterixdb by apache.
the class LicenseMojo method addDependencyToLicenseMap.
private void addDependencyToLicenseMap(MavenProject depProject, List<Pair<String, String>> depLicenses, String depLocation) {
final String depGav = toGav(depProject);
getLog().debug("adding " + depGav + ", location: " + depLocation);
final MutableBoolean usedMetric = new MutableBoolean(false);
if (depLicenses.size() > 1) {
Collections.sort(depLicenses, (o1, o2) -> {
final int metric1 = getLicenseMetric(o1.getLeft());
final int metric2 = getLicenseMetric(o2.getLeft());
usedMetric.setValue(usedMetric.booleanValue() || metric1 != LicenseSpec.UNDEFINED_LICENSE_METRIC || metric2 != LicenseSpec.UNDEFINED_LICENSE_METRIC);
return Integer.compare(metric1, metric2);
});
if (usedMetric.booleanValue()) {
getLog().info("Multiple licenses for " + depGav + ": " + depLicenses + "; taking lowest metric: " + depLicenses.get(0));
} else {
getLog().warn("Multiple licenses for " + depGav + ": " + depLicenses + "; taking first listed: " + depLicenses.get(0));
}
} else if (depLicenses.isEmpty()) {
getLog().info("no license defined in model for " + depGav);
depLicenses.add(new ImmutablePair<>("MISSING_LICENSE", null));
}
Pair<String, String> key = depLicenses.get(0);
String licenseUrl = key.getLeft();
final String displayName = key.getRight();
if (!urlToLicenseMap.containsKey(licenseUrl)) {
// assuming we've not already mapped it, annotate the URL with artifact info, if not an actual URL
try {
getLog().debug("- URL: " + new URL(licenseUrl));
// life is good
} catch (MalformedURLException e) {
// we encounter this a lot. Log a warning, and use an annotated key
final String fakeLicenseUrl = depGav.replaceAll(":", "--") + "_" + licenseUrl;
getLog().info("- URL for " + depGav + " is malformed: " + licenseUrl + "; using: " + fakeLicenseUrl);
licenseUrl = fakeLicenseUrl;
}
}
addProject(new Project(depProject, depLocation, depProject.getArtifact().getFile()), new LicenseSpec(licenseUrl, displayName), true);
}
use of org.apache.hyracks.maven.license.project.Project in project asterixdb by apache.
the class SourcePointerResolver method ensureCDDLSourcesPointer.
private void ensureCDDLSourcesPointer(Collection<Project> projects, ArtifactRepository central, ArtifactResolutionRequest request) throws ProjectBuildingException, IOException {
for (Project p : projects) {
if (p.getSourcePointer() != null) {
continue;
}
mojo.getLog().debug("finding sources for artifact: " + p);
Artifact sourcesArtifact = new DefaultArtifact(p.getGroupId(), p.getArtifactId(), p.getVersion(), Artifact.SCOPE_COMPILE, "jar", "sources", null);
MavenProject mavenProject = mojo.resolveDependency(sourcesArtifact);
sourcesArtifact.setArtifactHandler(mavenProject.getArtifact().getArtifactHandler());
final ArtifactRepository localRepo = mojo.getSession().getLocalRepository();
final File marker = new File(localRepo.getBasedir(), localRepo.pathOf(sourcesArtifact) + ".oncentral");
final File antimarker = new File(localRepo.getBasedir(), localRepo.pathOf(sourcesArtifact) + ".nocentral");
boolean onCentral;
if (marker.exists() || antimarker.exists()) {
onCentral = marker.exists();
} else {
request.setArtifact(sourcesArtifact);
ArtifactResolutionResult result = mojo.getArtifactResolver().resolve(request);
mojo.getLog().debug("result: " + result);
onCentral = result.isSuccess();
if (onCentral) {
FileUtils.touch(marker);
} else {
FileUtils.touch(antimarker);
}
}
StringBuilder noticeBuilder = new StringBuilder("You may obtain ");
noticeBuilder.append(p.getName()).append(" in Source Code form code here:\n");
if (onCentral) {
noticeBuilder.append(central.getUrl()).append("/").append(central.pathOf(sourcesArtifact));
} else {
mojo.getLog().warn("Unable to find sources in 'central' for " + p + ", falling back to project url: " + p.getUrl());
noticeBuilder.append(p.getUrl() != null ? p.getUrl() : "MISSING SOURCE POINTER");
}
p.setSourcePointer(noticeBuilder.toString());
}
}
use of org.apache.hyracks.maven.license.project.Project in project asterixdb by apache.
the class GenerateFileMojo method rebuildLicenseContentProjectMap.
private void rebuildLicenseContentProjectMap() throws IOException {
int counter = 0;
Map<String, LicensedProjects> licenseMap2 = new TreeMap<>(WHITESPACE_NORMALIZED_COMPARATOR);
for (LicensedProjects lps : licenseMap.values()) {
for (Project p : lps.getProjects()) {
String licenseText = p.getLicenseText();
if (licenseText == null) {
getLog().warn("Using license other than from within artifact: " + p.gav());
licenseText = resolveLicenseContent(lps.getLicense(), false);
}
LicenseSpec spec = lps.getLicense();
if (spec.getDisplayName() == null) {
LicenseSpec canonicalLicense = urlToLicenseMap.get(spec.getUrl());
if (canonicalLicense != null) {
spec.setDisplayName(canonicalLicense.getDisplayName());
}
}
if (!licenseMap2.containsKey(licenseText)) {
if (!licenseText.equals(lps.getLicense().getContent())) {
spec = new LicenseSpec(new ArrayList<>(), licenseText, null, spec.getDisplayName(), spec.getMetric(), spec.getUrl() + (counter++));
}
licenseMap2.put(licenseText, new LicensedProjects(spec));
}
final LicensedProjects lp2 = licenseMap2.get(licenseText);
if (lp2.getLicense().getDisplayName() == null) {
lp2.getLicense().setDisplayName(lps.getLicense().getDisplayName());
}
lp2.addProject(p);
}
}
licenseMap = licenseMap2;
}
use of org.apache.hyracks.maven.license.project.Project in project asterixdb by apache.
the class GenerateFileMojo method combineCommonGavs.
private void combineCommonGavs() {
for (LicensedProjects licensedProjects : licenseMap.values()) {
Map<String, Project> projectMap = new HashMap<>();
for (Iterator<Project> iter = licensedProjects.getProjects().iterator(); iter.hasNext(); ) {
Project project = iter.next();
if (projectMap.containsKey(project.gav())) {
Project first = projectMap.get(project.gav());
first.setLocation(first.getLocation() + "," + project.getLocation());
iter.remove();
} else {
projectMap.put(project.gav(), project);
}
}
}
}
use of org.apache.hyracks.maven.license.project.Project in project asterixdb by apache.
the class GenerateFileMojo method buildNoticeProjectMap.
private void buildNoticeProjectMap() {
noticeMap = new TreeMap<>(WHITESPACE_NORMALIZED_COMPARATOR);
for (Project p : getProjects()) {
prependSourcePointerToNotice(p);
final String noticeText = p.getNoticeText();
if (noticeText == null) {
continue;
}
if (!noticeMap.containsKey(noticeText)) {
noticeMap.put(noticeText, new TreeSet<>(Project.PROJECT_COMPARATOR));
}
noticeMap.get(noticeText).add(p);
}
}
Aggregations