diff --git a/dd-java-agent/instrumentation/datanucleus-4.0.5/build.gradle b/dd-java-agent/instrumentation/datanucleus-4.0.5/build.gradle index 4fb501a01ab..d440e52111b 100644 --- a/dd-java-agent/instrumentation/datanucleus-4.0.5/build.gradle +++ b/dd-java-agent/instrumentation/datanucleus-4.0.5/build.gradle @@ -1,24 +1,3 @@ -import org.datanucleus.enhancer.DataNucleusEnhancer - -buildscript { - repositories { - mavenLocal() - if (project.rootProject.hasProperty("mavenRepositoryProxy")) { - maven { - url project.rootProject.property("mavenRepositoryProxy") - allowInsecureProtocol = true - } - } - mavenCentral() - } - - dependencies { - classpath group: 'org.datanucleus', name: 'datanucleus-core', version: '4.0.5' - classpath group: 'org.datanucleus', name: 'datanucleus-api-jdo', version: '4.0.5' - classpath group: 'org.datanucleus', name: 'javax.jdo', version: '3.2.0-m1' - } -} - muzzle { // 2 libraries are instrumented. // Muzzle is tested by keeping one version fixed and modifying the other @@ -44,24 +23,34 @@ apply from: "${rootDir}/gradle/java.gradle" def datanucleusVersion = '4.0.5' +def datanucleusEnhancer = configurations.register("datanucleusEnhancer") { + canBeConsumed = false + canBeResolved = true +} + // Datanucleus modifies persistable objects with bytecode manipulation // The unofficial plugin (org.rm3l.datanucleus-gradle-plugin) doesn't work with our build // The enhancement is done manually here for the test classes // LatestDepTest can't be used because the enhancer class generates incompatible code // Specifically, org.datanucleus.enhancer.Persistable changes package -// Only one version can be set as the script classpath in the 'buildScript' block tasks.register('enhance') { doLast { - def outputUrls = (sourceSets.test.output.classesDirs.files + sourceSets.test.output.resourcesDir) + def outputUrls = (datanucleusEnhancer.get().files + sourceSets.test.output.classesDirs.files + sourceSets.test.output.resourcesDir) + .findAll { it != null } .collect { it.toURI().toURL() } as URL[] def testClassloader = new URLClassLoader(outputUrls, Thread.currentThread().getContextClassLoader()) - - DataNucleusEnhancer enhancer = new DataNucleusEnhancer("JDO", null) - enhancer.setVerbose(true).addPersistenceUnit("testPersistenceUnit") - enhancer.setSystemOut(true) - enhancer.setClassLoader(testClassloader) - enhancer.enhance() + try { + def enhancerClass = testClassloader.loadClass("org.datanucleus.enhancer.DataNucleusEnhancer") + enhancerClass.getConstructor(String, Properties).newInstance("JDO", null).with { + setVerbose(true).addPersistenceUnit("testPersistenceUnit") + setSystemOut(true) + setClassLoader(testClassloader) + enhance() + } + } finally { + testClassloader.close() + } } dependsOn "testClasses" @@ -82,4 +71,8 @@ dependencies { testImplementation group: 'org.datanucleus', name: 'datanucleus-rdbms', version: datanucleusVersion testImplementation group: 'org.datanucleus', name: 'javax.jdo', version: '3.2.0-m1' testImplementation group: 'com.h2database', name: 'h2', version: '1.3.169' + + add(datanucleusEnhancer.name, "org.datanucleus:datanucleus-core:$datanucleusVersion") + add(datanucleusEnhancer.name, "org.datanucleus:datanucleus-api-jdo:$datanucleusVersion") + add(datanucleusEnhancer.name, "org.datanucleus:javax.jdo:3.2.0-m1") } diff --git a/dd-java-agent/instrumentation/datanucleus-4.0.5/gradle.lockfile b/dd-java-agent/instrumentation/datanucleus-4.0.5/gradle.lockfile index ffdadc911fe..0b34165eb6e 100644 --- a/dd-java-agent/instrumentation/datanucleus-4.0.5/gradle.lockfile +++ b/dd-java-agent/instrumentation/datanucleus-4.0.5/gradle.lockfile @@ -54,7 +54,7 @@ de.thetaphi:forbiddenapis:3.10=compileClasspath,testCompileClasspath,testRuntime io.leangen.geantyref:geantyref:1.3.16=testRuntimeClasspath io.sqreen:libsqreen:17.3.0=testRuntimeClasspath javax.servlet:javax.servlet-api:3.1.0=testCompileClasspath,testRuntimeClasspath -javax.transaction:transaction-api:1.1=compileClasspath,testCompileClasspath,testRuntimeClasspath +javax.transaction:transaction-api:1.1=compileClasspath,datanucleusEnhancer,testCompileClasspath,testRuntimeClasspath jaxen:jaxen:2.0.0=spotbugs junit:junit:4.13.2=testRuntimeClasspath 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 org.codehaus.groovy:groovy:3.0.23=codenarc org.codehaus.groovy:groovy:3.0.25=testCompileClasspath,testRuntimeClasspath org.codenarc:CodeNarc:3.7.0=codenarc -org.datanucleus:datanucleus-api-jdo:4.0.5=compileClasspath,testCompileClasspath,testRuntimeClasspath -org.datanucleus:datanucleus-core:4.0.5=compileClasspath,testCompileClasspath,testRuntimeClasspath +org.datanucleus:datanucleus-api-jdo:4.0.5=compileClasspath,datanucleusEnhancer,testCompileClasspath,testRuntimeClasspath +org.datanucleus:datanucleus-core:4.0.5=compileClasspath,datanucleusEnhancer,testCompileClasspath,testRuntimeClasspath org.datanucleus:datanucleus-rdbms:4.0.5=testCompileClasspath,testRuntimeClasspath -org.datanucleus:javax.jdo:3.2.0-m1=compileClasspath,testCompileClasspath,testRuntimeClasspath +org.datanucleus:javax.jdo:3.2.0-m1=compileClasspath,datanucleusEnhancer,testCompileClasspath,testRuntimeClasspath org.dom4j:dom4j:2.2.0=spotbugs org.gmetrics:GMetrics:2.1.0=codenarc org.hamcrest:hamcrest-core:1.3=testRuntimeClasspath diff --git a/gradle/forbiddenapis.gradle b/gradle/forbiddenapis.gradle index 4318766c9ac..788d5b1b979 100644 --- a/gradle/forbiddenapis.gradle +++ b/gradle/forbiddenapis.gradle @@ -1,27 +1,3 @@ -buildscript { - repositories { - mavenLocal() - if (project.rootProject.hasProperty("gradlePluginProxy")) { - maven { - url project.rootProject.property("gradlePluginProxy") - allowInsecureProtocol = true - } - } - if (project.rootProject.hasProperty("mavenRepositoryProxy")) { - maven { - url project.rootProject.property("mavenRepositoryProxy") - allowInsecureProtocol = true - } - } - gradlePluginPortal() - mavenCentral() - } - - dependencies { - classpath libs.forbiddenapis - } -} - apply plugin: "de.thetaphi.forbiddenapis" def mainFilterFile = files("$rootDir/gradle/forbiddenApiFilters/main.txt")