import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.lang.management.ManagementFactory;
+import java.nio.file.DirectoryStream;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
}
/** Compile all the bundles which have been passed via the --bundle argument. */
- @SuppressWarnings("restriction")
void compile(Map<String, List<String>> options) throws IOException {
List<String> bundles = options.get("--bundles");
Objects.requireNonNull(bundles, "--bundles argument must be set");
}
});
+ // add legal notices and licenses
+ for (Path p : listLegalFilesToInclude(source).values()) {
+ jarOut.putNextEntry(new JarEntry(p.getFileName().toString()));
+ Files.copy(p, jarOut);
+ }
+
// add sources
// TODO add effective BND, Eclipse project file, etc., in order to be able to
// repackage
try (JarOutputStream srcJarOut = new JarOutputStream(Files.newOutputStream(srcJarP), srcManifest)) {
copySourcesToJar(srcP, srcJarOut, "");
+ // add legal notices and licenses
+ for (Path p : listLegalFilesToInclude(source).values()) {
+ jarOut.putNextEntry(new JarEntry(p.getFileName().toString()));
+ Files.copy(p, jarOut);
+ }
}
} else {
copySourcesToJar(srcP, jarOut, "OSGI-OPT/src/");
}
}
+ /** List the relevant legal files to include, from the SDK source base. */
+ Map<String, Path> listLegalFilesToInclude(Path bundleBase) throws IOException {
+ Map<String, Path> toInclude = new HashMap<>();
+ DirectoryStream<Path> sdkSrcLegal = Files.newDirectoryStream(sdkSrcBase, (p) -> {
+ String fileName = p.getFileName().toString();
+ return switch (fileName) {
+ case "NOTICE":
+ case "LICENSE":
+ case "COPYING":
+ case "COPYING.LESSER":
+ yield true;
+ default:
+ yield false;
+ };
+ });
+ for (Path p : sdkSrcLegal)
+ toInclude.put(p.getFileName().toString(), p);
+ DirectoryStream<Path> bundleLegal = Files.newDirectoryStream(bundleBase, (p) -> {
+ String fileName = p.getFileName().toString();
+ return switch (fileName) {
+ case "NOTICE":
+ case "LICENSE":
+ case "COPYING":
+ case "COPYING.LESSER":
+ yield true;
+ default:
+ yield false;
+ };
+ });
+ // bundle can override
+ for (Path p : bundleLegal)
+ toInclude.put(p.getFileName().toString(), p);
+ return toInclude;
+ }
+
/*
* UTILITIES
*/