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