Search in sources :

Example 1 with Project

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);
}
Also used : Project(org.apache.hyracks.maven.license.project.Project) MavenProject(org.apache.maven.project.MavenProject) MalformedURLException(java.net.MalformedURLException) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) URL(java.net.URL)

Example 2 with Project

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());
    }
}
Also used : Project(org.apache.hyracks.maven.license.project.Project) MavenProject(org.apache.maven.project.MavenProject) MavenProject(org.apache.maven.project.MavenProject) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 3 with Project

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;
}
Also used : LicensedProjects(org.apache.hyracks.maven.license.project.LicensedProjects) Project(org.apache.hyracks.maven.license.project.Project) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap)

Example 4 with Project

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);
            }
        }
    }
}
Also used : LicensedProjects(org.apache.hyracks.maven.license.project.LicensedProjects) Project(org.apache.hyracks.maven.license.project.Project) HashMap(java.util.HashMap)

Example 5 with 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);
    }
}
Also used : Project(org.apache.hyracks.maven.license.project.Project)

Aggregations

Project (org.apache.hyracks.maven.license.project.Project)6 LicensedProjects (org.apache.hyracks.maven.license.project.LicensedProjects)3 MavenProject (org.apache.maven.project.MavenProject)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 Artifact (org.apache.maven.artifact.Artifact)1 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)1