import de.undercouch.gradle.tasks.download.Download
import de.undercouch.gradle.tasks.download.Verify

apply plugin: 'com.android.library'
apply plugin: 'witness'
apply plugin: 'de.undercouch.download'

android {
	compileSdkVersion 23
	buildToolsVersion "23.0.3"

	defaultConfig {
		minSdkVersion 14
		targetSdkVersion 22
		versionCode 1609
		versionName "0.16.9"
		consumerProguardFiles 'proguard-rules.txt'
	}

	compileOptions {
		sourceCompatibility JavaVersion.VERSION_1_7
		targetCompatibility JavaVersion.VERSION_1_7
	}
}

dependencies {
	compile project(':bramble-core')
	compile fileTree(dir: 'libs', include: '*.jar')
	provided 'javax.annotation:jsr250-api:1.0'
}

def torBinaryDir = 'src/main/res/raw'

task downloadTorGeoIp(type: Download) {
	src 'https://briarproject.org/build/geoip-2017-09-06.zip'
	dest "$torBinaryDir/geoip.zip"
	onlyIfNewer true
}

task downloadTorBinaryArm(type: Download) {
	src 'https://briarproject.org/build/tor-0.2.9.12-arm.zip'
	dest "$torBinaryDir/tor_arm.zip"
	onlyIfNewer true
}

task downloadTorBinaryArmPie(type: Download) {
	src 'https://briarproject.org/build/tor-0.2.9.12-arm-pie.zip'
	dest "$torBinaryDir/tor_arm_pie.zip"
	onlyIfNewer true
}

task downloadTorBinaryX86(type: Download) {
	src 'https://briarproject.org/build/tor-0.2.9.12-x86.zip'
	dest "$torBinaryDir/tor_x86.zip"
	onlyIfNewer true
}

task downloadTorBinaryX86Pie(type: Download) {
	src 'https://briarproject.org/build/tor-0.2.9.12-x86-pie.zip'
	dest "$torBinaryDir/tor_x86_pie.zip"
	onlyIfNewer true
}

task verifyTorGeoIp(type: Verify, dependsOn: 'downloadTorGeoIp') {
	src "$torBinaryDir/geoip.zip"
	algorithm 'SHA-256'
	checksum 'fe49d3adb86d3c512373101422a017dbb86c85a570524663f09dd8ce143a24f3'
}

task verifyTorBinaryArm(type: Verify, dependsOn: 'downloadTorBinaryArm') {
	src "$torBinaryDir/tor_arm.zip"
	algorithm 'SHA-256'
	checksum '8ed0b347ffed1d6a4d2fd14495118eb92be83e9cc06e057e15220dc288b31688'
}

task verifyTorBinaryArmPie(type: Verify, dependsOn: 'downloadTorBinaryArmPie') {
	src "$torBinaryDir/tor_arm_pie.zip"
	algorithm 'SHA-256'
	checksum '64403262511c29f462ca5e7c7621bfc3c944898364d1d5ad35a016bb8a034283'
}

task verifyTorBinaryX86(type: Verify, dependsOn: 'downloadTorBinaryX86') {
	src "$torBinaryDir/tor_x86.zip"
	algorithm 'SHA-256'
	checksum '61e014607a2079bcf1646289c67bff6372b1aded6e1d8d83d7791efda9a4d5ab'
}

task verifyTorBinaryX86Pie(type: Verify, dependsOn: 'downloadTorBinaryX86Pie') {
	src "$torBinaryDir/tor_x86_pie.zip"
	algorithm 'SHA-256'
	checksum '18fbc98356697dd0895836ab46d5c9877d1c539193464f7db1e82a65adaaf288'
}

project.afterEvaluate {
	preBuild.dependsOn {
		[
				'verifyTorGeoIp',
				'verifyTorBinaryArm',
				'verifyTorBinaryArmPie',
				'verifyTorBinaryX86',
				'verifyTorBinaryX86Pie'
		]
	}
}
