PageRenderTime 19ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/hudson-core/src/main/java/hudson/PluginFirstClassLoader.java

http://github.com/hudson/hudson
Java | 105 lines | 61 code | 12 blank | 32 comment | 1 complexity | a283bf3174dcd92ceceefdca02dfdb95 MD5 | raw file
  1/*
  2 * The MIT License
  3 * 
  4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Olivier Lamy
  5 * 
  6 * Permission is hereby granted, free of charge, to any person obtaining a copy
  7 * of this software and associated documentation files (the "Software"), to deal
  8 * in the Software without restriction, including without limitation the rights
  9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 10 * copies of the Software, and to permit persons to whom the Software is
 11 * furnished to do so, subject to the following conditions:
 12 * 
 13 * The above copyright notice and this permission notice shall be included in
 14 * all copies or substantial portions of the Software.
 15 * 
 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 22 * THE SOFTWARE.
 23 */
 24package hudson;
 25
 26import java.io.Closeable;
 27import java.io.File;
 28import java.io.IOException;
 29import java.io.InputStream;
 30import java.net.URL;
 31import java.util.ArrayList;
 32import java.util.Collection;
 33import java.util.Enumeration;
 34import java.util.List;
 35
 36import org.apache.tools.ant.AntClassLoader;
 37
 38/**
 39 * classLoader which use first /WEB-INF/lib/*.jar and /WEB-INF/classes before core classLoader
 40 * <b>you must use the pluginFirstClassLoader true in the maven-hpi-plugin</b>
 41 * @author olamy
 42 * @since 1.371
 43 */
 44public class PluginFirstClassLoader
 45    extends AntClassLoader
 46    implements Closeable
 47{
 48    
 49    private List<URL> urls = new ArrayList<URL>();
 50
 51    public void addPathFiles( Collection<File> paths )
 52        throws IOException
 53    {
 54        for ( File f : paths )
 55        {
 56            urls.add( f.toURI().toURL() );
 57            addPathFile( f );
 58        }
 59    }
 60
 61    /**
 62     * @return List of jar used by the plugin /WEB-INF/lib/*.jar and classes directory /WEB-INF/classes
 63     */
 64    public List<URL> getURLs() 
 65    {
 66        return urls;
 67    }
 68    
 69    public void close()
 70        throws IOException
 71    {
 72        cleanup();
 73    }
 74
 75    @Override
 76    protected Enumeration findResources( String arg0, boolean arg1 )
 77        throws IOException
 78    {
 79        Enumeration enu = super.findResources( arg0, arg1 );
 80        return enu;
 81    }
 82
 83    @Override
 84    protected Enumeration findResources( String name )
 85        throws IOException
 86    {
 87        Enumeration enu = super.findResources( name );
 88        return enu;
 89    }
 90
 91    @Override
 92    public URL getResource( String arg0 )
 93    {
 94        URL url = super.getResource( arg0 );
 95        return url;
 96    }
 97
 98    @Override
 99    public InputStream getResourceAsStream( String name )
100    {
101        InputStream is = super.getResourceAsStream( name );
102        return is;
103    }   
104    
105}