String provider = pluginDescriptor.valueOf("/FindbugsPlugin/@provider"); if (!provider.equals("")) plugin.setProvider(provider); String website = pluginDescriptor.valueOf("/FindbugsPlugin/@website"); if (!website.equals("")) plugin.setWebsite(website);   Node pluginShortDesc = null; try { pluginShortDesc = findMessageNode( messageCollectionList, "/MessageCollection/Plugin/ShortDescription", "no plugin description"); } catch (PluginException e) {  } if (pluginShortDesc != null) { plugin.setShortDescription(pluginShortDesc.getText()); }
	private void init() throws PluginException {		// Plugin descriptor (a.k.a, "findbugs.xml").  Defines		// the bug detectors and bug patterns that the plugin provides.		Document pluginDescriptor;				// Unique plugin id		String pluginId;		// List of message translation files in decreasing order of precedence		ArrayList<Document> messageCollectionList = new ArrayList<Document>();		// Read the plugin descriptor		try {			URL descriptorURL = findResource("findbugs.xml");			if (descriptorURL == null)				throw new PluginException("Couldn't find \"findbugs.xml\" in plugin");			SAXReader reader = new SAXReader();			pluginDescriptor = reader.read(descriptorURL);		} catch (DocumentException e) {			throw new PluginException("Couldn't parse \"findbugs.xml\"", e);		}				// Get the unique plugin id (or generate one, if none is present)		pluginId = pluginDescriptor.valueOf("/FindbugsPlugin/@pluginid");		if (pluginId.equals("")) {			synchronized (PluginLoader.class) {				pluginId = "plugin" + nextUnknownId++;			}		}		// See if the plugin is enabled or disabled by default.		// Note that if there is no "defaultenabled" attribute,		// then we assume that the plugin IS enabled by default.		String defaultEnabled = pluginDescriptor.valueOf("/FindbugsPlugin/@defaultenabled");		boolean pluginEnabled = defaultEnabled.equals("") ? true : Boolean.valueOf(defaultEnabled);		// Load the message collections		try {			Locale locale = Locale.getDefault();			String language = locale.getLanguage();			String country = locale.getCountry();			if (country != null)				addCollection(messageCollectionList, "messages_" + language + "_" + country + ".xml");			addCollection(messageCollectionList, "messages_" + language + ".xml");			addCollection(messageCollectionList, "messages.xml");		} catch (DocumentException e) {			e.printStackTrace();			throw new PluginException("Couldn't parse \"messages.xml\"", e);		}				// Create the Plugin object (but don't assign to the plugin field yet,		// since we're still not sure if everything will load correctly)		Plugin plugin = new Plugin(pluginId);		plugin.setEnabled(pluginEnabled);		// Create a DetectorFactory for all Detector nodes		HashMap<String, DetectorFactory> detectorFactoryMap = new HashMap<String, DetectorFactory>();		try {			List detectorNodeList = pluginDescriptor.selectNodes("/FindbugsPlugin/Detector");			for (Iterator i = detectorNodeList.iterator(); i.hasNext();) {				Node detectorNode = (Node) i.next();				String className = detectorNode.valueOf("@class");				String speed = detectorNode.valueOf("@speed");				String disabled = detectorNode.valueOf("@disabled");				String reports = detectorNode.valueOf("@reports");				String requireJRE = detectorNode.valueOf("@requirejre");					//System.out.println("Found detector: class="+className+", disabled="+disabled);					Class detectorClass = loadClass(className);				DetectorFactory factory = new DetectorFactory(						plugin,						detectorClass, !disabled.equals("true"),				        speed, reports, requireJRE);				plugin.addDetectorFactory(factory);				detectorFactoryMap.put(className, factory);				// Find Detector node in one of the messages files,				// to get the detail HTML.				Node node = findMessageNode(messageCollectionList,				        "/MessageCollection/Detector[@class='" + className + "']/Details",				        "Missing Detector description for detector " + className);				Element details = (Element) node;				String detailHTML = details.getText();				StringBuffer buf = new StringBuffer();				buf.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");				buf.append("<HTML><HEAD><TITLE>Detector Description</TITLE></HEAD><BODY>\n");				buf.append(detailHTML);				buf.append("</BODY></HTML>\n");				factory.setDetailHTML(buf.toString());			}		} catch (ClassNotFoundException e) {			throw new PluginException("Could not instantiate detector class: " + e, e);		}		// Create BugPatterns		List bugPatternNodeList = pluginDescriptor.selectNodes("/FindbugsPlugin/BugPattern");		for (Iterator i = bugPatternNodeList.iterator(); i.hasNext();) {			Node bugPatternNode = (Node) i.next();			String type = bugPatternNode.valueOf("@type");			String abbrev = bugPatternNode.valueOf("@abbrev");			String category = bugPatternNode.valueOf("@category");			String experimental = bugPatternNode.valueOf("@experimental");			// Find the matching element in messages.xml (or translations)			String query = "/MessageCollection/BugPattern[@type='" + type + "']";			Node messageNode = findMessageNode(messageCollectionList, query,			        "messages.xml missing BugPattern element for type " + type);			String shortDesc = getChildText(messageNode, "ShortDescription");			String longDesc = getChildText(messageNode, "LongDescription");			String detailText = getChildText(messageNode, "Details");			BugPattern bugPattern = new BugPattern(type, abbrev, category,			        Boolean.valueOf(experimental).booleanValue(),			        shortDesc, longDesc, detailText);			plugin.addBugPattern(bugPattern);		}		// Create BugCodes		HashSet<String> definedBugCodes = new HashSet<String>();		for (Iterator<Document> i = messageCollectionList.iterator(); i.hasNext();) {			Document messageCollection = i.next();			List bugCodeNodeList = messageCollection.selectNodes("/MessageCollection/BugCode");			for (Iterator j = bugCodeNodeList.iterator(); j.hasNext();) {				Node bugCodeNode = (Node) j.next();				String abbrev = bugCodeNode.valueOf("@abbrev");				if (abbrev.equals(""))					throw new PluginException("BugCode element with missing abbrev attribute");				if (definedBugCodes.contains(abbrev))					continue;				String description = bugCodeNode.getText();				BugCode bugCode = new BugCode(abbrev, description);				plugin.addBugCode(bugCode);				definedBugCodes.add(abbrev);			}		}				// Success!		// Assign to the plugin field, so getPlugin() can return the		// new Plugin object.		this.plugin = plugin;	}