public void testitMNG3746_UsingCLIProperty() throws Exception {
    // The testdir is computed from the location of this
    // file.
    File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-3746");
    File pluginDir = new File(testDir, "maven-mng3746-plugin");
    File projectDir = new File(testDir, "project");

    Verifier verifier;

    verifier = newVerifier(pluginDir.getAbsolutePath(), "remote");
    verifier.setLogFileName("log-cli.txt");
    verifier.executeGoal("install");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();

    verifier = newVerifier(projectDir.getAbsolutePath());
    verifier.setLogFileName("log-cli.txt");

    verifier.getCliOptions().add("-Dtest.verification=cli");
    verifier.getCliOptions().add("-Dtest.usingCliValue=true");
    verifier.getCliOptions().add("-Djava.version=cli");

    verifier.executeGoal("validate");
    verifier.verifyErrorFreeLog();
    verifier.resetStreams();
  }
  /** 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());
  }
示例#3
0
  /**
   * Creates a Verifier against passed in {@link MavenDeployment}.
   *
   * @param mavenDeployment
   * @return
   * @throws VerificationException
   * @throws IOException
   */
  public Verifier createMavenVerifier(final MavenDeployment mavenDeployment)
      throws VerificationException, IOException {
    System.setProperty("maven.home", mavenDeployment.getMavenHomeFile().getAbsolutePath());
    Verifier verifier =
        new Verifier(mavenDeployment.getMavenProjectFile().getAbsolutePath()) {
          @Override
          public void executeGoals(List<String> goals, Map envVars) throws VerificationException {
            try {
              super.executeGoals(goals, envVars);
            } catch (VerificationException e) {
              // HACK: Strip out the entire log which is included in the message by default! :-(
              File logFile = new File(getBasedir(), getLogFileName());
              throw new VerificationException(
                  "Goals execution failed: "
                      + goals
                      + "; see log for more details: "
                      + logFile.getAbsolutePath(),
                  e.getCause());
            }
          }
        };
    verifier.setLogFileName(mavenDeployment.getLogFileName());
    verifier.setLocalRepo(mavenDeployment.getLocalRepositoryFile().getAbsolutePath());
    verifier.resetStreams();

    List<String> options = new ArrayList<String>();
    options.add("-X");
    options.add("-Dmaven.repo.local=" + mavenDeployment.getLocalRepositoryFile().getAbsolutePath());
    options.add("-s " + mavenDeployment.getSettingsXmlFile().getAbsolutePath());
    verifier.setCliOptions(options);
    return verifier;
  }
  /**
   * @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();
  }
  protected void testJspc(File testDir) throws VerificationException {
    Verifier verifier = new Verifier(testDir.getAbsolutePath());
    verifier.setLogFileName("verifier.log");

    //        verifier.setDebug(true);
    //        verifier.setMavenDebug(true);

    verifier.executeGoal("clean");
    verifier.executeGoal("package");

    verifier.verifyErrorFreeLog();

    verifier.assertFilePresent("target/jspweb.xml");
    verifier.assertFilePresent("target/classes/jsp/index_jsp.class");
  }
  /**
   * @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");
    }
  }