コード例 #1
0
  /**
   * @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");
    }
  }