提交 fded8ce6 编写于 作者: O olamy

[HUDSON-5360] add a new classloader ("a la" child first for plugin)

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@35076 71c3de6d-444a-0410-be80-ed276b4c234a
上级 21d7e261
......@@ -38,6 +38,10 @@ THE SOFTWARE.
<description>
Contains the core Hudson code and view files to render HTML.
</description>
<properties>
<staplerFork>true</staplerFork>
</properties>
<build>
<plugins>
......@@ -78,7 +82,7 @@ THE SOFTWARE.
</dependency>
</dependencies>
<configuration>
<fork>true</fork><!-- the source code is big enough now that otherwise it fails with OutOfMemoryError -->
<fork>${staplerFork}</fork><!-- the source code is big enough now that otherwise it fails with OutOfMemoryError -->
<maxmem>128m</maxmem>
</configuration>
</plugin>
......
......@@ -170,13 +170,28 @@ public class ClassicPluginStrategy implements PluginStrategy {
ClassLoader dependencyLoader = new DependencyClassLoader(getBaseClassLoader(atts), archive, Util.join(dependencies,optionalDependencies));
return new PluginWrapper(pluginManager, archive, manifest, baseResourceURL,
createClassLoader(paths, dependencyLoader), disableFile, dependencies, optionalDependencies);
createClassLoader(paths, dependencyLoader, atts), disableFile, dependencies, optionalDependencies);
}
@Deprecated
protected ClassLoader createClassLoader(List<File> paths, ClassLoader parent) throws IOException {
return createClassLoader( paths, parent, null );
}
/**
* Creates the classloader that can load all the specified jar files and delegate to the given parent.
*/
protected ClassLoader createClassLoader(List<File> paths, ClassLoader parent) throws IOException {
protected ClassLoader createClassLoader(List<File> paths, ClassLoader parent, Attributes atts) throws IOException {
if (atts != null) {
String usePluginFirstClassLoader = atts.getValue( "PluginFirstClassLoader" );
if (Boolean.valueOf( usePluginFirstClassLoader )) {
PluginFirstClassLoader classLoader = new PluginFirstClassLoader();
classLoader.setParentFirst( false );
classLoader.setParent( parent );
classLoader.addPathFiles( paths );
return classLoader;
}
}
if(useAntClassLoader) {
// using AntClassLoader with Closeable so that we can predictably release jar files opened by URLClassLoader
AntClassLoader2 classLoader = new AntClassLoader2(parent);
......
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Olivier Lamy
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.List;
import org.apache.tools.ant.AntClassLoader;
/**
* classLoader which use first /WEB-INF/lib/*.jar and /WEB-INF/classes before core classLoader
* <b>you must use the pluginFirstClassLoader true in the maven-hpi-plugin</b>
* @author olamy
* @since 1.371
*/
public class PluginFirstClassLoader
extends AntClassLoader
implements Closeable
{
private List<URL> urls = new ArrayList<URL>();
public void addPathFiles( Collection<File> paths )
throws IOException
{
for ( File f : paths )
{
urls.add( f.toURI().toURL() );
addPathFile( f );
}
}
/**
* @return List of jar used by the plugin /WEB-INF/lib/*.jar and classes directory /WEB-INF/classes
*/
public List<URL> getURLs()
{
return urls;
}
public void close()
throws IOException
{
cleanup();
}
@Override
protected Enumeration findResources( String arg0, boolean arg1 )
throws IOException
{
Enumeration enu = super.findResources( arg0, arg1 );
return enu;
}
@Override
protected Enumeration findResources( String name )
throws IOException
{
Enumeration enu = super.findResources( name );
return enu;
}
@Override
public URL getResource( String arg0 )
{
URL url = super.getResource( arg0 );
return url;
}
@Override
public InputStream getResourceAsStream( String name )
{
InputStream is = super.getResourceAsStream( name );
return is;
}
}
......@@ -52,7 +52,8 @@ public final class Permission {
/**
* {@inheritDoc}
*/
@Override
// break eclipse compilation
//Override
public int compare(Permission one, Permission two) {
return one.getId().compareTo(two.getId());
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册