001 /** 002 * Copyright 2010-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.codehaus.mojo.license; 017 018 import org.apache.maven.plugin.MojoExecutionException; 019 import org.apache.maven.plugin.MojoFailureException; 020 import org.codehaus.mojo.license.header.transformer.FileHeaderTransformer; 021 022 import java.util.*; 023 024 /** 025 * Displays all the available comment style to box file headers. 026 * 027 * @author themit <chemit@codelutin.com> 028 * @requiresProject false 029 * @requiresDirectInvocation 030 * @goal comment-style-list 031 * @since 1.0 032 */ 033 public class CommentStyleListMojo 034 extends AbstractLicenseMojo 035 { 036 037 /** 038 * A flag to display also the content of each license. 039 * 040 * @parameter expression="${detail}" 041 * @since 1.0 042 */ 043 private boolean detail; 044 045 /** 046 * All available header transformers. 047 * 048 * @component role="org.codehaus.mojo.license.header.transformer.FileHeaderTransformer" 049 * @since 1.0 050 */ 051 private Map<String, FileHeaderTransformer> transformers; 052 053 @Override 054 protected void init() 055 throws Exception 056 { 057 //nothing to do 058 } 059 060 @Override 061 public void doAction() 062 throws MojoExecutionException, MojoFailureException 063 { 064 065 StringBuilder buffer = new StringBuilder(); 066 if ( isVerbose() ) 067 { 068 buffer.append( "\n\n-------------------------------------------------------------------------------\n" ); 069 buffer.append( " license-maven-plugin\n" ); 070 buffer.append( "-------------------------------------------------------------------------------\n\n" ); 071 } 072 List<String> names = new ArrayList<String>( transformers.keySet() ); 073 Collections.sort( names ); 074 075 int maxLength = 0; 076 int maxDLength = 0; 077 for ( String name : names ) 078 { 079 if ( name.length() > maxLength ) 080 { 081 maxLength = name.length(); 082 } 083 FileHeaderTransformer transformer = transformers.get( name ); 084 if ( transformer.getDescription().length() > maxDLength ) 085 { 086 maxDLength = transformer.getDescription().length(); 087 } 088 } 089 090 String pattern = " - %1$-" + maxLength + "s : %2$-" + maxDLength + "s, extensions : %3$s\n"; 091 092 buffer.append( "List of available comment styles:\n\n" ); 093 for ( String transformerName : names ) 094 { 095 FileHeaderTransformer transformer = transformers.get( transformerName ); 096 buffer.append( String.format( pattern, transformerName, transformer.getDescription(), 097 Arrays.toString( transformer.getDefaultAcceptedExtensions() ) ) ); 098 if ( detail ) 099 { 100 buffer.append( "\n example : \n" ); 101 buffer.append( transformer.boxComment( "header", true ) ); 102 buffer.append( '\n' ); 103 } 104 } 105 106 getLog().info( buffer.toString() ); 107 } 108 109 public boolean isDetail() 110 { 111 return detail; 112 } 113 114 public void setDetail( boolean detail ) 115 { 116 this.detail = detail; 117 } 118 119 public Map<String, FileHeaderTransformer> getTransformers() 120 { 121 return transformers; 122 } 123 124 public void setTransformers( Map<String, FileHeaderTransformer> transformers ) 125 { 126 this.transformers = transformers; 127 } 128 }