Improve JTS support
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 29 Sep 2023 16:17:13 +0000 (18:17 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 29 Sep 2023 16:17:13 +0000 (18:17 +0200)
org.argeo.api.acr/src/org/argeo/api/acr/Content.java
org.argeo.cms.jshell/src/org/argeo/internal/cms/jshell/osgi/OsgiExecutionControlProvider.java

index df5c149e6fc1fc696187d197766ad5f9cf0c2c52..33ddeecedb2d07018cbdbd3d8248193350be3b1b 100644 (file)
@@ -89,12 +89,29 @@ public interface Content extends Iterable<Content>, Map<QName, Object> {
        /*
         * CONTENT OPERATIONS
         */
+       /** Adds a new empty {@link Content} to this {@link Content}. */
        Content add(QName name, QName... classes);
 
+       /**
+        * Adds a new {@link Content} to this {@link Content}, setting the provided
+        * attributes. The provided attributes can be used as hints by the
+        * implementation. In particular, setting {@link DName#getcontenttype} will
+        * imply that this content has a file semantic.
+        */
+       default Content add(QName name, Map<QName, Object> attrs, QName... classes) {
+               Content child = add(name, classes);
+               putAll(attrs);
+               return child;
+       }
+
        default Content add(String name, QName... classes) {
                return add(unqualified(name), classes);
        }
 
+       default Content add(String name, Map<QName, Object> attrs, QName... classes) {
+               return add(unqualified(name), attrs, classes);
+       }
+
        void remove();
 
        /*
index fbca085861759a1410b743555d8eb1d817db6367..4a8f1685f769b0d622373cff420362902dbea124 100644 (file)
@@ -22,6 +22,7 @@ import org.argeo.api.cms.CmsLog;
 import org.argeo.cms.jshell.CmsExecutionControl;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
 import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.Version;
 import org.osgi.framework.namespace.PackageNamespace;
@@ -89,6 +90,25 @@ public class OsgiExecutionControlProvider implements ExecutionControlProvider {
        public static Path getBundleStartupScript(Long bundleId) {
                BundleContext bc = FrameworkUtil.getBundle(OsgiExecutionControlProvider.class).getBundleContext();
                Bundle fromBundle = bc.getBundle(bundleId);
+
+               int bundleState = fromBundle.getState();
+               if (Bundle.INSTALLED == bundleState)
+                       throw new IllegalStateException("Bundle " + fromBundle.getSymbolicName() + " is not resolved");
+               if (Bundle.RESOLVED == bundleState) {
+                       try {
+                               fromBundle.start();
+                       } catch (BundleException e) {
+                               throw new IllegalStateException("Cannot start bundle " + fromBundle.getSymbolicName(), e);
+                       }
+                       while (Bundle.ACTIVE != fromBundle.getState())
+                               try {
+                                       Thread.sleep(100);
+                               } catch (InterruptedException e) {
+                                       // we assume the session has been closed
+                                       throw new RuntimeException("Bundle " + fromBundle.getSymbolicName() + " is not active", e);
+                               }
+               }
+
                Path bundleStartupScript = fromBundle.getDataFile("BUNDLE.jsh").toPath();
 
                BundleWiring fromBundleWiring = fromBundle.adapt(BundleWiring.class);
@@ -101,8 +121,13 @@ public class OsgiExecutionControlProvider implements ExecutionControlProvider {
                        packagesToImport.add(pkg.getName());
                }
 
-               List<BundleWire> bundleWires = fromBundleWiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
-               for (BundleWire bw : bundleWires) {
+//             List<BundleWire> exportedWires = fromBundleWiring.getProvidedWires(BundleRevision.PACKAGE_NAMESPACE);
+//             for (BundleWire bw : exportedWires) {
+//                     packagesToImport.add(bw.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE).toString());
+//             }
+
+               List<BundleWire> importedWires = fromBundleWiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
+               for (BundleWire bw : importedWires) {
                        packagesToImport.add(bw.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE).toString());
                }