Improve A2
authorMathieu <mbaudier@argeo.org>
Sun, 20 Nov 2022 10:43:35 +0000 (11:43 +0100)
committerMathieu <mbaudier@argeo.org>
Sun, 20 Nov 2022 10:43:35 +0000 (11:43 +0100)
Makefile-rcp.mk
org.argeo.api.cms/bnd.bnd
org.argeo.init/src/org/argeo/init/a2/AbstractProvisioningSource.java
org.argeo.init/src/org/argeo/init/a2/FsA2Source.java

index d534e2f96dc57aeb8c8e71fe4781095132604116..29f1a23a382f3dcabe556338fd56c61f8d68fa67 100644 (file)
@@ -21,7 +21,6 @@ osgi/api/org.argeo.tp.osgi \
 swt/rcp/org.argeo.tp.swt \
 lib/linux/x86_64/swt/rcp/org.argeo.tp.swt \
 swt/rcp/org.argeo.tp.swt.workbench \
-org.argeo.tp.jcr
 
 
 clean:
index 3517484841e881db7bbf6cf8c3327cc949de3978..36cde6410b661217d9016bf03cb81b3179082af7 100644 (file)
@@ -1,4 +1,5 @@
 Import-Package: \
+javax.transaction.xa,\
 javax.security.*,\
 org.osgi.service.useradmin,\
 
index 7df851b2452c0d788c5618a9372238459d712021..617e7887806f451a9eb89cd874610ccf8bab0344 100644 (file)
@@ -28,10 +28,10 @@ import org.osgi.framework.Version;
 public abstract class AbstractProvisioningSource implements ProvisioningSource {
        protected final Map<String, A2Contribution> contributions = Collections.synchronizedSortedMap(new TreeMap<>());
 
-       private final boolean useReference;
+       private final boolean usingReference;
 
-       public AbstractProvisioningSource(boolean useReference) {
-               this.useReference = useReference;
+       public AbstractProvisioningSource(boolean usingReference) {
+               this.usingReference = usingReference;
        }
 
        public Iterable<A2Contribution> listContributions(Object filter) {
@@ -42,7 +42,7 @@ public abstract class AbstractProvisioningSource implements ProvisioningSource {
        public Bundle install(BundleContext bc, A2Module module) {
                try {
                        Object locator = module.getLocator();
-                       if (useReference && locator instanceof Path locatorPath) {
+                       if (usingReference && locator instanceof Path locatorPath) {
                                String referenceUrl = "reference:file:" + locatorPath.toString();
                                Bundle bundle = bc.installBundle(referenceUrl);
                                return bundle;
@@ -69,7 +69,7 @@ public abstract class AbstractProvisioningSource implements ProvisioningSource {
        public void update(Bundle bundle, A2Module module) {
                try {
                        Object locator = module.getLocator();
-                       if (useReference && locator instanceof Path) {
+                       if (usingReference && locator instanceof Path) {
                                try (InputStream in = newInputStream(locator)) {
                                        bundle.update(in);
                                }
@@ -196,6 +196,20 @@ public abstract class AbstractProvisioningSource implements ProvisioningSource {
                return symbolicName;
        }
 
+       protected boolean isUsingReference() {
+               return usingReference;
+       }
+
+       private InputStream newInputStream(Object locator) throws IOException {
+               if (locator instanceof Path) {
+                       return Files.newInputStream((Path) locator);
+               } else if (locator instanceof URL) {
+                       return ((URL) locator).openStream();
+               } else {
+                       throw new IllegalArgumentException("Unsupported module locator type " + locator.getClass());
+               }
+       }
+
        private static Manifest findManifest(Path currentPath) {
                Path metaInfPath = currentPath.resolve("META-INF");
                if (Files.exists(metaInfPath) && Files.isDirectory(metaInfPath)) {
@@ -241,13 +255,4 @@ public abstract class AbstractProvisioningSource implements ProvisioningSource {
 
        }
 
-       private InputStream newInputStream(Object locator) throws IOException {
-               if (locator instanceof Path) {
-                       return Files.newInputStream((Path) locator);
-               } else if (locator instanceof URL) {
-                       return ((URL) locator).openStream();
-               } else {
-                       throw new IllegalArgumentException("Unsupported module locator type " + locator.getClass());
-               }
-       }
 }
index d4aa863869aa682f3aec5c92e80e8212d8042f2c..e0e2e437f58307c50b60e53500634b3111da2f21 100644 (file)
@@ -9,6 +9,7 @@ import java.nio.file.Path;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.SortedMap;
+import java.util.StringJoiner;
 import java.util.TreeMap;
 
 import org.argeo.init.osgi.OsgiBootUtils;
@@ -17,16 +18,16 @@ import org.osgi.framework.Version;
 /** A file system {@link AbstractProvisioningSource} in A2 format. */
 public class FsA2Source extends AbstractProvisioningSource implements A2Source {
        private final Path base;
-       private final Map<String, String> xOr;
+       private final Map<String, String> variantsXOr;
 
 //     public FsA2Source(Path base) {
 //             this(base, new HashMap<>());
 //     }
 
-       public FsA2Source(Path base, Map<String, String> xOr, boolean useReference) {
-               super(useReference);
+       public FsA2Source(Path base, Map<String, String> variantsXOr, boolean usingReference) {
+               super(usingReference);
                this.base = base;
-               this.xOr = new HashMap<>(xOr);
+               this.variantsXOr = new HashMap<>(variantsXOr);
        }
 
        void load() throws IOException {
@@ -44,7 +45,7 @@ public class FsA2Source extends AbstractProvisioningSource implements A2Source {
                                } else {// variants
                                        Path variantPath = null;
                                        // is it an explicit variant?
-                                       String variant = xOr.get(contributionPath.getFileName().toString());
+                                       String variant = variantsXOr.get(contributionPath.getFileName().toString());
                                        if (variant != null) {
                                                variantPath = contributionPath.resolve(variant);
                                        }
@@ -119,7 +120,16 @@ public class FsA2Source extends AbstractProvisioningSource implements A2Source {
                URI baseUri = base.toUri();
                try {
                        if (baseUri.getScheme().equals("file")) {
-                               return new URI(SCHEME_A2, null, base.toString(), null);
+                               String queryPart = "";
+                               if (!getVariantsXOr().isEmpty()) {
+                                       StringJoiner sj = new StringJoiner("&");
+                                       for (String key : getVariantsXOr().keySet()) {
+                                               sj.add(key + "=" + getVariantsXOr().get(key));
+                                       }
+                                       queryPart = sj.toString();
+                               }
+                               return new URI(isUsingReference() ? SCHEME_A2_REFERENCE : SCHEME_A2, null, base.toString(), queryPart,
+                                               null);
                        } else {
                                throw new UnsupportedOperationException("Unsupported scheme " + baseUri.getScheme());
                        }
@@ -128,6 +138,10 @@ public class FsA2Source extends AbstractProvisioningSource implements A2Source {
                }
        }
 
+       protected Map<String, String> getVariantsXOr() {
+               return variantsXOr;
+       }
+
 //     public static void main(String[] args) {
 //             if (args.length == 0)
 //                     throw new IllegalArgumentException("Usage: <path to A2 base>");