コード例 #1
0
ファイル: CapReqBuilder.java プロジェクト: kwin/bnd
 public CapReqBuilder addDirectives(Attrs directives) {
   for (Entry<String, String> e : directives.entrySet()) {
     String key = Attrs.toDirective(e.getKey());
     if (key != null) addDirective(key, e.getValue());
   }
   return this;
 }
コード例 #2
0
ファイル: CapReqBuilder.java プロジェクト: kwin/bnd
  public void addFilter(String ns, String name, String version, Attrs attrs) {
    List<String> parts = new ArrayList<String>();

    parts.add("(" + ns + "=" + name + ")");
    if (version != null && VersionRange.isOSGiVersionRange(version)) {
      VersionRange range = VersionRange.parseOSGiVersionRange(version);
      parts.add(range.toFilter());
    }

    String mandatory = attrs.get(Constants.MANDATORY_DIRECTIVE + ":");
    if (mandatory != null) {
      String mandatoryAttrs[] = mandatory.split("\\s*,\\s*");
      Arrays.sort(mandatoryAttrs);
      for (String mandatoryAttr : mandatoryAttrs) {
        String value = attrs.get(mandatoryAttr);
        if (value != null) {
          parts.add("(" + mandatoryAttr + "=" + escapeFilterValue(value) + ")");
        }
      }
    }

    StringBuilder sb = new StringBuilder();
    if (parts.size() > 0) sb.append("(&");
    for (String s : parts) {
      sb.append(s);
    }
    if (parts.size() > 0) sb.append(")");
    addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, sb.toString());
  }
コード例 #3
0
 public static VersionedClause convertRepoBundleVersion(RepositoryBundleVersion bundleVersion) {
   Attrs attribs = new Attrs();
   if (isWorkspaceRepo(bundleVersion.getBundle().getRepo()))
     attribs.put(Constants.VERSION_ATTRIBUTE, VERSION_LATEST);
   else attribs.put(Constants.VERSION_ATTRIBUTE, bundleVersion.getVersion().toString());
   return new VersionedClause(bundleVersion.getBundle().getBsn(), attribs);
 }
コード例 #4
0
 public static VersionedClause convertRepoBundle(RepositoryBundle bundle) {
   Attrs attribs = new Attrs();
   if (isWorkspaceRepo(bundle.getRepo())) {
     attribs.put(Constants.VERSION_ATTRIBUTE, VERSION_LATEST);
   }
   return new VersionedClause(bundle.getBsn(), attribs);
 }
コード例 #5
0
ファイル: ContractTest.java プロジェクト: GitHubTE/bnd
  /**
   * 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:"));
  }
コード例 #6
0
ファイル: CapReqBuilder.java プロジェクト: kwin/bnd
 /**
  * In bnd, we only use one map for both directives & attributes. This method will properly
  * dispatch them AND take care of typing
  *
  * @param attrs
  * @throws Exception
  */
 public void addAttributesOrDirectives(Attrs attrs) throws Exception {
   for (Entry<String, String> e : attrs.entrySet()) {
     String directive = Attrs.toDirective(e.getKey());
     if (directive != null) {
       addDirective(directive, e.getValue());
     } else {
       Object typed = attrs.getTyped(e.getKey());
       if (typed instanceof aQute.bnd.version.Version) {
         typed = new Version(typed.toString());
       }
       addAttribute(e.getKey(), typed);
     }
   }
 }
コード例 #7
0
ファイル: CapReqBuilder.java プロジェクト: kwin/bnd
 public CapReqBuilder(String ns, Attrs attrs) throws Exception {
   this.namespace = ns;
   for (Entry<String, String> entry : attrs.entrySet()) {
     String key = entry.getKey();
     if (key.endsWith(":")) addDirective(key.substring(0, key.length() - 1), entry.getValue());
     else addAttribute(key, entry.getValue());
   }
 }
コード例 #8
0
ファイル: VersionPolicyTest.java プロジェクト: JSlain/bnd
  /**
   * Tests if the implementation of the EventHandler (which is marked as a ConsumerType) causes the
   * import of the api package to use the consumer version policy.
   */
  public static void testConsumerType() throws Exception {
    Builder a = new Builder();
    a.addClasspath(new File("bin"));
    a.setPrivatePackage("test.versionpolicy.uses");
    a.setExportPackage("test.versionpolicy.api");
    a.setProperty("build", "123");
    Jar jar = a.build();
    assertTrue(a.check());
    Manifest m = jar.getManifest();
    m.write(System.err);
    Domain d = Domain.domain(m);

    Parameters parameters = d.getImportPackage();
    Attrs attrs = parameters.get("test.versionpolicy.api");
    assertNotNull(attrs);
    assertEquals("[1.2,2)", attrs.get("version"));
  }
コード例 #9
0
ファイル: VersionPolicyTest.java プロジェクト: JSlain/bnd
  /**
   * Test if the implementation of "AnnotatedProviderInterface", which is annotated with OSGi
   * R6 @ProviderType, causes import of the api package to use the provider version policy
   */
  public static void testProviderTypeR6() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setPrivatePackage("test.versionpolicy.implemented.osgi");
    b.setProperty("build", "123");

    Jar jar = b.build();
    assertTrue(b.check());
    Manifest m = jar.getManifest();
    m.write(System.err);

    Domain d = Domain.domain(m);
    Parameters params = d.getImportPackage();
    Attrs attrs = params.get("test.version.annotations.osgi");
    assertNotNull(attrs);
    assertEquals("[1.2,1.3)", attrs.get("version"));
  }
コード例 #10
0
  /** 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;
  }
コード例 #11
0
ファイル: CapReqBuilder.java プロジェクト: kwin/bnd
  public Attrs toAttrs() {
    Attrs attrs = new Attrs();

    if (attributes != null) {
      for (Entry<String, Object> e : attributes.entrySet()) {
        Object value = e.getValue();

        if (e.getKey().equals("version") || value instanceof Version) value = toBndVersions(value);

        attrs.putTyped(e.getKey(), value);
      }
    }

    if (directives != null)
      for (Entry<String, String> e : directives.entrySet()) {
        attrs.put(e.getKey() + ":", e.getValue());
      }

    return attrs;
  }
コード例 #12
0
ファイル: VersionPolicyTest.java プロジェクト: JSlain/bnd
  /**
   * Tests if the implementation of the EventAdmin (which is marked as a ProviderType) causes the
   * import of the api package to use the provider version policy.
   */
  public static void testProviderType() throws Exception {
    Builder a = new Builder();
    a.addClasspath(new File("bin"));
    a.setPrivatePackage("test.versionpolicy.implemented");
    a.setExportPackage("test.versionpolicy.api");
    a.setImportPackage("test.versionpolicy.api"); // what changed so this is
    // not automatically
    // added?
    a.setProperty("build", "123");
    Jar jar = a.build();
    assertTrue(a.check());
    Manifest m = jar.getManifest();
    m.write(System.err);
    Domain d = Domain.domain(m);

    Parameters parameters = d.getImportPackage();
    Attrs attrs = parameters.get("test.versionpolicy.api");
    assertNotNull(attrs);
    assertEquals("[1.2,1.3)", attrs.get("version"));
  }
コード例 #13
0
ファイル: CapReqBuilder.java プロジェクト: kwin/bnd
 public static CapReqBuilder createCapReqBuilder(String namespace, Attrs attrs) throws Exception {
   CapReqBuilder builder = new CapReqBuilder(namespace);
   for (Entry<String, String> entry : attrs.entrySet()) {
     String key = entry.getKey();
     if (key.endsWith(":")) {
       key = key.substring(0, key.length() - 1);
       builder.addDirective(key, entry.getValue());
     } else {
       builder.addAttribute(key, entry.getValue());
     }
   }
   return builder;
 }
コード例 #14
0
ファイル: ContractTest.java プロジェクト: GitHubTE/bnd
  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());
  }
コード例 #15
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();
    }
  }
コード例 #16
0
  private void _processURL(StringBundler sb, URL url, String[] ignoredFragments) {

    Manifest manifest = null;

    try {
      manifest = new Manifest(url.openStream());
    } catch (IOException ioe) {
      _log.error(ioe, ioe);

      return;
    }

    Attributes attributes = manifest.getMainAttributes();

    String bundleSymbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);

    if (Validator.isNull(bundleSymbolicName)) {
      String urlString = url.toString();

      if (urlString.contains(PropsValues.LIFERAY_LIB_PORTAL_DIR)) {
        manifest = _calculateManifest(url, manifest);

        attributes = manifest.getMainAttributes();

        bundleSymbolicName =
            attributes.getValue(new Attributes.Name(Constants.BUNDLE_SYMBOLICNAME));

        if (Validator.isNull(bundleSymbolicName)) {
          return;
        }
      } else {
        return;
      }
    }

    String rootBundleSymbolicName = bundleSymbolicName;

    int index = rootBundleSymbolicName.indexOf(StringPool.SEMICOLON);

    if (index != -1) {
      rootBundleSymbolicName = rootBundleSymbolicName.substring(0, index);
    }

    for (String ignoredFragment : ignoredFragments) {
      String ignoredFramentPrefix = ignoredFragment.substring(0, ignoredFragment.length() - 1);

      if (rootBundleSymbolicName.equals(ignoredFragment)
          || (ignoredFragment.endsWith(StringPool.STAR)
              && rootBundleSymbolicName.startsWith(ignoredFramentPrefix))) {

        return;
      }
    }

    String exportPackage = GetterUtil.getString(attributes.getValue(Constants.EXPORT_PACKAGE));

    Parameters parameters = OSGiHeader.parseHeader(exportPackage);

    for (Map.Entry<String, Attrs> entry : parameters.entrySet()) {
      String key = entry.getKey();

      List<URL> urls = _extraPackageMap.get(key);

      if (urls == null) {
        urls = new ArrayList<URL>();

        _extraPackageMap.put(key, urls);
      }

      urls.add(url);

      sb.append(key);

      Attrs value = entry.getValue();

      if (value.containsKey("version")) {
        sb.append(";version=\"");
        sb.append(value.get("version"));
        sb.append("\"");
      }

      sb.append(StringPool.COMMA);
    }
  }