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 17 package androidx.build.checkapi 18 19 import org.gradle.api.tasks.InputFile 20 import org.gradle.api.tasks.JavaExec 21 import org.gradle.api.tasks.Optional 22 import org.gradle.api.tasks.OutputFile 23 import java.io.File 24 25 /** 26 * Task that converts the given API file to XML format. 27 */ 28 open class ApiXmlConversionTask : JavaExec() { 29 @Optional 30 @InputFile 31 var inputApiFile: File? = null 32 33 @get:OutputFile 34 lateinit var outputApiXmlFile: File 35 36 init { 37 maxHeapSize = "1024m" 38 39 // Despite this tool living in ApiCheck, its purpose more fits with doclava's "purposes", 40 // generation of api files in this case. Thus, I am putting this in the doclava package. 41 main = "com.google.doclava.apicheck.ApiCheck" 42 } 43 execnull44 override fun exec() { 45 val input = inputApiFile 46 if (input != null) { 47 args = listOf("-convert2xml", input.absolutePath, outputApiXmlFile.absolutePath) 48 super.exec() 49 } else { 50 outputApiXmlFile.delete() 51 outputApiXmlFile.writeText("<api>\n</api>") 52 } 53 } 54 } 55