X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Finit%2Fa2%2FProvisioningManager.java;h=a237fdf48aecaa79349df7f0999c183c0e05a8e6;hb=c66685995c1bf2c59bdf6d68753470c85828310a;hp=6d842650c2620fd2d26249bf69d7d741a37aa3fd;hpb=0a0a90e832a2fe24dc55d1cf67d75e276ad61b2c;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.init/src/org/argeo/init/a2/ProvisioningManager.java b/org.argeo.init/src/org/argeo/init/a2/ProvisioningManager.java index 6d842650c..a237fdf48 100644 --- a/org.argeo.init/src/org/argeo/init/a2/ProvisioningManager.java +++ b/org.argeo.init/src/org/argeo/init/a2/ProvisioningManager.java @@ -1,5 +1,8 @@ package org.argeo.init.a2; +import static org.argeo.init.a2.A2Source.SCHEME_A2; +import static org.argeo.init.a2.A2Source.SCHEME_A2_REFERENCE; + import java.io.File; import java.io.UnsupportedEncodingException; import java.net.URI; @@ -9,7 +12,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -25,7 +27,6 @@ import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; import org.osgi.framework.Version; -import org.osgi.framework.launch.Framework; import org.osgi.framework.wiring.FrameworkWiring; /** Loads provisioning sources into an OSGi context. */ @@ -72,7 +73,7 @@ public class ProvisioningManager { xOr.put(key, lst.get(0)); } - if (A2Source.SCHEME_A2.equals(u.getScheme())) { + if (SCHEME_A2.equals(u.getScheme()) || SCHEME_A2_REFERENCE.equals(u.getScheme())) { if (u.getHost() == null || "".equals(u.getHost())) { String baseStr = u.getPath(); if (File.separatorChar == '\\') {// MS Windows @@ -80,12 +81,19 @@ public class ProvisioningManager { } Path base = Paths.get(baseStr); if (Files.exists(base)) { - FsA2Source source = new FsA2Source(base, xOr); + FsA2Source source = new FsA2Source(base, xOr, SCHEME_A2_REFERENCE.equals(u.getScheme())); source.load(); addSource(source); OsgiBootUtils.info("Registered " + uri + " as source"); + } else { + OsgiBootUtils.debug("Source " + base + " does not exist, ignoring."); } + } else { + throw new UnsupportedOperationException( + "Remote installation is not yet supported, cannot add source " + u); } + } else { + throw new IllegalArgumentException("Unkown scheme: for source " + u); } } catch (Exception e) { throw new A2Exception("Cannot add source " + uri, e); @@ -217,46 +225,46 @@ public class ProvisioningManager { } } - public static void main(String[] args) { - if (args.length == 0) - throw new IllegalArgumentException("Usage: "); - Map configuration = new HashMap<>(); - configuration.put("osgi.console", "2323"); - configuration.put("org.osgi.framework.bootdelegation", - "com.sun.jndi.ldap,com.sun.jndi.ldap.sasl,com.sun.security.jgss,com.sun.jndi.dns,com.sun.nio.file,com.sun.nio.sctp,sun.nio.cs"); - Framework framework = OsgiBootUtils.launch(configuration); - try { - ProvisioningManager pm = new ProvisioningManager(framework.getBundleContext()); - Map xOr = new HashMap<>(); - xOr.put("osgi", "equinox"); - xOr.put("swt", "rap"); - FsA2Source context = new FsA2Source(Paths.get(args[0]), xOr); - context.load(); - pm.addSource(context); - if (framework.getBundleContext().getBundles().length == 1) {// initial - pm.install(null); - } else { - pm.update(); - } - - Thread.sleep(2000); - - Bundle[] bundles = framework.getBundleContext().getBundles(); - Arrays.sort(bundles, (b1, b2) -> b1.getSymbolicName().compareTo(b2.getSymbolicName())); - for (Bundle b : bundles) - if (b.getState() == Bundle.RESOLVED || b.getState() == Bundle.STARTING || b.getState() == Bundle.ACTIVE) - System.out.println(b.getSymbolicName() + " " + b.getVersion()); - else - System.err.println(b.getSymbolicName() + " " + b.getVersion() + " (" + b.getState() + ")"); - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - framework.stop(); - } catch (Exception e) { - e.printStackTrace(); - } - } - } +// public static void main(String[] args) { +// if (args.length == 0) +// throw new IllegalArgumentException("Usage: "); +// Map configuration = new HashMap<>(); +// configuration.put("osgi.console", "2323"); +// configuration.put("org.osgi.framework.bootdelegation", +// "com.sun.jndi.ldap,com.sun.jndi.ldap.sasl,com.sun.security.jgss,com.sun.jndi.dns,com.sun.nio.file,com.sun.nio.sctp,sun.nio.cs"); +// Framework framework = OsgiBootUtils.launch(configuration); +// try { +// ProvisioningManager pm = new ProvisioningManager(framework.getBundleContext()); +// Map xOr = new HashMap<>(); +// xOr.put("osgi", "equinox"); +// xOr.put("swt", "rap"); +// FsA2Source context = new FsA2Source(Paths.get(args[0]), xOr); +// context.load(); +// pm.addSource(context); +// if (framework.getBundleContext().getBundles().length == 1) {// initial +// pm.install(null); +// } else { +// pm.update(); +// } +// +// Thread.sleep(2000); +// +// Bundle[] bundles = framework.getBundleContext().getBundles(); +// Arrays.sort(bundles, (b1, b2) -> b1.getSymbolicName().compareTo(b2.getSymbolicName())); +// for (Bundle b : bundles) +// if (b.getState() == Bundle.RESOLVED || b.getState() == Bundle.STARTING || b.getState() == Bundle.ACTIVE) +// System.out.println(b.getSymbolicName() + " " + b.getVersion()); +// else +// System.err.println(b.getSymbolicName() + " " + b.getVersion() + " (" + b.getState() + ")"); +// } catch (Exception e) { +// e.printStackTrace(); +// } finally { +// try { +// framework.stop(); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// } }