/** Check isStale */
  public static void testIsStale() throws Exception {
    Workspace ws = Workspace.getWorkspace(new File("test/ws"));
    ws.setOffline(false);
    Project top = ws.getProject("p-stale");
    assertNotNull(top);
    top.build();
    Project bottom = ws.getProject("p-stale-dep");
    assertNotNull(bottom);
    bottom.build();

    long lastModified = bottom.lastModified();
    top.getPropertiesFile().setLastModified(lastModified + 1000);

    stale(top, true);
    stale(bottom, true);
    assertTrue(top.isStale());
    assertTrue(bottom.isStale());

    stale(top, false);
    stale(bottom, true);
    assertTrue(top.isStale());
    assertTrue(bottom.isStale());

    stale(top, true);
    stale(bottom, false);
    assertTrue(top.isStale());
    assertFalse(bottom.isStale());

    // Thread.sleep(1000);
    // stale(top, false);
    // stale(bottom, false);
    // assertFalse(top.isStale());
    // assertFalse(bottom.isStale());
  }
  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);
    }
  }
  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);
    }
  }
  /** Check if the getSubBuilders properly predicts the output. */
  public static void testSubBuilders() throws Exception {
    Workspace ws = Workspace.getWorkspace(new File("test/ws"));
    Project project = ws.getProject("p4-sub");

    Collection<? extends Builder> bs = project.getSubBuilders();
    assertNotNull(bs);
    assertEquals(3, bs.size());
    Set<String> names = new HashSet<String>();
    for (Builder b : bs) {
      names.add(b.getBsn());
    }
    assertTrue(names.contains("p4-sub.a"));
    assertTrue(names.contains("p4-sub.b"));
    assertTrue(names.contains("p4-sub.c"));

    File[] files = project.build();
    assertTrue(project.check());

    System.err.println(Processor.join(project.getErrors(), "\n"));
    System.err.println(Processor.join(project.getWarnings(), "\n"));
    assertEquals(0, project.getErrors().size());
    assertEquals(0, project.getWarnings().size());
    assertNotNull(files);
    assertEquals(3, files.length);
    for (File file : files) {
      Jar jar = new Jar(file);
      Manifest m = jar.getManifest();
      assertTrue(names.contains(m.getMainAttributes().getValue("Bundle-SymbolicName")));
    }
  }
  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);
    }
  }
Beispiel #6
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();
  }
 /**
  * Check multiple repos
  *
  * @throws Exception
  */
 public static void testMultipleRepos() throws Exception {
   Workspace ws = Workspace.getWorkspace(new File("test/ws"));
   Project project = ws.getProject("p1");
   System.err.println(
       project.getBundle("org.apache.felix.configadmin", "1.1.0", Strategy.EXACT, null));
   System.err.println(
       project.getBundle("org.apache.felix.configadmin", "1.1.0", Strategy.HIGHEST, null));
   System.err.println(
       project.getBundle("org.apache.felix.configadmin", "1.1.0", Strategy.LOWEST, null));
 }
  public static void testParseSystemCapabilities() throws Exception {
    Workspace ws = Workspace.getWorkspace(new File("src/test/ws"));
    Project project = ws.getProject("p1");

    ProjectLauncherImpl launcher = new ProjectLauncherImpl(project);
    launcher.prepare();

    String systemCaps = launcher.getSystemCapabilities();
    assertEquals(
        "osgi.native;osgi.native.osname:List<String>=\"Win7,Windows7,Windows 7\";osgi.native.osversion:Version=6.1",
        systemCaps);
  }
  public static void testRunBuilds() throws Exception {
    Workspace ws = Workspace.getWorkspace(new File("test/ws"));

    // Running a .bnd includes built bundles by default
    Project p1 = ws.getProject("p1");
    assertTrue(p1.getRunBuilds());

    // Can override the default by specifying -runbuilds: false
    Project p2 = ws.getProject("p2");
    assertFalse(p2.getRunBuilds());

    // Running a .bndrun DOES NOT include built bundles by default
    Project p1a = new Project(ws, new File("test/ws/p1"), new File("test/ws/p1/p1a.bndrun"));
    assertFalse(p1a.getRunBuilds());

    // ... unless we override the default by specifying -runbuilds: true
    Project p1b = new Project(ws, new File("test/ws/p1"), new File("test/ws/p1/p1b.bndrun"));
    assertTrue(p1b.getRunBuilds());
  }
  public static void testParseRunProperties() throws Exception {
    Workspace ws = Workspace.getWorkspace(new File("src/test/ws"));
    Project project = ws.getProject("p1");

    ProjectLauncherImpl launcher = new ProjectLauncherImpl(project);
    launcher.prepare();

    String arg = launcher.getRunVM().iterator().next();
    String s = "-D" + LauncherConstants.LAUNCHER_PROPERTIES + "=";
    String propertiesPath = arg.substring(s.length());
    Matcher matcher = Pattern.compile("^([\"'])(.*)\\1$").matcher(propertiesPath);
    if (matcher.matches()) {
      propertiesPath = matcher.group(2);
    }

    Properties launchProps = new Properties();
    launchProps.load(new FileInputStream(new File(propertiesPath)));
    assertEquals(
        new File("src/test/ws/p1/generated/p1.jar").getAbsolutePath(),
        launchProps.get("launch.bundles"));
  }
Beispiel #11
0
  public static void testRepoMacro() throws Exception {
    Workspace ws = Workspace.getWorkspace(new File("test/ws"));
    Project project = ws.getProject("p2");
    System.err.println(project.getPlugins(FileRepo.class));
    String s = project.getReplacer().process(("${repo;libtest}"));
    System.err.println(s);
    assertTrue(
        s.contains(
            "org.apache.felix.configadmin"
                + File.separator
                + "org.apache.felix.configadmin-1.2.0"));
    assertTrue(
        s.contains("org.apache.felix.ipojo" + File.separator + "org.apache.felix.ipojo-1.0.0.jar"));

    s = project.getReplacer().process(("${repo;libtestxyz}"));
    assertTrue(s.matches("<<[^>]+>>"));

    s = project.getReplacer().process("${repo;org.apache.felix.configadmin;1.0.0;highest}");
    assertTrue(s.endsWith("org.apache.felix.configadmin-1.2.0.jar"));
    s = project.getReplacer().process("${repo;org.apache.felix.configadmin;1.0.0;lowest}");
    assertTrue(s.endsWith("org.apache.felix.configadmin-1.0.1.jar"));
  }
Beispiel #12
0
  public static void testOutofDate() throws Exception {
    Workspace ws = Workspace.getWorkspace(new File("test/ws"));
    Project project = ws.getProject("p3");
    File bnd = new File("test/ws/p3/bnd.bnd");
    assertTrue(bnd.exists());

    project.clean();
    File pt = project.getTarget();
    if (!pt.exists() && !pt.mkdirs()) {
      throw new IOException("Could not create directory " + pt);
    }
    try {
      // Now we build it.
      File[] files = project.build();
      System.err.println(project.getErrors());
      System.err.println(project.getWarnings());
      assertTrue(project.isOk());
      assertNotNull(files);
      assertEquals(1, files.length);

      // Now we should not rebuild it
      long lastTime = files[0].lastModified();
      files = project.build();
      assertEquals(1, files.length);
      assertTrue(files[0].lastModified() == lastTime);

      Thread.sleep(2000);

      project.updateModified(System.currentTimeMillis(), "Testing");
      files = project.build();
      assertEquals(1, files.length);
      assertTrue("Must have newer files now", files[0].lastModified() > lastTime);
    } finally {
      project.clean();
    }
  }
Beispiel #13
0
  /**
   * Tests the handling of the -sub facility
   *
   * @throws Exception
   */
  public static void testSub() throws Exception {
    Workspace ws = Workspace.getWorkspace(new File("test/ws"));
    Project project = ws.getProject("p4-sub");
    File[] files = project.build();
    Arrays.sort(files);

    System.err.println(Processor.join(project.getErrors(), "\n"));
    System.err.println(Processor.join(project.getWarnings(), "\n"));

    assertEquals(0, project.getErrors().size());
    assertEquals(0, project.getWarnings().size());
    assertNotNull(files);
    assertEquals(3, files.length);

    Jar a = new Jar(files[0]);
    Jar b = new Jar(files[1]);
    Manifest ma = a.getManifest();
    Manifest mb = b.getManifest();

    assertEquals("base", ma.getMainAttributes().getValue("Base-Header"));
    assertEquals("base", mb.getMainAttributes().getValue("Base-Header"));
    assertEquals("a", ma.getMainAttributes().getValue("Sub-Header"));
    assertEquals("b", mb.getMainAttributes().getValue("Sub-Header"));
  }
Beispiel #14
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);
    }
  }