/** Test that the CLI parameter -l can be used to direct logging to a file. */
  public void testit() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-3183");

    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.addCliOption("-l");
    verifier.addCliOption("maven.log");
    verifier.setLogFileName("stdout.txt");
    new File(testDir, "stdout.txt").delete();
    new File(testDir, "maven.log").delete();
    verifier.executeGoal("validate");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();

    List<String> stdout = verifier.loadLines("stdout.txt", "UTF-8");

    for (Iterator<String> it = stdout.iterator(); it.hasNext(); ) {
      String line = it.next();
      if (line.startsWith("+") || line.startsWith("EMMA")) {
        it.remove();
      }
    }

    assertEquals(Collections.EMPTY_LIST, stdout);

    List<String> log = verifier.loadLines("maven.log", "UTF-8");

    assertFalse(log.isEmpty());
  }
  /** Test support of "@requiresDependencyResolution compile+runtime". */
  public void testit() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4293");

    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.deleteDirectory("target");
    verifier.deleteArtifacts("org.apache.maven.its.mng4293");
    Properties filterProps = verifier.newDefaultFilterProperties();
    verifier.filterFile("pom-template.xml", "pom.xml", "UTF-8", filterProps);
    verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8", filterProps);
    verifier.getCliOptions().add("--settings");
    verifier.getCliOptions().add("settings.xml");
    verifier.executeGoal("validate");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();

    List compileClassPath = verifier.loadLines("target/compile-cp.txt", "UTF-8");
    assertTrue(compileClassPath.toString(), compileClassPath.contains("system-0.1.jar"));
    assertTrue(compileClassPath.toString(), compileClassPath.contains("provided-0.1.jar"));
    assertTrue(compileClassPath.toString(), compileClassPath.contains("compile-0.1.jar"));
    assertFalse(compileClassPath.toString(), compileClassPath.contains("test-0.1.jar"));

    List runtimeClassPath = verifier.loadLines("target/runtime-cp.txt", "UTF-8");
    assertTrue(runtimeClassPath.toString(), runtimeClassPath.contains("compile-0.1.jar"));
    assertTrue(runtimeClassPath.toString(), runtimeClassPath.contains("runtime-0.1.jar"));
    assertFalse(runtimeClassPath.toString(), runtimeClassPath.contains("test-0.1.jar"));
  }
  /**
   * Verify that overriding a transitive compile time dependency as provided in a WAR ensures it is
   * not included.
   */
  public void testitMNG1233() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-1233");

    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.deleteDirectory("target");
    verifier.deleteArtifacts("org.apache.maven.its.it0083");
    verifier.filterFile(
        "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties());
    verifier.addCliOption("--settings");
    verifier.addCliOption("settings.xml");
    verifier.executeGoal("validate");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();

    Collection<String> compileArtifacts = verifier.loadLines("target/compile.txt", "UTF-8");
    assertTrue(
        compileArtifacts.toString(),
        compileArtifacts.contains("org.apache.maven.its.it0083:direct-dep:jar:0.1"));
    assertTrue(
        compileArtifacts.toString(),
        compileArtifacts.contains("org.apache.maven.its.it0083:trans-dep:jar:0.1"));

    Collection<String> runtimeArtifacts = verifier.loadLines("target/runtime.txt", "UTF-8");
    assertTrue(
        runtimeArtifacts.toString(),
        runtimeArtifacts.contains("org.apache.maven.its.it0083:direct-dep:jar:0.1"));
    assertFalse(
        runtimeArtifacts.toString(),
        runtimeArtifacts.contains("org.apache.maven.its.it0083:trans-dep:jar:0.1"));
  }
  /**
   * Verify that dependency resolution prefers newer local snapshots over outdated remote snapshots
   * that use the new metadata format.
   */
  public void testit() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4955");

    Verifier verifier = newVerifier(new File(testDir, "dep").getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.deleteDirectory("target");
    verifier.deleteArtifacts("org.apache.maven.its.mng4955");
    verifier.executeGoal("validate");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();

    verifier = newVerifier(testDir.getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.deleteDirectory("target");
    verifier.addCliOption("-s");
    verifier.addCliOption("settings.xml");
    verifier.filterFile(
        "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties());
    verifier.executeGoal("validate");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();

    List<String> classpath = verifier.loadLines("target/classpath.txt", "UTF-8");

    File jarFile = new File(classpath.get(1).toString());
    assertEquals("eeff09b1b80e823eeb2a615b1d4b09e003e86fd3", ItUtils.calcHash(jarFile, "SHA-1"));
  }
  /**
   * Verify that default plugin executions contributed by the packaging are executed before
   * user-defined executions from the POM's build section, regardless whether the executions are
   * defined in the regular plugins section or the plugin management section.
   */
  public void testit() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4332");

    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.deleteDirectory("target");
    verifier.executeGoal("process-resources");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();

    List<String> lines = verifier.loadLines("target/resources-resources.txt", "UTF-8");
    assertEquals(Arrays.asList(new String[] {"default", "test-1", "test-2"}), lines);
  }
  /**
   * Verify that aggregator-only projects (i.e. not used as parent for inheritance) get built after
   * their modules.
   */
  public void testit() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4618");

    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.deleteDirectory("target");
    verifier.executeGoal("validate");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();

    List mods = verifier.loadLines("target/log.txt", "UTF-8");
    assertEquals(Arrays.asList(new String[] {"mod-a", "mod-b", "mod-c", "aggregator"}), mods);
  }
  /**
   * Test that plugin executions are properly merged during inheritance, even if the child plugin
   * section has no version.
   */
  public void testitMNG3916() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-3916");

    Verifier verifier = newVerifier(new File(testDir, "sub").getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.deleteDirectory("target");
    verifier.executeGoal("validate");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();

    List<String> executions = verifier.loadLines("target/exec.log", "UTF-8");
    // NOTE: Ordering of executions is another issue (MNG-3887), so ignore/normalize order
    Collections.sort(executions);
    List<String> expected = Arrays.asList(new String[] {"child-1", "child-default", "parent-1"});
    assertEquals(expected, executions);
  }
  /**
   * Test that unreadable metadata from one repository does not fail the entire dependency
   * resolution.
   */
  public void testit() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4498");

    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.deleteDirectory("target");
    verifier.deleteArtifacts("org.apache.maven.its.mng4498");
    verifier.filterFile(
        "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties());
    verifier.addCliOption("--settings");
    verifier.addCliOption("settings.xml");
    verifier.executeGoal("validate");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();

    List<String> classpath = verifier.loadLines("target/classpath.txt", "UTF-8");
    assertTrue(classpath.toString(), classpath.contains("dep-0.1-SNAPSHOT.jar"));
  }
  /**
   * Verify that dependency resolution by an aggregator before the build has actually produced any
   * artifacts doesn't prevent later resolution of project artifacts from the reactor if the
   * aggregator originally resolved them from the remote repo.
   */
  public void testit() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4814");

    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.deleteDirectory("consumer/target");
    verifier.deleteArtifacts("org.apache.maven.its.mng4814");
    verifier.addCliOption("-s");
    verifier.addCliOption("settings.xml");
    verifier.filterFile(
        "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties());
    List<String> goals = new ArrayList<String>();
    goals.add(
        "org.apache.maven.its.plugins:maven-it-plugin-dependency-resolution:2.1-SNAPSHOT:aggregate-test");
    goals.add("validate");
    verifier.executeGoals(goals);
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();

    List<String> compile = verifier.loadLines("consumer/target/compile.txt", "UTF-8");

    assertFalse(compile.toString(), compile.contains("0.1-SNAPSHOT/producer-0.1-SNAPSHOT.jar"));
    assertTrue(compile.toString(), compile.contains("producer/pom.xml"));
  }