コード例 #1
0
  private void filterNot(Properties properties, @Nullable List<String> exclusions) {
    if (exclusions == null) return;

    List<Predicate<CharSequence>> excludePredicates =
        Lists.transform(
            exclusions,
            new Function<String, Predicate<CharSequence>>() {
              @Override
              public Predicate<CharSequence> apply(String exclude) {
                return Predicates.containsPattern(exclude);
              }
            });

    Predicate<CharSequence> shouldExclude = Predicates.alwaysFalse();
    for (Predicate<CharSequence> predicate : excludePredicates) {
      shouldExclude = Predicates.or(shouldExclude, predicate);
    }

    for (String key : properties.stringPropertyNames()) {
      if (shouldExclude.apply(key)) {
        loggerBridge.debug("shouldExclude.apply(" + key + ") = " + shouldExclude.apply(key));
        properties.remove(key);
      }
    }
  }
コード例 #2
0
 /**
  * Reacts to an exception based on the {@code failOnUnableToExtractRepoInfo} setting. If it's
  * true, an MojoExecutionException will be throw, otherwise we just log an error message.
  *
  * @throws MojoExecutionException which will be should be throw within an MojoException in case
  *     the {@code failOnUnableToExtractRepoInfo} setting was set to true.
  */
 private void handlePluginFailure(Exception e) throws MojoExecutionException {
   if (failOnUnableToExtractRepoInfo) {
     throw new MojoExecutionException("Could not complete Mojo execution...", e);
   } else {
     loggerBridge.error(
         e.getMessage(), com.google.common.base.Throwables.getStackTraceAsString(e));
   }
 }
コード例 #3
0
  public void execute() throws MojoExecutionException {
    // Set the verbose setting now it should be correctly loaded from maven.
    loggerBridge.setVerbose(verbose);

    if (skip) {
      log("skip is true, return");
      return;
    }

    if (isPomProject(project) && skipPoms) {
      log("isPomProject is true and skipPoms is true, return");
      return;
    }

    dotGitDirectory = lookupGitDirectory();
    throwWhenRequiredDirectoryNotFound(
        dotGitDirectory,
        failOnNoGitDirectory,
        ".git directory could not be found! Please specify a valid [dotGitDirectory] in your pom.xml");

    if (dotGitDirectory != null) {
      log("dotGitDirectory", dotGitDirectory.getAbsolutePath());
    } else {
      log("dotGitDirectory is null, aborting execution!");
      return;
    }

    try {
      properties = initProperties();

      String trimmedPrefix = prefix.trim();
      prefixDot = trimmedPrefix.equals("") ? "" : trimmedPrefix + ".";

      loadGitData(properties);
      loadBuildTimeData(properties);
      loadShortDescribe(properties);
      filterNot(properties, excludeProperties);
      logProperties(properties);

      if (generateGitPropertiesFile) {
        generatePropertiesFile(properties, project.getBasedir(), generateGitPropertiesFilename);
      }

      if (injectAllReactorProjects) {
        appendPropertiesToReactorProjects(properties);
      }
    } catch (Exception e) {
      e.printStackTrace();
      handlePluginFailure(e);
    }
  }
コード例 #4
0
 void log(String... parts) {
   loggerBridge.log((Object[]) parts);
 }