source: build.gradle @ 6d9aa92

Last change on this file since 6d9aa92 was fd311c7, checked in by str4d <str4d@…>, 15 months ago

Gradle: Fix getBuiltBy() to work when override.properties does not exist

  • Property mode set to 100644
File size: 6.8 KB
RevLine 
[56c1739d]1plugins {
2    id 'idea'
3}
[4512a94]4
[a1b67e3]5String getReleaseVersion() {
6    def releaseVersion
7    file("core/java/src/net/i2p/CoreVersion.java").readLines().findAll({ line ->
8        line.contains("public final static String VERSION")
9    }).first().eachMatch('.*"([^"]+)";', {
10        releaseVersion = it[1]
11    })
12    releaseVersion
13}
14
15String getBuildVersion() {
16    def buildVersion
17    file("router/java/src/net/i2p/router/RouterVersion.java").readLines().findAll({ line ->
18        line.contains("public final static long BUILD")
19    }).first().eachMatch('.*=\\s+([0-9]+);', {
20        buildVersion = it[1]
21    })
22    buildVersion
23}
24
25String getBuildExtra() {
26    def buildExtra
27    file("router/java/src/net/i2p/router/RouterVersion.java").readLines().findAll({ line ->
28        line.contains("public final static String EXTRA")
29    }).first().eachMatch('.*"(.*)";', {
30        buildExtra = it[1]
31    })
32    buildExtra
33}
34
[1cc330b]35String getBuiltBy() {
[fd311c7]36    def builtBy = ""
37    def overrideProps = file("override.properties")
38    if (overrideProps.exists()) {
39        overrideProps.readLines().findAll({ line ->
40            line.contains("build.built-by")
41        }).first().eachMatch('.*=(.*)', {
42            builtBy = it[1]
43        })
44    }
[1cc330b]45    builtBy
46}
47
48boolean haveMonotone() {
49    file("_MTN").exists()
50}
51
52String getWorkspaceVersion() {
53    if (haveMonotone()) {
54        def stdout = new ByteArrayOutputStream()
55        exec {
56            executable 'mtn'
57            args 'automate', 'get_base_revision_id'
58            standardOutput = stdout
59        }
60        stdout.toString().trim()
61    } else {
62        'unknown'
63    }
64}
65
[9731c20]66String compat(String src) {
67    if (src.contains('.')) {
68        src.substring(src.lastIndexOf('.') + 1)
69    } else {
70        src
71    }
72}
73
[2556c77]74String javaExecutable(String targetJavaHome, String execName) {
75    def javaExecutablesPath = new File(targetJavaHome, "bin")
76    def executable = new File(javaExecutablesPath, execName)
77    if (!executable.exists()) {
78        throw new IllegalArgumentException("There is no ${execName} executable in ${javaExecutablesPath}")
79    }
80    executable.toString()
81}
82
[a1b67e3]83def releaseVersion = getReleaseVersion()
84def buildVersion = getBuildVersion()
85def buildExtra = getBuildExtra()
86def fullVersion = "$releaseVersion-$buildVersion$buildExtra"
87
[1cc330b]88def builtBy = getBuiltBy()
89def workspaceVersion = getWorkspaceVersion()
90
[36a313cc]91// Exclude apps/ dir itself, but include its subdirs
[19016ed]92def javaProjects = subprojects - project(':apps')
93
94configure(javaProjects) {
[da777c1]95    apply plugin: 'java'
[19016ed]96    apply plugin: 'jacoco'
[a3df4a3]97    apply plugin: 'eclipse'
[e011d60]98    apply plugin: 'idea'
[da777c1]99
[aa3ac754]100    repositories {
[041f547]101        jcenter()
[aa3ac754]102    }
103
104    dependencies {
105        testCompile 'junit:junit:4.+'
[c78af82]106        testCompile 'org.hamcrest:hamcrest-library:1.3'
[d13bf0b]107        testCompile 'org.mockito:mockito-core:2.5.0'
[aa3ac754]108    }
109
[1cc330b]110    sourceCompatibility = 1.7
111    targetCompatibility = 1.7
112
[da777c1]113    jar {
[1cc330b]114        // Empty attributes are set by each project. They are initialized
115        // here in order to create a defined ordering of the attributes.
[da777c1]116        manifest {
[1cc330b]117            attributes 'Specification-Title': ''
118            attributes 'Specification-Version': "$releaseVersion"
119            attributes 'Specification-Vendor': 'The I2P Project https://geti2p.net/'
120            attributes 'Implementation-Title': ''
[a1b67e3]121            attributes 'Implementation-Version': "$fullVersion"
[1cc330b]122            attributes 'Implementation-Vendor': 'The I2P Project https://geti2p.net/'
123            attributes 'Built-By': "$builtBy"
124            attributes 'Build-Date': 'reproducible'
125            attributes 'Base-Revision': "$workspaceVersion"
126            attributes 'Workspace-Changes': ''
127            attributes 'X-Compile-Source-JDK': "$sourceCompatibility"
128            attributes 'X-Compile-Target-JDK': "$targetCompatibility"
[da777c1]129        }
130    }
[3eef793b]131
[967dde4]132    tasks.withType(AbstractArchiveTask) {
133        preserveFileTimestamps = false
134        reproducibleFileOrder = true
135    }
136
[9731c20]137    def i2pBootClasspath
138    // Set java7BootClasspath=/path/to/rt.jar:/path/to/jce.jar in ~/.gradle/gradle.properties if needed
139    if (java7BootClasspath) {
140        i2pBootClasspath = java7BootClasspath
141    } else {
142        def java7Home = System.getenv("JAVA7_HOME")
143        if (java7Home) {
144            i2pBootClasspath = "${java7Home}/jre/lib/jce.jar:${java7Home}/jre/lib/rt.jar"
145        }
146    }
147
[49d970c]148    if (i2pBootClasspath) {
149        tasks.withType(AbstractCompile, { AbstractCompile ac ->
150            ac.options.bootstrapClasspath = files(i2pBootClasspath)
151        })
[9731c20]152    } else {
153        if (JavaVersion.current().java8Compatible && !JavaVersion.current().java9Compatible) {
154            throw new GradleException("Set java7BootClasspath property or JAVA7_HOME environment variable to enable cross-compilation, or run Gradle with JDK 9+")
155        }
[4f6b58e]156        project.afterEvaluate {
157            tasks.withType(JavaCompile) {
158                def version = compat(sourceCompatibility)
159                logger.info("Configuring $name to use --release $version")
160                options.compilerArgs.addAll(['--release', version])
161            }
[9731c20]162        }
[49d970c]163    }
[2556c77]164
165    // Set up Java override if configured (used to test with Java 7).
166    def targetJavaHome = System.getenv("TARGET_JAVA_HOME")
167    if (targetJavaHome) {
168        if (JavaVersion.current().java9Compatible) {
169            throw new GradleException("Only set TARGET_JAVA_HOME with JDK 8")
170        }
171
172        project.afterEvaluate {
173            logger.info("Target Java home set to ${targetJavaHome}")
174            logger.info("Configuring Gradle to use forked compilation and testing")
175
176            tasks.withType(JavaCompile) {
177                options.fork = true
178                options.forkOptions.javaHome = file(targetJavaHome)
179            }
180
181            tasks.withType(Javadoc) {
182                executable = javaExecutable(targetJavaHome, "javadoc")
183            }
184
185            tasks.withType(Test) {
186                executable = javaExecutable(targetJavaHome, "java")
187            }
188
189            tasks.withType(JavaExec) {
190                executable = javaExecutable(targetJavaHome, "java")
191            }
192        }
193    }
[da777c1]194}
[0bfe45be]195
[19016ed]196task codeCoverageReport(type: JacocoReport) {
197    dependsOn(javaProjects.test)
198
199    jacocoClasspath = project(':core').configurations.jacocoAnt
[2788706]200    additionalSourceDirs.from(files(javaProjects.sourceSets.main.allSource.srcDirs))
201    sourceDirectories.from(files(javaProjects.sourceSets.main.allSource.srcDirs))
202    classDirectories.from(files(javaProjects.sourceSets.main.output))
203    executionData.from(files(javaProjects.jacocoTestReport.executionData))
[19016ed]204
205    doFirst {
206        executionData = files(executionData.findAll { it.exists() })
207    }
208
209    reports {
210        xml.enabled true
[1ae9879]211        xml.destination file("${buildDir}/reports/jacoco/report.xml")
[19016ed]212        html.enabled true
[1ae9879]213        html.destination file("${buildDir}/reports/jacoco/html")
[19016ed]214    }
215}
216
[0bfe45be]217//apply from: file('gradle/update.gradle')
Note: See TracBrowser for help on using the repository browser.