private File createLicenseReport()

in src/main/java/org/apache/sling/feature/maven/mojos/ApisJarMojo.java [2175:2235]


    private File createLicenseReport(
            final ApisJarContext ctx,
            final ApiRegion region,
            final Collection<ArtifactInfo> infos,
            final List<String> report)
            throws MojoExecutionException {
        final File out = new File(this.getTmpDir(), region.getName() + "-license-report.txt");
        if (!out.exists()) {

            final List<String> output = new ArrayList<>();

            output.add(ctx.getConfig().getLicenseReportHeader());
            output.add("");
            for (final ArtifactInfo info : infos) {
                final String licenseDefault = ctx.getConfig().getLicenseDefault(info.getId());

                final StringBuilder sb = new StringBuilder(info.getId().toMvnId());
                boolean exclude = false;
                if (licenseDefault != null) {
                    if (licenseDefault.isEmpty()) {
                        exclude = true;
                        getLog().debug("Excluding from license report "
                                + info.getId().toMvnId());
                    } else {
                        sb.append(" - License(s) : ");
                        sb.append(licenseDefault);
                    }
                } else {
                    final List<License> licenses = this.getLicenses(ctx, info);

                    if (!licenses.isEmpty()) {
                        sb.append(" - License(s) : ");
                        sb.append(String.join(
                                ", ",
                                licenses.stream()
                                        .map(l -> l.getName()
                                                .concat(" (")
                                                .concat(l.getUrl())
                                                .concat(")"))
                                        .collect(Collectors.toList())));
                    } else {
                        report.add(
                                "No license info found for ".concat(info.getId().toMvnId()));
                    }
                }
                if (!exclude) {
                    output.add(sb.toString());
                }
            }
            if (ctx.getConfig().getLicenseReportFooter() != null) {
                output.add("");
                output.add(ctx.getConfig().getLicenseReportFooter());
            }
            try {
                Files.write(out.toPath(), output);
            } catch (IOException e) {
                throw new MojoExecutionException("Unable to write license report: " + e.getMessage(), e);
            }
        }
        return out;
    }