123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- import java.util.jar.JarEntry
- import java.util.jar.JarFile
- import java.util.jar.JarOutputStream
- import static java.util.Collections.list
- plugins {
- id 'java'
- id 'idea'
- id 'org.jetbrains.kotlin.jvm'
- id 'org.jetbrains.kotlin.kapt'
- id 'witness'
- }
- apply from: 'witness.gradle'
- configurations {
- windows {
- extendsFrom runtimeClasspath
- }
- linux {
- extendsFrom runtimeClasspath
- }
- }
- sourceCompatibility = 1.8
- targetCompatibility = 1.8
- dependencies {
- implementation project(':bramble-core')
- implementation project(':bramble-java')
- implementation project(':briar-core')
- linux "org.briarproject:tor-linux:$tor_version"
- linux "org.briarproject:obfs4proxy-linux:$obfs4proxy_version"
- linux "org.briarproject:snowflake-linux:$snowflake_version"
- windows "org.briarproject:tor-windows:$tor_version"
- windows "org.briarproject:obfs4proxy-windows:$obfs4proxy_version"
- windows "org.briarproject:snowflake-windows:$snowflake_version"
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
- implementation 'io.javalin:javalin:3.5.0'
- implementation 'org.slf4j:slf4j-simple:1.7.30'
- implementation 'com.github.ajalt:clikt:2.2.0'
- implementation "org.bouncycastle:bcprov-jdk15to18:$bouncy_castle_version"
- implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
- implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
- implementation "org.briarproject:onionwrapper-java:$onionwrapper_version"
- kapt "com.google.dagger:dagger-compiler:$dagger_version"
- testImplementation project(path: ':bramble-api', configuration: 'testOutput')
- testImplementation project(path: ':bramble-core', configuration: 'testOutput')
- testImplementation project(path: ':briar-core', configuration: 'testOutput')
- def junitVersion = '5.5.2'
- testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
- testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
- testImplementation 'io.mockk:mockk:1.12.4'
- testImplementation 'org.skyscreamer:jsonassert:1.5.0'
- testImplementation "com.squareup.okhttp3:okhttp:4.10.0"
- testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
- kaptTest "com.google.dagger:dagger-compiler:$dagger_version"
- }
- void jarFactory(Jar jarTask, os, architecture, configuration) {
- def jarArchitecture = os + "-" + architecture
- jarTask.dependsOn(
- ':bramble-api:jar',
- ':bramble-core:jar',
- ':bramble-java:jar',
- ':briar-api:jar',
- ':briar-core:jar'
- )
- jarTask.dependsOn(jar)
- jarTask.doFirst {
- println 'Building ' + jarArchitecture + ' version has started'
- }
- jarTask.manifest {
- attributes(
- 'Main-Class': 'org.briarproject.briar.headless.MainKt'
- )
- }
- jarTask.setArchiveClassifier(jarArchitecture)
- jarTask.from {
- configuration.collect { it.isDirectory() ? it : zipTree(it) }
- }
- {
- it.duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
- if (os == "linux") {
- String[] architectures = [
- "aarch64",
- "armhf",
- "x86_64",
- ]
- for (String arch : architectures) {
- if (arch != architecture) {
- exclude arch + "/obfs4proxy"
- exclude arch + "/tor"
- exclude arch + "/snowflake"
- }
- }
- }
- exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA'
- }
- jarTask.with jar
- jarTask.doLast {
- // Rename the original jar
- File jar = jarTask.archiveFile.get().asFile
- String srcPath = jar.toString().replaceFirst('\\.jar$', '.unsorted.jar')
- File srcFile = new File(srcPath)
- jar.renameTo(srcFile)
- JarFile srcJarFile = new JarFile(srcFile)
- OutputStream destStream = new JarOutputStream(new FileOutputStream(jar))
- // Read and sort the entries
- Map<String, JarEntry> entries = new TreeMap<>()
- for (JarEntry e : list(srcJarFile.entries())) entries.put(e.getName(), e)
- // Write the sorted entries
- for (JarEntry srcEntry : entries.values()) {
- JarEntry destEntry = new JarEntry(srcEntry.getName())
- destEntry.setTime(0)
- destStream.putNextEntry(destEntry)
- InputStream srcStream = srcJarFile.getInputStream(srcEntry)
- int read
- byte[] buf = new byte[4096]
- while ((read = srcStream.read(buf, 0, buf.length)) != -1) {
- destStream.write(buf, 0, read)
- }
- destStream.closeEntry()
- srcStream.close()
- }
- destStream.close()
- srcJarFile.close()
- println 'Building ' + jarArchitecture + ' version has finished'
- }
- }
- task aarch64LinuxJar(type: Jar) {
- jarFactory(it, 'linux', 'aarch64', configurations.linux)
- }
- task armhfLinuxJar(type: Jar) {
- jarFactory(it, 'linux', 'armhf', configurations.linux)
- }
- task x86LinuxJar(type: Jar) {
- jarFactory(it, 'linux', 'x86_64', configurations.linux)
- }
- task windowsJar(type: Jar) {
- jarFactory(it, 'windows', 'x86_64', configurations.windows)
- }
- task linuxJars {
- dependsOn(aarch64LinuxJar, armhfLinuxJar, x86LinuxJar)
- }
- // At the moment for non-Android projects we need to explicitly mark the code generated by kapt
- // as 'generated source code' for correct highlighting and resolve in IDE.
- idea {
- module {
- sourceDirs += file('build/generated/source/kapt/main')
- testSourceDirs += file('build/generated/source/kapt/test')
- generatedSourceDirs += file('build/generated/source/kapt/main')
- }
- }
- test {
- useJUnitPlatform()
- testLogging {
- events "passed", "skipped", "failed"
- }
- }
|