]> git.argeo.org Git - cc0/argeo-build.git/blobdiff - src/org/argeo/build/Make.java
Generate JPM module-info
[cc0/argeo-build.git] / src / org / argeo / build / Make.java
index 9f6f0846d1a6447c7664bb04ad66db3f5451a482..2b6187bcd6d9912d570232e7c40dd0426f5ffa86 100644 (file)
@@ -38,12 +38,14 @@ import java.util.jar.Attributes;
 import java.util.jar.JarEntry;
 import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
+import java.util.stream.Collectors;
 import java.util.zip.Deflater;
 
 import org.eclipse.jdt.core.compiler.CompilationProgress;
 
 import aQute.bnd.osgi.Analyzer;
 import aQute.bnd.osgi.Jar;
+import aQute.bnd.plugin.jpms.JPMSModuleInfoPlugin;
 
 /**
  * Minimalistic OSGi compiler and packager, meant to be used as a single file
@@ -175,7 +177,8 @@ public class Make {
 
                List<String> a2Categories = options.getOrDefault("--dep-categories", new ArrayList<>());
                List<String> a2Bases = options.getOrDefault("--a2-bases", new ArrayList<>());
-               if (a2Bases.isEmpty() || !a2Bases.contains(a2Output.toString())) {
+               a2Bases = a2Bases.stream().distinct().collect(Collectors.toList());// remove duplicates
+               if (a2Bases.isEmpty() || !a2Bases.contains(a2Output.toString())) {// make sure a2 output is available
                        a2Bases.add(a2Output.toString());
                }
 
@@ -204,10 +207,9 @@ public class Make {
                                                        A2Jar current = a2Jars.get(a2Jar.name);
                                                        if (a2Jar.major > current.major)
                                                                a2Jars.put(a2Jar.name, a2Jar);
-                                                       else if (a2Jar.major == current.major //
-                                                                       // if minor equals, we take the last one
-                                                                       && a2Jar.minor >= current.minor)
+                                                       else if (a2Jar.major == current.major && a2Jar.minor > current.minor)
                                                                a2Jars.put(a2Jar.name, a2Jar);
+                                                       // keep if minor equals
                                                } else {
                                                        a2Jars.put(a2Jar.name, a2Jar);
                                                }
@@ -380,7 +382,7 @@ public class Make {
                                Path targetParent = targetJarP.getParent();
                                if (targetParent.startsWith(targetA2))
                                        deleteEmptyParents(targetA2, targetParent);
-                               if (targetParent.startsWith(nativeTargetA2))
+                               if (nativeTargetA2 != null && targetParent.startsWith(nativeTargetA2))
                                        deleteEmptyParents(nativeTargetA2, targetParent);
                        } else { // install
                                Files.createDirectories(targetJarP.getParent());
@@ -416,6 +418,14 @@ public class Make {
 
        /** Delete empty parent directory up to the base directory (included). */
        void deleteEmptyParents(Path baseDir, Path targetParent) throws IOException {
+               if (!targetParent.startsWith(baseDir))
+                       throw new IllegalArgumentException(targetParent + " does not start with " + baseDir);
+               if (!Files.exists(baseDir))
+                       return;
+               if (!Files.exists(targetParent)) {
+                       deleteEmptyParents(baseDir, targetParent.getParent());
+                       return;
+               }
                if (!Files.isDirectory(targetParent))
                        throw new IllegalArgumentException(targetParent + " must be a directory");
                boolean isA2target = Files.isSameFile(baseDir, targetParent);
@@ -477,6 +487,9 @@ public class Make {
                        Jar jar = new Jar(bundleSymbolicName, binP.toFile());
                        bndAnalyzer.setJar(jar);
                        manifest = bndAnalyzer.calcManifest();
+
+                       JPMSModuleInfoPlugin jpmsModuleInfoPlugin = new JPMSModuleInfoPlugin();
+                       jpmsModuleInfoPlugin.verify(bndAnalyzer);
                } catch (Exception e) {
                        throw new RuntimeException("Bnd analysis of " + compiled + " failed", e);
                }