Пример #1
0
  /**
   * Test if we can select
   *
   * @throws Exception
   */
  public void testSelect() throws Exception {
    Jar bjara = getContractExporter("atest", "2.5", "${exports}");
    Jar bjarb = getContractExporter("btest", "2.5", "${exports}");

    Builder a = newBuilder();
    a.setTrace(true);

    a.addClasspath(bjara); // 1x
    a.addClasspath(bjarb); // 2x
    a.setProperty(Constants.CONTRACT, "atest;alpha=1");
    a.setImportPackage("org.osgi.service.cm,*");
    a.setProperty("Export-Package", "test.refer");
    Jar ajar = a.build();
    assertTrue(a.check());
    ajar.getManifest().write(System.out);

    Domain domain = Domain.domain(ajar.getManifest());
    Parameters p = domain.getRequireCapability();
    p.remove("osgi.ee");
    assertNotNull(p);
    assertEquals(1, p.size());
    Attrs attrs = p.get("osgi.contract");
    String alpha = attrs.get("alpha");
    assertEquals("1", alpha);
    assertEquals("(&(osgi.contract=atest)(version=2.5.0))", attrs.get("filter:"));
  }
Пример #2
0
  /** @throws Exception */
  File[] getBundleClasspathFiles() throws Exception {

    if (this.bundleClasspathExpansion != null) return bundleClasspathExpansion;

    File file = getFile();

    Manifest m = getManifest();
    String bundleClassPath;
    if (m == null
        || (bundleClassPath = m.getMainAttributes().getValue(Constants.BUNDLE_CLASSPATH)) == null) {
      this.bundleClasspathExpansion = new File[] {file};
    } else {

      File bundleClasspathDirectory =
          IO.getFile(file.getParentFile(), "." + file.getName() + "-bcp");
      Parameters header = new Parameters(bundleClassPath);
      this.bundleClasspathExpansion = new File[header.size()];
      bundleClasspathDirectory.mkdir();

      int n = 0;
      Jar jar = null;
      try {
        for (Map.Entry<String, Attrs> entry : header.entrySet()) {
          if (".".equals(entry.getKey())) {
            this.bundleClasspathExpansion[n] = file;
          } else {
            File member = new File(bundleClasspathDirectory, n + "-" + toName(entry.getKey()));
            if (!isCurrent(file, member)) {

              if (jar == null) {
                jar = new Jar(file);
              }

              Resource resource = jar.getResource(entry.getKey());
              if (resource == null) {
                warning += "Invalid bcp entry: " + entry.getKey() + "\n";
              } else {
                IO.copy(resource.openInputStream(), member);
                member.setLastModified(file.lastModified());
              }
            }
            this.bundleClasspathExpansion[n] = member;
          }
          n++;
        }
      } finally {
        if (jar != null) jar.close();
      }
    }

    return this.bundleClasspathExpansion;
  }
Пример #3
0
  /**
   * Make sure we do not add a contract if not used
   *
   * @throws Exception
   */
  public void testUnused() throws Exception {
    Jar bjara = getContractExporter("atest", "2.5", "${exports}");

    Builder a = newBuilder();
    a.setTrace(true);
    a.addClasspath(bjara);

    a.setProperty(Constants.CONTRACT, "*");
    a.setImportPackage("test.packageinfo,*");
    a.setProperty("Export-Package", "test.refer");
    Jar ajar = a.build();
    assertTrue(a.check());

    Domain domain = Domain.domain(ajar.getManifest());
    Parameters p = domain.getRequireCapability();
    p.remove("osgi.ee");
    assertEquals(0, p.size());
  }
Пример #4
0
  /**
   * Test the warnings that we have no no version
   *
   * @throws Exception
   */
  public void testWarningVersion() throws Exception {
    Jar bjara = getContractExporter("abc", null, "${exports}");

    Builder a = newBuilder();
    a.setTrace(true);
    a.addClasspath(bjara);

    a.setProperty(Constants.CONTRACT, "*");
    a.setImportPackage("test.packageinfo,*");
    a.setProperty("Export-Package", "test.refer");
    Jar ajar = a.build();
    assertTrue(
        a.check(
            "Contract \\[name=abc;version=0.0.0;from=biz.aQute.bndlib.tests] does not declare a version"));

    Domain domain = Domain.domain(ajar.getManifest());
    Parameters p = domain.getRequireCapability();
    p.remove("osgi.ee");
    assertEquals(0, p.size());
  }
Пример #5
0
  public void testSimple() throws Exception {
    Jar bjar = getContractExporter("test", "2.5", "${exports}");

    Builder a = newBuilder();
    a.setTrace(true);
    a.addClasspath(bjar);
    a.setProperty(Constants.CONTRACT, "*");
    a.setImportPackage("org.osgi.service.cm,*");
    a.setProperty("Export-Package", "test.refer");
    Jar ajar = a.build();
    assertTrue(a.check());
    Domain domain = Domain.domain(ajar.getManifest());
    Parameters rc = domain.getRequireCapability();
    rc.remove("osgi.ee");
    System.out.println(rc);
    assertEquals(1, rc.size());

    Packages ps = a.getImports();
    assertTrue(ps.containsFQN("org.osgi.service.cm"));
    Attrs attrs = ps.getByFQN("org.osgi.service.cm");
    assertNotNull(attrs);
    assertNull(attrs.getVersion());
  }
Пример #6
0
  public CommandData parseCommandData(ArtifactData artifact) throws Exception {
    File source = new File(artifact.file);
    if (!source.isFile()) throw new FileNotFoundException();

    CommandData data = new CommandData();
    data.sha = artifact.sha;
    data.jpmRepoDir = repoDir.getCanonicalPath();
    JarFile jar = new JarFile(source);
    try {
      reporter.trace("Parsing %s", source);
      Manifest m = jar.getManifest();
      Attributes main = m.getMainAttributes();
      data.name = data.bsn = main.getValue("Bundle-SymbolicName");
      String version = main.getValue("Bundle-Version");
      if (version == null) data.version = Version.LOWEST;
      else data.version = new Version(version);

      data.main = main.getValue("Main-Class");
      data.description = main.getValue("Bundle-Description");
      data.title = main.getValue("JPM-Name");

      reporter.trace("name " + data.name + " " + data.main + " " + data.title);
      DependencyCollector path = new DependencyCollector(this);
      path.add(artifact);
      DependencyCollector bundles = new DependencyCollector(this);
      if (main.getValue("JPM-Classpath") != null) {
        Parameters requires = OSGiHeader.parseHeader(main.getValue("JPM-Classpath"));

        for (Map.Entry<String, Attrs> e : requires.entrySet()) {
          path.add(e.getKey(), e.getValue().get("name")); // coordinate
        }
      } else if (!artifact.local) { // No JPM-Classpath, falling back to
        // server's revision
        // Iterable<RevisionRef> closure =
        // library.getClosure(artifact.sha,
        // false);
        // System.out.println("getting closure " + artifact.url + " " +
        // Strings.join("\n",closure));

        // if (closure != null) {
        // for (RevisionRef ref : closure) {
        // path.add(Hex.toHexString(ref.revision));
        // }
        // }
      }

      if (main.getValue("JPM-Runbundles") != null) {
        Parameters jpmrunbundles = OSGiHeader.parseHeader(main.getValue("JPM-Runbundles"));

        for (Map.Entry<String, Attrs> e : jpmrunbundles.entrySet()) {
          bundles.add(e.getKey(), e.getValue().get("name"));
        }
      }

      reporter.trace("collect digests runpath");
      data.dependencies.addAll(path.getDigests());
      reporter.trace("collect digests bundles");
      data.runbundles.addAll(bundles.getDigests());

      Parameters command = OSGiHeader.parseHeader(main.getValue("JPM-Command"));
      if (command.size() > 1) reporter.error("Only one command can be specified");

      for (Map.Entry<String, Attrs> e : command.entrySet()) {
        data.name = e.getKey();

        Attrs attrs = e.getValue();

        if (attrs.containsKey("jvmargs")) data.jvmArgs = attrs.get("jvmargs");

        if (attrs.containsKey("title")) data.title = attrs.get("title");

        if (data.title != null) data.title = data.name;
      }
      return data;
    } finally {
      jar.close();
    }
  }