Beispiel #1
0
  private File findFramework(MultiStatus status) {
    String runFramework = model.getRunFramework();
    Map<String, Map<String, String>> header = OSGiHeader.parseHeader(runFramework);
    if (header.size() != 1) {
      status.add(
          new Status(
              IStatus.ERROR,
              Plugin.PLUGIN_ID,
              0,
              "Invalid format for " + BndConstants.RUNFRAMEWORK + " header",
              null));
      return null;
    }

    Entry<String, Map<String, String>> entry = header.entrySet().iterator().next();
    VersionedClause clause = new VersionedClause(entry.getKey(), entry.getValue());

    String versionRange = clause.getVersionRange();
    if (versionRange == null) versionRange = new Version(0, 0, 0).toString();

    try {
      Container container =
          getProject().getBundle(clause.getName(), versionRange, Strategy.HIGHEST, null);
      if (container.getType() == TYPE.ERROR) {
        status.add(
            new Status(
                IStatus.ERROR,
                Plugin.PLUGIN_ID,
                0,
                "Unable to find specified OSGi framework: " + container.getError(),
                null));
        return null;
      }
      return container.getFile();
    } catch (Exception e) {
      status.add(
          new Status(
              IStatus.ERROR,
              Plugin.PLUGIN_ID,
              0,
              "Error while trying to find the specified OSGi framework.",
              e));
      return null;
    }
  }
  /** Created a JAR that is a bundle and that contains its dependencies */
  @Override
  public Jar executable() throws Exception {
    Collection<String> bsns = getProject().getBsns();
    if (bsns.size() != 1)
      throw new IllegalArgumentException(
          "Can only handle a single bsn for a run configuration " + bsns);
    String bsn = bsns.iterator().next();

    Jar jar = new Jar(bsn);
    String path = "aQute/remote/embedded/activator/EmbeddedActivator.class";
    URLResource resource = new URLResource(getClass().getClassLoader().getResource(path));
    jar.putResource("aQute/remote/embedded/activator/EmbeddedActivator.class", resource);

    Collection<Container> rb = getProject().getRunbundles();
    rb = Container.flatten(rb);
    Attrs attrs = new Attrs();

    for (Container c : rb) {
      if (c.getError() != null) {
        getProject().error("invalid runbundle %s", c);
      } else {
        File f = c.getFile();
        String tbsn = c.getBundleSymbolicName();
        String version = c.getVersion();
        if (version == null || !Version.isVersion(version))
          getProject()
              .warning("The version of embedded bundle %s does not have a proper version", c);

        jar.putResource("jar/" + c.getBundleSymbolicName() + ".jar", new FileResource(f));

        attrs.put(tbsn, version);
      }
    }

    Analyzer a = new Analyzer(getProject());
    a.setJar(jar);

    a.setBundleActivator(EmbeddedActivator.class.getName());
    a.setProperty("Bnd-Embedded", attrs.toString().replace(';', ','));
    Manifest manifest = a.calcManifest();
    jar.setManifest(manifest);
    getProject().getInfo(a);
    return jar;
  }