1apply plugin: 'android-library'
2archivesBaseName = 'support-v4'
3
4// create a jar task for the code internal implementation
5tasks.create(name: "internalJar", type: Jar) {
6    baseName "internal_impl"
7}
8
9// --------------------------
10// TO ADD NEW PLATFORM SPECIFIC CODE, UPDATE THIS:
11// create and configure the sourcesets/dependencies for platform-specific code.
12// values are: sourceset name, source folder name, api level, previous sourceset.
13
14ext.allSS = []
15
16def baseSS         = createApiSourceset('donut',         'donut',          '4',       null)
17def eclairSS       = createApiSourceset('eclair',       'eclair',        '5',       baseSS)
18def eclairMr1SS    = createApiSourceset('eclairmr1',    'eclair-mr1',    '7',       eclairSS)
19def froyoSS        = createApiSourceset('froyo',        'froyo',         '8',       eclairMr1SS)
20def gingerbreadSS  = createApiSourceset('gingerbread',  'gingerbread',   '9',       froyoSS)
21def honeycombSS    = createApiSourceset('honeycomb',    'honeycomb',     '11',      gingerbreadSS)
22def honeycombMr1SS = createApiSourceset('honeycombmr1', 'honeycomb_mr1', '12',      honeycombSS)
23def honeycombMr2SS = createApiSourceset('honeycombmr2', 'honeycomb_mr2', '13',      honeycombMr1SS)
24def icsSS          = createApiSourceset('ics',          'ics',           '14',      honeycombMr2SS)
25def icsMr1SS       = createApiSourceset('icsmr1',       'ics-mr1',       '15',      icsSS)
26def jbSS           = createApiSourceset('jellybean',    'jellybean',     '16',      icsMr1SS)
27def jbMr1SS        = createApiSourceset('jellybeanmr1', 'jellybean-mr1', '17',      jbSS)
28def jbMr2SS        = createApiSourceset('jellybeanmr2', 'jellybean-mr2', '18',      jbMr1SS)
29def kitkatSS       = createApiSourceset('kitkat',       'kitkat',        '19',      jbMr2SS)
30def api20SS        = createApiSourceset('api20',        'api20',         '20', kitkatSS)
31def api21SS        = createApiSourceset('api21',        'api21',         '21', api20SS)
32def api22SS        = createApiSourceset('api22',        'api22',         'current', api21SS)
33
34
35def createApiSourceset(String name, String folder, String apiLevel, SourceSet previousSource) {
36    def sourceSet = sourceSets.create(name)
37    sourceSet.java.srcDirs = [folder]
38
39    def configName = sourceSet.getCompileConfigurationName()
40
41    project.getDependencies().add(configName, getAndroidPrebuilt(apiLevel))
42    if (previousSource != null) {
43        setupDependencies(configName, previousSource)
44    }
45    ext.allSS.add(sourceSet)
46
47    internalJar.from sourceSet.output
48
49    return sourceSet
50}
51
52def setupDependencies(String configName, SourceSet previousSourceSet) {
53    project.getDependencies().add(configName, previousSourceSet.output)
54    project.getDependencies().add(configName, previousSourceSet.compileClasspath)
55}
56
57dependencies {
58    compile project(':support-annotations')
59    donutCompile project(':support-annotations')
60
61    // add the internal implementation as a dependency.
62    // this is not enough to make the regular compileJava task
63    // depend on the generation of this jar. This is done below
64    // when manipulating the libraryVariants.
65    compile files(internalJar.archivePath)
66}
67
68android {
69    compileSdkVersion 4
70    buildToolsVersion "19.0.1"
71
72    defaultConfig {
73        minSdkVersion 4
74        // TODO: get target from branch
75        //targetSdkVersion 19
76    }
77
78    sourceSets {
79        main.manifest.srcFile 'AndroidManifest.xml'
80        main.java.srcDirs = ['java']
81        main.aidl.srcDirs = ['java']
82
83        androidTest.setRoot('tests')
84        androidTest.java.srcDir 'tests/java'
85    }
86
87    lintOptions {
88        // TODO: fix errors and reenable.
89        abortOnError false
90    }
91}
92
93android.libraryVariants.all { variant ->
94    variant.javaCompile.dependsOn internalJar
95
96    def name = variant.buildType.name
97
98    if (name.equals(com.android.builder.BuilderConstants.DEBUG)) {
99        return; // Skip debug builds.
100    }
101    def suffix = name.capitalize()
102
103    def jarTask = project.tasks.create(name: "jar${suffix}", type: Jar){
104        dependsOn variant.javaCompile
105        from variant.javaCompile.destinationDir
106        from 'LICENSE.txt'
107    }
108    def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
109        source android.sourceSets.main.allJava
110        classpath = files(variant.javaCompile.classpath.files) + files(
111                "${android.plugin.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
112    }
113
114    def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
115        classifier = 'javadoc'
116        from 'build/docs/javadoc'
117    }
118
119    def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
120        classifier = 'sources'
121        from android.sourceSets.main.allSource
122    }
123
124    project.ext.allSS.each { ss ->
125        javadocTask.source ss.allJava
126        sourcesJarTask.from ss.allSource
127    }
128
129    artifacts.add('archives', javadocJarTask);
130    artifacts.add('archives', sourcesJarTask);
131}
132
133uploadArchives {
134    repositories {
135        mavenDeployer {
136            repository(url: uri(rootProject.ext.supportRepoOut)) {
137            }
138
139            pom.project {
140                name 'Android Support Library v4'
141                description "The Support Library is a static library that you can add to your Android application in order to use APIs that are either not available for older platform versions or utility APIs that aren't a part of the framework APIs. Compatible on devices running API 4 or later."
142                url 'http://developer.android.com/tools/extras/support-library.html'
143                inceptionYear '2011'
144
145                licenses {
146                    license {
147                        name 'The Apache Software License, Version 2.0'
148                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
149                        distribution 'repo'
150                    }
151                }
152
153                scm {
154                    url "http://source.android.com"
155                    connection "scm:git:https://android.googlesource.com/platform/frameworks/support"
156                }
157                developers {
158                    developer {
159                        name 'The Android Open Source Project'
160                    }
161                }
162            }
163        }
164    }
165}
166