+ /** Get the value from either a {@link Manifest} or a {@link Properties}. */
+ String get(Object map) {
+ if (map instanceof Manifest manifest)
+ return manifest.getMainAttributes().getValue(headerName);
+ else if (map instanceof Properties props)
+ return props.getProperty(headerName);
+ else
+ throw new IllegalArgumentException("Unsupported mapping " + map.getClass());
+ }
+
+ /** Put the value into either a {@link Manifest} or a {@link Properties}. */
+ void put(Object map, String value) {
+ if (map instanceof Manifest manifest)
+ manifest.getMainAttributes().putValue(headerName, value);
+ else if (map instanceof Properties props)
+ props.setProperty(headerName, value);
+ else
+ throw new IllegalArgumentException("Unsupported mapping " + map.getClass());
+ }
+ }
+
+ /** Name of the file centralising information for multiple M2 artifacts. */
+ final static String COMMON_BND = "common.bnd";
+ /** Name of the file centralising information for mergin M2 artifacts. */
+ final static String MERGE_BND = "merge.bnd";
+ /**
+ * Subdirectory of the jar file where origin informations (changes, legal
+ * notices etc. are stored)
+ */
+ final static String ARGEO_ORIGIN = "ARGEO-ORIGIN";
+ /** File detailing modifications to the original component. */
+ final static String CHANGES = ARGEO_ORIGIN + "/changes";
+ /**
+ * Name of the file at the root of the repackaged jar, which prominently
+ * notifies that the component has be repackaged.
+ */
+ final static String README_REPACKAGED = "README.repackaged";
+
+ // cache
+ /** Summary of all license seen during the repackaging. */
+ final static Map<String, Set<String>> licensesUsed = new TreeMap<>();
+
+ /** Directory where to download archives */
+ final Path originBase;
+ /** Directory where to download Maven artifacts */
+ final Path mavenBase;
+
+ /** A2 repository base for binary bundles */
+ final Path a2Base;
+ /** A2 repository base for source bundles */
+ final Path a2SrcBase;
+ /** A2 base for native components */
+ final Path a2LibBase;
+ /** Location of the descriptors driving the packaging */
+ final Path descriptorsBase;
+ /** URIs of archives to download */
+ final Properties uris = new Properties();
+ /** Mirrors for archive download. Key is URI prefix, value list of base URLs */
+ final Map<String, List<String>> mirrors = new HashMap<String, List<String>>();
+
+ /** Whether sources should be packaged separately */
+ final boolean separateSources;
+
+ /** Constructor initialises the various variables */
+ public Repackage(Path a2Base, Path descriptorsBase) {
+ separateSources = Boolean.parseBoolean(System.getenv(ENV_SOURCE_BUNDLES));
+ if (separateSources)
+ logger.log(INFO, "Sources will be packaged separately");