View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   */
19  package org.apache.rat.annotation;
20  
21  import java.io.File;
22  
23  
24  /**
25   * Add an Apache Licence V2 licence header to a 
26   * document. This appender does not check for the
27   * existence of an existing licence header, it is assumed that either a second
28   * licence header is intentional or that there is no licence header present
29   * already. 
30   * 
31   */
32  public class ApacheV2LicenceAppender extends AbstractLicenceAppender {
33  
34    private String copyright;
35  
36    /**
37     * Create a licence appender with the standard ASF licence header.
38     */
39    public ApacheV2LicenceAppender() {
40      super();
41    }
42  
43    /**
44     * Create a licence appender with the given copyright line. This should be of
45     * the form "Copyright 2008 Foo"
46     * 
47     * @param copyright copyright line. 
48     */
49    public ApacheV2LicenceAppender(String copyright) {
50      super();
51      this.copyright = copyright;
52    }
53  
54    @Override
55    public String getLicenceHeader(File document) {
56      int type = getType(document);
57      StringBuilder sb = new StringBuilder();
58      if (copyright == null) {
59        sb.append(getFirstLine(type));
60        sb.append(getLine(type, "Licensed to the Apache Software Foundation (ASF) under one"));
61        sb.append(getLine(type, "or more contributor license agreements.  See the NOTICE file"));
62        sb.append(getLine(type, "distributed with this work for additional information"));
63        sb.append(getLine(type, "regarding copyright ownership.  The ASF licenses this file"));
64        sb.append(getLine(type, "to you under the Apache License, Version 2.0 (the"));
65        sb.append(getLine(type, "\"License\"); you may not use this file except in compliance"));
66        sb.append(getLine(type, "with the License.  You may obtain a copy of the License at"));
67        sb.append(getLine(type, ""));
68        sb.append(getLine(type, "  http://www.apache.org/licenses/LICENSE-2.0"));
69        sb.append(getLine(type, ""));
70        sb.append(getLine(type, "Unless required by applicable law or agreed to in writing,"));
71        sb.append(getLine(type, "software distributed under the License is distributed on an"));
72        sb.append(getLine(type, "\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY"));
73        sb.append(getLine(type, "KIND, either express or implied.  See the License for the"));
74        sb.append(getLine(type, "specific language governing permissions and limitations"));
75        sb.append(getLine(type, "under the License."));
76        sb.append(getLastLine(type));
77      } else {
78        sb.append(getFirstLine(type));
79        sb.append(getLine(type, copyright));
80        sb.append(getLine(type, ""));
81        sb.append(getLine(type, "Licensed under the Apache License, Version 2.0 (the \"License\");"));
82        sb.append(getLine(type, "you may not use this file except in compliance with the License."));
83        sb.append(getLine(type, "You may obtain a copy of the License at"));
84        sb.append(getLine(type, ""));
85        sb.append(getLine(type, "  http://www.apache.org/licenses/LICENSE-2.0"));
86        sb.append(getLine(type, ""));
87        sb.append(getLine(type, "Unless required by applicable law or agreed to in writing,"));
88        sb.append(getLine(type, "software distributed under the License is distributed on an"));
89        sb.append(getLine(type, "\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY"));
90        sb.append(getLine(type, "KIND, either express or implied.  See the License for the"));
91        sb.append(getLine(type, "specific language governing permissions and limitations"));
92        sb.append(getLine(type, "under the License."));
93        sb.append(getLastLine(type));
94      }
95      return sb.toString();
96    }
97    
98    
99  
100 }