File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\PluginFirstClassLoader.java.html

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 */
24 package hudson;
25
26 import java.io.Closeable;
27 import java.io.File;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.net.URL;
31 import java.util.ArrayList;
32 import java.util.Collection;
33 import java.util.Enumeration;
34 import java.util.List;
35
36 import 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 */
44 public 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 }
106