Example #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);
    }
  }
Example #2
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);
    }
  }
Example #3
0
  /** 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")));
    }
  }
Example #4
0
  /** 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());
  }
Example #5
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);
    }
  }
Example #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();
  }
Example #7
0
 private static Project testBuildAll(String dependsOn, int count) throws Exception {
   Workspace ws = new Workspace(new File("test/ws"));
   Project all = ws.getProject("build-all");
   all.setProperty("-dependson", dependsOn);
   all.prepare();
   Collection<Project> dependson = all.getDependson();
   assertEquals(count, dependson.size());
   return all;
 }
Example #8
0
 /** Duplicates in runbundles gave a bad error, should be ignored */
 public static void testRunbundleDuplicates() throws Exception {
   Workspace ws = new Workspace(new File("test/ws"));
   Project top = ws.getProject("p1");
   top.clear();
   top.setProperty("-runbundles", "org.apache.felix.configadmin,org.apache.felix.configadmin");
   Collection<Container> runbundles = top.getRunbundles();
   assertTrue(top.check("Multiple bundles with the same final URL"));
   assertNotNull(runbundles);
   assertEquals(1, runbundles.size());
 }
Example #9
0
 /**
  * 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));
 }
Example #10
0
 /** Test bnd.bnd of project `foo`: `-runbundles: foo;version=latest` */
 public static void testRunBundlesContainsSelf() throws Exception {
   Workspace ws = new Workspace(new File("test/ws"));
   Project top = ws.getProject("p1");
   top.setProperty("-runbundles", "p1;version=latest");
   top.setChanged();
   top.isStale();
   Collection<Container> runbundles = top.getRunbundles();
   assertTrue(top.check("Circular dependency"));
   assertNotNull(runbundles);
   assertEquals(0, runbundles.size());
 }
Example #11
0
 /** Test 2 equal bsns but diff. versions */
 public static void testSameBsnRunBundles() throws Exception {
   Workspace ws = new Workspace(new File("test/ws"));
   Project top = ws.getProject("p1");
   top.setProperty(
       "-runbundles",
       "org.apache.felix.configadmin;version='[1.0.1,1.0.1]',org.apache.felix.configadmin;version='[1.1.0,1.1.0]'");
   Collection<Container> runbundles = top.getRunbundles();
   assertTrue(top.check());
   assertNotNull(runbundles);
   assertEquals(2, runbundles.size());
 }
Example #12
0
  /*
   * Launches against the agent& main
   */
  public void testAgentAndMain() throws Exception {
    Project project = workspace.getProject("p1");
    Run bndrun = new Run(workspace, project.getBase(), project.getFile("one.bndrun"));
    bndrun.setProperty("-runpath", "biz.aQute.remote.launcher");
    bndrun.setProperty("-runbundles", "bsn-1,bsn-2");
    bndrun.setProperty("-runremote", "agent,main;agent=1090");

    final RemoteProjectLauncherPlugin pl =
        (RemoteProjectLauncherPlugin) bndrun.getProjectLauncher();
    pl.prepare();

    List<? extends RunSession> sessions = pl.getRunSessions();
    assertEquals(2, sessions.size());

    RunSession agent = sessions.get(0);
    RunSession main = sessions.get(1);

    CountDownLatch agentLatch = launch(agent);
    CountDownLatch mainLatch = launch(main);

    agent.waitTillStarted(1000);
    main.waitTillStarted(1000);
    Thread.sleep(500);

    agent.cancel();
    main.cancel();

    agentLatch.await();
    mainLatch.await();
    assertEquals(-3, agent.getExitCode());
    assertEquals(-3, main.getExitCode());

    bndrun.close();
  }
Example #13
0
  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());
  }
Example #14
0
  @Override
  public void created(Project p) throws IOException {
    Workspace workspace = p.getWorkspace();

    copy("pom.xml", "pom.xml", p);

    File root = workspace.getFile("pom.xml");

    doRoot(p, root);

    String rootPom = IO.collect(root);
    if (!rootPom.contains(getTag(p))) {
      rootPom =
          rootPom.replaceAll(
              "<!-- DO NOT EDIT MANAGED BY BND MAVEN LIFECYCLE PLUGIN -->\n",
              "$0\n\t\t" + getTag(p) + "\n");
      IO.store(rootPom, root);
    }
  }
Example #15
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"));
  }
Example #16
0
  /*
   * Launches against the agent
   */
  public void testSimpleLauncher() throws Exception {
    Project project = workspace.getProject("p1");
    Run bndrun = new Run(workspace, project.getBase(), project.getFile("one.bndrun"));
    bndrun.setProperty("-runpath", "biz.aQute.remote.launcher");
    bndrun.setProperty("-runbundles", "bsn-1,bsn-2");
    bndrun.setProperty("-runremote", "test");

    final RemoteProjectLauncherPlugin pl =
        (RemoteProjectLauncherPlugin) bndrun.getProjectLauncher();
    pl.prepare();
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicInteger exitCode = new AtomicInteger(-1);

    List<? extends RunSession> sessions = pl.getRunSessions();
    assertEquals(1, sessions.size());

    final RunSession session = sessions.get(0);

    Thread t =
        new Thread("test-launch") {
          public void run() {
            try {
              exitCode.set(session.launch());
            } catch (Exception e) {
              e.printStackTrace();
            } finally {
              latch.countDown();
            }
          }
        };
    t.start();
    Thread.sleep(500);

    for (Bundle b : context.getBundles()) {
      System.out.println(b.getLocation());
    }
    assertEquals(4, context.getBundles().length);
    String p1 = t1.getAbsolutePath();
    System.out.println(p1);

    assertNotNull(context.getBundle(p1));
    assertNotNull(context.getBundle(t2.getAbsolutePath()));

    pl.cancel();
    latch.await();

    assertEquals(-3, exitCode.get());

    bndrun.close();
  }
Example #17
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"));
  }
Example #18
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();
    }
  }
Example #19
0
  public void _workspace(WorkspaceOptions opts) throws Exception {
    File base = bnd.getBase();

    String name = opts._arguments().get(0);

    File workspaceDir = Processor.getFile(base, name);
    name = workspaceDir.getName();
    base = workspaceDir.getParentFile();

    if (base == null) {
      bnd.error(
          "You cannot create a workspace in the root (%s). The parent of a workspace %n"
              + "must be a valid directory. Recommended is to dedicate a directory to %n"
              + "all (or related) workspaces.",
          workspaceDir);
      return;
    }

    if (!opts.anyname() && !Verifier.isBsn(name)) {
      bnd.error(
          "You specified a workspace name that does not follow the recommended pattern "
              + "(it should be like a Bundle Symbolic name). It is a bit pedantic but it "
              + "really helps hwne you get many workspaces. If you insist on this name, use the -a/--anyname option.");
      return;
    }

    Workspace ws = bnd.getWorkspace((File) null);

    if (ws != null && ws.isValid()) {
      bnd.error(
          "You are currently in a workspace already (%s) in %s. You can only create a new workspace outside an existing workspace",
          ws, base);
      return;
    }

    File eclipseDir = workspaceDir;
    workspaceDir.mkdirs();

    if (!opts.single()) workspaceDir = new File(workspaceDir, "scm");

    workspaceDir.mkdirs();

    if (!base.isDirectory()) {
      bnd.error("Could not create directory for the bnd workspace %s", base);
    } else if (!eclipseDir.isDirectory()) {
      bnd.error("Could not create directory for the Eclipse workspace %s", eclipseDir);
    }

    if (!workspaceDir.isDirectory()) {
      bnd.error("Could not create the workspace directory %s", workspaceDir);
      return;
    }

    if (!opts.update() && !opts.force() && workspaceDir.list().length > 0) {
      bnd.error(
          "The workspace directory %s is not empty, specify -u/--update to update or -f/--force to replace",
          workspaceDir);
    }

    InputStream in = getClass().getResourceAsStream("/templates/enroute.zip");
    if (in == null) {
      bnd.error("Cannot find template in this jar %s", "/templates/enroute.zip");
      return;
    }

    Pattern glob = Pattern.compile("[^/]+|cnf/.*|\\...+/.*");

    copy(workspaceDir, in, glob, opts.force());

    File readme = new File(workspaceDir, "README.md");
    if (readme.isFile()) IO.copy(readme, bnd.out);

    bnd.out.printf(
        "%nWorkspace %s created.%n%n" //
            + " Start Eclipse:%n" //
            + "   1) Select the Eclipse workspace %s%n" //
            + "   2) Package Explorer context menu: Import/General/Existing Projects from %s%n"
            + "%n"
            + "", //
        workspaceDir.getName(), eclipseDir, workspaceDir);
  }
Example #20
0
 /** #194 StackOverflowError when -runbundles in bnd.bnd refers to itself */
 public static void testProjectReferringToItself() throws Exception {
   Workspace ws = new Workspace(new File("test/ws"));
   Project top = ws.getProject("bug194");
   top.addClasspath(top.getOutput());
   assertTrue(top.check("Circular dependency context"));
 }
Example #21
0
 /**
  * Test if you can add directories and files to the classpath. Originally checked only for files
  */
 public static void testAddDirToClasspath() throws Exception {
   Workspace ws = new Workspace(new File("test/ws"));
   Project top = ws.getProject("p1");
   top.addClasspath(top.getOutput());
   assertTrue(top.check());
 }
Example #22
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);
    }
  }