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