• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2016 The Android Open Source Project
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
17package android.support.jdiff;
18
19import org.gradle.api.tasks.Input
20import org.gradle.api.tasks.InputFile
21import org.gradle.api.tasks.InputFiles
22import org.gradle.api.tasks.javadoc.Javadoc
23import org.gradle.api.tasks.Optional
24import org.gradle.api.tasks.ParallelizableTask
25
26@ParallelizableTask
27public class JDiffTask extends Javadoc {
28
29    @InputFiles
30    Collection<File> docletpath
31
32    @InputFile
33    File oldApiXmlFile
34
35    @InputFile
36    File newApiXmlFile
37
38    /**
39     * Relative path to the Javadoc corresponding to the old API, relative to
40     * "${destinationDir}/changes". Should end with the directory separator (usually '/').
41     */
42    @Input
43    @Optional
44    String oldJavadocPrefix
45
46    /**
47     * Relative path to the Javadoc corresponding to the new API, relative to
48     * "${destinationDir}/changes". Should end with the directory separator (usually '/').
49     */
50    @Input
51    String newJavadocPrefix
52
53    // HTML diff files will be placed in destinationDir, which is defined by the superclass.
54
55    @Input
56    boolean stats = true
57
58    public JDiffTask() {
59        failOnError = true
60        options.doclet = "jdiff.JDiff"
61        options.encoding("UTF-8")
62        maxMemory = "1280m"
63    }
64
65    /**
66     * Sets the doclet path which has the {@code com.gogole.doclava.Doclava} class.
67     * <p>
68     * This option will override any doclet path set in this instance's
69     * {@link #getOptions() JavadocOptions}.
70     *
71     * @see MinimalJavadocOptions#setDocletpath(java.util.List)
72     */
73    public void setDocletpath(Collection<File> docletpath) {
74        this.docletpath = docletpath
75
76        // Go ahead and keep the docletpath in our JavadocOptions object in sync.
77        options.docletpath = docletpath as List
78    }
79
80    /**
81     * "Configures" this JDiffTask with parameters that might not be at their final values
82     * until this task is run.
83     */
84    private void configureJDiffTask() {
85        options.docletpath = getDocletpath() as List
86
87        if (getStats()) {
88            options.addStringOption('stats')
89        }
90
91        File oldApiXmlFile = getOldApiXmlFile()
92        File newApiXmlFile = getNewApiXmlFile()
93
94        File oldApiXmlFileDir = oldApiXmlFile.parentFile
95        File newApiXmlFileDir = newApiXmlFile.parentFile
96
97        if (oldApiXmlFileDir) {
98            options.addStringOption('oldapidir', oldApiXmlFileDir.absolutePath)
99        }
100        // For whatever reason, jdiff appends .xml to the file name on its own.
101        // Strip the .xml off the end of the file name
102        options.addStringOption('oldapi',
103                oldApiXmlFile.name.substring(0, oldApiXmlFile.name.length() - 4))
104        if (newApiXmlFileDir) {
105            options.addStringOption('newapidir', newApiXmlFileDir.absolutePath)
106        }
107        options.addStringOption('newapi',
108                newApiXmlFile.name.substring(0, newApiXmlFile.name.length() - 4))
109
110        String oldJavadocPrefix = getOldJavadocPrefix()
111        String newJavadocPrefix = getNewJavadocPrefix()
112
113        if (oldJavadocPrefix) {
114            options.addStringOption('javadocold', oldJavadocPrefix)
115        }
116        if (newJavadocPrefix) {
117            options.addStringOption('javadocnew', newJavadocPrefix)
118        }
119    }
120
121    @Override
122    public void generate() {
123        configureJDiffTask();
124        super.generate();
125    }
126}
127