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

apply plugin: 'com.android.application'
apply plugin: 'witness'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'de.undercouch.download'

dependencies {
	def supportVersion = '23.2.1'
	compile project(':briar-api')
	compile project(':briar-core')
	compile fileTree(dir: 'libs', include: '*.jar')
	// This shouldn't be necessary; per section 23.4.4 of the Gradle docs:
	// "file dependencies are included in transitive project dependencies within the same build".
	compile files('../briar-core/libs/jsocks.jar')

	compile "com.android.support:support-v4:$supportVersion"
	compile("com.android.support:appcompat-v7:$supportVersion") {
		exclude module: 'support-v4'
	}

	compile("com.android.support:preference-v14:$supportVersion") {
		exclude module: 'support-v4'
	}
	compile("com.android.support:design:$supportVersion") {
		exclude module: 'support-v4'
		exclude module: 'recyclerview-v7'
	}
	compile('ch.acra:acra:4.8.5') {
		exclude module: 'support-v4'
		exclude module: 'support-annotations'
	}
	compile 'info.guardianproject.panic:panic:0.5'
	compile 'info.guardianproject.trustedintents:trustedintents:0.2'
	compile 'de.hdodenhof:circleimageview:2.0.0'
	compile 'com.google.zxing:core:3.2.1'
	apt 'com.google.dagger:dagger-compiler:2.0.2'
	provided 'javax.annotation:jsr250-api:1.0'

	testCompile 'junit:junit:4.12'
	testCompile 'net.jodah:concurrentunit:0.4.2'
	testApt 'com.google.dagger:dagger-compiler:2.0.2'
	testCompile project(path: ':briar-tests')
	testCompile 'org.robolectric:robolectric:3.0'
	testCompile 'org.mockito:mockito-core:1.10.19'

	androidTestCompile 'org.robolectric:robolectric:3.0'
	androidTestCompile 'org.mockito:mockito-core:1.10.19'
	androidTestApt 'com.google.dagger:dagger-compiler:2.0.2'
	androidTestCompile 'junit:junit:4.12'
}

dependencyVerification {
	verify = [
			'ch.acra:acra:afd5b28934d5166b55f261c85685ad59e8a4ebe9ca1960906afaa8c76d8dc9eb',
			'info.guardianproject.panic:panic:a7ed9439826db2e9901649892cf9afbe76f00991b768d8f4c26332d7c9406cb2',
			'info.guardianproject.trustedintents:trustedintents:6221456d8821a8d974c2acf86306900237cf6afaaa94a4c9c44e161350f80f3e',
			'de.hdodenhof:circleimageview:c76d936395b50705a3f98c9220c22d2599aeb9e609f559f6048975cfc1f686b8',
			'com.google.zxing:core:b4d82452e7a6bf6ec2698904b332431717ed8f9a850224f295aec89de80f2259',
			'com.android.support:support-v4:81ce890f26d35c75ad17d0f998a7e3230330c3b41e0b629566bc744bee89e448',
			'com.android.support:appcompat-v7:00f9d93acacd6731f309724054bf51492814b4b2869f16d7d5c0038dcb8c9a0d',
			'com.android.support:preference-v14:44881bb46094e86d0bc2426f205419674a5b4eb514b44b5a4659b5de29f71eb7',
			'com.android.support:design:003e0c0bea0a6891f8b2bc43f20ae7af2a49a17363e5bb10df5ee0bae12fa686',
			'com.android.support:support-annotations:786ab0d060774fb95cfdaf4878771e14b85733b1af9d72a4aae762dc7c1dff9f',
			'com.android.support:animated-vector-drawable:06d1963b85aa917099d7757e6a7b3e4dc06889413dc747f625ae8683606db3a1',
			'com.android.support:support-vector-drawable:799bafe4c3de812386f0b291f744d5d6876452722dd40189b9ab87dbbf594ea1',
			'com.android.support:recyclerview-v7:44040a888e23e0c93162a3377cfe06751080e3c22d369ab0d4301ef60d63b0fe',
	]
}

android {
	compileSdkVersion 23
	buildToolsVersion "23.0.3"

	defaultConfig {
		resValue "string", "app_package", "org.briarproject"
	}

	sourceSets {
		main {
			manifest.srcFile 'AndroidManifest.xml'
			java.srcDirs = ['src']
			resources.srcDirs = ['src']
			aidl.srcDirs = ['src']
			renderscript.srcDirs = ['src']
			res.srcDirs = ['res']
			assets.srcDirs = ['assets']
		}

		androidTest.setRoot('androidTest')
		androidTest {
			java.srcDirs = ['androidTest/java']
		}

		test.setRoot('test')
		test {
			java.srcDirs = ['test/java']
			testOptions {
				unitTests.returnDefaultValues = true
			}
		}


		// Move the build types to build-types/<type>
		// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
		// This moves them out of them default location under src/<type>/... which would
		// conflict with src/ being used by the main source set.
		// Adding new build types or product flavors should be accompanied
		// by a similar customization.
		debug.setRoot('build-types/debug')
		release.setRoot('build-types/release')
	}

	buildTypes {
		debug {
			minifyEnabled true
			proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
		}
		release {
			minifyEnabled true
			proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
		}
	}

	compileOptions {
		sourceCompatibility JavaVersion.VERSION_1_7
		targetCompatibility JavaVersion.VERSION_1_7
	}

	lintOptions {
		warning 'MissingTranslation'
		warning 'ImpliedQuantity'
	}

	dexOptions {
		incremental true
	}
}

task downloadTorGeoIp(type: Download) {
    src 'https://briarproject.org/build/geoip-2015-12-01.zip'
    dest 'assets/geoip.zip'
    onlyIfNewer true
}

task downloadTorBinaryArm(type: Download) {
    src 'https://briarproject.org/build/tor-0.2.7.6-arm.zip'
    dest 'assets/tor-arm.zip'
    onlyIfNewer true
}

task downloadTorBinaryArmPie(type: Download) {
    src 'https://briarproject.org/build/tor-0.2.7.6-arm-pie.zip'
    dest 'assets/tor-arm-pie.zip'
    onlyIfNewer true
}

task downloadTorBinaryX86(type: Download) {
    src 'https://briarproject.org/build/tor-0.2.7.6-x86.zip'
    dest 'assets/tor-x86.zip'
    onlyIfNewer true
}

task downloadTorBinaryX86Pie(type: Download) {
    src 'https://briarproject.org/build/tor-0.2.7.6-x86-pie.zip'
    dest 'assets/tor-x86-pie.zip'
    onlyIfNewer true
}

task verifyTorGeoIp(type: Verify, dependsOn: 'downloadTorGeoIp') {
    src 'assets/geoip.zip'
    algorithm 'SHA-256'
    checksum '9bcdaf0a7ba0933735328d8ec466c25c25dbb459efc2bce9e55c774eabea5162'
}

task verifyTorBinaryArm(type: Verify, dependsOn: 'downloadTorBinaryArm') {
    src 'assets/tor-arm.zip'
    algorithm 'SHA-256'
    checksum '83272962eda701cd5d74d2418651c4ff0f0b1dff51f558a292d1a1c42bf12146'
}

task verifyTorBinaryArmPie(type: Verify, dependsOn: 'downloadTorBinaryArmPie') {
    src 'assets/tor-arm-pie.zip'
    algorithm 'SHA-256'
    checksum 'd0300d1e45de11ebb24ed62b9c492be9c2e88590b7822195ab38c7a76ffcf646'
}

task verifyTorBinaryX86(type: Verify, dependsOn: 'downloadTorBinaryX86') {
    src 'assets/tor-x86.zip'
    algorithm 'SHA-256'
    checksum 'b8813d97b01ee1b9c9a4233c1b9bbe9f9f6b494ae6f9cbd84de8a3911911615e'
}

task verifyTorBinaryX86Pie(type: Verify, dependsOn: 'downloadTorBinaryX86Pie') {
    src 'assets/tor-x86-pie.zip'
    algorithm 'SHA-256'
    checksum '9c66e765aa196dc089951a1b2140cc8290305c2fcbf365121f99e01a233baf4e'
}

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