forked from McModLauncher/securejarhandler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
215 lines (185 loc) · 6.54 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import net.neoforged.gradleutils.PomUtilsExtension.License
buildscript {
dependencies {
classpath('de.jjohannes.gradle:extra-java-module-info:0.14')
}
}
plugins {
id 'com.github.ben-manes.versions' version '0.42.0'
id 'net.neoforged.gradleutils' version '3.0.0-alpha.4'
}
apply plugin: 'maven-publish'
allprojects {
apply plugin: 'java-library'
apply plugin: 'eclipse'
apply plugin: 'de.jjohannes.extra-java-module-info'
group 'cpw.mods'
java {
toolchain.languageVersion = JavaLanguageVersion.of(project.java_version)
modularity.inferModulePath.set(true)
}
version = gradleutils.version
repositories {
mavenLocal()
maven {
name = 'forge'
url = 'https://maven.neoforged.net/releases'
}
}
dependencies.testRuntimeOnly('org.apiguardian:apiguardian-api:1.1.2') // No idea why, but windows needs this to not explode.
extraJavaModuleInfo {
failOnMissingModuleInfo = false
automaticModule('jmh-core-1.35.jar', 'jmh.core')
}
def isNonStable = { String version ->
def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { type -> version.toUpperCase().contains(type) }
def regex = /^[0-9,.v-]+(-r)?$/
return !stableKeyword && !(version ==~ regex)
}
dependencyUpdates {
rejectVersionIf {
isNonStable(it.candidate.version)
}
}
// Hack eclipse into knowing that the gradle deps are modules
eclipse {
classpath {
containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
file {
whenMerged {
entries.findAll { it.kind == 'con' && it.path == 'org.eclipse.buildship.core.gradleclasspathcontainer' }.each {
it.entryAttributes['module'] = 'true'
}
}
}
}
}
}
repositories {
mavenCentral()
}
def isNonStable = { String version ->
def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { it -> version.toUpperCase().contains(it) }
def regex = /^[0-9,.v-]+(-r)?$/
return !stableKeyword && !(version ==~ regex)
}
dependencyUpdates {
rejectVersionIf {
isNonStable(it.candidate.version)
}
}
sourceSets {
// Additional test JARs, to be loaded via SecureJar.from(...)
testjar1 {}
testjar2 {}
// Test classpath code, to make sure that ModuleClassLoader is properly isolated from the classpath
testjar_cp {}
test {
runtimeClasspath += sourceSets.testjar_cp.output
}
}
compileJava {
options.compilerArgs += [
'-Xlint:unchecked',
'--add-exports=java.base/sun.security.util=cpw.mods.securejarhandler',
]
}
compileTestJava {
options.compilerArgs += [
'--add-modules=jdk.zipfs',
'--add-exports=jdk.zipfs/jdk.nio.zipfs=cpw.mods.securejarhandler'
]
}
group = 'cpw.mods'
version = gradleutils.version
logger.lifecycle('Version: ' + version)
dependencies {
api("org.ow2.asm:asm:${project.asm_version}")
api("org.ow2.asm:asm-tree:${project.asm_version}")
api("org.ow2.asm:asm-commons:${project.asm_version}")
compileOnly("org.jetbrains:annotations:${project.jb_annotations_version}")
testImplementation('org.junit.jupiter:junit-jupiter-api:5.8.+')
testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.8.+')
}
test {
//exclude '**/*'
useJUnitPlatform()
jvmArgs += [
// Add test sourceset to the SJH module
'--patch-module=cpw.mods.securejarhandler=' + sourceSets.test.output.classesDirs.asPath,
// SJH needs this for UnionFileSystem
'--add-opens=java.base/java.lang.invoke=cpw.mods.securejarhandler',
// Allow JUnit to access the tests
'--add-opens=cpw.mods.securejarhandler/cpw.mods.cl.test=ALL-UNNAMED',
'--add-opens=cpw.mods.securejarhandler/cpw.mods.jarhandling.impl=ALL-UNNAMED',
'--add-opens=cpw.mods.securejarhandler/cpw.mods.niofs.union=ALL-UNNAMED',
// To test reading from the classpath
'--add-reads=cpw.mods.securejarhandler=ALL-UNNAMED',
]
dependsOn tasks.compileTestjar1Java
dependsOn tasks.processTestjar1Resources
dependsOn tasks.compileTestjar2Java
dependsOn tasks.processTestjar2Resources
environment "sjh.testjar1", sourceSets.testjar1.output.classesDirs.asPath + File.pathSeparator + sourceSets.testjar1.output.resourcesDir.absolutePath
environment "sjh.testjar2", sourceSets.testjar2.output.classesDirs.asPath + File.pathSeparator + sourceSets.testjar2.output.resourcesDir.absolutePath
// Add SJH and its dependencies to the module path
jvmArgumentProviders.add(new CommandLineArgumentProvider() {
@Override
Iterable<String> asArguments() {
// Dependencies
def modulePath = test.classpath.filter {
it.name.contains("asm")
}.join(File.pathSeparator)
// SJH itself
modulePath += File.pathSeparator + sourceSets.main.output.classesDirs.asPath
return [
"--module-path",
modulePath,
"--add-modules=ALL-MODULE-PATH",
]
}
})
}
java {
withSourcesJar()
}
jar {
manifest {
attributes(
'Specification-Title': 'securejarhandler',
'Specification-Vendor': 'mcmodlauncher',
'Specification-Version': '1', // We are version 1 of ourselves
'Implementation-Title': project.name,
'Implementation-Version': "${project.version}+${gradleutils.gitInfo.branch}.${gradleutils.gitInfo.abbreviatedId}",
'Implementation-Vendor':'mcmodlauncher',
'Git-Commit': gradleutils.gitInfo.abbreviatedId,
'Git-Branch': gradleutils.gitInfo.branch
)
}
}
artifacts {
archives jar
archives sourcesJar
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
pom {
name = 'Secure Modular Jar handler'
description = 'Making the Java modular system provide security information'
pomUtils.githubRepo(it, 'SecureJarHandler', 'McModLauncher')
pomUtils.license(it, License.MIT)
developers {
developer {
id = 'cpw'
name = 'cpw'
}
}
}
}
}
repositories {
maven gradleutils.publishingMaven
}
}