001 /* 002 * #%L 003 * License Maven Plugin 004 * 005 * $Id: CommentStyleListMojo.java 13519 2011-02-05 09:32:50Z tchemit $ 006 * $HeadURL: http://svn.codehaus.org/mojo/tags/license-maven-plugin-1.0/src/main/java/org/codehaus/mojo/license/CommentStyleListMojo.java $ 007 * %% 008 * Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit 009 * %% 010 * This program is free software: you can redistribute it and/or modify 011 * it under the terms of the GNU Lesser General Public License as 012 * published by the Free Software Foundation, either version 3 of the 013 * License, or (at your option) any later version. 014 * 015 * This program is distributed in the hope that it will be useful, 016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 018 * GNU General Lesser Public License for more details. 019 * 020 * You should have received a copy of the GNU General Lesser Public 021 * License along with this program. If not, see 022 * <http://www.gnu.org/licenses/lgpl-3.0.html>. 023 * #L% 024 */ 025 026 package org.codehaus.mojo.license; 027 028 import org.apache.maven.plugin.MojoExecutionException; 029 import org.apache.maven.plugin.MojoFailureException; 030 import org.codehaus.mojo.license.header.transformer.FileHeaderTransformer; 031 032 import java.util.*; 033 034 /** 035 * Displays all the available comment style to box file headers. 036 * 037 * @author themit <chemit@codelutin.com> 038 * @requiresProject false 039 * @requiresDirectInvocation 040 * @goal comment-style-list 041 * @since 1.0 042 */ 043 public class CommentStyleListMojo 044 extends AbstractLicenseMojo 045 { 046 047 /** 048 * A flag to display also the content of each license. 049 * 050 * @parameter expression="${detail}" 051 * @since 1.0 052 */ 053 private boolean detail; 054 055 /** 056 * All available header transformers. 057 * 058 * @component role="org.codehaus.mojo.license.header.transformer.FileHeaderTransformer" 059 * @since 1.0 060 */ 061 private Map<String, FileHeaderTransformer> transformers; 062 063 @Override 064 protected void init() 065 throws Exception 066 { 067 //nothing to do 068 } 069 070 @Override 071 public void doAction() 072 throws MojoExecutionException, MojoFailureException 073 { 074 075 StringBuilder buffer = new StringBuilder(); 076 if ( isVerbose() ) 077 { 078 buffer.append( "\n\n-------------------------------------------------------------------------------\n" ); 079 buffer.append( " license-maven-plugin\n" ); 080 buffer.append( "-------------------------------------------------------------------------------\n\n" ); 081 } 082 List<String> names = new ArrayList<String>( transformers.keySet() ); 083 Collections.sort( names ); 084 085 int maxLength = 0; 086 int maxDLength = 0; 087 for ( String name : names ) 088 { 089 if ( name.length() > maxLength ) 090 { 091 maxLength = name.length(); 092 } 093 FileHeaderTransformer transformer = transformers.get( name ); 094 if ( transformer.getDescription().length() > maxDLength ) 095 { 096 maxDLength = transformer.getDescription().length(); 097 } 098 } 099 100 String pattern = " - %1$-" + maxLength + "s : %2$-" + maxDLength + "s, extensions : %3$s\n"; 101 102 buffer.append( "List of available comment styles:\n\n" ); 103 for ( String transformerName : names ) 104 { 105 FileHeaderTransformer transformer = transformers.get( transformerName ); 106 buffer.append( String.format( pattern, transformerName, transformer.getDescription(), 107 Arrays.toString( transformer.getDefaultAcceptedExtensions() ) ) ); 108 if ( detail ) 109 { 110 buffer.append( "\n example : \n" ); 111 buffer.append( transformer.boxComment( "header", true ) ); 112 buffer.append( '\n' ); 113 } 114 } 115 116 getLog().info( buffer.toString() ); 117 } 118 119 public boolean isDetail() 120 { 121 return detail; 122 } 123 124 public void setDetail( boolean detail ) 125 { 126 this.detail = detail; 127 } 128 129 public Map<String, FileHeaderTransformer> getTransformers() 130 { 131 return transformers; 132 } 133 134 public void setTransformers( Map<String, FileHeaderTransformer> transformers ) 135 { 136 this.transformers = transformers; 137 } 138 }