Disable source packaging via environment property
authorMathieu <mbaudier@argeo.org>
Thu, 3 Nov 2022 11:22:23 +0000 (12:22 +0100)
committerMathieu <mbaudier@argeo.org>
Thu, 3 Nov 2022 11:22:23 +0000 (12:22 +0100)
src/org/argeo/build/Make.java
src/org/argeo/build/Repackage.java

index 0da82b0cab00677432c497077740dca741abee9d..b9fd48d3e96ca08539c74fd53c726b66fa1a0796 100644 (file)
@@ -50,6 +50,12 @@ import aQute.bnd.osgi.Jar;
 public class Make {
        private final static Logger logger = System.getLogger(Make.class.getName());
 
+       /**
+        * Environment properties on whether sources should be packaged separately or
+        * integrated in the bundles.
+        */
+       private final static String ENV_BUILD_SOURCE_BUNDLES = "BUILD_SOURCE_BUNDLES";
+
        /** Name of the local-specific Makefile (sdk.mk). */
        final static String SDK_MK = "sdk.mk";
        /** Name of the branch definition Makefile (branch.mk). */
@@ -71,8 +77,15 @@ public class Make {
        /** The base of the a2 output for all layers. */
        final Path a2Output;
 
+       /** Whether sources should be packaged separately */
+       final boolean sourceBundles;
+
        /** Constructor initialises the base directories. */
        public Make() throws IOException {
+               sourceBundles = Boolean.parseBoolean(System.getenv(ENV_BUILD_SOURCE_BUNDLES));
+               if (sourceBundles)
+                       logger.log(Level.INFO, "Sources will be packaged separately");
+
                execDirectory = Paths.get(System.getProperty("user.dir"));
                Path sdkMkP = findSdkMk(execDirectory);
                Objects.requireNonNull(sdkMkP, "No " + SDK_MK + " found under " + execDirectory);
@@ -331,16 +344,19 @@ public class Make {
                        // add sources
                        // TODO add effective BND, Eclipse project file, etc., in order to be able to
                        // repackage
-                       Files.walkFileTree(srcP, new SimpleFileVisitor<Path>() {
-                               @Override
-                               public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
-                                       jarOut.putNextEntry(new JarEntry("OSGI-OPT/src/" + srcP.relativize(file).toString()));
-                                       if (!Files.isDirectory(file))
-                                               Files.copy(file, jarOut);
-                                       return FileVisitResult.CONTINUE;
-                               }
-                       });
-
+                       if (sourceBundles) {
+                               // TODO package sources separately
+                       } else {
+                               Files.walkFileTree(srcP, new SimpleFileVisitor<Path>() {
+                                       @Override
+                                       public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+                                               jarOut.putNextEntry(new JarEntry("OSGI-OPT/src/" + srcP.relativize(file).toString()));
+                                               if (!Files.isDirectory(file))
+                                                       Files.copy(file, jarOut);
+                                               return FileVisitResult.CONTINUE;
+                                       }
+                               });
+                       }
                }
        }
 
index de99e5f8c453af44d532d69f67db3952ddafc204..588b0b81197139b827cfa2e4d6c9b299fa7bf8f6 100644 (file)
@@ -35,6 +35,7 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.Properties;
 import java.util.TreeMap;
+import java.util.concurrent.CompletableFuture;
 import java.util.jar.Attributes;
 import java.util.jar.JarEntry;
 import java.util.jar.JarInputStream;
@@ -49,6 +50,8 @@ import aQute.bnd.osgi.Jar;
 public class Repackage {
        private final static Logger logger = System.getLogger(Repackage.class.getName());
 
+       private final static String ENV_BUILD_SOURCE_BUNDLES = "BUILD_SOURCE_BUNDLES";
+
        /** Main entry point. */
        public static void main(String[] args) {
                if (args.length < 2) {
@@ -57,12 +60,14 @@ public class Repackage {
                }
                Path a2Base = Paths.get(args[0]).toAbsolutePath().normalize();
                Path descriptorsBase = Paths.get(".").toAbsolutePath().normalize();
-               Repackage factory = new Repackage(a2Base, descriptorsBase, true);
+               Repackage factory = new Repackage(a2Base, descriptorsBase);
 
+               List<CompletableFuture<Void>> toDos = new ArrayList<>();
                for (int i = 1; i < args.length; i++) {
                        Path p = Paths.get(args[i]);
-                       factory.processCategory(p);
+                       toDos.add(CompletableFuture.runAsync(() -> factory.processCategory(p)));
                }
+               CompletableFuture.allOf(toDos.toArray(new CompletableFuture[toDos.size()])).join();
        }
 
        private final static String COMMON_BND = "common.bnd";
@@ -75,12 +80,16 @@ public class Repackage {
 
        private Properties uris = new Properties();
 
-       private boolean includeSources = true;
-
        /** key is URI prefix, value list of base URLs */
        private Map<String, List<String>> mirrors = new HashMap<String, List<String>>();
 
-       public Repackage(Path a2Base, Path descriptorsBase, boolean includeSources) {
+       private final boolean sourceBundles;
+
+       public Repackage(Path a2Base, Path descriptorsBase) {
+               sourceBundles = Boolean.parseBoolean(System.getenv(ENV_BUILD_SOURCE_BUNDLES));
+               if (sourceBundles)
+                       logger.log(Level.INFO, "Sources will be packaged separately");
+
                Objects.requireNonNull(a2Base);
                Objects.requireNonNull(descriptorsBase);
                this.originBase = Paths.get(System.getProperty("user.home"), ".cache", "argeo/build/origin");
@@ -90,7 +99,6 @@ public class Repackage {
                this.descriptorsBase = descriptorsBase;
                if (!Files.exists(this.descriptorsBase))
                        throw new IllegalArgumentException(this.descriptorsBase + " does not exist");
-               this.includeSources = includeSources;
 
                // URIs mapping
                Path urisPath = this.descriptorsBase.resolve("uris.properties");
@@ -499,7 +507,7 @@ public class Repackage {
        /** Download and integrates sources for a single Maven artifact. */
        protected void downloadAndProcessM2Sources(String repoStr, M2Artifact artifact, Path targetBundleDir)
                        throws IOException {
-               if (!includeSources)
+               if (sourceBundles)
                        return;
                M2Artifact sourcesArtifact = new M2Artifact(artifact.toM2Coordinates(), "sources");
                URL sourcesUrl = M2ConventionsUtils.mavenRepoUrl(repoStr, sourcesArtifact);
@@ -626,9 +634,11 @@ public class Repackage {
                                                                        return FileVisitResult.CONTINUE;
                                                                }
                                                        }
-                                                       if (includeSources && file.getFileName().toString().contains(".source_")) {
-                                                               processEclipseSourceJar(file, targetCategoryBase);
-                                                               logger.log(Level.DEBUG, () -> "Processed source " + file);
+                                                       if (file.getFileName().toString().contains(".source_")) {
+                                                               if (!sourceBundles) {
+                                                                       processEclipseSourceJar(file, targetCategoryBase);
+                                                                       logger.log(Level.DEBUG, () -> "Processed source " + file);
+                                                               }
 
                                                        } else {
                                                                Map<String, String> map = new HashMap<>();