X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=src%2Forg%2Fargeo%2Fbuild%2FRepackage.java;h=90202952607eb15b9cab2a53e597250b7b0372ad;hb=56823b2fa7daf14ccff45e329f9653cdc3273ec4;hp=8d48c2f9f6e2a47a128cc8222e4a7f07684944fe;hpb=fe6c61fa7630164e2d5160b19cf8d2ad6f93b7ab;p=cc0%2Fargeo-build.git diff --git a/src/org/argeo/build/Repackage.java b/src/org/argeo/build/Repackage.java index 8d48c2f..9020295 100644 --- a/src/org/argeo/build/Repackage.java +++ b/src/org/argeo/build/Repackage.java @@ -9,6 +9,7 @@ import static java.nio.file.FileVisitResult.CONTINUE; import static java.util.jar.Attributes.Name.MANIFEST_VERSION; import static org.argeo.build.Repackage.ManifestConstants.ARGEO_ORIGIN_M2; import static org.argeo.build.Repackage.ManifestConstants.ARGEO_ORIGIN_M2_REPO; +import static org.argeo.build.Repackage.ManifestConstants.BUNDLE_LICENSE; import static org.argeo.build.Repackage.ManifestConstants.BUNDLE_SYMBOLICNAME; import static org.argeo.build.Repackage.ManifestConstants.BUNDLE_VERSION; import static org.argeo.build.Repackage.ManifestConstants.ECLIPSE_SOURCE_BUNDLE; @@ -43,7 +44,9 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Properties; +import java.util.Set; import java.util.TreeMap; +import java.util.TreeSet; import java.util.concurrent.CompletableFuture; import java.util.jar.Attributes; import java.util.jar.JarEntry; @@ -60,16 +63,20 @@ import aQute.bnd.osgi.Jar; * repository. */ public class Repackage { - private final static Logger logger = System.getLogger(Repackage.class.getName()); + final static Logger logger = System.getLogger(Repackage.class.getName()); /** * Environment variable on whether sources should be packaged separately or * integrated in the bundles. */ - private final static String ENV_SOURCE_BUNDLES = "SOURCE_BUNDLES"; + final static String ENV_SOURCE_BUNDLES = "SOURCE_BUNDLES"; /** Whethere repackaging should run in parallel or sequentially. */ - private final static boolean parallel = true; + final static boolean parallel = true; + + // cache + /** Summary of all license seen during the repackaging. */ + final static Map> licensesUsed = new TreeMap<>(); /** Main entry point. */ public static void main(String[] args) { @@ -90,31 +97,38 @@ public class Repackage { factory.processCategory(p); } CompletableFuture.allOf(toDos.toArray(new CompletableFuture[toDos.size()])).join(); + + // Summary + StringBuilder sb = new StringBuilder(); + for (String licenseId : licensesUsed.keySet()) + for (String name : licensesUsed.get(licenseId)) + sb.append((licenseId.equals("") ? "Proprietary" : licenseId) + "\t\t" + name + "\n"); + logger.log(INFO, "# License summary:\n" + sb); } - private final static String COMMON_BND = "common.bnd"; - private final static String MERGE_BND = "merge.bnd"; + final static String COMMON_BND = "common.bnd"; + final static String MERGE_BND = "merge.bnd"; /** Directory where to download archives */ - private Path originBase; + Path originBase; /** Directory where to download Maven artifacts */ - private Path mavenBase; + Path mavenBase; /** A2 repository base for binary bundles */ - private Path a2Base; + Path a2Base; /** A2 repository base for source bundles */ - private Path a2SrcBase; + Path a2SrcBase; /** A2 base for native components */ - private Path a2LibBase; + Path a2LibBase; /** Location of the descriptors driving the packaging */ - private Path descriptorsBase; + Path descriptorsBase; /** URIs of archives to download */ - private Properties uris = new Properties(); + Properties uris = new Properties(); /** Mirrors for archive download. Key is URI prefix, value list of base URLs */ - private Map> mirrors = new HashMap>(); + Map> mirrors = new HashMap>(); /** Whether sources should be packaged separately */ - private final boolean sourceBundles; + final boolean sourceBundles; /** Constructor initialises the various variables */ public Repackage(Path a2Base, Path descriptorsBase) { @@ -835,8 +849,8 @@ public class Repackage { String value = entries.get(key); String previousValue = manifest.getMainAttributes().getValue(key); boolean wasDifferent = previousValue != null && !previousValue.equals(value); + boolean keepPrevious = false; if (wasDifferent) { - boolean keepPrevious = false; if (SPDX_LICENSE_IDENTIFIER.toString().equals(key) && previousValue != null) keepPrevious = true; else if (BUNDLE_VERSION.toString().equals(key) && wasDifferent) @@ -852,7 +866,7 @@ public class Repackage { } manifest.getMainAttributes().putValue(key, value); - if (wasDifferent) { + if (wasDifferent && !keepPrevious) { if (IMPORT_PACKAGE.toString().equals(key) || EXPORT_PACKAGE.toString().equals(key)) logger.log(TRACE, () -> file.getFileName() + ": " + key + " was modified"); else @@ -866,6 +880,19 @@ public class Repackage { manifest.getMainAttributes().remove(key); } } + + // last checks + String spdxLicenceId = manifest.getMainAttributes().getValue(SPDX_LICENSE_IDENTIFIER.toString()); + String bundleLicense = manifest.getMainAttributes().getValue(BUNDLE_LICENSE.toString()); + if (spdxLicenceId == null) { + logger.log(ERROR, file.getFileName() + ": " + SPDX_LICENSE_IDENTIFIER + " not available, " + + BUNDLE_LICENSE + " is " + bundleLicense); + } else { + if (!licensesUsed.containsKey(spdxLicenceId)) + licensesUsed.put(spdxLicenceId, new TreeSet<>()); + licensesUsed.get(spdxLicenceId).add(nameVersion.toString()); + } + try (OutputStream out = Files.newOutputStream(manifestPath)) { manifest.write(out); } @@ -1062,6 +1089,8 @@ public class Repackage { BUNDLE_SYMBOLICNAME("Bundle-SymbolicName"), // /** OSGi bundle version. */ BUNDLE_VERSION("Bundle-Version"), // + /** OSGi bundle license. */ + BUNDLE_LICENSE("Bundle-License"), // /** OSGi exported packages list. */ EXPORT_PACKAGE("Export-Package"), // /** OSGi imported packages list. */ @@ -1070,8 +1099,14 @@ public class Repackage { /** Java module name. */ AUTOMATIC_MODULE_NAME("Automatic-Module-Name"), // // Eclipse + /** Eclipse source bundle. */ ECLIPSE_SOURCE_BUNDLE("Eclipse-SourceBundle"), // // SPDX + /** + * SPDX license identifier. + * + * @see https://spdx.org/licenses/ + */ SPDX_LICENSE_IDENTIFIER("SPDX-License-Identifier"), // // Argeo Origin /**