Changeset 3819


Ignore:
Timestamp:
Oct 12, 2007, 11:30:01 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

Merged log:trunk#3795:3815 into filedb branch

Location:
branches/filedb/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/filedb/src/core/net/sf/basedb/util/PluginInfo.java

    r3783 r3819  
    134134         
    135135      //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.
    137137      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)
    143139      {
    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        }
    146191      }
    147      
    148       //Loop through each classelement in the xml file and create a PluginInfo-object
    149       //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             try
    170             {
    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             finally
    179             {
    180               if (confStream != null) confStream.close();
    181             }
    182           }         
    183           pluginInfos.add(new PluginInfo(jarFile.getPath(), classname, baseVersion, about, configs));         
    184         }       
    185       }
    186192    }
    187193    catch(Throwable ex)
    188194    {
    189       throw new BaseException();
     195      throw new BaseException(ex);
    190196    }
    191197    finally
  • branches/filedb/src/test/TestExternalPluginInstaller.java

    r3783 r3819  
    127127        {         
    128128          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          }
    130137          pluginIds.add(pluginid);
    131138        }
     
    137144      catch(Throwable th)
    138145      {
     146        th.printStackTrace();
    139147        if (pluginid > 0)
    140148        {
Note: See TracChangeset for help on using the changeset viewer.