All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.smartics.maven.plugin.buildmetadata.common.MojoUtils Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2006-2019 smartics, Kronseder & Reiner GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package de.smartics.maven.plugin.buildmetadata.common;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;

import java.util.List;

/**
 * Utilities for this Mojo.
 */
public final class MojoUtils {
  // ********************************* Fields *********************************

  // --- constants ------------------------------------------------------------

  // --- members --------------------------------------------------------------

  // ****************************** Initializer *******************************

  // ****************************** Constructors ******************************

  /**
   * Utilities pattern.
   */
  private MojoUtils() {}

  // ****************************** Inner Classes *****************************

  // ********************************* Methods ********************************

  // --- init -----------------------------------------------------------------

  // --- get&set --------------------------------------------------------------

  // --- business -------------------------------------------------------------

  /**
   * Logs and creates the given exception.
   *
   * @param log the logger to use.
   * @param exception the original exception to throw.
   * @param message the message to log and add to the mojo exception.
   * @return the exception that wraps the given exception.
   */
  public static MojoExecutionException createException(final Log log,
      final Throwable exception, final String message) {
    if (log.isWarnEnabled()) {
      log.warn(message, exception);
    }

    return new MojoExecutionException(message, exception);
  }

  /**
   * Turns the list to its string representation, removing the starting and
   * trailing brackets.
   *
   * @param list the list whose string representation is requested.
   * @return the string representation of the list.
   */
  public static String toPrettyString(final List list) {
    if (list != null) {
      final String string = String.valueOf(list);
      final int end = string.length() - 1;
      if (string.charAt(0) == '[' && string.charAt(end) == ']') {
        return string.substring(1, end);
      } else {
        return string;
      }
    }
    return null;
  }

  // --- object basics --------------------------------------------------------

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy