Home | History | Annotate | Download | only in compilerCommon
      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 
     17 apply plugin: 'java'
     18 
     19 sourceSets {
     20     main {
     21         java {
     22             srcDir 'src/main/java'
     23             srcDir 'src/main/xml-gen'
     24             srcDir 'src/main/grammar-gen'
     25         }
     26     }
     27     test {
     28         java {
     29             srcDir 'src/test/java'
     30         }
     31     }
     32 
     33 }
     34 
     35 dependencies {
     36     testCompile 'junit:junit:4.12'
     37     compile project(':dataBinding:baseLibrary')
     38     compile 'org.antlr:antlr4:4.5.3'
     39     compile 'commons-io:commons-io:2.4'
     40     compile 'com.googlecode.juniversalchardet:juniversalchardet:1.0.3'
     41     compile 'com.google.guava:guava:17.0'
     42     compile 'com.android.tools:annotations:24.5.0'
     43 }
     44 
     45 project.tasks.create(name : "generateXmlLexer", type : JavaExec) {
     46     classpath configurations.runtime
     47     main "org.antlr.v4.Tool"
     48     workingDir projectDir
     49     args "XMLLexer.g4", "-visitor", "-lib", projectDir.absolutePath, "-o", "src/main/xml-gen/android/databinding/parser", "-package", "android.databinding.parser"
     50 }
     51 
     52 project.tasks.create(name : "generateXmlParser", type : JavaExec) {
     53     classpath configurations.runtime
     54     main "org.antlr.v4.Tool"
     55     workingDir projectDir
     56     args "XMLParser.g4", "-visitor", "-lib", projectDir.absolutePath, "-o", "src/main/xml-gen/android/databinding/parser", "-package", "android.databinding.parser"
     57     dependsOn "generateXmlLexer"
     58 }
     59 
     60 project.tasks.create(name : "generateGrammar", type : JavaExec) {
     61     classpath configurations.runtime
     62     main "org.antlr.v4.Tool"
     63     args "BindingExpression.g4", "-visitor", "-o", "src/main/grammar-gen/android/databinding/parser", "-package", "android.databinding.parser"
     64 }
     65 
     66 tasks.create(name : 'exportBuildVersions') << {
     67     def props = new HashMap();
     68     def buildVersionFile = new File(sourceSets.main.output.resourcesDir,"data_binding_version_info.properties")
     69     // Using Java Properties appends date to the output which is bad for incremental compilation.
     70     // Instead, we build it manually.
     71     props.put("compilerCommon", project.version)
     72     props.put("compiler", rootProject.findProject("dataBinding:compiler").version)
     73     props.put("baseLibrary", rootProject.findProject("dataBinding:baseLibrary").version)
     74     props.put("extensions", dataBindingConfig.extensionsVersion)
     75     buildVersionFile.getParentFile().mkdirs()
     76     println("writing build versions file to $buildVersionFile")
     77     def propText = new StringBuilder();
     78     props.each {
     79         propText.append(it.key).append("=").append(it.value).append(System.getProperty("line.separator"))
     80     }
     81     file(buildVersionFile).write(propText.toString())
     82 }
     83 
     84 tasks['jar'].dependsOn('exportBuildVersions')
     85 tasks['exportBuildVersions'].dependsOn('processResources')
     86 
     87 project.ext.pomName = 'Data Binding Compiler Common'
     88 project.ext.pomDesc = 'Common library that can be shared between different build tools'
     89 enablePublishing(this, true)
     90