/**
   * 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 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"));
  }
  /** 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 a project-level plugin dependency class/resource can be loaded from both the plugin
   * classloader and the context classloader available to the plugin.
   */
  public void testit0087() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/it0087");
    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.deleteDirectory("target");
    verifier.deleteArtifacts("org.apache.maven.its.it0087");
    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();

    Properties pclProps = verifier.loadProperties("target/pcl.properties");
    assertNotNull(pclProps.getProperty("org.apache.maven.plugin.coreit.ClassA"));
    assertNotNull(pclProps.getProperty("org.apache.maven.plugin.coreit.ClassB"));
    assertNotNull(pclProps.getProperty("org.apache.maven.its.it0087.IT0087"));
    assertNotNull(pclProps.getProperty("src/main/java/org/apache/maven/its/it0087/IT0087.java"));
    assertEquals(
        "1", pclProps.getProperty("src/main/java/org/apache/maven/its/it0087/IT0087.java.count"));

    Properties tcclProps = verifier.loadProperties("target/tccl.properties");
    assertEquals(pclProps, tcclProps);
  }
  /** 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());
  }
  public void testitSameValueAcrossModules() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-2562/reactor");

    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.deleteDirectory("target");
    verifier.deleteDirectory("child-1/target");
    verifier.deleteDirectory("child-2/target");
    verifier.deleteDirectory("child-3/target");
    verifier.executeGoal("validate");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();

    Properties props = verifier.loadProperties("target/pom.properties");
    String timestamp = props.getProperty("project.properties.timestamp", "");

    Properties props1 = verifier.loadProperties("child-1/target/pom.properties");
    String timestamp1 = props1.getProperty("project.properties.timestamp", "");

    Properties props2 = verifier.loadProperties("child-2/target/pom.properties");
    String timestamp2 = props2.getProperty("project.properties.timestamp", "");

    Properties props3 = verifier.loadProperties("child-3/target/pom.properties");
    String timestamp3 = props3.getProperty("project.properties.timestamp", "");

    assertEquals(timestamp, timestamp1);
    assertEquals(timestamp, timestamp2);
    assertEquals(timestamp, timestamp3);
  }
  /**
   * Test that POM interpolation uses the property values from the dominant profile source (POM vs.
   * profiles.xml vs. settings.xml). This boils down to the proper order of profile injection and
   * interpolation, i.e. interpolate after profiles from all sources are injected.
   */
  public void testitMNG4107() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4107");

    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.addCliOption("--settings");
    verifier.addCliOption("settings.xml");
    verifier.executeGoal("validate");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();

    Properties props = verifier.loadProperties("target/pom.properties");

    assertEquals("applied", props.getProperty("project.properties.pomProfile"));
    assertEquals("applied", props.getProperty("project.properties.settingsProfile"));
    assertEquals("settings", props.getProperty("project.properties.pomVsSettings"));
    assertEquals("settings", props.getProperty("project.properties.pomVsSettingsInterpolated"));

    if (matchesVersionRange("(,3.0-alpha-1)")) {
      // MNG-4060, profiles.xml support dropped
      assertEquals("applied", props.getProperty("project.properties.profilesProfile"));
      assertEquals("profiles", props.getProperty("project.properties.pomVsProfiles"));
      assertEquals("profiles", props.getProperty("project.properties.pomVsProfilesInterpolated"));
      assertEquals("settings", props.getProperty("project.properties.profilesVsSettings"));
      assertEquals(
          "settings", props.getProperty("project.properties.profilesVsSettingsInterpolated"));
    }
  }
  @Test
  public void buildExecutable() throws VerificationException {
    Verifier verifier = new Verifier(getRoot().getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.setMavenDebug(true);

    verifier.executeGoal("package");

    verifier.verifyErrorFreeLog();
  }
  /**
   * Checks the quick-start archetype with the emulator parameter.
   *
   * @throws IOException a file cannot be read
   * @throws VerificationException the maven launch failed
   */
  @Test
  public void testQuickStartWithEmulator() throws VerificationException, IOException {

    File root = Helper.prepareDirectory("quickstart-default");

    Verifier verifier = new Verifier(root.getAbsolutePath(), false);
    verifier.setAutoclean(false);

    verifier.displayStreamBuffers();

    @SuppressWarnings("unchecked")
    List<String> cli = verifier.getCliOptions();
    cli.add("-DarchetypeArtifactId=android-quickstart");
    cli.add("-DarchetypeGroupId=de.akquinet.android.archetypes");
    cli.add("-DarchetypeVersion=" + System.getProperty("archetype.version"));
    cli.add("-DgroupId=" + Constants.TEST_GROUP_ID);
    cli.add("-DartifactId=" + Constants.TEST_ARTIFACT_ID);
    cli.add("-DinteractiveMode=false");
    cli.add("-DarchetypeCatalog=local");
    cli.add("-DarchetypeRepository=local");
    cli.add("-Demulator=test");
    cli.add("-Dandroid-plugin-version=3.0.0-alpha-2");
    verifier.executeGoal("org.apache.maven.plugins:maven-archetype-plugin:2.0:generate");

    // Check folder create.
    verifier.assertFilePresent("android-test");
    verifier.assertFilePresent("android-test/AndroidManifest.xml");
    verifier.assertFilePresent("android-test/pom.xml");
    verifier.assertFilePresent("android-test/res/values/strings.xml");
    verifier.assertFilePresent("android-test/res/layout/main.xml");
    verifier.assertFilePresent("android-test/assets");
    verifier.assertFilePresent(
        "android-test/src/main/java/android/archetypes/test/HelloAndroidActivity.java");

    Helper.assertContains(
        new File("target/it/quickstart-default/android-test/pom.xml"),
        "<artifactId>maven-android-plugin</artifactId>");
    Helper.assertContains(
        new File("target/it/quickstart-default/android-test/pom.xml"), "<platform>7</platform>");
    Helper.assertContains(
        new File("target/it/quickstart-default/android-test/AndroidManifest.xml"),
        "<activity android:name=\".HelloAndroidActivity\">");
    Helper.assertContains(
        new File("target/it/quickstart-default/android-test/AndroidManifest.xml"),
        "package=\"android.archetypes.test\"");

    // Check that the Eclipse file is created (default.properties)
    Helper.assertContains(
        new File("target/it/quickstart-default/android-test/default.properties"),
        "target=android-7");

    // Check the emulator part
    Helper.assertContains(
        new File("target/it/quickstart-default/android-test/pom.xml"), "<avd>test</avd>");
  }
  /**
   * 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);
  }
  /**
   * 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);
  }
  /**
   * @param baseDir
   * @param model
   * @throws VerificationException
   */
  private void installArchetype(File baseDir, Model model) throws VerificationException {
    log.info("Installing Archetype *****: " + model);
    Verifier installer = new Verifier(baseDir.getAbsolutePath());
    if (onlyMavenCentral) {
      installer.addCliOption("-s " + testOutputDirectory + File.separator + "settings-clear.xml");
    }
    installer.setLogFileName("install.log");
    installer.setAutoclean(cleanArchetypes);
    installer.executeGoal("install");

    // Remove install.log from inside archetype
    new File(baseDir, "install.log").delete();
  }
  /**
   * @param archetypeVersion
   * @throws ComponentLookupException
   * @throws PlexusContainerException
   */
  private void executeCreateArchetype(Model model) throws Exception {
    log.info("Creating project from Archetype: " + model);
    String goal = "org.apache.maven.plugins:maven-archetype-plugin:2.2:generate";
    Properties properties = new Properties();
    properties.put("archetypeGroupId", model.getGroupId());
    properties.put("archetypeArtifactId", model.getArtifactId());
    properties.put("archetypeVersion", model.getVersion());
    properties.put("groupId", "org.jboss.as.quickstarts");
    String artifactId =
        System.currentTimeMillis() + "-" + model.toString().replaceAll("[^a-zA-Z_0-9]", "");
    properties.put("artifactId", artifactId);
    properties.put("version", "0.0.1-SNAPSHOT");
    Verifier verifier = new org.apache.maven.it.Verifier(outputDir);
    verifier.setAutoclean(false);
    verifier.setSystemProperties(properties);
    verifier.setLogFileName(artifactId + "-generate.txt");

    verifier.executeGoal(goal);

    log.info("Building project from Archetype: " + model);
    Verifier buildVerifier = new Verifier(outputDir + File.separator + artifactId);
    if (onlyMavenCentral) {
      buildVerifier.addCliOption(
          "-s " + testOutputDirectory + File.separator + "settings-clear.xml");
    }
    buildVerifier.executeGoal("compile"); // buildVerifier log is inside each project
    String functionalTestsFolder =
        outputDir + File.separator + artifactId + File.separator + "functional-tests";
    if (new File(functionalTestsFolder).exists()) {
      log.info("Building functional-tests from: " + functionalTestsFolder);
      Verifier functionalTestsVerifier = new Verifier(functionalTestsFolder);
      functionalTestsVerifier.setAutoclean(cleanArchetypes);
      if (onlyMavenCentral) {
        functionalTestsVerifier.addCliOption(
            "-s " + testOutputDirectory + File.separator + "settings-clear.xml");
      }
      functionalTestsVerifier.executeGoal("compile");
    }
  }
  /** Test that exclusions defined on a dependency apply to its transitive dependencies as well. */
  public void testit() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4208");

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

    Properties props = verifier.loadProperties("target/pom.properties");
    assertEquals("PASSED", props.getProperty("project.properties.interpolatedProperty"));
  }
  /**
   * Verify that a dependency's optional flag is not subject to dependency management. This part of
   * the test checks the effective model.
   */
  public void testitModel() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4600/model");

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

    Properties props = verifier.loadProperties("target/pom.properties");
    assertEquals("dep", props.getProperty("project.dependencies.0.artifactId"));
    assertEquals("false", props.getProperty("project.dependencies.0.optional"));
  }
  /**
   * Verify that the reactor's project sorter considers artifact versions when checking for cycles.
   */
  public void testitMNG3814() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-3814");

    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.deleteArtifacts("org.apache.maven.its.mng3814");
    verifier.filterFile(
        "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties());
    verifier.getCliOptions().add("--settings");
    verifier.getCliOptions().add("settings.xml");
    verifier.executeGoal("validate");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();
  }
  /**
   * Test that wagon providers pulled in via transitive dependencies of Maven core artifacts get
   * excluded from plugin realms (in favor of potentially newer wagons bundled with the core). This
   * requirement is mostly a hack to compensate for the historic slip of Maven core artifacts
   * depending on wagon providers. Those old wagon providers conflict with the usually newer wagons
   * bundled with the core distro and cause grief under a class loader hierarchy where wagons are
   * loaded from the plugin realm (if available) like in Maven 3.
   */
  public void testit() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4528");

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

    Properties props = verifier.loadProperties("target/wagon.properties");
    String version = props.getProperty("version", "");
    assertFalse("Bad wagon version used: " + version, version.equals("1.0-alpha-6"));
  }
  /**
   * Checks the quick-start archetype with the <tt>platform</tt> and <tt>package</tt> parameters.
   *
   * @throws VerificationException
   * @throws IOException
   */
  @Test
  public void testQuickStartWithPlatformAndPackage() throws VerificationException, IOException {

    File root = Helper.prepareDirectory("quickstart-with-platform-and-package");

    Verifier verifier = new Verifier(root.getAbsolutePath(), false);
    verifier.setAutoclean(false);

    verifier.displayStreamBuffers();

    @SuppressWarnings("unchecked")
    List<String> cli = verifier.getCliOptions();
    cli.add("-DarchetypeArtifactId=android-quickstart");
    cli.add("-DarchetypeGroupId=de.akquinet.android.archetypes");
    cli.add("-DarchetypeVersion=" + System.getProperty("archetype.version"));
    cli.add("-DgroupId=" + Constants.TEST_GROUP_ID);
    cli.add("-DartifactId=" + Constants.TEST_ARTIFACT_ID);
    cli.add("-DinteractiveMode=false");
    cli.add("-DarchetypeCatalog=local");
    cli.add("-DarchetypeRepository=local");
    cli.add("-Dplatform=4");
    cli.add("-Dpackage=foo");

    verifier.executeGoal("org.apache.maven.plugins:maven-archetype-plugin:2.0:generate");

    // Check folder create.
    verifier.assertFilePresent("android-test");
    verifier.assertFilePresent("android-test/AndroidManifest.xml");
    verifier.assertFilePresent("android-test/pom.xml");
    verifier.assertFilePresent("android-test/res/values/strings.xml");
    verifier.assertFilePresent("android-test/res/layout/main.xml");
    verifier.assertFilePresent("android-test/assets");
    verifier.assertFilePresent("android-test/src/main/java/foo/HelloAndroidActivity.java");

    Helper.assertContains(
        new File("target/it/quickstart-with-platform-and-package/android-test/pom.xml"),
        "<artifactId>maven-android-plugin</artifactId>");
    Helper.assertContains(
        new File("target/it/quickstart-with-platform-and-package/android-test/pom.xml"),
        "<platform>4</platform>");
    Helper.assertContains(
        new File("target/it/quickstart-with-platform-and-package/android-test/pom.xml"),
        "1.6_r2"); // Android lib version
    Helper.assertContains(
        new File("target/it/quickstart-with-platform-and-package/android-test/AndroidManifest.xml"),
        "<activity android:name=\".HelloAndroidActivity\">");
    Helper.assertContains(
        new File("target/it/quickstart-with-platform-and-package/android-test/AndroidManifest.xml"),
        "package=\"foo\"");
  }
  /** Verify that active collections of core components are properly injected into plugins. */
  public void testitMNG3422() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-3422");

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

    Properties props = verifier.loadProperties("target/layout.properties");
    assertFalse("0".equals(props.getProperty("layouts", "0")));
    assertFalse("".equals(props.getProperty("layouts.default", "")));
  }
  /**
   * 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);
  }
  /** Tests context passing between mojos in the same plugin. */
  public void testitMNG0823() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-0823");

    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.deleteDirectory("target");
    List<String> goals =
        Arrays.asList(
            new String[] {
              "org.apache.maven.its.plugins:maven-it-plugin-context-passing:throw",
              "org.apache.maven.its.plugins:maven-it-plugin-context-passing:catch"
            });
    verifier.executeGoals(goals);
    verifier.assertFilePresent("target/thrown-value");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();
  }
  /**
   * 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"));
  }
  public void testitCustomFormat() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-2562/custom");

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

    Date now = new Date();

    Properties props = verifier.loadProperties("target/pom.properties");

    String timestamp1 = props.getProperty("project.properties.timestamp", "");
    Date date = new SimpleDateFormat("mm:HH dd-MM-yyyy").parse(timestamp1);
    assertTrue(now + " vs " + date, Math.abs(now.getTime() - date.getTime()) < 24 * 60 * 60 * 1000);
  }
  /**
   * Verify that repositories which have both releases and snapshots disabled aren't touched when
   * looking for plugin prefix mappings.
   */
  public void testit() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4771");

    final List<String> requestedUris = Collections.synchronizedList(new ArrayList<String>());

    AbstractHandler logHandler =
        new AbstractHandler() {
          public void handle(
              String target, HttpServletRequest request, HttpServletResponse response, int dispatch)
              throws IOException, ServletException {
            requestedUris.add(request.getRequestURI());
          }
        };

    HandlerList handlerList = new HandlerList();
    handlerList.addHandler(logHandler);
    handlerList.addHandler(new DefaultHandler());

    Server server = new Server(0);
    server.setHandler(handlerList);
    server.start();

    Verifier verifier = newVerifier(testDir.getAbsolutePath());
    try {
      verifier.setAutoclean(false);
      verifier.deleteDirectory("target");
      Properties filterProps = verifier.newDefaultFilterProperties();
      filterProps.setProperty("@port@", Integer.toString(server.getConnectors()[0].getLocalPort()));
      verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8", filterProps);
      verifier.addCliOption("-U");
      verifier.addCliOption("-s");
      verifier.addCliOption("settings.xml");
      verifier.executeGoal("mng4771:touch");
      verifier.verifyErrorFreeLog();
      fail("Build should have failed to resolve unknown prefix");
    } catch (VerificationException e) {
      assertTrue(true);
    } finally {
      verifier.resetStreams();
      server.stop();
    }

    assertTrue(requestedUris.toString(), requestedUris.isEmpty());
  }
  /**
   * Verify that plugin dependencies defined by plugin management of a parent profile are not lost
   * when the parent's main plugin management section is also present.
   */
  public void testitMNG2174() throws Exception {
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-2174");

    Verifier verifier = newVerifier(new File(testDir, "sub").getAbsolutePath());
    verifier.setAutoclean(false);
    verifier.deleteDirectory("target");
    verifier.deleteArtifacts("org.apache.maven.its.mng2174");
    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();

    Properties props = verifier.loadProperties("target/pcl.properties");
    assertEquals("1", props.getProperty("mng-2174.properties.count"));
    assertNotNull(props.getProperty("mng-2174.properties"));
  }
  /**
   * 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"));
  }
Exemplo n.º 27
0
  /**
   * 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);
  }
  /**
   * Checks the with-test archetype with the <tt>platform</tt> parameter bellow 7 for correct
   * constructor.
   *
   * @throws VerificationException
   * @throws IOException
   */
  @Test
  public void testWithTestConstructorCorrectness() throws VerificationException, IOException {

    File root = Helper.prepareDirectory("with-test-with-platform");

    Verifier verifier = new Verifier(root.getAbsolutePath(), false);
    verifier.setAutoclean(false);

    verifier.displayStreamBuffers();

    @SuppressWarnings("unchecked")
    List<String> cli = verifier.getCliOptions();
    cli.add("-DarchetypeArtifactId=android-with-test");
    cli.add("-DarchetypeGroupId=de.akquinet.android.archetypes");
    cli.add("-DarchetypeVersion=" + System.getProperty("archetype.version"));
    cli.add("-DgroupId=" + Constants.TEST_GROUP_ID);
    cli.add("-DartifactId=" + Constants.TEST_ARTIFACT_ID);
    cli.add("-DinteractiveMode=false");
    cli.add("-Dplatform=7");
    cli.add("-DarchetypeCatalog=local");
    cli.add("-DarchetypeRepository=local");

    verifier.executeGoal("org.apache.maven.plugins:maven-archetype-plugin:2.0:generate");

    // Check folder create.
    verifier.assertFilePresent("android-test/" + Constants.TEST_ARTIFACT_ID);
    verifier.assertFilePresent("android-test/" + Constants.TEST_ARTIFACT_ID + "-it");
    verifier.assertFilePresent(
        "android-test/" + Constants.TEST_ARTIFACT_ID + "/AndroidManifest.xml");
    verifier.assertFilePresent(
        "android-test/" + Constants.TEST_ARTIFACT_ID + "-it/AndroidManifest.xml");
    verifier.assertFilePresent("android-test/pom.xml");
    verifier.assertFilePresent("android-test/" + Constants.TEST_ARTIFACT_ID + "/pom.xml");
    verifier.assertFilePresent("android-test/" + Constants.TEST_ARTIFACT_ID + "-it/pom.xml");

    verifier.assertFilePresent(
        "android-test/" + Constants.TEST_ARTIFACT_ID + "/res/values/strings.xml");
    verifier.assertFilePresent(
        "android-test/" + Constants.TEST_ARTIFACT_ID + "/res/layout/main.xml");
    verifier.assertFilePresent("android-test/" + Constants.TEST_ARTIFACT_ID + "/assets");
    verifier.assertFilePresent(
        "android-test/"
            + Constants.TEST_ARTIFACT_ID
            + "/src/main/java/android/archetypes/test/HelloAndroidActivity.java");
    verifier.assertFilePresent(
        "android-test/"
            + Constants.TEST_ARTIFACT_ID
            + "-it/src/main/java/android/archetypes/test/test/HelloAndroidActivityTest.java");

    Helper.assertContains(
        new File(
            "target/it/with-test-with-platform/android-test/"
                + Constants.TEST_ARTIFACT_ID
                + "/pom.xml"),
        "<artifactId>android-maven-plugin</artifactId>");
    Helper.assertContains(
        new File(
            "target/it/with-test-with-platform/android-test/"
                + Constants.TEST_ARTIFACT_ID
                + "/pom.xml"),
        "<platform>7</platform>");
    Helper.assertContains(
        new File(
            "target/it/with-test-with-platform/android-test/"
                + Constants.TEST_ARTIFACT_ID
                + "/AndroidManifest.xml"),
        "<activity android:name=\".HelloAndroidActivity\">");
    Helper.assertContains(
        new File(
            "target/it/with-test-with-platform/android-test/"
                + Constants.TEST_ARTIFACT_ID
                + "/AndroidManifest.xml"),
        "package=\"android.archetypes.test\"");

    Helper.assertContains(
        new File(
            "target/it/with-test-with-platform/android-test/"
                + Constants.TEST_ARTIFACT_ID
                + "-it/pom.xml"),
        "<artifactId>android-maven-plugin</artifactId>");
    Helper.assertContains(
        new File(
            "target/it/with-test-with-platform/android-test/"
                + Constants.TEST_ARTIFACT_ID
                + "-it/pom.xml"),
        "<platform>7</platform>");
    Helper.assertContains(
        new File(
            "target/it/with-test-with-platform/android-test/"
                + Constants.TEST_ARTIFACT_ID
                + "-it/AndroidManifest.xml"),
        "<uses-library android:name=\"android.test.runner\" />");
    Helper.assertContains(
        new File(
            "target/it/with-test-with-platform/android-test/"
                + Constants.TEST_ARTIFACT_ID
                + "-it/AndroidManifest.xml"),
        "<instrumentation android:targetPackage=\"android.archetypes.test\"");

    Helper.assertContains(
        new File(
            "target/it/with-test-with-platform/android-test/"
                + Constants.TEST_ARTIFACT_ID
                + "-it/src/main/java/android/archetypes/test/test/HelloAndroidActivityTest.java"),
        "super(\"android.archetypes.test\", HelloAndroidActivity.class);");
  }