Esempio n. 1
0
  public static void testBump() throws Exception {
    File tmp = new File("tmp-ws");
    if (tmp.exists()) IO.deleteWithException(tmp);
    tmp.mkdir();
    assertTrue(tmp.isDirectory());

    try {
      IO.copy(new File("test/ws"), tmp);
      Workspace ws = Workspace.getWorkspace(tmp);
      Project project = ws.getProject("p1");
      int size = project.getProperties().size();
      Version old = new Version(project.getProperty("Bundle-Version"));
      System.err.println("Old version " + old);
      project.bump("=+0");
      Version newv = new Version(project.getProperty("Bundle-Version"));
      System.err.println("New version " + newv);
      assertEquals(old.getMajor(), newv.getMajor());
      assertEquals(old.getMinor() + 1, newv.getMinor());
      assertEquals(0, newv.getMicro());
      assertEquals(size, project.getProperties().size());
      assertEquals("sometime", newv.getQualifier());
    } finally {
      IO.deleteWithException(tmp);
    }
  }
Esempio n. 2
0
  @Override
  protected void setUp() throws Exception {
    tmp = IO.getFile("generated/tmp");
    tmp.mkdirs();

    configuration = new HashMap<String, Object>();
    configuration.put(
        Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
    configuration.put(Constants.FRAMEWORK_STORAGE, new File(tmp, "fwstorage").getAbsolutePath());
    configuration.put(
        Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.4");
    framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration);
    framework.init();
    framework.start();
    BundleContext context = framework.getBundleContext();

    String[] bundles = {
      "../cnf/repo/osgi.cmpn/osgi.cmpn-4.3.1.jar", "testdata/slf4j-simple-1.7.12.jar",
      "testdata/slf4j-api-1.7.12.jar", "testdata/org.apache.aries.util-1.1.0.jar",
      "testdata/org.apache.aries.jmx-1.1.1.jar", "generated/biz.aQute.remote.test.jmx.jar"
    };

    for (String bundle : bundles) {
      String location = "reference:" + IO.getFile(bundle).toURI().toString();
      Bundle b = context.installBundle(location);
      if (!bundle.contains("slf4j-simple")) {
        b.start();
      }
    }

    super.setUp();
  }
Esempio n. 3
0
  public static void testBumpIncludeFile() throws Exception {
    File tmp = new File("tmp-ws");
    if (tmp.exists()) IO.deleteWithException(tmp);
    tmp.mkdir();
    assertTrue(tmp.isDirectory());

    try {
      IO.copy(new File("test/ws"), tmp);
      Workspace ws = Workspace.getWorkspace(tmp);
      Project project = ws.getProject("bump-included");
      project.setTrace(true);
      Version old = new Version(project.getProperty("Bundle-Version"));
      assertEquals(new Version(1, 0, 0), old);
      project.bump("=+0");

      Processor processor = new Processor();
      processor.setProperties(project.getFile("include.txt"));

      Version newv = new Version(processor.getProperty("Bundle-Version"));
      System.err.println("New version " + newv);
      assertEquals(1, newv.getMajor());
      assertEquals(1, newv.getMinor());
      assertEquals(0, newv.getMicro());
    } finally {
      IO.deleteWithException(tmp);
    }
  }
Esempio n. 4
0
  public static void testBumpSubBuilders() throws Exception {
    File tmp = new File("tmp-ws");
    if (tmp.exists()) IO.deleteWithException(tmp);
    tmp.mkdir();
    assertTrue(tmp.isDirectory());

    try {
      IO.copy(new File("test/ws"), tmp);
      Workspace ws = Workspace.getWorkspace(tmp);
      Project project = ws.getProject("bump-sub");
      project.setTrace(true);

      assertNull(project.getProperty("Bundle-Version"));

      project.bump("=+0");

      assertNull(project.getProperty("Bundle-Version"));

      for (Builder b : project.getSubBuilders()) {
        assertEquals(new Version(1, 1, 0), new Version(b.getVersion()));
      }
    } finally {
      IO.deleteWithException(tmp);
    }
  }
Esempio n. 5
0
 private static void checkPackageInfoFiles(
     Project project, String packageName, boolean expectPackageInfo, boolean expectPackageInfoJava)
     throws Exception {
   File pkgInfo = IO.getFile(project.getSrc(), packageName + "/packageinfo");
   File pkgInfoJava = IO.getFile(project.getSrc(), packageName + "/package-info.java");
   assertEquals(expectPackageInfo, pkgInfo.exists());
   assertEquals(expectPackageInfoJava, pkgInfoJava.exists());
 }
Esempio n. 6
0
 @Override
 protected void tearDown() throws Exception {
   super.tearDown();
   framework.stop();
   IO.delete(tmp);
   Main.stop();
   IO.delete(IO.getFile("generated/cache"));
   IO.delete(IO.getFile("generated/storage"));
   framework.waitForStop(100000);
   super.tearDown();
 }
Esempio n. 7
0
  public static void testEnum() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty("-metatype", "*");
    b.build();
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());

    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$Enums.xml");
    IO.copy(r.openInputStream(), System.err);

    Document d = db.parse(r.openInputStream());
    assertEquals(
        "http://www.osgi.org/xmlns/metatype/v1.1.0", d.getDocumentElement().getNamespaceURI());

    Properties p = new Properties();
    p.setProperty("r", "requireConfiguration");
    p.setProperty("i", "ignoreConfiguration");
    p.setProperty("o", "optionalConfiguration");
    Enums enums = Configurable.createConfigurable(Enums.class, (Map<Object, Object>) p);
    assertEquals(Enums.X.requireConfiguration, enums.r());
    assertEquals(Enums.X.ignoreConfiguration, enums.i());
    assertEquals(Enums.X.optionalConfiguration, enums.o());
  }
Esempio n. 8
0
  public void testSimple() throws Exception {
    File tmp = new File("tmp");
    PersistentMap<String> pm = new PersistentMap<String>(new File(tmp, "simple"), String.class);
    try {

      assertNull(pm.put("abc", "def"));
      assertEquals("def", pm.get("abc"));

      pm.close();

      PersistentMap<String> pm2 = new PersistentMap<String>(new File(tmp, "simple"), String.class);
      assertEquals("def", pm2.get("abc"));

      assertEquals(Arrays.asList("abc"), new ArrayList<String>(pm2.keySet()));

      for (Map.Entry<String, String> e : pm2.entrySet()) {
        e.setValue("XXX");
      }
      assertEquals("XXX", pm2.get("abc"));
      pm2.close();
    } finally {
      pm.close();
      IO.delete(tmp);
    }
  }
Esempio n. 9
0
 @Override
 protected void tearDown() throws Exception {
   framework.stop();
   framework.waitForStop(10000);
   IO.delete(tmp);
   super.tearDown();
 }
Esempio n. 10
0
  public void testStructs() throws Exception {
    File tmp = new File("tmp");
    PersistentMap<X> pm = new PersistentMap<X>(new File(tmp, "simple"), X.class);
    try {
      X x = new X();
      x.abc = "def";
      x.def = 5;
      x.list.add("abc");
      assertNull(pm.put("abc", x));
      pm.close();

      PersistentMap<X> pm2 = new PersistentMap<X>(new File(tmp, "simple"), X.class);

      X x2 = pm2.get("abc");
      assertEquals("def", x2.abc);
      assertEquals(5, x2.def);

      pm2.remove("abc");

      assertEquals(0, pm2.size());

      pm2.close();
    } finally {
      pm.close();
      IO.delete(tmp);
    }
  }
Esempio n. 11
0
 /** The default policy is truncate micro. Check if this is applied to the import. */
 public static void testImportMicroTruncated() throws Exception {
   Builder b = new Builder();
   b.addClasspath(IO.getFile("jar/osgi.jar"));
   b.setProperty("Import-Package", "org.osgi.service.event");
   b.build();
   String s = b.getImports().getByFQN("org.osgi.service.event").get("version");
   assertEquals("[1.0,2)", s);
 }
Esempio n. 12
0
 /** Test if we can get the version from the source and apply the default policy. */
 public static void testVersionPolicyImportedExportsDefaultPolicy() throws Exception {
   Builder b = new Builder();
   b.addClasspath(IO.getFile("jar/osgi.jar"));
   b.addClasspath(new File("bin"));
   b.setProperty("Export-Package", "org.osgi.service.event");
   b.setProperty("Private-Package", "test.refer");
   b.build();
   String s = b.getImports().getByFQN("org.osgi.service.event").get("version");
   assertEquals("[1.0,2)", s);
 }
Esempio n. 13
0
 /**
  * See if we a can override the version from the export statement and the version from the source.
  */
 public static void testImportOverridesDiscoveredVersion() throws Exception {
   Builder b = new Builder();
   b.addClasspath(IO.getFile("jar/osgi.jar"));
   b.addClasspath(new File("bin"));
   b.setProperty("Export-Package", "org.osgi.service.event");
   b.setProperty("Private-Package", "test.refer");
   b.setProperty("Import-Package", "org.osgi.service.event;version=2.1.3.q");
   b.build();
   String s = b.getImports().getByFQN("org.osgi.service.event").get("version");
   assertEquals("2.1.3.q", s);
 }
Esempio n. 14
0
 /** Check if we can set a specific version on the import that does not use a version policy. */
 public static void testImportMicroNotTruncated() throws Exception {
   Builder b = new Builder();
   b.addClasspath(IO.getFile("jar/osgi.jar"));
   b.setProperty(
       "Import-Package",
       "org.osgi.service.event;version=${@}, org.osgi.service.log;version=\"${range;[==,=+)}\"");
   b.build();
   String s = b.getImports().getByFQN("org.osgi.service.event").get("version");
   String l = b.getImports().getByFQN("org.osgi.service.log").get("version");
   assertEquals("1.0.1", s);
   assertEquals("[1.3,1.4)", l);
 }
Esempio n. 15
0
  @Override
  protected void setUp() throws Exception {
    tmp = IO.getFile("generated/tmp");
    tmp.mkdirs();
    IO.copy(IO.getFile("testdata/ws"), tmp);
    workspace = Workspace.getWorkspace(tmp);
    workspace.refresh();

    InfoRepository repo = workspace.getPlugin(InfoRepository.class);
    t1 = create("bsn-1", new Version(1, 0, 0));
    t2 = create("bsn-2", new Version(1, 0, 0));

    repo.put(new FileInputStream(t1), null);
    repo.put(new FileInputStream(t2), null);
    t1 = repo.get("bsn-1", new Version(1, 0, 0), null);
    t2 = repo.get("bsn-2", new Version(1, 0, 0), null);
    repo.put(new FileInputStream(IO.getFile("generated/biz.aQute.remote.launcher.jar")), null);

    workspace.getPlugins().add(repo);

    File storage = IO.getFile("generated/storage-1");
    storage.mkdirs();

    configuration = new HashMap<String, Object>();
    configuration.put(
        Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
    configuration.put(Constants.FRAMEWORK_STORAGE, storage.getAbsolutePath());

    configuration.put(
        Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.2");

    framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration);
    framework.init();
    framework.start();
    context = framework.getBundleContext();
    location = "reference:" + IO.getFile("generated/biz.aQute.remote.agent.jar").toURI().toString();
    agent = context.installBundle(location);
    agent.start();

    thread =
        new Thread() {
          @Override
          public void run() {
            try {
              Main.main(
                  new String[] {
                    "-s", "generated/storage", "-c", "generated/cache", "-p", "1090", "-et"
                  });
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        };
    thread.setDaemon(true);
    thread.start();

    super.setUp();
  }
Esempio n. 16
0
  public static void testADWithInheritance() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty("-metatype", "*");
    b.setProperty("-metatype-inherit", "true");
    b.build();
    Resource r =
        b.getJar()
            .getResource(
                "OSGI-INF/metatype/test.metatype.MetatypeTest$TestADWithInheritanceChild.xml");
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());
    System.err.println(b.getJar().getResources().keySet());
    assertNotNull(r);
    IO.copy(r.openInputStream(), System.err);

    Document d = db.parse(r.openInputStream());

    assertAD(
        d, "fromChild", "From child", "fromChild", null, null, null, 0, "String", null, null, null);
    assertAD(
        d,
        "fromSuperOne",
        "From super one",
        "fromSuperOne",
        null,
        null,
        null,
        0,
        "String",
        null,
        null,
        null);
    assertAD(
        d,
        "fromSuperTwo",
        "From super two",
        "fromSuperTwo",
        null,
        null,
        null,
        0,
        "String",
        null,
        null,
        null);
  }
Esempio n. 17
0
  /** Test import provide:. */
  public static void testExportProvided() throws Exception {
    Builder a = new Builder();
    a.addClasspath(IO.getFile("jar/osgi.jar"));
    a.addClasspath(new File("bin"));
    a.setProperty("Private-Package", "test.refer");
    a.setProperty("Export-Package", "org.osgi.service.http;provide:=true");
    Jar jar = a.build();
    Map<String, String> event = a.getImports().getByFQN("org.osgi.service.event");
    assertEquals("[1.0,2)", event.get("version"));
    Map<String, String> http = a.getImports().getByFQN("org.osgi.service.http");
    assertEquals("[1.2,1.3)", http.get("version"));

    Manifest m = jar.getManifest();
    String imports = m.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);
    assertFalse(imports.contains(Constants.PROVIDE_DIRECTIVE));
  }
Esempio n. 18
0
  /** hardcoded imports */
  public static void testHardcodedImports() throws Exception {
    Builder b = new Builder();
    b.addClasspath(IO.getFile("jar/osgi.jar"));
    b.setProperty("-versionpolicy", "${range;[==,+)}");
    b.setProperty("Private-Package", "org.objectweb.asm");
    b.setProperty("Import-Package", "org.osgi.framework,org.objectweb.asm,abc;version=2.0.0,*");
    b.build();
    Manifest m = b.getJar().getManifest();
    m.write(System.err);
    String s = b.getImports().getByFQN("org.objectweb.asm").get("version");
    assertNull(s);
    s = b.getImports().getByFQN("abc").get("version");
    assertEquals("2.0.0", s);

    s = b.getImports().getByFQN("org.osgi.framework").get("version");
    assertEquals("[1.3,2)", s);
  }
Esempio n. 19
0
  private File create(String bsn, Version v) throws Exception {
    String name = bsn + "-" + v;
    Builder b = new Builder();
    b.setBundleSymbolicName(bsn);
    b.setBundleVersion(v);
    b.setProperty("Random", random++ + "");
    b.setProperty("-resourceonly", true + "");
    b.setIncludeResource("foo;literal='foo'");
    Jar jar = b.build();
    assertTrue(b.check());

    File file = IO.getFile(tmp, name + ".jar");
    file.getParentFile().mkdirs();
    jar.updateModified(System.currentTimeMillis(), "Force it to now");
    jar.write(file);
    b.close();
    return file;
  }
Esempio n. 20
0
  public static void testSimple() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty("-metatype", "*");
    b.build();
    Resource r =
        b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$TestSimple.xml");
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());
    System.err.println(b.getJar().getResources().keySet());
    assertNotNull(r);
    IO.copy(r.openInputStream(), System.err);

    Document d = db.parse(r.openInputStream());

    assertEquals("TestSimple", xpath.evaluate("//OCD/@name", d));
    assertEquals("simple", xpath.evaluate("//OCD/@description", d));
    assertEquals("test.metatype.MetatypeTest$TestSimple", xpath.evaluate("//OCD/@id", d));
    assertEquals("test.metatype.MetatypeTest$TestSimple", xpath.evaluate("//Designate/@pid", d));
    assertEquals("test.metatype.MetatypeTest$TestSimple", xpath.evaluate("//Object/@ocdref", d));
    assertEquals("simple", xpath.evaluate("//OCD/AD[@id='simple']/@id", d));
    assertEquals("Simple", xpath.evaluate("//OCD/AD[@id='simple']/@name", d));
    assertEquals("String", xpath.evaluate("//OCD/AD[@id='simple']/@type", d));
    assertEquals("true", xpath.evaluate("//OCD/AD[@id='notSoSimple']/@required", d));
    /**
     * https://github.com/bndtools/bnd/issues/281
     *
     * <p>Using the Bnd annotations library (1.52.3), the generated metatype file will have
     * required='false' for all fields annotated with @Meta.AD(). When this annotation is omitted,
     * or when the required property is explicitly set, the field is correctly marked as required.
     * Taking a glance at the code, the bug appears to be due to aQute.bnd.osgi.Annotation using
     * aQute.bnd.annotation.metatype.Configurable internally for bridging Bnd-annotations to
     * Java-annotations. This configurable only obtains the values from the Bnd-annotation, omitting
     * the defaults defined in the Java annotation. The workaround is to explicitly mention the
     * required property on each field annotated with @Meta.AD.
     */
    assertEquals("true", xpath.evaluate("//OCD/AD[@id='simple']/@required", d));
    assertEquals(
        Integer.MAX_VALUE + "", xpath.evaluate("//OCD/AD[@id='notSoSimple']/@cardinality", d));
  }
Esempio n. 21
0
  public void testJMXBundleDeployer() throws Exception {
    JMXBundleDeployer jmxBundleDeployer = new JMXBundleDeployer();

    long bundleId =
        jmxBundleDeployer.deploy(
            "biz.aQute.remote.agent", IO.getFile("generated/biz.aQute.remote.agent.jar"));

    assertTrue(bundleId > 0);

    BundleDTO agentBundle = null;
    long state = -1;

    for (BundleDTO bundle : jmxBundleDeployer.listBundles()) {
      if (bundle.symbolicName.equals("biz.aQute.remote.agent")) {
        agentBundle = bundle;
        state = bundle.state;
      }
    }

    assertNotNull(agentBundle);
    assertEquals(Bundle.ACTIVE, state);
  }
Esempio n. 22
0
  static void assertOCD(
      Builder b,
      String cname,
      String id,
      String name,
      String description,
      String designate,
      boolean factory,
      String localization)
      throws Exception {
    Resource r = b.getJar().getResource("OSGI-INF/metatype/" + cname + ".xml");
    assertNotNull(r);
    IO.copy(r.openInputStream(), System.err);
    Document d = db.parse(r.openInputStream());
    assertEquals(id, xpath.evaluate("//OCD/@id", d, XPathConstants.STRING));
    assertEquals(name, xpath.evaluate("//OCD/@name", d, XPathConstants.STRING));
    assertEquals(
        localization == null ? cname : localization,
        xpath.evaluate("//OCD/@localization", d, XPathConstants.STRING));
    assertEquals(
        description == null ? "" : description,
        xpath.evaluate("//OCD/@description", d, XPathConstants.STRING));

    if (designate == null) {
      assertEquals(id, xpath.evaluate("//Designate/@pid", d, XPathConstants.STRING));
      if (factory)
        assertEquals(id, xpath.evaluate("//Designate/@factoryPid", d, XPathConstants.STRING));
    } else {
      assertEquals(designate, xpath.evaluate("//Designate/@pid", d, XPathConstants.STRING));
      if (factory)
        assertEquals(
            designate, xpath.evaluate("//Designate/@factoryPid", d, XPathConstants.STRING));
    }

    assertEquals(id, xpath.evaluate("//Object/@ocdref", d, XPathConstants.STRING));
  }
Esempio n. 23
0
  public static void testReturnTypes() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty("-metatype", "*");
    b.build();
    Resource r =
        b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$TestReturnTypes.xml");
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());
    System.err.println(b.getJar().getResources().keySet());
    assertNotNull(r);
    IO.copy(r.openInputStream(), System.err);

    Document d = db.parse(r.openInputStream());
    assertEquals(
        "http://www.osgi.org/xmlns/metatype/v1.1.0", d.getDocumentElement().getNamespaceURI());
    // Primitives
    assertEquals("Boolean", xpath.evaluate("//OCD/AD[@id='rpBoolean']/@type", d));
    assertEquals("Byte", xpath.evaluate("//OCD/AD[@id='rpByte']/@type", d));
    assertEquals("Character", xpath.evaluate("//OCD/AD[@id='rpCharacter']/@type", d));
    assertEquals("Short", xpath.evaluate("//OCD/AD[@id='rpShort']/@type", d));
    assertEquals("Integer", xpath.evaluate("//OCD/AD[@id='rpInt']/@type", d));
    assertEquals("Long", xpath.evaluate("//OCD/AD[@id='rpLong']/@type", d));
    assertEquals("Float", xpath.evaluate("//OCD/AD[@id='rpFloat']/@type", d));
    assertEquals("Double", xpath.evaluate("//OCD/AD[@id='rpDouble']/@type", d));

    // Primitive Wrappers
    assertEquals("Boolean", xpath.evaluate("//OCD/AD[@id='rBoolean']/@type", d));
    assertEquals("Byte", xpath.evaluate("//OCD/AD[@id='rByte']/@type", d));
    assertEquals("Character", xpath.evaluate("//OCD/AD[@id='rCharacter']/@type", d));
    assertEquals("Short", xpath.evaluate("//OCD/AD[@id='rShort']/@type", d));
    assertEquals("Integer", xpath.evaluate("//OCD/AD[@id='rInt']/@type", d));
    assertEquals("Long", xpath.evaluate("//OCD/AD[@id='rLong']/@type", d));
    assertEquals("Float", xpath.evaluate("//OCD/AD[@id='rFloat']/@type", d));
    assertEquals("Double", xpath.evaluate("//OCD/AD[@id='rDouble']/@type", d));

    // Primitive Arrays
    assertEquals("Boolean", xpath.evaluate("//OCD/AD[@id='rpaBoolean']/@type", d));
    assertEquals("Byte", xpath.evaluate("//OCD/AD[@id='rpaByte']/@type", d));
    assertEquals("Character", xpath.evaluate("//OCD/AD[@id='rpaCharacter']/@type", d));
    assertEquals("Short", xpath.evaluate("//OCD/AD[@id='rpaShort']/@type", d));
    assertEquals("Integer", xpath.evaluate("//OCD/AD[@id='rpaInt']/@type", d));
    assertEquals("Long", xpath.evaluate("//OCD/AD[@id='rpaLong']/@type", d));
    assertEquals("Float", xpath.evaluate("//OCD/AD[@id='rpaFloat']/@type", d));
    assertEquals("Double", xpath.evaluate("//OCD/AD[@id='rpaDouble']/@type", d));

    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaBoolean']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaByte']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaCharacter']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaShort']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaInt']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaLong']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaFloat']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaDouble']/@cardinality", d));

    // Wrapper + Object arrays
    assertEquals("Boolean", xpath.evaluate("//OCD/AD[@id='raBoolean']/@type", d));
    assertEquals("Byte", xpath.evaluate("//OCD/AD[@id='raByte']/@type", d));
    assertEquals("Character", xpath.evaluate("//OCD/AD[@id='raCharacter']/@type", d));
    assertEquals("Short", xpath.evaluate("//OCD/AD[@id='raShort']/@type", d));
    assertEquals("Integer", xpath.evaluate("//OCD/AD[@id='raInt']/@type", d));
    assertEquals("Long", xpath.evaluate("//OCD/AD[@id='raLong']/@type", d));
    assertEquals("Float", xpath.evaluate("//OCD/AD[@id='raFloat']/@type", d));
    assertEquals("Double", xpath.evaluate("//OCD/AD[@id='raDouble']/@type", d));
    assertEquals("String", xpath.evaluate("//OCD/AD[@id='raString']/@type", d));
    assertEquals("String", xpath.evaluate("//OCD/AD[@id='raURI']/@type", d));

    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raBoolean']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raByte']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raCharacter']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raShort']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raInt']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raLong']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raFloat']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raDouble']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raString']/@cardinality", d));
    assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raURI']/@cardinality", d));

    // Wrapper + Object collections
    assertEquals("Boolean", xpath.evaluate("//OCD/AD[@id='rBooleans']/@type", d));
    assertEquals("Byte", xpath.evaluate("//OCD/AD[@id='rBytes']/@type", d));
    assertEquals("Character", xpath.evaluate("//OCD/AD[@id='rCharacter']/@type", d));
    assertEquals("Short", xpath.evaluate("//OCD/AD[@id='rShorts']/@type", d));
    assertEquals("Integer", xpath.evaluate("//OCD/AD[@id='rInts']/@type", d));
    assertEquals("Long", xpath.evaluate("//OCD/AD[@id='rLongs']/@type", d));
    assertEquals("Float", xpath.evaluate("//OCD/AD[@id='rFloats']/@type", d));
    assertEquals("Double", xpath.evaluate("//OCD/AD[@id='rDoubles']/@type", d));
    assertEquals("String", xpath.evaluate("//OCD/AD[@id='rStrings']/@type", d));
    assertEquals("String", xpath.evaluate("//OCD/AD[@id='rURIs']/@type", d));

    assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rBooleans']/@cardinality", d));
    assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rBytes']/@cardinality", d));
    assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rCharacters']/@cardinality", d));
    assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rShorts']/@cardinality", d));
    assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rInts']/@cardinality", d));
    assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rLongs']/@cardinality", d));
    assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rFloats']/@cardinality", d));
    assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rDoubles']/@cardinality", d));
    assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rStrings']/@cardinality", d));
    assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rURIs']/@cardinality", d));
  }
Esempio n. 24
0
  public static void testSetPackageVersion() throws Exception {
    File tmp = new File("tmp-ws");
    if (tmp.exists()) IO.deleteWithException(tmp);
    tmp.mkdir();
    assertTrue(tmp.isDirectory());

    try {
      IO.copy(new File("test/ws"), tmp);
      Workspace ws = Workspace.getWorkspace(tmp);
      Project project = ws.getProject("p5");
      project.setTrace(true);

      Version newVersion = new Version(2, 0, 0);

      // Package with no package info
      project.setPackageInfo("pkg1", newVersion);
      Version version = project.getPackageInfo("pkg1");
      assertEquals(newVersion, version);
      checkPackageInfoFiles(project, "pkg1", true, false);

      // Package with package-info.java containing @Version("1.0.0")
      project.setPackageInfo("pkg2", newVersion);
      version = project.getPackageInfo("pkg2");
      assertEquals(newVersion, version);
      checkPackageInfoFiles(project, "pkg2", false, true);

      // Package with package-info.java containing @aQute.bnd.annotations.Version("1.0.0")
      project.setPackageInfo("pkg3", newVersion);
      version = project.getPackageInfo("pkg3");
      assertEquals(newVersion, version);
      checkPackageInfoFiles(project, "pkg3", false, true);

      // Package with package-info.java containing @aQute.bnd.annotations.Version(value="1.0.0")
      project.setPackageInfo("pkg4", newVersion);
      version = project.getPackageInfo("pkg4");
      assertEquals(newVersion, version);
      checkPackageInfoFiles(project, "pkg4", false, true);

      // Package with package-info.java containing version + packageinfo
      project.setPackageInfo("pkg5", newVersion);
      version = project.getPackageInfo("pkg5");
      assertEquals(newVersion, version);
      checkPackageInfoFiles(project, "pkg5", true, true);

      // Package with package-info.java NOT containing version + packageinfo
      project.setPackageInfo("pkg6", newVersion);
      version = project.getPackageInfo("pkg6");
      assertEquals(newVersion, version);
      checkPackageInfoFiles(project, "pkg6", true, true);

      // Package with package-info.java NOT containing version
      project.setPackageInfo("pkg7", newVersion);
      version = project.getPackageInfo("pkg7");
      assertEquals(newVersion, version);
      checkPackageInfoFiles(project, "pkg7", true, true);

      newVersion = new Version(2, 2, 0);

      // Update packageinfo file
      project.setPackageInfo("pkg1", newVersion);
      version = project.getPackageInfo("pkg1");
      assertEquals(newVersion, version);
      checkPackageInfoFiles(project, "pkg1", true, false);

    } finally {
      IO.deleteWithException(tmp);
    }
  }
Esempio n. 25
0
  public static void testNaming() throws Exception {
    Map<String, Object> map = Create.map();

    map.put("_secret", "_secret");
    map.put("_secret", "_secret");
    map.put(".secret", ".secret");
    map.put("$new", "$new");
    map.put("new", "new");
    map.put("secret", "secret");
    map.put("a_b_c", "a_b_c");
    map.put("a.b.c", "a.b.c");
    map.put(".a_b", ".a_b");
    map.put("$$$$a_b", "$$$$a_b");
    map.put("$$$$a.b", "$$$$a.b");
    map.put("a", "a");
    map.put("a$", "a$");
    map.put("a$$", "a$$");
    map.put("a$.$", "a$.$");
    map.put("a$_$", "a$_$");
    map.put("a..", "a..");
    map.put("noid", "noid");
    map.put("nullid", "nullid");

    Naming trt = Configurable.createConfigurable(Naming.class, map);

    // By name
    assertEquals("secret", trt.secret());
    assertEquals("_secret", trt.__secret());
    assertEquals(".secret", trt._secret());
    assertEquals("new", trt.$new());
    assertEquals("$new", trt.$$new());
    assertEquals("a.b.c", trt.a_b_c());
    assertEquals("a_b_c", trt.a__b__c());
    assertEquals(".a_b", trt._a__b());
    assertEquals("$$$$a.b", trt.$$$$$$$$a_b());
    assertEquals("$$$$a_b", trt.$$$$$$$$a__b());
    assertEquals("a", trt.a$());
    assertEquals("a$", trt.a$$());
    assertEquals("a$", trt.a$$$());
    assertEquals("a$.$", trt.a$$_$$());
    assertEquals("a$_$", trt.a$$__$$());
    assertEquals("a..", trt.a_$_());
    assertEquals("noid", trt.noid());
    assertEquals("nullid", trt.nullid());

    // By AD
    assertEquals("secret", trt.xsecret());
    assertEquals("_secret", trt.x__secret());
    assertEquals(".secret", trt.x_secret());
    assertEquals("new", trt.x$new());
    assertEquals("$new", trt.x$$new());
    assertEquals("a.b.c", trt.xa_b_c());
    assertEquals("a_b_c", trt.xa__b__c());
    assertEquals(".a_b", trt.x_a__b());
    assertEquals("$$$$a.b", trt.x$$$$$$$$a_b());
    assertEquals("$$$$a_b", trt.x$$$$$$$$a__b());
    assertEquals("a", trt.xa$());
    assertEquals("a$", trt.xa$$());
    assertEquals("a$", trt.xa$$$());
    assertEquals("a$.$", trt.xa$$_$$());

    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty("-metatype", "*");
    b.build();
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());

    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$Naming.xml");
    IO.copy(r.openInputStream(), System.err);
    Document d = db.parse(r.openInputStream(), "UTF-8");
    assertEquals(
        "http://www.osgi.org/xmlns/metatype/v1.1.0", d.getDocumentElement().getNamespaceURI());
  }
Esempio n. 26
0
  public static void testAD() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty("-metatype", "*");
    b.build();
    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$TestAD.xml");
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());
    System.err.println(b.getJar().getResources().keySet());
    assertNotNull(r);
    IO.copy(r.openInputStream(), System.err);

    Document d = db.parse(r.openInputStream());

    assertAD(
        d,
        "noSettings",
        "No settings",
        "noSettings",
        null,
        null,
        null,
        0,
        "String",
        null,
        null,
        null);
    assertAD(d, "withId", "With id", "id", null, null, null, 0, "String", null, null, null);
    assertAD(d, "name", "name", "withName", null, null, null, 0, "String", null, null, null);
    assertAD(d, "withMax", "With max", "withMax", null, "1", null, 0, "String", null, null, null);
    assertAD(d, "withMin", "With min", "withMin", "-1", null, null, 0, "String", null, null, null);
    assertAD(d, "withC1", "With c1", "withC1", null, null, null, 1, "String", null, null, null);
    assertAD(
        d, "withC0", "With c0", "withC0", null, null, null, 2147483647, "String", null, null, null);
    assertAD(d, "withC_1", "With c 1", "withC.1", null, null, null, -1, "String", null, null, null);
    assertAD(
        d,
        "withC_1ButArray",
        "With c 1 but array",
        "withC.1ButArray",
        null,
        null,
        null,
        -1,
        "String",
        null,
        null,
        null);
    assertAD(
        d,
        "withC1ButCollection",
        "With c1 but collection",
        "withC1ButCollection",
        null,
        null,
        null,
        1,
        "String",
        null,
        null,
        null);
    assertAD(d, "withInt", "With int", "withInt", null, null, null, 0, "String", null, null, null);
    assertAD(
        d,
        "withString",
        "With string",
        "withString",
        null,
        null,
        null,
        0,
        "Integer",
        null,
        null,
        null);
    assertAD(
        d, "a", "A", "a", null, null, null, 0, "String", "description_xxx\"xxx'xxx", null, null);
    assertAD(
        d,
        "valuesOnly",
        "Values only",
        "valuesOnly",
        null,
        null,
        null,
        0,
        "String",
        null,
        new String[] {"a", "b"},
        new String[] {"a", "b"});
    assertAD(
        d,
        "labelsAndValues",
        "Labels and values",
        "labelsAndValues",
        null,
        null,
        null,
        0,
        "String",
        null,
        new String[] {"a", "b"},
        new String[] {"A", "A"});
  }