1 /* 2 * Copyright 2006-2012 smartics, Kronseder & Reiner GmbH 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package de.smartics.maven.plugin.buildmetadata.common; 17 18 import java.util.List; 19 20 import org.apache.maven.plugin.MojoExecutionException; 21 import org.apache.maven.plugin.logging.Log; 22 23 /** 24 * Utilities for this Mojo. 25 * 26 * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a> 27 * @version $Revision:591 $ 28 */ 29 public final class MojoUtils 30 { 31 // ********************************* Fields ********************************* 32 33 // --- constants ------------------------------------------------------------ 34 35 // --- members -------------------------------------------------------------- 36 37 // ****************************** Initializer ******************************* 38 39 // ****************************** Constructors ****************************** 40 41 /** 42 * Utilities pattern. 43 */ 44 private MojoUtils() 45 { 46 } 47 48 // ****************************** Inner Classes ***************************** 49 50 // ********************************* Methods ******************************** 51 52 // --- init ----------------------------------------------------------------- 53 54 // --- get&set -------------------------------------------------------------- 55 56 // --- business ------------------------------------------------------------- 57 58 /** 59 * Logs and creates the given exception. 60 * 61 * @param log the logger to use. 62 * @param e the original exception to throw. 63 * @param message the message to log and add to the mojo exception. 64 * @return the exception that wraps the given exception. 65 */ 66 public static MojoExecutionException createException( 67 final Log log, 68 final Throwable e, 69 final String message) 70 { 71 if (log.isWarnEnabled()) 72 { 73 log.warn(message, e); 74 } 75 76 return new MojoExecutionException(message, e); 77 } 78 79 /** 80 * Turns the list to its string representation, removing the starting and trailing brackets. 81 * 82 * @param list the list whose string representation is requested. 83 * @return the string representation of the list. 84 */ 85 public static String toPrettyString(final List<?> list) 86 { 87 if (list != null) 88 { 89 final String string = String.valueOf(list); 90 final int end = string.length() - 1; 91 if (string.charAt(0) == '[' && string.charAt(end) == ']') 92 { 93 return string.substring(1, end); 94 } 95 else 96 { 97 return string; 98 } 99 } 100 return null; 101 } 102 103 // --- object basics -------------------------------------------------------- 104 105 }