public void update(UpdateMemo memo) throws Exception {

    ArtifactData target = put(memo.best.urls.iterator().next());

    memo.current.version = new Version(memo.best.version);
    target.sync();
    memo.current.sha = target.sha;
    // memo.current.dependencies = target.dependencies;
    // memo.current.dependencies.add((new File(repoDir,
    // Hex.toHexString(target.sha))).getCanonicalPath());
    // memo.current.runbundles = target.runbundles;
    // memo.current.description = target.description;
    memo.current.time = target.time;

    if (memo.current instanceof ServiceData) {
      Service service = getService((ServiceData) memo.current);
      service.remove();
      createService((ServiceData) memo.current);
      IO.delete(new File(IO.getFile(serviceDir, memo.current.name), "data"));
      storeData(new File(IO.getFile(serviceDir, memo.current.name), "data"), memo.current);
    } else {
      platform.deleteCommand(memo.current);
      createCommand(memo.current, false);
      IO.delete(IO.getFile(commandDir, memo.current.name));
      storeData(IO.getFile(commandDir, memo.current.name), memo.current);
    }
  }
Example #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();
  }
Example #3
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());
 }
Example #4
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();
  }
Example #5
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();
 }
Example #6
0
 public void setUp() throws Exception {
   tmp = new File("generated/tmp/test/" + getName());
   tmp.mkdirs();
   IO.copy(IO.getFile("testdata/ws"), tmp);
   ws = new Workspace(tmp);
   assertTrue(ws.check());
 }
Example #7
0
  private Builder newBuilder() throws IOException {
    Builder b = new Builder();
    b.addClasspath(IO.getFile("jar/osgi.jar"));
    b.addClasspath(new File("bin"));

    return b;
  }
Example #8
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);
 }
Example #9
0
 /** Delete a cache entry */
 public boolean deleteCache(byte[] id) throws Exception {
   File dir = IO.getFile(cache, Hex.toHexString(id));
   if (dir.isDirectory()) {
     IO.delete(dir);
     return true;
   }
   return false;
 }
Example #10
0
 public static void testAbsentIncludes() throws IOException {
   Analyzer analyzer = new Analyzer();
   analyzer.setBase(IO.getFile("src/test"));
   Properties p = new Properties();
   p.put("-include", "-iamnotthere.txt");
   analyzer.setProperties(p);
   System.err.println(analyzer.getErrors());
   assertEquals(0, analyzer.getErrors().size());
 }
Example #11
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);
 }
  public ArtifactData get(byte[] sha) throws Exception {
    String name = Hex.toHexString(sha);
    File data = IO.getFile(repoDir, name + ".json");
    reporter.trace("artifact data file %s", data);
    if (data.isFile()) { // Bin + metadata
      ArtifactData artifact = codec.dec().from(data).get(ArtifactData.class);
      artifact.file = IO.getFile(repoDir, name).getAbsolutePath();
      return artifact;
    }
    File bin = IO.getFile(repoDir, name);
    if (bin.exists()) { // Only bin
      ArtifactData artifact = new ArtifactData();
      artifact.file = bin.getAbsolutePath();
      artifact.sha = sha;
      return artifact;
    }

    return null;
  }
Example #13
0
  public void testBasicSnapshotRelease() throws Exception {
    File fpom =
        IO.getFile(local, "commons-cli/commons-cli/1.4-SNAPSHOT/commons-cli-1.4-SNAPSHOT.pom");
    File rpom =
        IO.getFile(
            remote, "commons-cli/commons-cli/1.4-SNAPSHOT/commons-cli-1.4-19700101.000010.pom");
    Program program = Program.valueOf("commons-cli", "commons-cli");
    Revision revision = Program.valueOf("commons-cli", "commons-cli").version("1.4-SNAPSHOT");
    Archive apom = revision.archive("pom", null);
    assertFalse(fpom.exists());

    Release r = storage.release(revision);
    r.setBuild(10000, null);
    r.add("pom", null, new ByteArrayInputStream(new byte[0]));

    r.close();

    assertTrue(fpom.isFile());
    assertTrue(rpom.isFile());
  }
Example #14
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);
 }
Example #15
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);
 }
Example #16
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;
  }
Example #17
0
  public static void testSimple() throws Exception {
    Builder bmaker = new Builder();
    bmaker.addClasspath(IO.getFile("jar/mina.jar"));
    bmaker.set("Export-Package", "org.apache.mina.*;version=1");
    bmaker.set("DynamicImport-Package", "org.slf4j");
    Jar jar = bmaker.build();
    assertTrue(bmaker.check());

    Manifest m = jar.getManifest();
    m.write(System.err);
    assertTrue(m.getMainAttributes().getValue("Import-Package").indexOf("org.slf4j") >= 0);
    assertTrue(m.getMainAttributes().getValue("DynamicImport-Package").indexOf("org.slf4j") >= 0);
  }
Example #18
0
  @Override
  public void setUp() {
    System.setProperty("jpm4j.in.test", "true");

    tmp = IO.getFile("generated/tmp");
    IO.delete(tmp);
    tmp.mkdirs();

    repo = new Repository();
    Map<String, String> props = new HashMap<String, String>();
    props.put("location", new File(tmp, "loc").getAbsolutePath());
    props.put("index", new File(tmp, "index").getAbsolutePath());
    repo.setProperties(props);
  }
Example #19
0
 public static void testIncludeHeader() throws IOException {
   Analyzer analyzer = new Analyzer();
   analyzer.setBase(IO.getFile("src/test"));
   Properties p = new Properties();
   p.put("a", "1");
   p.put("-include", "includeheadertest.mf, includeheadertest.prop");
   analyzer.setProperties(p);
   System.err.println(analyzer.getProperties());
   assertEquals("1", analyzer.getProperty("a"));
   assertEquals("end", analyzer.getProperty("last-props"));
   assertEquals("end", analyzer.getProperty("last-manifest"));
   assertEquals("abcd", analyzer.getProperty("manifest"));
   assertEquals("abcd", analyzer.getProperty("props"));
   assertEquals("1", analyzer.getProperty("test"));
 }
Example #20
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));
  }
Example #21
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);
  }
Example #22
0
  /**
   * Create a require capality directive test
   *
   * @throws Exception
   */
  public void testValidDirectivesOnRequirement() throws Exception {
    Builder b = new Builder();
    b.addClasspath(IO.getFile("jar/osgi.jar"));
    b.setExportPackage("org.osgi.framework");
    b.setProperty(
        "Require-Capability",
        "test; resolution:=mandatory, "
            + " test; resolution:=optional, "
            + " test; cardinality:=single, "
            + " test; cardinality:=multiple, "
            + " test; effective:=foo, "
            + " test; filter:=\"(&(version>=1.1)(long.list=1)(long.list=2))\", "
            + " test; x-custom:=bar, ");

    b.build();
    assertTrue(b.check());
  }
Example #23
0
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   reporter.setTrace(true);
   Config config = new Config();
   fnx = new FakeNexus(config, remote);
   fnx.start();
   IO.delete(remote);
   IO.delete(local);
   IO.copy(IO.getFile("testresources/mavenrepo"), remote);
   remote.mkdirs();
   local.mkdirs();
   repo =
       new MavenRemoteRepository(local, new HttpClient(), fnx.getBaseURI() + "/repo/", reporter);
   storage =
       new MavenRepository(
           local, "fnexus", this.repo, null, null, new ReporterAdapter(System.out), null);
 }
Example #24
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;
  }
Example #25
0
  public static void testPrecedence() throws Exception {
    File base = IO.getFile("src/test");
    String a = "a=a.props\n";
    String b = "a=b.props\n";
    File aa = new File(base, "a.props");
    File bb = new File(base, "b.props");
    write(aa, a);
    write(bb, b);

    Analyzer analyzer = new Analyzer();
    analyzer.setBase(base);
    Properties x = new Properties();
    x.put("a", "x");
    x.put("-include", "a.props, b.props");
    analyzer.setProperties(x);
    assertEquals("b.props", analyzer.getProperty("a")); // from org

    analyzer = new Analyzer();
    analyzer.setBase(base);
    x = new Properties();
    x.put("a", "x");
    x.put("-include", "~a.props, b.props");
    analyzer.setProperties(x);
    assertEquals("b.props", analyzer.getProperty("a")); // from org

    analyzer = new Analyzer();
    analyzer.setBase(base);
    x = new Properties();
    x.put("a", "x");
    x.put("-include", "a.props, ~b.props");
    analyzer.setProperties(x);
    assertEquals("a.props", analyzer.getProperty("a")); // from org

    analyzer = new Analyzer();
    analyzer.setBase(base);
    x = new Properties();
    x.put("a", "x");
    x.put("-include", "~a.props, ~b.props");
    analyzer.setProperties(x);
    assertEquals("x", analyzer.getProperty("a")); // from org

    aa.delete();
    bb.delete();
  }
  private String listSupportFiles(List<File> toDelete) throws Exception {
    Formatter f = new Formatter();
    try {
      if (toDelete == null) {
        toDelete = new ArrayList<File>();
      }
      int precount = toDelete.size();
      File confFile = IO.getFile(platform.getConfigFile()).getCanonicalFile();
      if (confFile.exists()) {
        f.format("    * %s \t0 Config file%n", confFile);
        toDelete.add(confFile);
      }

      String result = (toDelete.size() > precount) ? f.toString() : null;
      return result;
    } finally {
      f.close();
    }
  }
Example #27
0
  public void testImmutable() throws Exception {
    File fpom = IO.getFile(local, "commons-cli/commons-cli/1.2/commons-cli-1.2.pom");
    Program program = Program.valueOf("commons-cli", "commons-cli");
    Revision revision = Program.valueOf("commons-cli", "commons-cli").version("1.2");
    Archive apom = revision.archive("pom", null);
    assertFalse(fpom.exists());

    Archive rapom = storage.resolveSnapshot(apom);
    assertTrue(rapom.isResolved());
    assertEquals(rapom, apom);

    File f = storage.get(rapom).getValue();
    assertEquals(fpom, f);
    assertRecent(f);

    f.setLastModified(10000);
    f = storage.get(rapom).getValue();
    assertEquals(fpom, f);
    assertEquals(10000L, f.lastModified());
  }
Example #28
0
  public void testJpm() throws Exception {
    File file = IO.getFile("testdata/ws/cnf/jar/biz.aQute.bnd.annotation-2.3.0.jar");
    boolean dropTarget = repo.dropTarget(file.toURI());
    assertTrue(dropTarget);
    File f = repo.get("biz.aQute.bnd.annotation", new Version("2.3.0.201404170725"), null);
    assertNotNull(f);

    ResourceDescriptor descriptor =
        repo.getDescriptor("biz.aQute.bnd.annotation", new Version("2.3.0.201404170725"));

    assertNotNull(descriptor);
    assertEquals(
        "230ae22893a124cdda8910e240d9c12edbacbbe13d8d080610adfc12b06623ff",
        Hex.toHexString(descriptor.sha256));
    assertEquals(file.toURI().toString(), descriptor.url.toString());

    SortedSet<Version> versions = repo.versions("biz.aQute.bnd.annotation");
    assertEquals(1, versions.size());

    assertEquals(new Version("2.3.0.201404170725"), versions.iterator().next());
  }
Example #29
0
  /**
   * Create a require capality filter verification test
   *
   * @throws Exception
   */
  public void testInvalidFilterOnRequirement() throws Exception {
    Builder b = new Builder();
    b.addClasspath(IO.getFile("jar/osgi.jar"));
    b.setExportPackage("org.osgi.framework");
    b.setProperty(
        "Require-Capability",
        "test; filter:=\"(&(test=aName)(version>=1.1.0))\", "
            + " test; filter:=\"(&(version>=1.1)(string~=astring))\", "
            + " test; filter:=\"(&(version>=1.1)(long>=99))\", "
            + " test; filter:=\"(&(version>=1.1)(double>=1.0))\",  "
            + " test; filter:=\"(&(version>=1.1)(version.list=1.0)(version.list=1.1)(version.list=1.2))\", "
            + " test; filter:=\"(&(version>=1.1)(long.list=1)(long.list=2)(long.list=3)(long.list=4))\", "
            + " test; filter:=\"(&(version>=1.1)(double.list=1.001)(double.list=1.002)(double.list=1.003)(double.list<=1.3))\", "
            + " test; filter:=\"(&(version>=1.1)(string.list~=astring)(string.list~=bstring)(string.list=cString))\", "
            + " test; filter:=\"(&(version>=1.1)(string.list2=a\\\"quote)(string.list2=a\\,comma)(string.list2= aSpace )(string.list2=\\\"start)(string.list2=\\,start)(string.list2=end\\\")(string.list2=end\\,))\", "
            + " test; filter:=\"(&(version>=1.1)(string.list3= aString )(string.list3= bString )(string.list3= cString ))\", "
            + " test.effective; effective:=\"active\"; filter:=\"(willResolve=false)\", test.no.attrs");

    b.build();
    assertTrue(b.check());
  }
Example #30
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);
  }