Changeset 6595


Ignore:
Timestamp:
Nov 14, 2014, 11:22:40 AM (8 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1889: Allow extensions to be installed in disabled state

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/src/docbook/developer/extensions.xml

    r6443 r6595  
    335335          new values in the extension's <sgmltag class="starttag">about</sgmltag>
    336336          tag.
     337        </para>
     338      </tip>
     339     
     340      <tip>
     341        <title>Start out in disabled state</title>
     342       
     343        <para>
     344          The <sgmltag class="starttag">about</sgmltag> tag can be used to specify
     345          that an extension should start out in disabled state. This can be useful
     346          if there are multiple variants of an extension or if some extensions
     347          are considered "advanced mode" and only should be enabled after some
     348          serious thinking. To use this feature, simply set <code>&lt;about disabled="1"&gt;</code>
     349          in the XML file.
    337350        </para>
    338351      </tip>
  • trunk/src/core/net/sf/basedb/util/extensions/manager/processor/RegisterExtensionsProcessor.java

    r6444 r6595  
    2828import java.util.List;
    2929
     30import net.sf.basedb.core.plugin.About;
    3031import net.sf.basedb.util.FileUtil;
     32import net.sf.basedb.util.Values;
     33import net.sf.basedb.util.extensions.ExtendedAbout;
    3134import net.sf.basedb.util.extensions.Extension;
    3235import net.sf.basedb.util.extensions.ExtensionPoint;
     
    4043import net.sf.basedb.util.extensions.manager.ProcessResults;
    4144import net.sf.basedb.util.extensions.manager.ExtensionsFile.WriteableExtensionsFile;
     45import net.sf.basedb.util.extensions.manager.Settings;
    4246import net.sf.basedb.util.extensions.manager.filter.ValidAndNewOrModifiedFilter;
    4347import net.sf.basedb.util.extensions.xml.XmlLoader;
     
    339343      {
    340344        wFile.open();
    341         int num = registerExtensions(data, registry, forceUpdate || xtFile.wasModified());
     345        int num = registerExtensions(data, manager, forceUpdate || xtFile.wasModified());
    342346        if (num > 0 && results != null)
    343347        {
     
    444448  }
    445449 
    446   private int registerExtensions(FileData data, Registry registry, boolean forceUpdate)
     450  private int registerExtensions(FileData data, ExtensionsManager manager, boolean forceUpdateOrModified)
    447451    throws IOException
    448452  {
    449453    int numRegistered = 0;
     454    Registry registry = manager.getRegistry();
     455    Settings settings = manager.getSettings();
    450456    for (Extension<?> ext : data.extensions)
    451457    {
    452       if (forceUpdate || !registry.extensionIsRegistered(ext.getId()))
     458      boolean isNew = !registry.extensionIsRegistered(ext.getId());
     459      if (forceUpdateOrModified || isNew)
    453460      {
    454461        log.debug("Registering extension: " + ext);
     
    459466        registry.registerExtension(ext, data.writeableFile.getExtensionsFile().getClassLoader());
    460467        numRegistered++;
     468        // Check disabled="*" attribute for new extensions
     469        // isNew==true also at server startup, so we must also check 'forceUpdate'
     470        // since it is set when installing (forceUpdateOrModified is also set for modified files)
     471        if (isNew && forceUpdate)
     472        {
     473          // Check if disabled="1" is set in <about>
     474          About about = ext.getAbout();
     475          if (about instanceof ExtendedAbout)
     476          {
     477            boolean disable = Values.getBoolean(((ExtendedAbout)ext.getAbout()).getAttribute("disabled"));
     478            settings.enableExtension(ext.getId(), !disable);
     479          }
     480        }
    461481      }
    462482    }
Note: See TracChangeset for help on using the changeset viewer.