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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2010, Kohsuke Kawaguchi
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
25 package hudson;
26
27 import jenkins.model.Jenkins;
28
29 import javax.servlet.ServletContext;
30 import java.io.File;
31 import java.io.IOException;
32 import java.net.URL;
33 import java.util.Collection;
34 import java.util.Collections;
35 import java.util.HashSet;
36 import java.util.Set;
37 import java.util.logging.Level;
38 import java.util.logging.Logger;
39
40 /**
41 * {@link PluginManager}
42 *
43 * @author Kohsuke Kawaguchi
44 */
45 public class LocalPluginManager extends PluginManager {
46 public LocalPluginManager(Jenkins jenkins) {
47 super(jenkins.servletContext, new File(jenkins.getRootDir(),"plugins"));
48 }
49
50 public LocalPluginManager(File rootDir) {
51 super(null, new File(rootDir,"plugins"));
52 }
53
54 /**
55 * If the war file has any "/WEB-INF/plugins/*.jpi", extract them into the plugin directory.
56 *
57 * @return
58 * File names of the bundled plugins. Like {"ssh-slaves.jpi","subvesrion.jpi"}
59 */
60 @Override
61 protected Collection<String> loadBundledPlugins() {
62 // this is used in tests, when we want to override the default bundled plugins with .jpl (or .hpl) versions
63 if (System.getProperty("hudson.bundled.plugins") != null) {
64 return Collections.emptySet();
65 }
66
67 Set<String> names = new HashSet<String>();
68
69 ServletContext context = Jenkins.getInstance().servletContext;
70
71 for( String path : Util.fixNull((Set<String>)context.getResourcePaths("/WEB-INF/plugins"))) {
72 String fileName = path.substring(path.lastIndexOf('/')+1);
73 if(fileName.length()==0) {
74 // see http://www.nabble.com/404-Not-Found-error-when-clicking-on-help-td24508544.html
75 // I suspect some containers are returning directory names.
76 continue;
77 }
78 try {
79 names.add(fileName);
80
81 URL url = context.getResource(path);
82 copyBundledPlugin(url, fileName);
83 } catch (IOException e) {
84 LOGGER.log(Level.SEVERE, "Failed to extract the bundled plugin "+fileName,e);
85 }
86 }
87
88 return names;
89 }
90
91 private static final Logger LOGGER = Logger.getLogger(LocalPluginManager.class.getName());
92 }
93