forked from hyphanet/plugin-WebOfTrust
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
142 lines (126 loc) · 6.09 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
apply plugin: 'java'
defaultTasks 'jar', 'test'
sourceSets.main.java.srcDirs = ['src/']
sourceSets.test.java.srcDirs = ['test/']
sourceCompatibility = targetCompatibility = 7
tasks.withType(JavaCompile) { options.encoding = "UTF-8" }
javadoc.enabled = false
repositories {
if(System.getenv('WOT__DOWNLOAD_DEPENDENCIES') == '1') {
println 'WARNING: Download of dependencies is enabled! Watch out for supply chain attacks!'
mavenCentral()
}
}
configurations { junit } // Needed when we manually specify the tests' classpath
dependencies {
// Run fred's Gradle with "./gradlew jar copyRuntimeLibs" to produce this directory
// TODO: mvn.freenetproject.org is not browseable so I don't know the proper URI for fred and
// its dependencies and hence am including the dependencies as flat files.
// Use Gradle's dependency management + gradle-witness once this has been resolved.
compile fileTree(dir: '../fred/build/output/', include: '*.jar')
compile files('db4o-7.4/db4o.jar')
if(System.getenv('WOT__DOWNLOAD_DEPENDENCIES') == '1')
junit('junit:junit:4.11') // Hamcrest is automatically included as transitive dependency.
else
junit files('/usr/share/java/junit4.jar', '/usr/share/java/hamcrest-core.jar')
testCompile configurations.junit
}
task compileDb4o(type: Exec) {
// See https://bugs.freenetproject.org/view.php?id=7058
outputs.upToDateWhen { file('db4o-7.4/db4o.jar').exists() }
workingDir 'db4o-7.4'
commandLine 'ant', "-Djavac.source.version=" + sourceCompatibility,
"-Djavac.target.version=" + targetCompatibility
}
compileJava {
dependsOn 'compileDb4o'
}
task prepareVersionFile(type: Copy) {
outputs.upToDateWhen { false }
from sourceSets.main.java.srcDirs ; into "${buildDir}/custom/versionFileJava/"
include 'plugins/WebOfTrust/Version.java' ; filter {
it.replaceAll("@custom@", "git describe --always --abbrev=4 --dirty".execute().text.trim())
}
}
task compileVersionFile(type: JavaCompile, dependsOn: ['compileJava', 'prepareVersionFile']) {
classpath = sourceSets.main.compileClasspath
source = prepareVersionFile.destinationDir
destinationDir = file("${buildDir}/custom/versionFileClass/")
}
["jar", "testJar"].each { jarType ->
task("$jarType", type: Jar, overwrite: true, dependsOn: tasks.withType(AbstractCompile)) {
preserveFileTimestamps = false
reproducibleFileOrder = true
duplicatesStrategy = "fail"
baseName = (jarType == 'testJar') ? 'WebOfTrust-with-unit-tests' : 'WebOfTrust'
destinationDir = new File(projectDir, (jarType == 'testJar') ? "build-test" : "dist")
manifest { attributes("Plugin-Main-Class": "plugins.WebOfTrust.WebOfTrust") }
from(sourceSets.main.output.classesDir) { exclude 'plugins/WebOfTrust/Version.class' }
from(compileVersionFile.destinationDir) { include 'plugins/WebOfTrust/Version.class' }
from(sourceSets.main.java.srcDirs) { include 'plugins/WebOfTrust/l10n/*.l10n' }
from zipTree('db4o-7.4/db4o.jar')
if(jarType == 'testJar') from sourceSets.test.output.classesDir
}}
test {
dependsOn 'testJar'
// Reset classpath to only use the JAR, not the class files, because some WoT test need a JAR to
// load into a Freenet node, and given the JAR is needed we shouldn't duplicate its classes.
classpath = fileTree(dir: '../fred/build/output/', include: '*.jar')
classpath+= files(testJar.archivePath)
classpath+= configurations.junit
scanForTestClasses = false
include '**/*Test*.class'
// Must exclude member classes: Java creates them for switch() upon enums, JUnit would complain
exclude '**/*$*.class'
exclude '**/*Benchmark*.class'
exclude 'com/db4o/**'
if(!hasProperty('test.unreliable')) {
exclude '**/SynchronousDelayedBackgroundJobTest.class'
exclude '**/TickerDelayedBackgroundJobTest.class'
}
// Workaround for db4o breaking, and thus unit tests failing, with Java >= 16:
// Java 16 disallows using reflection to look into JRE's core classes. But db4o needs that to
// fulfill its purpose of being a database which can store Java classes without adding any
// code to them. Thus we allow it by a command line option.
//
// We run this on Java 9 and above, not just 16 and above, to support old Gradle versions which
// won't be able to detect Java 16 as such. 9 is the minimum needed to support '--add-opens'.
if(JavaVersion.current().getMajorVersion().toInteger() >= 9)
jvmArgs '--add-opens', 'java.base/java.lang=ALL-UNNAMED'
/* TODO: Performance: As of 2019-04-28 doesn't work on Travis CI yet because the Gradle version
/* on Ubuntu Trusty is too old - and we cannot use Ubuntu Xenial because Java 7 doesn't work
/* there but it is still the minimal Java version required by Freenet. */
// failFast = true
maxHeapSize = "512m"
maxParallelForks = Runtime.runtime.availableProcessors()
forkEvery = 1 // One VM per test, for safety and probably needed for maxParallelForks to work
systemProperties += [
"is_WOT_unit_test": "true",
"WOT_test_jar": testJar.archivePath
]
workingDir = "${buildDir}/tmp/testsWorkingDir"
doFirst { delete workingDir ; mkdir workingDir }
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
// Allow enabling stdout/stderr so developers can obtain random seeds to reproduce failed
// test runs.
// TODO: Code quality: Have developers (by updating the README.md) and .travis.yml do this
// on the command line without requiring this code here once Travis CI contains a
// sufficiently recent Gradle for
// "-Doverride.test.testLogging.info.showStandardStreams=true" to work.
// Notice that the ".info" may be a typo from the person who posted this to
// stackoverflow.com as the working code below does not contain ".info", so you may have to
// remove that string.
//
// Enabling stdout/stderr requires us to tell Gradle to assume that the outputs are
// outdated to ensure they are updated even if the user doesn't run the 'clean' target.
outputs.upToDateWhen { false }
showStandardStreams = (System.getenv('WOT__SHOW_GRADLE_TEST_OUTPUT') == '1')
}
}
clean {
[ 'build-test', 'test-coverage', 'dist' ].each { // Beyond defaults also delete Ant's output
delete "${projectDir}/" + it }
doLast { exec { workingDir 'db4o-7.4' ; commandLine 'ant','clean' } }
}