1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.plexus;
22
23 import java.io.ByteArrayInputStream;
24 import java.io.InputStream;
25 import java.io.InputStreamReader;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.codehaus.plexus.PlexusContainer;
30 import org.codehaus.plexus.configuration.PlexusConfigurationResourceException;
31
32 /***
33 * Utility methods for dealing with Plexus
34 */
35 public class PlexusUtils {
36 private static final Log log = LogFactory.getLog(PlexusObjectFactory.class);
37
38 /***
39 * Configures the container with the configuration file
40 *
41 * @param pc The plexus container
42 * @param file The file path
43 * @throws PlexusConfigurationResourceException If the plexus configuration can't be loaded
44 */
45 public static void configure(PlexusContainer pc, String file) throws PlexusConfigurationResourceException {
46 InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
47 if (is == null) {
48 log.info("Could not find " + file + ", skipping");
49 is = new ByteArrayInputStream("<plexus><components></components></plexus>".getBytes());
50 }
51 pc.setConfigurationResource(new InputStreamReader(is));
52 }
53 }