Changeset 3733


Ignore:
Timestamp:
Sep 14, 2007, 2:08:01 PM (15 years ago)
Author:
Martin Svensson
Message:

References #364 The functionallity is more or less done. The internal class in PluginInfo? to read jars
needs to be refactored and moved to class JarClassLoader?, also some testing and documentation before this
can be closed.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/util/PluginConfigInfo.java

    r3704 r3733  
    5757  private String description;
    5858 
     59  /**
     60    Constructor to create a new instance with information for a plugin configuration.
     61      @param pluginClassName The class name of PluginDefinition this configuration belongs to,
     62        see{@link net.sf.basedb.core.PluginConfiguration#getPluginDefinition()}
     63      @param configName Name of the plugin configuration,
     64        see{@link net.sf.basedb.core.PluginConfiguration#getName()}
     65      @param descr Description about the configuration
     66        see {@link net.sf.basedb.core.PluginConfiguration#getDescription()}
     67   */
    5968  public PluginConfigInfo(String pluginClassName, String configName, String descr)
    6069  {
  • trunk/src/core/net/sf/basedb/util/PluginInfo.java

    r3706 r3733  
    8181    about each plugin class in the jar file.
    8282   */
    83   private static final String xmlFile = "base-plugins.xml";
    84  
    85  
     83  private static final String xmlFile = "META-INF/base-plugins.xml";
     84 
     85  /**
     86    The path in a jar-file to the file that holds
     87    configurations to import
     88   */
     89  private static final String configurationImportFile = "META-INF/base-configurations.xml";
    8690 
    8791  /**
     
    9195      @param minBaseVersion BASE version that the plugin at least requires
    9296      @param about Information about the plugin.
    93       @param configurations A list with configurations for this plugin.
     97      @param configs A list with configurations for this plugin.
    9498   */
    9599  public PluginInfo (String jarPath, String className, String minBaseVersion, About about, List<PluginConfigInfo> configs)
     
    108112    {@link net.sf.basedb.core.plugin.Plugin} will not be included in the list but already
    109113    installed plugins will.
    110     @param jarPath The jar file to load the plugin info from.
    111     @returns List with PluginInfo about the plugins that were found in jar file.
     114    @param jarFile The jar file to load the plugin info from.
     115    @return List with PluginInfo about the plugins that were found in jar file.
    112116      @throws JDOMException If any error loading the XML-document
    113117      @throws IOException If any error with file reading, eg when
     
    131135      //Get the info in base-plugins.xml file.
    132136      //An exception is thrown if the jar file's name is not the same as the xml-file suggest.
    133       is = jar.getInputStream(new JarEntry("META-INF/" + xmlFile));
     137      is = jar.getInputStream(new JarEntry(xmlFile));
    134138      URL installDtdURL = PluginInfo.class.getResource("/net/sf/basedb/core/dtd/" + dtdFile);
    135139      Element rootElement = XMLUtil.getValidatedXML(is , installDtdURL, null).getRootElement();
     
    196200    return pluginInfos;
    197201  }
    198   //TODO Methods to load new plugins, installed plugins and
    199   //plugins which class already exist but in another jar-file.
    200202 
    201203  /**
     
    235237  }
    236238 
     239  /**
     240    Gets information about the configurations that come together with the plugin in the jar.
     241      @return A list with information about each plugin configuration.
     242   */
    237243  public List<PluginConfigInfo> getConfigurations()
    238244  {
    239245    return configs;
     246  }
     247 
     248  /**
     249    The path inside a jar to the xml-file that holds
     250    the pluginconfigurations that can be imported.
     251      @return String format path.
     252   */
     253  public String getConfigurationsPath()
     254  {
     255    return configurationImportFile;
    240256  }
    241257 
  • trunk/www/admin/plugindefinitions/auto_install.jsp

    r3714 r3733  
    4040  import="net.sf.basedb.core.query.Expressions"
    4141  import="net.sf.basedb.util.FileUtil"
     42  import="net.sf.basedb.util.JarClassLoader"
    4243  import="net.sf.basedb.util.PluginInfo"
    4344  import="net.sf.basedb.util.PluginConfigInfo"
     
    6566  message.append("<b>").append("Class: ").append("</b>");
    6667  message.append(HTML.encodeTags(info.getClassName())).append("<br>");
     68 
     69  message.append("<b>").append("Version: ").append("</b>");
     70  message.append(HTML.encodeTags(info.getAbout().getVersion())).append("<br>");
    6771 
    6872  message.append("<b>").append("Works with: ").append("</b>");
     
    148152          {
    149153           
    150             if (cnf[i].value == 'yes')
     154            if (cnf[i].value == '1')
    151155            {
    152156              cnf.selectedIndex = i;
     
    167171          {
    168172           
    169             if (cnf[i].value == 'no')
     173            if (cnf[i].value == '0')
    170174            {
    171175              cnf.selectedIndex = i;
     
    183187      var pluginList = document.getElementById('setplugin.' + pluginId);
    184188      var pluginOption = pluginList[pluginList.selectedIndex].value;
    185       if ( (configOption == 'yes' && !pluginExists && pluginOption == '') ||
    186         (configOption == 'no' && pluginOption == 'plugin+confs') )
     189      if ( (configOption == '1' && !pluginExists && pluginOption == '') ||
     190        (configOption == '0' && pluginOption == 'plugin+confs') )
    187191      {
    188192        for (var i=0; i<pluginList.length;i++)
     
    239243              boolean hasConfigs = cnfInfos != null && !cnfInfos.isEmpty();
    240244              boolean classExists = true;
    241               boolean jarExists = true;
     245              boolean jarExists = false;
    242246              PluginDefinition pd = null;
    243247              try
     
    308312                  <input type="hidden" name="<%=info.getClassName()%>.jarExists" value="<%=jarExists%>">
    309313                  <base:icon image="<%=classExists&&!jarExists ? "itemexists.gif" : "" %>"
    310                     tooltip="Plugin from another jar-file but with the same class-name is installed"
     314                    tooltip="The plugin is loaded from a different jar-file"
    311315                  />
    312316                  <base:icon image="<%=classExists&&jarExists ? "hasvalues.gif" : "" %>"
     
    370374                      <select id="setconfig.<%=plugin%>.<%=cnf%>" name="<%=info.getClassName()%>.<%=cnfInfo.getName()%>"
    371375                        onChange="setPluginOnChange(<%=plugin%>, this, <%=classExists%>)">
    372                         <option value="no" title="Configuration will not be imported">no</option>
    373                         <option value="yes" title="Configuration will be imported">yes</option>
     376                        <option value="0" title="Configuration will not be imported">no</option>
     377                        <option value="1" title="Configuration will be imported">yes</option>
    374378                      </select>
    375379                      <base:icon image="<%=isDublicate ? "warning.gif" : ""%>" tooltip="Plugin already has a configuration with this name"/>
     
    386390          &nbsp;<i><base:icon image="warning.gif" /> = dublicate configuration</i><br>
    387391          &nbsp;<i><base:icon image="hasvalues.gif" /> = plugin already installed</i><br>
    388           &nbsp;<i><base:icon image="itemexists.gif" /> = installed using a different jar-file</i><br>
     392          &nbsp;<i><base:icon image="itemexists.gif" /> = exists in a different jar-file,<br>
     393            installing will change the jar path.</i><br>
    389394        </div>
    390395      </t:tab>
  • trunk/www/admin/plugindefinitions/index.jsp

    r3714 r3733  
    4949  import="net.sf.basedb.util.FileUtil"
    5050  import="net.sf.basedb.util.PluginInfo"
     51  import="net.sf.basedb.util.PluginConfigInfo"
    5152  import="net.sf.basedb.util.RemovableUtil"
    5253  import="net.sf.basedb.util.ShareableUtil"
     
    5859  import="net.sf.basedb.util.Values"
    5960  import="net.sf.basedb.clients.web.util.HTML"
     61  import="net.sf.basedb.plugins.PluginConfigurationImporter"
    6062  import="java.util.Enumeration"
    6163  import="java.util.Set"
     64  import="java.util.HashMap"
    6265  import="java.util.HashSet"
    6366  import="java.util.List"
     
    133136    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
    134137    cc.setId(0);
    135     if (Application.getNonCorePluginDirectory() == null)
    136     {
    137       redirect = editPage;
    138     }
    139     else
     138   
     139    //Go directly to manually installation if plugin directory isn't specified in base.config, plugin directory doesn't exists or
     140    //  no jar files were found in that directory.
     141    if (Application.getNonCorePluginDirectory() != null  &&  Application.getNonCorePluginDirectory().exists() &&
     142        !FileUtil.findFiles(Application.getNonCorePluginDirectory(), null, "jar", true ).isEmpty())
    140143    {
    141144      String pluginPath = Application.getNonCorePluginDirectory().getPath();
    142145      redirect = "select_installation_type.jsp?ID="+ID+"&plugin_path="+pluginPath;
    143146    }
     147    else
     148    {
     149      redirect = editPage;
     150    }
    144151  }
    145152  else if("InstallationType".equals(cmd))
     
    159166  else if("LoadPlugins".equals(cmd))
    160167  {
    161     //Loads plugins from jars that have been selected in auto_installer.jsp
     168    //Loads and install plugins that have been selected in auto_installer.jsp
    162169    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
    163170    dc = sc.newDbControl();
     
    165172    List<PluginInfo> pluginInfos = new ArrayList<PluginInfo>();
    166173    List<java.io.File> jarFiles = FileUtil.findFiles(pluginDir, null, "jar", true);
     174    StringBuilder notInstalledPlugins = new StringBuilder();
    167175   
     176    //Get information about all plugins in jar-files that were found.
    168177    for (java.io.File file : jarFiles)
    169178    {
    170179      pluginInfos.addAll(PluginInfo.loadFromJar(file));
    171180    }
     181    //Load selected plugins.
    172182    for (PluginInfo info : pluginInfos)
    173183    {
    174184      String selectedOption = request.getParameter(info.getJarPath() + "." + info.getClassName());
    175       if (selectedOption == null) selectedOption = "";
    176       StringBuilder installedPlugins = new StringBuilder();
    177       StringBuilder notInstalledPlugins = new StringBuilder();
     185      if (selectedOption == null) selectedOption = "";     
    178186      boolean classExists = Values.getBoolean(request.getParameter(info.getClassName()+".classExists"));
     187      boolean jarExists = Values.getBoolean(request.getParameter(info.getClassName()+".jarExists"));
    179188      int usePermissions = Values.getInt(request.getParameter("use_permissions"));
    180       if (selectedOption.equals("plugin") || selectedOption.equals("plugin+configurations"))
     189      if (selectedOption.equals("plugin") || selectedOption.equals("plugin+confs"))
    181190      {
     191        //The plugin doesn't exists
    182192        if (!classExists)
    183193        {
     
    189199          catch(BaseException bex)
    190200          {
    191             notInstalledPlugins.append("Could notinstall: " +
     201            notInstalledPlugins.append("Could not install: " +
    192202                info.getClassName() + " in jar:" + info.getJarPath() + "\n");
    193203          }
    194204          if (pd != null)
    195205          {
    196             installedPlugins.append("Installed :" + pd.getClassName() + "\n");
    197206            dc.saveItem(pd);
    198207            pd.setTrusted(Values.getBoolean(request.getParameter("trusted")));
     
    202211          }
    203212        }
     213        //The plugin exists but in a different jar, this will change the plugin's jarpath
     214        else if (classExists && !jarExists)
     215        {
     216          try
     217          {
     218            PluginDefinition pd = PluginDefinition.getByClassName(dc, info.getClassName());
     219            pd.loadPluginInformation(info.getJarPath(), info.getClassName(), usePermissions == 2);
     220          }
     221          catch(BaseException bex)
     222          {
     223            notInstalledPlugins.append("Could not update the jarpath for plugin: " + info.getClassName());
     224          }
     225        }
     226      }     
     227    }
     228    dc.commit();
     229   
     230    //Import selected configurations for each plugin in pluginInfos
     231    dc = sc.newDbControl();
     232    for (PluginInfo info : pluginInfos)
     233    {
     234      List<PluginConfigInfo> configInfos = info.getConfigurations();
     235      if (configInfos != null && configInfos.size() > 0)
     236      {
     237        HashMap<Integer, Boolean> configurations = new HashMap<Integer, Boolean>();
     238        int configurationNumber = 0;
     239        for (PluginConfigInfo cnfInfo : configInfos)
     240        {
     241          Boolean toImport = Values.getBoolean(request.getParameter(info.getClassName() + "." + cnfInfo.getName()));
     242          configurations.put(configurationNumber, toImport);
     243          configurationNumber++;
     244        }
     245        try
     246        {
     247          PluginConfigurationImporter configImporter = new PluginConfigurationImporter();
     248          configImporter.init(sc, null, null);
     249          configImporter.importPluginConfigurationsFromJar(info.getJarPath(), info.getConfigurationsPath(), configurations, false, true );
     250        }
     251        catch (Throwable th)
     252        {
     253          notInstalledPlugins.append("Could not import configurations: " + th.getMessage() + "\n");
     254        }
    204255      }
    205256    }
    206     dc.commit();
    207     cc.removeObject("item");
     257    message = notInstalledPlugins.length() > 0 ?
     258        notInstalledPlugins.toString() : "All selected plugins and configurations were installed";
    208259  }
    209260  else if ("UpdateItem".equals(cmd))
Note: See TracChangeset for help on using the changeset viewer.