提交 0202466b 编写于 作者: K kohsuke

DefaultClassRealm in classworlds is child-first delegation, so when loading...

DefaultClassRealm in classworlds is child-first delegation, so when loading classes in a child container (which creates its own realm), MojoScanner interface ends up loaded locally.
So really the only solution is to hide the maven-plugin-tools-api.jar from embedded Maven.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@2107 71c3de6d-444a-0410-be80-ed276b4c234a
上级 eeada0a6
......@@ -6,9 +6,12 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Enumeration;
import java.net.URL;
/**
* @author Kohsuke Kawaguchi
......@@ -24,7 +27,7 @@ class MavenUtil {
MavenEmbedder maven = new MavenEmbedder();
ClassLoader cl = MavenUtil.class.getClassLoader();
maven.setClassLoader(cl);
maven.setClassLoader(new MaskingClassLoader(cl));
maven.setLogger( new EmbedderLoggerImpl(listener) );
// if we let Plexus find components, there's no guaranteed ordering,
// so Plexus may well find the DefaultPluginManager from maven.jar instead of
......@@ -70,4 +73,38 @@ class MavenUtil {
project.setCollectedProjects(modules);
}
private static final class MaskingClassLoader extends ClassLoader {
public MaskingClassLoader(ClassLoader parent) {
super(parent);
}
public Enumeration<URL> getResources(String name) throws IOException {
final Enumeration<URL> e = super.getResources(name);
return new Enumeration<URL>() {
URL next;
public boolean hasMoreElements() {
fetch();
return next!=null;
}
public URL nextElement() {
fetch();
URL r = next;
next = null;
return r;
}
private void fetch() {
while(next==null && e.hasMoreElements()) {
next = e.nextElement();
if(next.toExternalForm().contains("maven-plugin-tools-api"))
next = null;
}
}
};
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册