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