Skip to content
Browse files


Integrated bytecode-compatibility-transformer that allows core to
do signature changes on properties that plugins might depend on.

The library performs necessary bytecode transformation to achieve this.

The first use of this is to fix plugins that looks for List
AbstractProject.triggers, thereby resolving JENKINS-18677.

For the time being, I'm not loading such compatibility annotations from
plugins, but I did code that in PluginManager. Let's see how this
feature work out for a while in the core, and if it looks stable and
solid, we'll open it up to plugins at that point.
  • Loading branch information
kohsuke committed Aug 3, 2013
1 parent e7b9143 commit 47de54d070f67af95b4fefb6d006a72bb31a5cb8
@@ -55,6 +55,12 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=bug>
Fixed <tt>NoSuchFieldError: triggers</tt> with older Maven plugin
(<a href="">issue 18677</a>)
<li class=rfe>
Added bytecode transformation driven compatibility ensurance mechanism
(<a href="!topic/jenkinsci-dev/7qCClb36njo">discussion</a>)
<li class=rfe>
Improve search to locate items inside folders.
(<a href="">pull request 848</a>)
@@ -214,6 +214,11 @@ THE SOFTWARE.
@@ -59,7 +59,6 @@
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -223,19 +222,10 @@ protected ClassLoader createClassLoader(List<File> paths, ClassLoader parent, At
return classLoader;
if(useAntClassLoader && !Closeable.class.isAssignableFrom(URLClassLoader.class)) {
// using AntClassLoader with Closeable so that we can predictably release jar files opened by URLClassLoader
AntClassLoader2 classLoader = new AntClassLoader2(parent);
return classLoader;
} else {
// Tom reported that AntClassLoader has a performance issue when Hudson keeps trying to load a class that doesn't exist,
// so providing a legacy URLClassLoader support, too
List<URL> urls = new ArrayList<URL>();
for (File path : paths)
return new URLClassLoader(urls.toArray(new URL[urls.size()]),parent);

AntClassLoader2 classLoader = new AntClassLoader2(parent);
return classLoader;

@@ -652,7 +642,7 @@ protected URL findResource(String name) {
* {@link AntClassLoader} with a few methods exposed and {@link Closeable} support.
* Deprecated as of Java 7, retained only for Java 5/6.
private static final class AntClassLoader2 extends AntClassLoader implements Closeable {
private final class AntClassLoader2 extends AntClassLoader implements Closeable {
private final Vector pathComponents;

private AntClassLoader2(ClassLoader parent) {
@@ -669,6 +659,7 @@ private AntClassLoader2(ClassLoader parent) {

public void addPathFiles(Collection<File> paths) throws IOException {
for (File f : paths)
@@ -699,6 +690,11 @@ protected URL findResource(String name) {

return url;

protected Class defineClassFromData(File container, byte[] classData, String classname) throws IOException {
return super.defineClassFromData(container, pluginManager.getCompatibilityTransformer().transform(classname,classData), classname);

public static boolean useAntClassLoader = Boolean.getBoolean(ClassicPluginStrategy.class.getName()+".useAntClassLoader");
@@ -59,6 +59,7 @@
import org.apache.commons.logging.LogFactory;
import org.jenkinsci.bytecode.Transformer;
import org.jvnet.hudson.reactor.Executable;
import org.jvnet.hudson.reactor.Reactor;
import org.jvnet.hudson.reactor.ReactorException;
@@ -151,6 +152,8 @@
// and load plugin-contributed classes.
public final ClassLoader uberClassLoader = new UberClassLoader();

private final Transformer compatibilityTransformer = new Transformer();

* Once plugin is uploaded, this flag becomes true.
* This is used to report a message that Jenkins needs to be restarted
@@ -179,6 +182,17 @@ public PluginManager(ServletContext context, File rootDir) {

strategy = createPluginStrategy();

// load up rules for the core first
try {
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to load compatibility rewrite rules",e);

public Transformer getCompatibilityTransformer() {
return compatibilityTransformer;

public Api getApi() {
@@ -301,6 +315,13 @@ protected void reactOnCycle(PluginWrapper q, List<PluginWrapper> cycle)

// Let's see for a while until we open this functionality up to plugins
// g.followedBy().attains(PLUGINS_LISTED).add("Load compatibility rules", new Executable() {
// public void run(Reactor reactor) throws Exception {
// compatibilityTransformer.loadRules(uberClassLoader);
// }
// });


pluginListed = true; // technically speaking this is still too early, as at this point tasks are merely scheduled, not necessarily executed.
@@ -95,6 +95,7 @@
import org.acegisecurity.Authentication;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.jenkinsci.bytecode.AdaptField;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.args4j.Argument;
@@ -242,6 +243,7 @@
* List of all {@link Trigger}s for this project.
protected volatile DescribableList<Trigger<?>,TriggerDescriptor> triggers = new DescribableList<Trigger<?>,TriggerDescriptor>(this);
private static final AtomicReferenceFieldUpdater<AbstractProject,DescribableList> triggersUpdater
= AtomicReferenceFieldUpdater.newUpdater(AbstractProject.class,DescribableList.class,"triggers");
@@ -174,7 +174,7 @@ THE SOFTWARE.


0 comments on commit 47de54d

Please sign in to comment.
You can’t perform that action at this time.