View Javadoc

1   /*
2    * #%L
3    * License Maven Plugin
4    * 
5    * $Id: FileHeader.java 13519 2011-02-05 09:32:50Z tchemit $
6    * $HeadURL: http://svn.codehaus.org/mojo/tags/license-maven-plugin-1.0/src/main/java/org/codehaus/mojo/license/header/FileHeader.java $
7    * %%
8    * Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
9    * %%
10   * This program is free software: you can redistribute it and/or modify
11   * it under the terms of the GNU Lesser General Public License as 
12   * published by the Free Software Foundation, either version 3 of the 
13   * License, or (at your option) any later version.
14   * 
15   * This program is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   * GNU General Lesser Public License for more details.
19   * 
20   * You should have received a copy of the GNU General Lesser Public 
21   * License along with this program.  If not, see
22   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
23   * #L%
24   */
25  
26  package org.codehaus.mojo.license.header;
27  
28  /**
29   * Contract of a file header.
30   * <p/>
31   * A header has three sections like in this example :
32   * <p/>
33   * <pre>
34   * Description
35   * %--
36   * Copyright (C) firstYear[ - lastYear] holder
37   * %--
38   * License
39   * </pre>
40   *
41   * @author tchemit <chemit@codelutin.com>
42   * @since 1.0
43   */
44  public class FileHeader
45  {
46  
47      /**
48       * Copyright to string format
49       */
50      protected static final String COPYRIGHT_TO_STRING_FORMAT = "Copyright (C) %1$s %2$s";
51  
52      /**
53       * Description of the project or module to add in header
54       */
55      protected String description;
56  
57      /**
58       * Copyright holder
59       */
60      protected String copyrightHolder;
61  
62      /**
63       * Copyright first year of application
64       */
65      protected Integer copyrightFirstYear;
66  
67      /**
68       * Copyright last year of application (can be nullif copyright is
69       * only on one year).
70       */
71      protected Integer copyrightLastYear;
72  
73      /**
74       * License used in the header.
75       */
76      protected String license;
77  
78      /**
79       * @return the project name, or nay other common informations for all
80       *         files of a project (or module)
81       */
82      public String getDescription()
83      {
84          return description;
85      }
86  
87      /**
88       * @return the copyright holder
89       */
90      public String getCopyrightHolder()
91      {
92          return copyrightHolder;
93      }
94  
95      /**
96       * @return the first year of the copyright
97       */
98      public Integer getCopyrightFirstYear()
99      {
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 }