001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2005 ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ********************************************************************************/package net.sourceforge.cruisecontrol.interceptor;
037:
038: import java.io.IOException;
039: import java.util.Collection;
040: import java.util.LinkedList;
041:
042: import javax.management.AttributeNotFoundException;
043: import javax.management.InstanceNotFoundException;
044: import javax.management.MBeanException;
045: import javax.management.ReflectionException;
046:
047: import net.sourceforge.cruisecontrol.Configuration;
048: import net.sourceforge.cruisecontrol.CruiseControlException;
049: import net.sourceforge.cruisecontrol.PluginDetail;
050: import net.sourceforge.cruisecontrol.PluginType;
051:
052: import org.jdom.JDOMException;
053:
054: /**
055: * Understands how to find plugins.
056: */
057: public class PluginLocator {
058: private Configuration configuration;
059:
060: public PluginLocator(Configuration configuration) {
061: this .configuration = configuration;
062: }
063:
064: public PluginDetail[] getAvailablePlugins(String type)
065: throws AttributeNotFoundException,
066: InstanceNotFoundException, MBeanException,
067: ReflectionException, IOException {
068: return getAvailablePlugins(PluginType.find(type));
069: }
070:
071: public PluginDetail[] getAvailablePlugins(PluginType type)
072: throws ReflectionException, IOException,
073: InstanceNotFoundException, MBeanException,
074: AttributeNotFoundException {
075: PluginDetail[] availablePlugins = configuration
076: .getPluginDetails();
077: Collection desiredPlugins = new LinkedList();
078: for (int i = 0; i < availablePlugins.length; i++) {
079: PluginDetail nextPlugin = availablePlugins[i];
080:
081: if (nextPlugin.getType() == type) {
082: desiredPlugins.add(nextPlugin);
083: }
084: }
085:
086: return (PluginDetail[]) desiredPlugins
087: .toArray(new PluginDetail[desiredPlugins.size()]);
088: }
089:
090: public PluginDetail[] getConfiguredPlugins(String project,
091: String type) throws AttributeNotFoundException,
092: InstanceNotFoundException, MBeanException,
093: ReflectionException, IOException, CruiseControlException,
094: JDOMException {
095: if ("listener".equals(type)) {
096: return configuration.getConfiguredListeners(project);
097: } else if ("bootstrapper".equals(type)) {
098: return configuration.getConfiguredBootstrappers(project);
099: } else if ("sourcecontrol".equals(type)) {
100: return configuration.getConfiguredSourceControls(project);
101: } else if ("builder".equals(type)) {
102: return configuration.getConfiguredBuilders(project);
103: } else if ("logger".equals(type)) {
104: return configuration.getConfiguredLoggers(project);
105: } else if ("publisher".equals(type)) {
106: return configuration.getConfiguredPublishers(project);
107: } else {
108: return null;
109: }
110: }
111:
112: public PluginDetail getPluginDetail(String name, String type)
113: throws AttributeNotFoundException,
114: InstanceNotFoundException, MBeanException,
115: ReflectionException, IOException {
116: PluginDetail[] plugins = getAvailablePlugins(type);
117: for (int i = 0; i < plugins.length; i++) {
118: if (plugins[i].getName().equals(name)) {
119: return plugins[i];
120: }
121: }
122:
123: return null;
124: }
125: }
|