Skip to content

Commit 4aaf9af

Browse files
authored
Remove remaining Gradle buildscript blocks (#11975)
chore(gradle): remove datanucleus buildscript block Load the DataNucleus enhancer from a dedicated project configuration instead of the script classpath. This keeps the enhancer dependencies in the normal dependency model and resolves them only when the enhance task runs. Also, this project already gets repository setup from the shared Java build scripts. chore(gradle): remove forbidden-apis buildscript block The root build already declares the forbidden-apis plugin version. Reuse that plugin declaration from the shared script instead of carrying a second script-level classpath and repository setup. Merge branch 'master' into bdu/remove-the-last-buildscripts Co-authored-by: brice.dutheil <brice.dutheil@datadoghq.com>
1 parent e98ec49 commit 4aaf9af

3 files changed

Lines changed: 26 additions & 57 deletions

File tree

dd-java-agent/instrumentation/datanucleus-4.0.5/build.gradle

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
import org.datanucleus.enhancer.DataNucleusEnhancer
2-
3-
buildscript {
4-
repositories {
5-
mavenLocal()
6-
if (project.rootProject.hasProperty("mavenRepositoryProxy")) {
7-
maven {
8-
url project.rootProject.property("mavenRepositoryProxy")
9-
allowInsecureProtocol = true
10-
}
11-
}
12-
mavenCentral()
13-
}
14-
15-
dependencies {
16-
classpath group: 'org.datanucleus', name: 'datanucleus-core', version: '4.0.5'
17-
classpath group: 'org.datanucleus', name: 'datanucleus-api-jdo', version: '4.0.5'
18-
classpath group: 'org.datanucleus', name: 'javax.jdo', version: '3.2.0-m1'
19-
}
20-
}
21-
221
muzzle {
232
// 2 libraries are instrumented.
243
// Muzzle is tested by keeping one version fixed and modifying the other
@@ -44,24 +23,34 @@ apply from: "${rootDir}/gradle/java.gradle"
4423

4524
def datanucleusVersion = '4.0.5'
4625

26+
def datanucleusEnhancer = configurations.register("datanucleusEnhancer") {
27+
canBeConsumed = false
28+
canBeResolved = true
29+
}
30+
4731
// Datanucleus modifies persistable objects with bytecode manipulation
4832
// The unofficial plugin (org.rm3l.datanucleus-gradle-plugin) doesn't work with our build
4933
// The enhancement is done manually here for the test classes
5034
// LatestDepTest can't be used because the enhancer class generates incompatible code
5135
// Specifically, org.datanucleus.enhancer.Persistable changes package
52-
// Only one version can be set as the script classpath in the 'buildScript' block
5336
tasks.register('enhance') {
5437
doLast {
55-
def outputUrls = (sourceSets.test.output.classesDirs.files + sourceSets.test.output.resourcesDir)
38+
def outputUrls = (datanucleusEnhancer.get().files + sourceSets.test.output.classesDirs.files + sourceSets.test.output.resourcesDir)
39+
.findAll { it != null }
5640
.collect { it.toURI().toURL() } as URL[]
5741

5842
def testClassloader = new URLClassLoader(outputUrls, Thread.currentThread().getContextClassLoader())
59-
60-
DataNucleusEnhancer enhancer = new DataNucleusEnhancer("JDO", null)
61-
enhancer.setVerbose(true).addPersistenceUnit("testPersistenceUnit")
62-
enhancer.setSystemOut(true)
63-
enhancer.setClassLoader(testClassloader)
64-
enhancer.enhance()
43+
try {
44+
def enhancerClass = testClassloader.loadClass("org.datanucleus.enhancer.DataNucleusEnhancer")
45+
enhancerClass.getConstructor(String, Properties).newInstance("JDO", null).with {
46+
setVerbose(true).addPersistenceUnit("testPersistenceUnit")
47+
setSystemOut(true)
48+
setClassLoader(testClassloader)
49+
enhance()
50+
}
51+
} finally {
52+
testClassloader.close()
53+
}
6554
}
6655

6756
dependsOn "testClasses"
@@ -82,4 +71,8 @@ dependencies {
8271
testImplementation group: 'org.datanucleus', name: 'datanucleus-rdbms', version: datanucleusVersion
8372
testImplementation group: 'org.datanucleus', name: 'javax.jdo', version: '3.2.0-m1'
8473
testImplementation group: 'com.h2database', name: 'h2', version: '1.3.169'
74+
75+
add(datanucleusEnhancer.name, "org.datanucleus:datanucleus-core:$datanucleusVersion")
76+
add(datanucleusEnhancer.name, "org.datanucleus:datanucleus-api-jdo:$datanucleusVersion")
77+
add(datanucleusEnhancer.name, "org.datanucleus:javax.jdo:3.2.0-m1")
8578
}

dd-java-agent/instrumentation/datanucleus-4.0.5/gradle.lockfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ de.thetaphi:forbiddenapis:3.10=compileClasspath,testCompileClasspath,testRuntime
5454
io.leangen.geantyref:geantyref:1.3.16=testRuntimeClasspath
5555
io.sqreen:libsqreen:17.3.0=testRuntimeClasspath
5656
javax.servlet:javax.servlet-api:3.1.0=testCompileClasspath,testRuntimeClasspath
57-
javax.transaction:transaction-api:1.1=compileClasspath,testCompileClasspath,testRuntimeClasspath
57+
javax.transaction:transaction-api:1.1=compileClasspath,datanucleusEnhancer,testCompileClasspath,testRuntimeClasspath
5858
jaxen:jaxen:2.0.0=spotbugs
5959
junit:junit:4.13.2=testRuntimeClasspath
6060
net.bytebuddy:byte-buddy-agent:1.18.10=buildTimeInstrumentationPlugin,compileClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
@@ -81,10 +81,10 @@ org.codehaus.groovy:groovy-xml:3.0.23=codenarc
8181
org.codehaus.groovy:groovy:3.0.23=codenarc
8282
org.codehaus.groovy:groovy:3.0.25=testCompileClasspath,testRuntimeClasspath
8383
org.codenarc:CodeNarc:3.7.0=codenarc
84-
org.datanucleus:datanucleus-api-jdo:4.0.5=compileClasspath,testCompileClasspath,testRuntimeClasspath
85-
org.datanucleus:datanucleus-core:4.0.5=compileClasspath,testCompileClasspath,testRuntimeClasspath
84+
org.datanucleus:datanucleus-api-jdo:4.0.5=compileClasspath,datanucleusEnhancer,testCompileClasspath,testRuntimeClasspath
85+
org.datanucleus:datanucleus-core:4.0.5=compileClasspath,datanucleusEnhancer,testCompileClasspath,testRuntimeClasspath
8686
org.datanucleus:datanucleus-rdbms:4.0.5=testCompileClasspath,testRuntimeClasspath
87-
org.datanucleus:javax.jdo:3.2.0-m1=compileClasspath,testCompileClasspath,testRuntimeClasspath
87+
org.datanucleus:javax.jdo:3.2.0-m1=compileClasspath,datanucleusEnhancer,testCompileClasspath,testRuntimeClasspath
8888
org.dom4j:dom4j:2.2.0=spotbugs
8989
org.gmetrics:GMetrics:2.1.0=codenarc
9090
org.hamcrest:hamcrest-core:1.3=testRuntimeClasspath

gradle/forbiddenapis.gradle

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
buildscript {
2-
repositories {
3-
mavenLocal()
4-
if (project.rootProject.hasProperty("gradlePluginProxy")) {
5-
maven {
6-
url project.rootProject.property("gradlePluginProxy")
7-
allowInsecureProtocol = true
8-
}
9-
}
10-
if (project.rootProject.hasProperty("mavenRepositoryProxy")) {
11-
maven {
12-
url project.rootProject.property("mavenRepositoryProxy")
13-
allowInsecureProtocol = true
14-
}
15-
}
16-
gradlePluginPortal()
17-
mavenCentral()
18-
}
19-
20-
dependencies {
21-
classpath libs.forbiddenapis
22-
}
23-
}
24-
251
apply plugin: "de.thetaphi.forbiddenapis"
262

273
def mainFilterFile = files("$rootDir/gradle/forbiddenApiFilters/main.txt")

0 commit comments

Comments
 (0)