Introduce include/exclude of A2 categories
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 4 Mar 2024 18:22:38 +0000 (19:22 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 4 Mar 2024 18:22:38 +0000 (19:22 +0100)
org.argeo.init/src/org/argeo/init/a2/A2Source.java
org.argeo.init/src/org/argeo/init/a2/FsA2Source.java
org.argeo.init/src/org/argeo/init/a2/ProvisioningManager.java

index 5c8329c85e8616329a2154047273ac4b4ed943dd..19134b784c10d77d64062be2f052759664995a3a 100644 (file)
@@ -14,5 +14,8 @@ public interface A2Source extends ProvisioningSource {
        final static String DEFAULT_A2_URI = SCHEME_A2 + ":///";
        final static String DEFAULT_A2_REFERENCE_URI = SCHEME_A2_REFERENCE + ":///";
 
+       final static String INCLUDE = "include";
+       final static String EXCLUDE = "exclude";
+
        URI getUri();
 }
index 921992da3371f0e12af8175b1d2f8911c5d46075..acc553d7d14b233adb9dacce510d2859840cc1a3 100644 (file)
@@ -7,6 +7,7 @@ import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.SortedMap;
 import java.util.StringJoiner;
@@ -20,14 +21,16 @@ public class FsA2Source extends AbstractProvisioningSource implements A2Source {
        private final Path base;
        private final Map<String, String> variantsXOr;
 
-//     public FsA2Source(Path base) {
-//             this(base, new HashMap<>());
-//     }
+       private final List<String> includes;
+       private final List<String> excludes;
 
-       public FsA2Source(Path base, Map<String, String> variantsXOr, boolean usingReference) {
+       public FsA2Source(Path base, Map<String, String> variantsXOr, boolean usingReference, List<String> includes,
+                       List<String> excludes) {
                super(usingReference);
                this.base = base;
                this.variantsXOr = new HashMap<>(variantsXOr);
+               this.includes = includes;
+               this.excludes = excludes;
        }
 
        void load() throws IOException {
@@ -85,8 +88,12 @@ public class FsA2Source extends AbstractProvisioningSource implements A2Source {
                        }
                }
 
-               for (Path contributionPath : contributions.keySet()) {
+               contributions: for (Path contributionPath : contributions.keySet()) {
                        String contributionId = contributionPath.getFileName().toString();
+                       if (includes != null && !includes.contains(contributionId))
+                               continue contributions;
+                       if (excludes != null && excludes.contains(contributionId))
+                               continue contributions;
                        A2Contribution contribution = getOrAddContribution(contributionId);
                        DirectoryStream<Path> modulePaths = Files.newDirectoryStream(contributionPath);
                        modules: for (Path modulePath : modulePaths) {
index 289870abc3ef945b7a2bb5f9b122027beb1af6cd..80006264c6cbb4b4acb7bd894a6142b16ab4b87f 100644 (file)
@@ -66,11 +66,19 @@ public class ProvisioningManager {
                        // XOR
                        Map<String, List<String>> properties = queryToMap(u);
                        Map<String, String> xOr = new HashMap<>();
+                       List<String> includes = null;
+                       List<String> excludes = null;
                        for (String key : properties.keySet()) {
                                List<String> lst = properties.get(key);
-                               if (lst.size() != 1)
-                                       throw new IllegalArgumentException("Invalid XOR definitions in " + uri);
-                               xOr.put(key, lst.get(0));
+                               if (A2Source.INCLUDE.equals(key)) {
+                                       includes = new ArrayList<>(lst);
+                               } else if (A2Source.EXCLUDE.equals(key)) {
+                                       excludes = new ArrayList<>(lst);
+                               } else {
+                                       if (lst.size() != 1)
+                                               throw new IllegalArgumentException("Invalid XOR definitions in " + uri);
+                                       xOr.put(key, lst.get(0));
+                               }
                        }
 
                        if (SCHEME_A2.equals(u.getScheme()) || SCHEME_A2_REFERENCE.equals(u.getScheme())) {
@@ -81,7 +89,8 @@ public class ProvisioningManager {
                                        }
                                        Path base = Paths.get(baseStr);
                                        if (Files.exists(base)) {
-                                               FsA2Source source = new FsA2Source(base, xOr, SCHEME_A2_REFERENCE.equals(u.getScheme()));
+                                               FsA2Source source = new FsA2Source(base, xOr, SCHEME_A2_REFERENCE.equals(u.getScheme()),
+                                                               includes, excludes);
                                                source.load();
                                                addSource(source);
                                                OsgiBootUtils.info("Registered " + uri + " as source");
@@ -91,7 +100,7 @@ public class ProvisioningManager {
                                                Path localLibBase = base.resolve(A2Contribution.LIB).resolve(localRelPath);
                                                if (Files.exists(localLibBase)) {
                                                        FsA2Source libSource = new FsA2Source(localLibBase, xOr,
-                                                                       SCHEME_A2_REFERENCE.equals(u.getScheme()));
+                                                                       SCHEME_A2_REFERENCE.equals(u.getScheme()), includes, excludes);
                                                        libSource.load();
                                                        addSource(libSource);
                                                        OsgiBootUtils.info("Registered OS-specific " + uri + " as source (" + localRelPath + ")");
@@ -166,7 +175,11 @@ public class ProvisioningManager {
                                        // TODO make it more dynamic, based on OSGi APIs
                                        // TODO remove old module? Or keep update history?
                                        osgiContext.registerBundle(bundle);
-                                       OsgiBootUtils.info("Updated bundle " + bundle.getLocation() + " to version " + moduleVersion);
+                                       if (compare == 0)
+                                               OsgiBootUtils
+                                                               .debug("Updated bundle " + bundle.getLocation() + " to same version " + moduleVersion);
+                                       else
+                                               OsgiBootUtils.info("Updated bundle " + bundle.getLocation() + " to version " + moduleVersion);
                                        return bundle;
                                } else {
                                        if (OsgiBootUtils.isDebug())