• 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.checkapi;
18
19import org.gradle.api.DefaultTask
20import org.gradle.api.Nullable
21import org.gradle.api.tasks.Input
22import org.gradle.api.tasks.InputFile
23import org.gradle.api.tasks.Optional
24import org.gradle.api.tasks.TaskAction
25import org.gradle.api.tasks.OutputFile
26import org.gradle.api.tasks.WorkResult
27
28public class UpdateApiTask extends DefaultTask {
29    @InputFile
30    File newApiFile
31    @InputFile
32    File newRemovedApiFile
33
34    @Input
35    @Optional
36    Set whitelistErrors = []
37
38    @OutputFile
39    File oldApiFile
40    @OutputFile
41    File oldRemovedApiFile
42
43    @OutputFile
44    @Optional
45    @Nullable
46    File whitelistErrorsFile
47
48    private WorkResult copyFromToFile(File src, File dest) {
49        return project.copy {
50            from src
51            into dest.parent
52            rename { dest.name }
53        }
54    }
55
56    @TaskAction
57    public void doUpdate() {
58        copyFromToFile(getNewApiFile(), getOldApiFile())
59        copyFromToFile(getNewRemovedApiFile(), getOldRemovedApiFile())
60
61        if (whitelistErrorsFile && !whitelistErrors.empty) {
62            if (whitelistErrorsFile.exists()) {
63                whitelistErrors.removeAll(whitelistErrorsFile.readLines())
64            }
65            whitelistErrors.each { whitelistErrorsFile << "$it\n" }
66            logger.lifecycle "Whitelisted ${whitelistErrors.size()} error(s)..."
67        }
68
69        logger.lifecycle "Wrote public API definition to ${oldApiFile.name}"
70    }
71}