View Javadoc
1   /*
2    * Copyright 2003-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.codehaus.gmavenplus.groovyworkarounds;
18  
19  import org.codehaus.gmavenplus.model.internal.Version;
20  
21  import static org.codehaus.gmavenplus.util.ClassWrangler.groovyAtLeast;
22  
23  
24  /**
25   * This class was taken mostly from the Groovy project
26   * (<a href="https://github.com/groovy/groovy-core/blob/master/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/gstringTemplates/GroovyDocTemplateInfo.java">GroovyDocTemplateInfo.java</a> and <a href="https://github.com/groovy/groovy-core/blob/master/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/groovydoc/GroovyDoc.java">GroovyDoc.java</a>)
27   * because it wasn't available prior to Groovy 1.7.
28   */
29  public class GroovyDocTemplateInfo {
30  
31      /**
32       * Groovy 2.5.0 version.
33       */
34      protected static final Version GROOVY_2_5_0 = new Version(2, 5, 0);
35  
36      /**
37       * Groovy 1.6.2 version.
38       */
39      protected static final Version GROOVY_1_6_2 = new Version(1, 6, 2);
40  
41      /**
42       * Groovy 1.6.0 version.
43       */
44      protected static final Version GROOVY_1_6_0 = new Version(1, 6, 0);
45  
46      /**
47       * Groovy 1.6.0 RC-2 version.
48       */
49      protected static final Version GROOVY_1_6_0_RC2 = new Version(1, 6, 0, "RC-2");
50  
51      /**
52       * The version of Groovy whose locations to use for GroovyDoc templates.
53       */
54      protected final Version groovyVersion;
55  
56      /**
57       * Base directory of templates.
58       */
59      protected final String templateBaseDir;
60  
61      /**
62       * Constructs a new GroovyDocTemplateInfo using the specified Groovy version to determine templates location.
63       *
64       * @param version the version of Groovy whose locations to use for templates
65       */
66      public GroovyDocTemplateInfo(Version version) {
67          groovyVersion = version;
68          if (groovyAtLeast(groovyVersion, GROOVY_1_6_2)) {
69              templateBaseDir = "org/codehaus/groovy/tools/groovydoc/gstringTemplates/";
70          } else {
71              templateBaseDir = "org/codehaus/groovy/tools/groovydoc/gstring-templates/";
72          }
73      }
74  
75      public String[] defaultDocTemplates() {
76          if (groovyAtLeast(groovyVersion, GROOVY_2_5_0)) {
77              return new String[]{
78                      templateBaseDir + "topLevel/index.html",
79                      templateBaseDir + "topLevel/overview-frame.html",
80                      templateBaseDir + "topLevel/allclasses-frame.html",
81                      templateBaseDir + "topLevel/overview-summary.html",
82                      templateBaseDir + "topLevel/help-doc.html",
83                      templateBaseDir + "topLevel/index-all.html",
84                      templateBaseDir + "topLevel/deprecated-list.html",
85                      templateBaseDir + "topLevel/stylesheet.css",
86                      templateBaseDir + "topLevel/inherit.gif",
87                      "org/apache/groovy/docgenerator/groovy.ico"
88              };
89          } else if (groovyAtLeast(groovyVersion, GROOVY_1_6_2)) {
90              return new String[]{
91                      templateBaseDir + "topLevel/index.html",
92                      templateBaseDir + "topLevel/overview-frame.html",
93                      templateBaseDir + "topLevel/allclasses-frame.html",
94                      templateBaseDir + "topLevel/overview-summary.html",
95                      templateBaseDir + "topLevel/help-doc.html",
96                      templateBaseDir + "topLevel/index-all.html",
97                      templateBaseDir + "topLevel/deprecated-list.html",
98                      templateBaseDir + "topLevel/stylesheet.css",
99                      templateBaseDir + "topLevel/inherit.gif",
100                     "org/codehaus/groovy/tools/groovy.ico"
101             };
102         } else if (groovyAtLeast(groovyVersion, GROOVY_1_6_0)) {
103             return new String[]{
104                     templateBaseDir + "top-level/index.html",
105                     templateBaseDir + "top-level/overview-frame.html",
106                     templateBaseDir + "top-level/allclasses-frame.html",
107                     templateBaseDir + "top-level/overview-summary.html",
108                     templateBaseDir + "top-level/help-doc.html",
109                     templateBaseDir + "top-level/index-all.html",
110                     templateBaseDir + "top-level/deprecated-list.html",
111                     templateBaseDir + "top-level/stylesheet.css",
112                     templateBaseDir + "top-level/inherit.gif"
113             };
114         } else if (groovyAtLeast(groovyVersion, GROOVY_1_6_0_RC2)) {
115             return new String[]{
116                     templateBaseDir + "top-level/index.html",
117                     templateBaseDir + "top-level/overview-frame.html",
118                     templateBaseDir + "top-level/allclasses-frame.html",
119                     templateBaseDir + "top-level/overview-summary.html",
120                     templateBaseDir + "top-level/stylesheet.css",
121                     templateBaseDir + "top-level/inherit.gif"
122             };
123         } else {
124             return new String[]{
125                     templateBaseDir + "top-level/index.html",
126                     templateBaseDir + "top-level/overview-frame.html",
127                     templateBaseDir + "top-level/allclasses-frame.html",
128                     templateBaseDir + "top-level/overview-summary.html",
129                     templateBaseDir + "top-level/stylesheet.css"
130             };
131         }
132     }
133 
134     public String[] defaultPackageTemplates() {
135         if (groovyAtLeast(groovyVersion, GROOVY_1_6_2)) {
136             return new String[]{
137                     templateBaseDir + "packageLevel/package-frame.html",
138                     templateBaseDir + "packageLevel/package-summary.html"
139             };
140         } else {
141             return new String[]{
142                     templateBaseDir + "package-level/package-frame.html",
143                     templateBaseDir + "package-level/package-summary.html"
144             };
145         }
146     }
147 
148     public String[] defaultClassTemplates() {
149         if (groovyAtLeast(groovyVersion, GROOVY_1_6_2)) {
150             return new String[]{
151                     templateBaseDir + "classLevel/classDocName.html"
152             };
153         } else {
154             return new String[]{
155                     templateBaseDir + "class-level/classDocName.html"
156             };
157         }
158     }
159 
160 }