001 /* 002 * #%L 003 * License Maven Plugin 004 * 005 * $Id: FileHeader.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/header/FileHeader.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.header; 027 028 /** 029 * Contract of a file header. 030 * <p/> 031 * A header has three sections like in this example : 032 * <p/> 033 * <pre> 034 * Description 035 * %-- 036 * Copyright (C) firstYear[ - lastYear] holder 037 * %-- 038 * License 039 * </pre> 040 * 041 * @author tchemit <chemit@codelutin.com> 042 * @since 1.0 043 */ 044 public class FileHeader 045 { 046 047 /** 048 * Copyright to string format 049 */ 050 protected static final String COPYRIGHT_TO_STRING_FORMAT = "Copyright (C) %1$s %2$s"; 051 052 /** 053 * Description of the project or module to add in header 054 */ 055 protected String description; 056 057 /** 058 * Copyright holder 059 */ 060 protected String copyrightHolder; 061 062 /** 063 * Copyright first year of application 064 */ 065 protected Integer copyrightFirstYear; 066 067 /** 068 * Copyright last year of application (can be nullif copyright is 069 * only on one year). 070 */ 071 protected Integer copyrightLastYear; 072 073 /** 074 * License used in the header. 075 */ 076 protected String license; 077 078 /** 079 * @return the project name, or nay other common informations for all 080 * files of a project (or module) 081 */ 082 public String getDescription() 083 { 084 return description; 085 } 086 087 /** 088 * @return the copyright holder 089 */ 090 public String getCopyrightHolder() 091 { 092 return copyrightHolder; 093 } 094 095 /** 096 * @return the first year of the copyright 097 */ 098 public Integer getCopyrightFirstYear() 099 { 100 return copyrightFirstYear; 101 } 102 103 /** 104 * @return the last year of the copyright (if copyright affects only one 105 * year, can be equals to the {@link #getCopyrightFirstYear()}). 106 */ 107 public Integer getCopyrightLastYear() 108 { 109 return copyrightLastYear; 110 } 111 112 /** 113 * Produces a string representation of the copyright. 114 * <p/> 115 * If copyright acts on one year : 116 * <pre> 117 * Copyright (C) 2010 Holder 118 * </pre> 119 * <p/> 120 * If copyright acts on more than one year : 121 * <pre> 122 * Copyright (C) 2010 - 2012 Holder 123 * </pre> 124 * 125 * @return the String representation of the copyright 126 */ 127 public String getCopyright() 128 { 129 String copyright; 130 if ( getCopyrightLastYear() == null ) 131 { 132 133 // copyright on one year 134 copyright = String.format( COPYRIGHT_TO_STRING_FORMAT, getCopyrightFirstYear(), getCopyrightHolder() ); 135 } 136 else 137 { 138 139 // copyright on more than one year 140 copyright = 141 String.format( COPYRIGHT_TO_STRING_FORMAT, getCopyrightFirstYear() + " - " + getCopyrightLastYear(), 142 getCopyrightHolder() ); 143 } 144 return copyright; 145 } 146 147 /** 148 * @return the license content (this is not the fully license content, 149 * but just a per file license resume) 150 */ 151 public String getLicense() 152 { 153 return license; 154 } 155 156 public void setDescription( String description ) 157 { 158 this.description = description; 159 } 160 161 public void setCopyrightHolder( String copyrightHolder ) 162 { 163 this.copyrightHolder = copyrightHolder; 164 } 165 166 public void setCopyrightFirstYear( Integer copyrightFirstYear ) 167 { 168 this.copyrightFirstYear = copyrightFirstYear; 169 } 170 171 public void setCopyrightLastYear( Integer copyrightLastYear ) 172 { 173 this.copyrightLastYear = copyrightLastYear; 174 } 175 176 public void setLicense( String license ) 177 { 178 this.license = license; 179 } 180 }