/**
  * Deploys the `probe` bundle, i.e. the bundle containing the test classes and the Wisdom Test
  * Utilities (such as the InVivo Runner). If such a bundle is already deployed, nothing is done,
  * else, the probe bundle is built, installed and started.
  *
  * @throws BundleException if the probe bundle cannot be started.
  */
 public void deployProbe() throws BundleException {
   for (Bundle bundle : chameleon.context().getBundles()) {
     if (bundle.getSymbolicName().equals(ProbeBundleMaker.BUNDLE_NAME)) {
       return;
     }
   }
   try {
     Bundle probe = chameleon.context().installBundle("local", ProbeBundleMaker.probe());
     probe.start();
   } catch (Exception e) {
     throw new RuntimeException("Cannot install or start the probe bundle", e);
   }
 }
  /**
   * Starts the underlying Chameleon instance.
   *
   * @param root the base directory of the Chameleon.
   * @throws java.io.IOException if the chameleon configuration cannot be read.
   * @throws org.osgi.framework.BundleException if the chameleon cannot be started.
   */
  private void start(File root) throws BundleException, IOException {
    ChameleonConfiguration configuration = new ChameleonConfiguration(root);
    StringBuilder packages = new StringBuilder();
    Packages.junit(packages);
    Packages.wisdomtest(packages);
    Packages.javaxinject(packages);
    Packages.assertj(packages);
    Packages.osgihelpers(packages);
    configuration.put("org.osgi.framework.system.packages.extra", packages.toString());

    chameleon = new Chameleon(configuration);
    fixLoggingSystem(root);
    chameleon.start();
    Stability.waitForStability(chameleon.context());
  }
  /**
   * Builds and deploy the application bundle. This method is called the application bundle is not
   * in the runtime or application directories.
   */
  public void deployApplication() throws BundleException {
    File application = new File(APPLICATION_BUNDLE);
    File base = new File(".");
    if (!application.isFile()) {
      try {
        BundlePackager.bundle(base, application);
      } catch (Exception e) {
        throw new RuntimeException("Cannot build the application bundle", e);
      }
    }

    try {
      Bundle app = chameleon.context().installBundle(application.toURI().toURL().toExternalForm());
      app.start();
    } catch (Exception e) {
      throw new RuntimeException("Cannot install or start the application bundle", e);
    }
  }
 private void stop() throws Exception {
   chameleon.stop();
 }
 /** @return the bundle context of the underlying Chameleon, {@literal null} if not started. */
 public BundleContext context() {
   return chameleon.context();
 }