]> git.argeo.org Git - cc0/argeo-build.git/blobdiff - src/org/argeo/build/Make.java
Exclude source jars from compilation classpath
[cc0/argeo-build.git] / src / org / argeo / build / Make.java
index 324cae8ab89725ef22d86d545b67a40a70e2dcf2..b83404da7f63928b2069aefe26bfe400bb49a88e 100644 (file)
@@ -62,6 +62,14 @@ public class Make {
         */
        private final static String ENV_SOURCE_BUNDLES = "SOURCE_BUNDLES";
 
+       /**
+        * Environment variable on whether legal files at the root of the sources should
+        * be included in the generated bundles. Should be set to true when building
+        * third-party software in order no to include the build harness license into
+        * the generated bundles.
+        */
+       private final static String ENV_NO_SDK_LEGAL = "NO_SDK_LEGAL";
+
        /**
         * Environment variable to override the default location for the Argeo Build
         * configuration files. Typically used if Argeo Build has been compiled and
@@ -79,7 +87,7 @@ public class Make {
        /** Base of the source code, typically the cloned git repository. */
        final Path sdkSrcBase;
        /**
-        * The base of the builder, typically a submodule pointing to the public
+        * The base of the builder, typically a submodule pointing to the INCLUDEpublic
         * argeo-build directory.
         */
        final Path argeoBuildBase;
@@ -92,14 +100,19 @@ public class Make {
        /** The base of the a2 sources when packages separately. */
        final Path a2srcOutput;
 
-       /** Whether sources should be packaged separately */
+       /** Whether sources should be packaged separately. */
        final boolean sourceBundles;
+       /** Whether common legal files should be included. */
+       final boolean noSdkLegal;
 
        /** Constructor initialises the base directories. */
        public Make() throws IOException {
                sourceBundles = Boolean.parseBoolean(System.getenv(ENV_SOURCE_BUNDLES));
                if (sourceBundles)
                        logger.log(Level.INFO, "Sources will be packaged separately");
+               noSdkLegal = Boolean.parseBoolean(System.getenv(ENV_NO_SDK_LEGAL));
+               if (noSdkLegal)
+                       logger.log(Level.INFO, "SDK legal files will NOT be included");
 
                execDirectory = Paths.get(System.getProperty("user.dir"));
                Path sdkMkP = findSdkMk(execDirectory);
@@ -171,8 +184,8 @@ public class Make {
                                        if (!Files.exists(a2Dir))
                                                continue categories;
 //                                     modulePath.add(a2Dir.toString());
-                                       for (Path jarP : Files.newDirectoryStream(a2Dir,
-                                                       (p) -> p.getFileName().toString().endsWith(".jar"))) {
+                                       for (Path jarP : Files.newDirectoryStream(a2Dir, (p) -> p.getFileName().toString().endsWith(".jar")
+                                                       && !p.getFileName().toString().endsWith(".src.jar"))) {
                                                A2Jar a2Jar = new A2Jar(jarP);
                                                if (a2Jars.containsKey(a2Jar.name)) {
                                                        A2Jar current = a2Jars.get(a2Jar.name);
@@ -447,35 +460,31 @@ public class Make {
        /** 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);
+               if (!noSdkLegal) {
+                       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);
+               }
+               for (Iterator<Map.Entry<String, Path>> entries = toInclude.entrySet().iterator(); entries.hasNext();) {
+                       Map.Entry<String, Path> entry = entries.next();
+                       Path inBundle = bundleBase.resolve(entry.getValue().getFileName());
+                       // remove file if it is also defined at bundle level
+                       // since it has already been copied
+                       // and has priority
+                       if (Files.exists(inBundle))
+                               entries.remove();
+               }
                return toInclude;
        }
 
@@ -575,6 +584,7 @@ public class Make {
                }
        }
 
+       /** A jar file in A2 format */
        static class A2Jar {
                final Path path;
                final String name;
@@ -582,13 +592,17 @@ public class Make {
                final int minor;
 
                A2Jar(Path path) {
-                       this.path = path;
-                       String fileName = path.getFileName().toString();
-                       fileName = fileName.substring(0, fileName.lastIndexOf('.'));
-                       minor = Integer.parseInt(fileName.substring(fileName.lastIndexOf('.') + 1));
-                       fileName = fileName.substring(0, fileName.lastIndexOf('.'));
-                       major = Integer.parseInt(fileName.substring(fileName.lastIndexOf('.') + 1));
-                       name = fileName.substring(0, fileName.lastIndexOf('.'));
+                       try {
+                               this.path = path;
+                               String fileName = path.getFileName().toString();
+                               fileName = fileName.substring(0, fileName.lastIndexOf('.'));
+                               minor = Integer.parseInt(fileName.substring(fileName.lastIndexOf('.') + 1));
+                               fileName = fileName.substring(0, fileName.lastIndexOf('.'));
+                               major = Integer.parseInt(fileName.substring(fileName.lastIndexOf('.') + 1));
+                               name = fileName.substring(0, fileName.lastIndexOf('.'));
+                       } catch (Exception e) {
+                               throw new IllegalArgumentException("Badly formatted A2 jar " + path, e);
+                       }
                }
        }