1 /* 2 * Copyright (C) 2015 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 package android.databinding.tool; 17 18 import android.databinding.tool.processing.Scope; 19 import android.databinding.tool.util.L; 20 21 import org.gradle.api.DefaultTask; 22 import org.gradle.api.tasks.TaskAction; 23 import org.xml.sax.SAXException; 24 import java.io.File; 25 import java.io.IOException; 26 27 import javax.xml.bind.JAXBException; 28 import javax.xml.parsers.ParserConfigurationException; 29 import javax.xml.xpath.XPathExpressionException; 30 31 /** 32 * Task that parses xml files and generated metadata. 33 * Will be removed when aapt supports binding tags. 34 */ 35 public class DataBindingProcessLayoutsTask extends DefaultTask { 36 37 private LayoutXmlProcessor xmlProcessor; 38 39 private File sdkDir; 40 41 private File xmlOutFolder; 42 43 private int minSdk; 44 45 @TaskAction processResources()46 public void processResources() 47 throws ParserConfigurationException, SAXException, XPathExpressionException, 48 IOException { 49 L.d("running process layouts task %s", getName()); 50 xmlProcessor.processResources(minSdk); 51 Scope.assertNoError(); 52 } 53 writeLayoutXmls()54 public void writeLayoutXmls() throws JAXBException { 55 xmlProcessor.writeLayoutInfoFiles(xmlOutFolder); 56 } 57 getXmlProcessor()58 public LayoutXmlProcessor getXmlProcessor() { 59 return xmlProcessor; 60 } 61 setXmlProcessor(LayoutXmlProcessor xmlProcessor)62 public void setXmlProcessor(LayoutXmlProcessor xmlProcessor) { 63 this.xmlProcessor = xmlProcessor; 64 } 65 getSdkDir()66 public File getSdkDir() { 67 return sdkDir; 68 } 69 setSdkDir(File sdkDir)70 public void setSdkDir(File sdkDir) { 71 this.sdkDir = sdkDir; 72 } 73 getXmlOutFolder()74 public File getXmlOutFolder() { 75 return xmlOutFolder; 76 } 77 setXmlOutFolder(File xmlOutFolder)78 public void setXmlOutFolder(File xmlOutFolder) { 79 this.xmlOutFolder = xmlOutFolder; 80 } 81 getMinSdk()82 public int getMinSdk() { 83 return minSdk; 84 } 85 setMinSdk(int minSdk)86 public void setMinSdk(int minSdk) { 87 this.minSdk = minSdk; 88 } 89 } 90