Home | History | Annotate | Download | only in checkapi
      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 android.support.checkapi;
     18 
     19 import org.gradle.api.tasks.InputFile;
     20 import org.gradle.api.tasks.JavaExec;
     21 import org.gradle.api.tasks.OutputFile;
     22 
     23 import java.io.File;
     24 import java.util.ArrayList;
     25 import java.util.List;
     26 
     27 /**
     28  * Task that converts the given API file to XML format.
     29  */
     30 public class ApiXmlConversionTask extends JavaExec {
     31 
     32     private File mInputApiFile;
     33 
     34     private File mOutputApiXmlFile;
     35 
     36     @InputFile
     37     public File getInputApiFile() {
     38         return mInputApiFile;
     39     }
     40 
     41     public void setInputApiFile(File inputApiFile) {
     42         this.mInputApiFile = inputApiFile;
     43     }
     44 
     45     @OutputFile
     46     public File getOutputApiXmlFile() {
     47         return mOutputApiXmlFile;
     48     }
     49 
     50     public void setOutputApiXmlFile(File outputApiXmlFile) {
     51         this.mOutputApiXmlFile = outputApiXmlFile;
     52     }
     53 
     54 
     55     public ApiXmlConversionTask() {
     56         setMaxHeapSize("1024m");
     57 
     58         // Despite this tool living in ApiCheck, its purpose more fits with doclava's "purposes",
     59         // generation of api files in this case. Thus, I am putting this in the doclava package.
     60         setMain("com.google.doclava.apicheck.ApiCheck");
     61     }
     62 
     63     /**
     64      * "Configures" this ApiXmlConversionTask with parameters that might not be at their final
     65      * values until this task is run.
     66      */
     67     private void configureApiXmlConversionTask() {
     68         List<String> arguments = new ArrayList<>();
     69         arguments.add("-convert2xml");
     70         arguments.add(getInputApiFile().getAbsolutePath());
     71         arguments.add(getOutputApiXmlFile().getAbsolutePath());
     72         setArgs(arguments);
     73     }
     74 
     75     @Override
     76     public void exec() {
     77         configureApiXmlConversionTask();
     78         super.exec();
     79     }
     80 }
     81