@Test
  public void testPomlessBuildExtension() throws Exception {
    Verifier verifier = getVerifier("testsetversionpomless", false);
    String newVersion = "2.0.0";
    verifier.addCliOption("-DnewVersion=" + newVersion);
    verifier.executeGoal(
        "org.eclipse.tycho:tycho-versions-plugin:" + getTychoVersion() + ":set-version");
    verifier.verifyErrorFreeLog();
    File baseDir = new File(verifier.getBasedir());

    PomFile rootPom = PomFile.read(new File(baseDir, "pom.xml"), false);
    Assert.assertEquals(newVersion, rootPom.getVersion());

    DefaultBundleReader reader = new DefaultBundleReader();
    OsgiManifest bundleManifest =
        reader.loadManifest(new File(baseDir, "bundle1/META-INF/MANIFEST.MF"));
    Assert.assertEquals(newVersion, bundleManifest.getBundleVersion());

    OsgiManifest testBundleManifest =
        reader.loadManifest(new File(baseDir, "bundle1.tests/META-INF/MANIFEST.MF"));
    Assert.assertEquals(newVersion, testBundleManifest.getBundleVersion());

    Feature feature = Feature.read(new File(baseDir, "feature/feature.xml"));
    Assert.assertEquals(newVersion, feature.getVersion());
  }
  @Test
  public void testReplaceCommon() throws Exception {
    Verifier verifier = getVerifier("newattachedartifact", baselineRepo);

    verifier.getCliOptions().add("-Dtycho.baseline=warn");
    verifier.getCliOptions().add("-Dtycho.baseline.replace=common");

    verifier.executeGoals(Arrays.asList("clean", "package"));
    verifier.verifyTextInLog(
        "baseline and build artifacts have same version but different contents");

    File repository = new File(verifier.getBasedir(), "repository/target/repository");
    assertBaselineContents(repository, "features/baseline.feature02_1.0.0.1.jar");

    File basedir = new File(verifier.getBasedir());
    assertFileExists(basedir, "feature02/target/baseline.feature02_root-1.0.0.1-root.zip");
    assertFileDoesNotExist(
        basedir, "repository/target/repository/binary/baseline.feature02_root_1.0.0.1");
  }
  @Test
  public void testRebuildOfTheSameCodebase() throws Exception {
    Verifier verifier = getVerifier("baseline/src", baselineRepo);

    verifier.executeGoals(Arrays.asList("clean", "package"));
    verifier.verifyErrorFreeLog();

    File repository = new File(verifier.getBasedir(), "repository/target/repository");

    assertBaselineContents(repository, "features/baseline.feature01_1.0.0.1.jar");
    assertBaselineContents(repository, "plugins/baseline.bundle01_1.0.0.1.jar");
    assertBaselineContents(repository, "plugins/baseline.bundle01.source_1.0.0.1.jar");
  }
  @Test
  public void testBaselineWarn_changedAttachedArtifact() throws Exception {
    Verifier verifier = getVerifier("changedattachedartifact", baselineRepo);

    verifier.getCliOptions().add("-Dtycho.baseline=warn");

    verifier.executeGoals(Arrays.asList("clean", "package"));
    verifier.verifyTextInLog(
        "baseline and build artifacts have same version but different contents");

    File repository = new File(verifier.getBasedir(), "repository/target/repository");
    assertBaselineContents(repository, "plugins/baseline.bundle01.source_1.0.0.1.jar");
  }
  @Before
  public void setUpProject() throws IOException, VerificationException {
    assumeTrue("Set the M2_HOME environment variable", System.getenv("M2_HOME") != null);
    assumeTrue(
        "Run from Maven or set the project.version system property",
        System.getProperty("project.version") != null);

    File projectDir =
        ResourceExtractor.extractResourcePath(getClass(), "/testing-project", tmp.getRoot(), true);
    testingProject.prepare(projectDir.toPath());

    verifier = new Verifier(projectDir.getAbsolutePath(), true);
    verifier.setForkJvm(true);

    logPath = Paths.get(verifier.getBasedir()).resolve(verifier.getLogFileName());
  }
  @Test
  public void buildUberjarAndRunTests()
      throws IOException, VerificationException, InterruptedException {
    String goal = "package";
    if (testingProject.canRunTests()) {
      goal = "verify";

      // a lot of these fail because of SWARM-873
      if (testingProject.additionalDependency == AdditionalDependency.USING_JAVA_EE) {
        goal = "package";
      }
    }

    try {
      verifier.executeGoal(goal);
    } catch (VerificationException e) {
      if (testingProject.dependencies == Dependencies.JAVA_EE_APIS
          && testingProject.autodetection == Autodetection.NEVER) {
        // the only situation when build failure is expected
        String log = new String(Files.readAllBytes(logPath), StandardCharsets.UTF_8);
        assertThat(log).contains("No WildFly Swarm Bootstrap fraction found");
        return;
      }

      throw e;
    }

    verifier.assertFilePresent(
        "target/testing-project." + testingProject.packaging.fileExtension());
    verifier.assertFilePresent("target/testing-project-swarm.jar");

    String log = new String(Files.readAllBytes(logPath), StandardCharsets.UTF_8);

    assertThat(log).doesNotContain("[ERROR]");
    assertThat(log).doesNotContain("[WARNING]");
    assertThat(log).contains("BUILD SUCCESS");

    checkFractionAutodetection(log);

    File uberjarFile = new File(verifier.getBasedir(), "target/testing-project-swarm.jar");
    Archive uberjar = ShrinkWrap.createFromZipFile(GenericArchive.class, uberjarFile);

    checkFractionsPresent(uberjar);

    checkMainClass(uberjar);
  }
  @Test
  public void testNewVersion() throws Exception {
    Verifier verifier = getVerifier("baseline/src", baselineRepo);
    verifier.getCliOptions().add("-DversionQualifier=2");

    verifier.executeGoals(Arrays.asList("clean", "package"));
    verifier.verifyErrorFreeLog();

    File repository = new File(verifier.getBasedir(), "repository/target/repository");

    assertFileDoesNotExist(repository, "features/baseline.feature01_1.0.0.1.jar");
    assertFileDoesNotExist(repository, "plugins/baseline.bundle01_1.0.0.1.jar");
    assertFileDoesNotExist(repository, "plugins/baseline.bundle01.source_1.0.0.1.jar");

    assertFileExists(repository, "features/baseline.feature01_1.0.0.2.jar");
    assertFileExists(repository, "plugins/baseline.bundle01_1.0.0.2.jar");
    assertFileExists(repository, "plugins/baseline.bundle01.source_1.0.0.2.jar");
  }
  @Test
  public void testTargetDefinition() throws Exception {
    String url = server.addServer("foo", new File("repositories/e342"));

    Verifier verifier =
        getVerifier(
            "/TYCHO319passwordProtectedP2Repository",
            false,
            new File("projects/TYCHO319passwordProtectedP2Repository/settings.xml"));

    File platformFile = new File(verifier.getBasedir(), "platform.target");
    Target platform = Target.read(platformFile);
    platform.getLocations().get(0).setRepositoryLocation(url);
    Target.write(platform, platformFile);

    verifier.getCliOptions().add("-P=target-definition");
    verifier.executeGoals(Arrays.asList("package", "-Dp2.repo=" + url));
    verifier.verifyErrorFreeLog();
  }
  /**
   * tests the goal "convert-phar"
   *
   * @throws Exception
   */
  public void testGoal() throws Exception {
    final Verifier verifierDep1 = this.getPhpMavenVerifier("mojos-phar/phar-with-dep1-folders");

    // delete the pom from previous runs
    verifierDep1.deleteArtifact("org.phpmaven.test", "phar-with-dep1-folders", "0.0.1", "pom");
    verifierDep1.deleteArtifact("org.phpmaven.test", "phar-with-dep1-folders", "0.0.1", "phar");

    // execute testing
    verifierDep1.executeGoal("package");

    // verify no error was thrown
    verifierDep1.verifyErrorFreeLog();

    // reset the streams
    verifierDep1.resetStreams();

    final File phar =
        new File(new File(verifierDep1.getBasedir()), "target/phar-with-dep1-folders-0.0.1.phar");
    assertTrue(phar.exists());

    verifierDep1.setAutoclean(false);

    // to zip
    verifierDep1.addCliOption("-Dfrom=" + phar.getAbsolutePath());
    verifierDep1.addCliOption(
        "-Dto=" + phar.getAbsolutePath().substring(0, phar.getAbsolutePath().length() - 4) + "zip");

    verifierDep1.executeGoal("org.phpmaven:maven-php-plugin:convert-phar");

    // verify no error was thrown
    verifierDep1.verifyErrorFreeLog();

    // reset the streams
    verifierDep1.resetStreams();

    verifierDep1.assertFilePresent("target/phar-with-dep1-folders-0.0.1.zip");

    // to jar
    verifierDep1.getCliOptions().clear();
    verifierDep1.addCliOption(
        "-Dfrom="
            + phar.getAbsolutePath().substring(0, phar.getAbsolutePath().length() - 4)
            + "zip");
    verifierDep1.addCliOption(
        "-Dto=" + phar.getAbsolutePath().substring(0, phar.getAbsolutePath().length() - 4) + "jar");

    verifierDep1.executeGoal("org.phpmaven:maven-php-plugin:convert-phar");

    // verify no error was thrown
    verifierDep1.verifyErrorFreeLog();

    // reset the streams
    verifierDep1.resetStreams();

    verifierDep1.assertFilePresent("target/phar-with-dep1-folders-0.0.1.jar");

    // to phar
    verifierDep1.getCliOptions().clear();
    verifierDep1.addCliOption(
        "-Dfrom="
            + phar.getAbsolutePath().substring(0, phar.getAbsolutePath().length() - 4)
            + "jar");
    verifierDep1.addCliOption(
        "-Dto="
            + phar.getAbsolutePath().substring(0, phar.getAbsolutePath().length() - 4)
            + "2.phar");

    verifierDep1.executeGoal("org.phpmaven:maven-php-plugin:convert-phar");

    // verify no error was thrown
    verifierDep1.verifyErrorFreeLog();

    // reset the streams
    verifierDep1.resetStreams();

    verifierDep1.assertFilePresent("target/phar-with-dep1-folders-0.0.1.2.phar");

    verifierDep1.getCliOptions().clear();
    verifierDep1.addCliOption("-Dphar=target/phar-with-dep1-folders-0.0.1.2.phar");
    verifierDep1.executeGoal("org.phpmaven:maven-php-plugin:list-phar-files");
    @SuppressWarnings("unchecked")
    final List<String> lines =
        verifierDep1.loadFile(verifierDep1.getBasedir(), verifierDep1.getLogFileName(), false);
    boolean found1 = false;
    boolean found2 = false;
    for (final String line : lines) {
      if (line.startsWith(
          "[INFO] " + File.separatorChar + "folderA" + File.separatorChar + "MyClassA.php")) {
        found1 = true;
      }
      if (line.startsWith(
          "[INFO] " + File.separatorChar + "folderB" + File.separatorChar + "MyClassB.php")) {
        found2 = true;
      }
    }

    // verify no error was thrown
    verifierDep1.verifyErrorFreeLog();

    // reset the streams
    verifierDep1.resetStreams();

    assertTrue(found1);
    assertTrue(found2);
  }