/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* .
*
*/
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'signing'
repositories {
mavenCentral()
}
group = 'org.apache.httpcomponents'
version = HC_VER
ext.isRelease = !version.endsWith('-SNAPSHOT')
ext.inceptionYear = '1999'
android {
// SDK versions and compileOptions adapted to DAVdroid needs
compileSdkVersion 22
buildToolsVersion '21.1.2'
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
}
/*compileOptions {
sourceCompatibility JavaVersion.VERSION_1_5
targetCompatibility JavaVersion.VERSION_1_5
}*/
}
configurations {
dist
}
signing {
required { isRelease }
}
ext.sharedManifest = manifest {
attributes (
'Specification-Title': "HttpComponents HttpClient for Android",
'Specification-Version': "$version",
'Specification-Vendor': "The Apache Software Foundation",
'Implementation-Title': "HttpComponents HttpClient for Android",
'Implementation-Version': "$version",
'Implementation-Vendor': "The Apache Software Foundation",
'Implementation-Vendor-Id': "org.apache",
'url': 'http://hc.apache.org/httpcomponents-client'
)
}
android.libraryVariants.all { variant ->
def name = variant.buildType.name
if (name == 'release') {
task createAndroidJar(type: Jar) {
dependsOn variant.javaCompile
from variant.javaCompile.destinationDir
from 'NOTICE.txt'
from 'LICENSE.txt'
rename '(NOTICE|LICENSE).txt', 'META-INF/$1'
manifest {
from sharedManifest
}
}
task createAndroidSrcJar(type: Jar) {
dependsOn variant.javaCompile
from variant.javaCompile.source
from 'NOTICE.txt'
from 'LICENSE.txt'
rename '(NOTICE|LICENSE).txt', 'META-INF/$1'
classifier = 'sources'
manifest {
from sharedManifest
}
}
task createAndroidJavadoc(type: Javadoc) {
dependsOn variant.javaCompile
source = variant.javaCompile.source
classpath = files(android.plugin.bootClasspath, variant.javaCompile.classpath.files)
title "Apache HttpClient for Android $HC_VER API"
configure (options) {
docTitle "Apache HttpClient for Android $HC_VER API"
bottom "Copyright © ${inceptionYear}-${Calendar.instance.get(Calendar.YEAR)} " +
"The Apache Software Foundation. " +
"All rights reserved."
}
}
task createAndroidJavadocJar(type: Jar) {
dependsOn createAndroidJavadoc
from createAndroidJavadoc.destinationDir
from 'NOTICE.txt'
from 'LICENSE.txt'
rename '(NOTICE|LICENSE).txt', 'META-INF/$1'
classifier = 'javadoc'
manifest {
from sharedManifest
}
}
artifacts {
dist createAndroidJar
dist createAndroidSrcJar
dist createAndroidJavadocJar
}
signing {
sign createAndroidJar
sign createAndroidSrcJar
sign createAndroidJavadocJar
}
artifacts {
tasks.withType(Sign) { Sign task ->
task.signatures.each { PublishArtifact artifact ->
dist artifact
}
}
}
}
}
// Deployment tasks
def askPassphrase = {
Console console = System.console()
if (console) {
String password = project.ext.has('signing.password') ? project.ext.'signing.password' : null
String keyId = project.ext.has('signing.keyId') ? project.ext.'signing.keyId' : null
if (keyId && !password) {
char[] raw = console.readPassword("\n> Please provide password for PGP key ${keyId}: ")
project.ext.'signing.password' = new String(raw)
}
}
}
def askCredentials(MavenDeployer mavenDeployer) {
Console console = System.console()
if (console) {
URL url = new URL(mavenDeployer.repository.url)
def auth = mavenDeployer.repository.authentication
if (auth) {
if (!auth.userName || auth.userName == '') {
String username = console.readLine("\n> Please enter user name for repository '${url}': ")
auth.userName = username
}
if (!auth.password || auth.password == '') {
char[] raw = console.readPassword("\n> Please enter password for repository '${url}': ")
auth.password = new String(raw)
}
}
}
}
project.ext.archiveSources = copySpec {
from (project.projectDir) {
include 'src/**'
include '*.txt'
include 'build.gradle'
include 'settings.gradle'
include 'gradle.properties'
}
}
task archiveSrcWin(type: Zip) {
with archiveSources
filter(['eol': org.apache.tools.ant.filters.FixCrLfFilter.CrLf.newInstance('crlf')],
org.apache.tools.ant.filters.FixCrLfFilter)
into "httpcomponents-client-android-$project.version"
classifier = 'src'
baseName = 'httpcomponents-client-android'
version = project.version
}
task archiveSrcUnix(type: Tar) {
with archiveSources
into "httpcomponents-client-android-$project.version"
filter(['eol': org.apache.tools.ant.filters.FixCrLfFilter.CrLf.newInstance('lf')],
org.apache.tools.ant.filters.FixCrLfFilter)
classifier = 'src'
baseName = 'httpcomponents-client-android'
version = project.version
extension = 'tar.gz'
compression = Compression.GZIP
}
task uploadDist(type: Upload) {
configuration = configurations.dist
repositories {
mavenDeployer {
def creds = [
userName: project.ext.has('asf.username') ? project.ext.'asf.username' : null,
password: project.ext.has('asf.password') ? project.ext.'asf.password' : null ]
if (System.properties['localRepo']) {
repository(url: "file:${buildDir.absolutePath}/repo")
} else {
if (version.endsWith('-SNAPSHOT')) {
repository(url: ASF_SNAPSHOT_REPO) {
authentication(creds)
}
} else {
repository(url: ASF_NEXUS_STAGE) {
authentication(creds)
}
}
}
pom.project {
name 'HttpComponents Client for Android'
url 'http://hc.apache.org/httpcomponents-client/'
organization {
name 'The Apache Software Foundation'
url 'http://www.apache.org/'
}
licenses {
license {
name 'Apache License, Version 2.0'
url 'LICENSE.txt'
distribution 'repo'
}
}
issueManagement {
system 'Jira'
url 'http://issues.apache.org/jira/browse/HTTPCLIENT'
}
}
if (isRelease) {
beforeDeployment { MavenDeployment deployment ->
askPassphrase()
signing.signPom(deployment)
}
}
}
}
}
gradle.taskGraph.whenReady { TaskExecutionGraph taskGraph ->
taskGraph.allTasks.findAll { Task task ->
task instanceof Upload }.each { Upload task ->
task.doFirst {
task.repositories.each { MavenDeployer mavenDeployer ->
askCredentials(mavenDeployer)
}
}
}
taskGraph.allTasks.findAll { Task task ->
task instanceof Sign }.each { Sign task ->
task.doFirst { askPassphrase() }
}
}