Skip to content

Commit fdf2741

Browse files
committed
Ensure shared plugin class-loader is rebuilt when processing different instrument setups
1 parent ce5994d commit fdf2741

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

buildSrc/src/main/groovy/InstrumentPlugin.groovy

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,20 @@ interface InstrumentWorkParameters extends WorkParameters {
178178
abstract class InstrumentAction implements WorkAction<InstrumentWorkParameters> {
179179
private static final Object lock = new Object()
180180
private static ClassLoader pluginCL
181-
private static volatile long lastBuildStamp
181+
private static String cachedPluginPath
182+
private static volatile long cachedBuildStamp
182183

183184
@Override
184185
void execute() {
185186
// reset shared class-loaders each time a new build starts
186187
long buildStamp = parameters.buildStartedTime.get()
187-
if (lastBuildStamp < buildStamp || !pluginCL) {
188+
String pluginPath = parameters.pluginClassPath.join(':')
189+
if (rebuildSharedClassLoader(buildStamp, pluginPath)) {
188190
synchronized (lock) {
189-
if (lastBuildStamp < buildStamp || !pluginCL) {
191+
if (rebuildSharedClassLoader(buildStamp, pluginPath)) {
190192
pluginCL = createClassLoader(parameters.pluginClassPath)
191-
lastBuildStamp = buildStamp
193+
cachedPluginPath = pluginPath
194+
cachedBuildStamp = buildStamp
192195
}
193196
}
194197
}
@@ -199,6 +202,10 @@ abstract class InstrumentAction implements WorkAction<InstrumentWorkParameters>
199202
InstrumentingPlugin.instrumentClasses(plugins, instrumentingCL, sourceDirectory, targetDirectory)
200203
}
201204

205+
static boolean rebuildSharedClassLoader(long buildStamp, String pluginPath) {
206+
return cachedBuildStamp < buildStamp || cachedPluginPath != pluginPath
207+
}
208+
202209
static ClassLoader createClassLoader(cp, parent = InstrumentAction.classLoader) {
203210
return new URLClassLoader(cp*.toURI()*.toURL() as URL[], parent as ClassLoader)
204211
}

0 commit comments

Comments
 (0)