Make A2 API more public.
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 28 May 2022 09:30:38 +0000 (11:30 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 28 May 2022 09:30:38 +0000 (11:30 +0200)
org.argeo.init/src/org/argeo/init/a2/A2Branch.java
org.argeo.init/src/org/argeo/init/a2/A2Component.java
org.argeo.init/src/org/argeo/init/a2/A2Contribution.java
org.argeo.init/src/org/argeo/init/a2/A2Module.java
org.argeo.init/src/org/argeo/init/a2/A2Source.java
org.argeo.init/src/org/argeo/init/a2/FsA2Source.java

index 9713d01d3ef6f0014d538789efed63df435b9494..cd8d8954142f4dfc1a1942b652e2a6932e165b9d 100644 (file)
@@ -24,6 +24,10 @@ public class A2Branch implements Comparable<A2Branch> {
                component.branches.put(id, this);
        }
 
+       public Iterable<A2Module> listModules(Object filter) {
+               return modules.values();
+       }
+
        A2Module getOrAddModule(Version version, Object locator) {
                if (modules.containsKey(version)) {
                        A2Module res = modules.get(version);
@@ -35,19 +39,19 @@ public class A2Branch implements Comparable<A2Branch> {
                        return new A2Module(this, version, locator);
        }
 
-       A2Module last() {
+       public A2Module last() {
                return modules.get(modules.lastKey());
        }
 
-       A2Module first() {
+       public A2Module first() {
                return modules.get(modules.firstKey());
        }
 
-       A2Component getComponent() {
+       public A2Component getComponent() {
                return component;
        }
 
-       String getId() {
+       public String getId() {
                return id;
        }
 
index 2b6814f6b839bb9dab2c0421069f0e98fe4bd9e0..cc2f564716858b5dee3389404bf7fcf8a431dd1e 100644 (file)
@@ -23,6 +23,10 @@ public class A2Component implements Comparable<A2Component> {
                contribution.components.put(id, this);
        }
 
+       public Iterable<A2Branch> listBranches(Object filter) {
+               return branches.values();
+       }
+
        A2Branch getOrAddBranch(String branchId) {
                if (branches.containsKey(branchId))
                        return branches.get(branchId);
@@ -36,15 +40,15 @@ public class A2Component implements Comparable<A2Component> {
                return module;
        }
 
-       A2Branch last() {
+       public A2Branch last() {
                return branches.get(branches.lastKey());
        }
 
-       A2Contribution getContribution() {
+       public A2Contribution getContribution() {
                return contribution;
        }
 
-       String getId() {
+       public String getId() {
                return id;
        }
 
index 3d33b55e281deb1b48dbc0db97b6e5cc65c3b9b2..9d1348294925c1d8a0d6be4ddcb4006eeaab1fe3 100644 (file)
@@ -30,6 +30,10 @@ public class A2Contribution implements Comparable<A2Contribution> {
 //                     context.contributions.put(id, this);
        }
 
+       public Iterable<A2Component> listComponents(Object filter) {
+               return components.values();
+       }
+
        A2Component getOrAddComponent(String componentId) {
                if (components.containsKey(componentId))
                        return components.get(componentId);
index b862c5435a2909dbf127e26528e1a5dcc9bb4ab8..0b6d3a91c5470033bfe8112b073188143964e0bd 100644 (file)
@@ -7,7 +7,7 @@ import org.osgi.framework.Version;
  * <code>Bundle-SymbolicName</code> and <code>Bundle-version</code>. This is the
  * equivalent of the full coordinates of a Maven artifact version.
  */
-class A2Module implements Comparable<A2Module> {
+public class A2Module implements Comparable<A2Module> {
        private final A2Branch branch;
        private final Version version;
        private final Object locator;
@@ -19,11 +19,11 @@ class A2Module implements Comparable<A2Module> {
                branch.modules.put(version, this);
        }
 
-       A2Branch getBranch() {
+       public A2Branch getBranch() {
                return branch;
        }
 
-       Version getVersion() {
+       public Version getVersion() {
                return version;
        }
 
index 388a85012061d8e685166e2f7973fa7f9cd7bce9..c28df3b238bf4a7acc85e4198fc93d55271e9356 100644 (file)
@@ -1,7 +1,11 @@
 package org.argeo.init.a2;
 
+import java.net.URI;
+
 /** A provisioning source in A2 format. */
 public interface A2Source extends ProvisioningSource {
        final static String SCHEME_A2 = "a2";
        final static String DEFAULT_A2_URI = SCHEME_A2 + ":///";
+
+       URI getUri();
 }
index 067537d5911d24bddd7fe8fa2bec73688bcc85de..eb00659dcb4b7db84d381a1d5f86642a6c8d215f 100644 (file)
@@ -1,6 +1,8 @@
 package org.argeo.init.a2;
 
 import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -16,7 +18,6 @@ public class FsA2Source extends AbstractProvisioningSource implements A2Source {
        private final Path base;
 
        public FsA2Source(Path base) {
-               super();
                this.base = base;
        }
 
@@ -75,6 +76,20 @@ public class FsA2Source extends AbstractProvisioningSource implements A2Source {
 
        }
 
+       @Override
+       public URI getUri() {
+               URI baseUri = base.toUri();
+               try {
+                       if (baseUri.getScheme().equals("file")) {
+                               return new URI(SCHEME_A2, null, base.toString(), null);
+                       } else {
+                               throw new UnsupportedOperationException("Unsupported scheme " + baseUri.getScheme());
+                       }
+               } catch (URISyntaxException e) {
+                       throw new IllegalStateException("Cannot build URI from " + baseUri, e);
+               }
+       }
+
        public static void main(String[] args) {
                try {
                        FsA2Source context = new FsA2Source(Paths.get(