| 1 |
/* |
| 2 |
* Copyright (C) 2014 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 |
import com.android.build.api.transform.Format; |
| 17 |
import com.android.build.api.transform.QualifiedContent; |
| 18 |
import com.android.build.api.transform.QualifiedContent.ContentType; |
| 19 |
import com.android.build.api.transform.QualifiedContent.Scope; |
| 20 |
import com.android.build.api.transform.Transform; |
| 21 |
import com.android.build.api.transform.Context; |
| 22 |
import com.android.build.api.transform.TransformInput; |
| 23 |
import com.android.build.api.transform.TransformOutputProvider; |
| 24 |
import com.android.build.api.transform.TransformException; |
| 25 |
import com.android.build.gradle.internal.pipeline.TransformManager; |
| 26 |
// Top-level build file where you can add dataBindingConfiguration options common to all sub-projects/modules. |
| 27 |
|
| 28 |
buildscript { |
| 29 |
dependencies { |
| 30 |
classpath "com.android.tools.build:gradle:${dataBindingConfig.androidPluginVersion}" |
| 31 |
// NOTE: Do not place your application dependencies here; they belong |
| 32 |
// in the individual module build.gradle files |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
apply plugin: 'com.android.library' |
| 37 |
|
| 38 |
android { |
| 39 |
compileSdkVersion dataBindingConfig.compileSdkVersion |
| 40 |
buildToolsVersion dataBindingConfig.buildToolsVersion |
| 41 |
|
| 42 |
defaultConfig { |
| 43 |
minSdkVersion 7 |
| 44 |
targetSdkVersion 23 |
| 45 |
versionCode 1 |
| 46 |
versionName "1.0" |
| 47 |
} |
| 48 |
compileOptions { |
| 49 |
sourceCompatibility dataBindingConfig.javaTargetCompatibility |
| 50 |
targetCompatibility dataBindingConfig.javaSourceCompatibility |
| 51 |
} |
| 52 |
buildTypes { |
| 53 |
release { |
| 54 |
minifyEnabled false |
| 55 |
} |
| 56 |
} |
| 57 |
packagingOptions { |
| 58 |
exclude 'META-INF/services/javax.annotation.processing.Processor' |
| 59 |
exclude 'META-INF/LICENSE.txt' |
| 60 |
exclude 'META-INF/NOTICE.txt' |
| 61 |
exclude 'android/databinding/DataBinderMapper.class' |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
configurations { |
| 66 |
jarArchives |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
dependencies { |
| 71 |
compile 'com.android.support:support-v4:21.0.3' |
| 72 |
compile "com.android.databinding:baseLibrary:${dataBindingConfig.version}" |
| 73 |
} |
| 74 |
|
| 75 |
//create jar tasks |
| 76 |
android.libraryVariants.all { variant -> |
| 77 |
def name = variant.buildType.name |
| 78 |
|
| 79 |
if (name.equals(com.android.builder.core.BuilderConstants.DEBUG)) { |
| 80 |
return; // Skip debug builds. |
| 81 |
} |
| 82 |
def suffix = name.capitalize() |
| 83 |
|
| 84 |
def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) { |
| 85 |
source variant.javaCompile.source |
| 86 |
options.showFromPublic() |
| 87 |
options.tags = ['hide'] |
| 88 |
classpath = files(variant.javaCompile.classpath.files) + files( |
| 89 |
"${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar") |
| 90 |
} |
| 91 |
|
| 92 |
def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) { |
| 93 |
classifier = 'javadoc' |
| 94 |
from 'build/docs/javadoc' |
| 95 |
} |
| 96 |
javadocJarTask.dependsOn javadocTask |
| 97 |
|
| 98 |
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) { |
| 99 |
classifier = 'sources' |
| 100 |
from android.sourceSets.main.java.srcDirs |
| 101 |
} |
| 102 |
|
| 103 |
artifacts.add('archives', javadocJarTask); |
| 104 |
artifacts.add('archives', sourcesJarTask); |
| 105 |
} |
| 106 |
uploadArchives { |
| 107 |
repositories { |
| 108 |
mavenDeployer { |
| 109 |
pom.artifactId = 'library' |
| 110 |
pom.project { |
| 111 |
licenses { |
| 112 |
license { |
| 113 |
name dataBindingConfig.licenseName |
| 114 |
url dataBindingConfig.licenseUrl |
| 115 |
distribution dataBindingConfig.licenseDistribution |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
class ExcludeShimTransform extends Transform { |
| 124 |
Project project; |
| 125 |
public ExcludeShimTransform(Project project) { |
| 126 |
this.project = project; |
| 127 |
} |
| 128 |
public Set<ContentType> getInputTypes() { |
| 129 |
return TransformManager.CONTENT_CLASS; |
| 130 |
} |
| 131 |
|
| 132 |
public Set<Scope> getScopes() { |
| 133 |
def result = new HashSet<Scope>(); |
| 134 |
result.add(Scope.PROJECT); |
| 135 |
return result; |
| 136 |
} |
| 137 |
|
| 138 |
public Set<Scope> getReferencedScopes() { |
| 139 |
return TransformManager.SCOPE_FULL_LIBRARY; |
| 140 |
} |
| 141 |
|
| 142 |
public boolean isIncremental() { |
| 143 |
return false; |
| 144 |
} |
| 145 |
|
| 146 |
public String getName() { |
| 147 |
return "DataBindingExcludeShimTransform"; |
| 148 |
} |
| 149 |
|
| 150 |
public void transform(Context context, Collection<TransformInput> inputs, |
| 151 |
Collection<TransformInput> referencedInputs, |
| 152 |
TransformOutputProvider outputProvider, |
| 153 |
boolean isIncremental) throws IOException, TransformException, InterruptedException { |
| 154 |
inputs.each { transformInput -> |
| 155 |
transformInput.getDirectoryInputs().each { |
| 156 |
File outputDir = outputProvider.getContentLocation("data-binding-filtered", |
| 157 |
it.getContentTypes(), it.getScopes(), Format.DIRECTORY); |
| 158 |
outputDir.delete(); |
| 159 |
outputDir.mkdirs(); |
| 160 |
FileTree tree = project.fileTree(dir: it.getFile()) |
| 161 |
tree.include '**/*.class' |
| 162 |
tree.exclude 'android/databinding/DataBindingComponent.*' |
| 163 |
tree.exclude 'android/databinding/DataBinderMapper.*' |
| 164 |
tree.copy { |
| 165 |
into outputDir |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
android.registerTransform(new ExcludeShimTransform(project)) |
| 173 |
|
| 174 |
task prebuildAar(type : Copy) { |
| 175 |
dependsOn uploadArchives |
| 176 |
from "$buildDir/outputs/aar/library-release.aar" |
| 177 |
into dataBindingConfig.prebuildFolder |
| 178 |
rename { String fileName -> |
| 179 |
"databinding-library.aar" |
| 180 |
} |
| 181 |
} |