Changeset 3815
- Timestamp:
- Oct 10, 2007, 2:58:22 PM (16 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/util/PluginInfo.java
r3760 r3815 134 134 135 135 //Get the info in base-plugins.xml file. 136 // An exception is thrown if the jar file's name is not the same as the xml-file suggest.136 //Nothing is done if the xml-file is missing. 137 137 is = jar.getInputStream(new JarEntry(xmlFile)); 138 URL installDtdURL = PluginInfo.class.getResource("/net/sf/basedb/core/dtd/" + dtdFile); 139 Element rootElement = XMLUtil.getValidatedXML(is , installDtdURL, null).getRootElement(); 140 String jarname = rootElement.getAttributeValue("jarname"); 141 ClassLoader jarLoader = JarClassLoader.newInstance(jarFile.getPath()); 142 if (!jarname.equalsIgnoreCase(jarFile.getName())) 138 if (is != null) 143 139 { 144 throw new InvalidDataException("Did not find the expected jar file: found '" + 145 jarFile.getName() + "' but expected: '" + jarname + "'"); 140 URL installDtdURL = PluginInfo.class.getResource("/net/sf/basedb/core/dtd/" + dtdFile); 141 Element rootElement = XMLUtil.getValidatedXML(is , installDtdURL, null).getRootElement(); 142 String jarname = rootElement.getAttributeValue("jarname"); 143 ClassLoader jarLoader = JarClassLoader.newInstance(jarFile.getPath()); 144 if (!jarname.equalsIgnoreCase(jarFile.getName())) 145 { 146 throw new InvalidDataException("Did not find the expected jar file: found '" + 147 jarFile.getName() + "' but expected: '" + jarname + "'"); 148 } 149 150 //Loop through each classelement in the xml file and create a PluginInfo-object 151 //if the class implements Plugin-interface. 152 List<Element> classElements = (List<Element>)rootElement.getChildren(); 153 for (Element classElement : classElements) 154 { 155 String classname = classElement.getAttributeValue("classname"); 156 String baseVersion = classElement.getChildText("minbaseversion"); 157 String configElement = classElement.getChildText("hasconfigurations"); 158 boolean hasConfigs = (configElement != null) && configElement.equals(hasConfigsValue); 159 160 Class c = jarLoader.loadClass(classname); 161 if (versionCompatible(baseVersion) && Plugin.class.isAssignableFrom(c)) 162 { 163 Plugin pl = (Plugin)c.newInstance(); 164 About about = pl.getAbout(); 165 List<PluginConfigInfo> configs = null; 166 167 //Get info about configurations if there are any. 168 if (hasConfigs) 169 { 170 InputStream confStream = null; 171 try 172 { 173 confStream = jar.getInputStream(new JarEntry("META-INF/" + configXMLFile)); 174 if (confStream != null) 175 { 176 URL configDtdURL = PluginInfo.class.getResource("/net/sf/basedb/core/dtd/" + configDtdFile); 177 Document configurationDoc = XMLUtil.getValidatedXML(confStream, configDtdURL, null); 178 configs = PluginConfigInfo.loadConfigurationsForPlugin(configurationDoc, classname); 179 } 180 } 181 catch (IOException ex) 182 {} 183 finally 184 { 185 if (confStream != null) confStream.close(); 186 } 187 } 188 pluginInfos.add(new PluginInfo(jarFile.getPath(), classname, baseVersion, about, configs)); 189 } 190 } 146 191 } 147 148 //Loop through each classelement in the xml file and create a PluginInfo-object149 //if the class implements Plugin-interface.150 List<Element> classElements = (List<Element>)rootElement.getChildren();151 for (Element classElement : classElements)152 {153 String classname = classElement.getAttributeValue("classname");154 String baseVersion = classElement.getChildText("minbaseversion");155 String configElement = classElement.getChildText("hasconfigurations");156 boolean hasConfigs = (configElement != null) && configElement.equals(hasConfigsValue);157 158 Class c = jarLoader.loadClass(classname);159 if (versionCompatible(baseVersion) && Plugin.class.isAssignableFrom(c))160 {161 Plugin pl = (Plugin)c.newInstance();162 About about = pl.getAbout();163 List<PluginConfigInfo> configs = null;164 165 //Get info about configurations if there are any.166 if (hasConfigs)167 {168 InputStream confStream = null;169 try170 {171 confStream = jar.getInputStream(new JarEntry("META-INF/" + configXMLFile));172 URL configDtdURL = PluginInfo.class.getResource("/net/sf/basedb/core/dtd/" + configDtdFile);173 Document configurationDoc = XMLUtil.getValidatedXML(confStream, configDtdURL, null);174 configs = PluginConfigInfo.loadConfigurationsForPlugin(configurationDoc, classname);175 }176 catch (IOException ex)177 {}178 finally179 {180 if (confStream != null) confStream.close();181 }182 }183 pluginInfos.add(new PluginInfo(jarFile.getPath(), classname, baseVersion, about, configs));184 }185 }186 192 } 187 193 catch(Throwable ex) 188 194 { 189 throw new BaseException( );195 throw new BaseException(ex); 190 196 } 191 197 finally -
trunk/src/test/TestExternalPluginInstaller.java
r3765 r3815 127 127 { 128 128 List<PluginConfigInfo> configurations = info.getConfigurations(); 129 write("--Configurations for this plugin that were found: " + configurations.size()); 129 if (configurations != null && configurations.size() > 0) 130 { 131 write("--Configurations for this plugin that were found: " + configurations.size()); 132 } 133 else 134 { 135 write ("--No configurations were found for this plugin"); 136 } 130 137 pluginIds.add(pluginid); 131 138 } … … 137 144 catch(Throwable th) 138 145 { 146 th.printStackTrace(); 139 147 if (pluginid > 0) 140 148 {
Note: See TracChangeset
for help on using the changeset viewer.