/** Returns approximate target platform version. */
  public static Version getEclipseVersion() {
    String location = EnvironmentUtil.getTargetPlatforn();

    DirectoryScanner ds = new DirectoryScanner();
    ds.setBasedir(new File(location, "plugins"));
    ds.setIncludes(new String[] {"org.eclipse.osgi_*.jar"});
    ds.scan();

    String[] files = ds.getIncludedFiles();
    if (files == null || files.length < 1) {
      throw new IllegalStateException(
          "Unable to determine version of the test target platform " + location);
    }

    String version =
        files[0].substring("org.eclipse.osgi_".length(), files[0].length() - ".jar".length());

    return Version.parseVersion(version);
  }
  @SuppressWarnings("unchecked")
  protected Verifier getVerifier(String test, boolean setTargetPlatform, File userSettings)
      throws Exception {
    /*
    Test JVM can be started in debug mode by passing the following
    env to execute(...) methods.

          java.util.Map<String, String> env = new java.util.HashMap<String, String>();
          env.put("MAVEN_OPTS", "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000");
     */

    // oddly enough, Verifier uses this system property to locate maven install
    System.setProperty("maven.home", getMavenHome());

    File testDir = getBasedir(test);

    Verifier verifier = new Verifier(testDir.getAbsolutePath());
    verifier.getCliOptions().add("-Dmaven.home=" + getMavenHome());
    verifier.getCliOptions().add("-Dtycho-version=" + getTychoVersion());
    if (setTargetPlatform) {
      verifier.getCliOptions().add("-Dtycho.targetPlatform=" + getTargetPlatforn());
    }
    verifier.getCliOptions().add("-X");
    verifier.getCliOptions().add("-s " + userSettings.getCanonicalPath());
    verifier.getVerifierProperties().put("use.mavenRepoLocal", "true");
    verifier.setLocalRepo(EnvironmentUtil.getLocalRepo());

    String customOptions = System.getProperty("it.cliOptions");
    if (customOptions != null && customOptions.trim().length() > 0) {
      verifier.getCliOptions().add(customOptions);
    }

    String m2eState = System.getProperty("m2eclipse.workspace.state");
    String m2eResolver = System.getProperty("m2eclipse.workspace.resolver");

    if (m2eState != null && m2eResolver != null) {
      verifier.getVerifierProperties().put("m2eclipse.workspace.state", m2eState);
    }

    return verifier;
  }
 protected String getTychoVersion() {
   return EnvironmentUtil.getTychoVersion();
 }
 protected String getMavenHome() {
   return EnvironmentUtil.getMavenHome();
 }
 protected String getTargetPlatforn() {
   return EnvironmentUtil.getTargetPlatforn();
 }