Changeset 5606


Ignore:
Timestamp:
Apr 14, 2011, 9:45:23 AM (10 years ago)
Author:
Nicklas Nordborg
Message:

References #1593: Extension system for the core API

References #1592: Unified installation procedure for plug-ins, extensions and more...

Servlets are now processed and loaded by the extensions system. Moved handling of settings to the core. Removed classes that are no longer used.

Location:
trunk
Files:
2 added
3 deleted
16 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/ExtensionsControl.java

    r5605 r5606  
    3939import net.sf.basedb.core.Application;
    4040import net.sf.basedb.core.Client;
    41 import net.sf.basedb.core.Config;
    4241import net.sf.basedb.core.DbControl;
    4342import net.sf.basedb.core.Permission;
     
    5352import net.sf.basedb.util.extensions.Registry;
    5453import net.sf.basedb.util.extensions.events.EventType;
     54import net.sf.basedb.util.extensions.manager.ExtensionKey;
    5555import net.sf.basedb.util.extensions.manager.ExtensionsFile;
    5656import net.sf.basedb.util.extensions.manager.ExtensionsManager;
    5757import net.sf.basedb.util.extensions.manager.ObjectKey;
    5858import net.sf.basedb.util.extensions.manager.ProcessResults;
     59import net.sf.basedb.util.extensions.manager.Settings;
    5960import net.sf.basedb.util.extensions.manager.filter.DeletedFilter;
    6061import net.sf.basedb.util.extensions.manager.filter.ValidAndNewOrModifiedFilter;
    6162import net.sf.basedb.util.extensions.manager.processor.DeleteResourcesProcessor;
    6263import net.sf.basedb.util.extensions.manager.processor.ExtractResourcesProcessor;
    63 import net.sf.basedb.util.extensions.manager.processor.MarkAsProcessedProcessor;
    6464import net.sf.basedb.util.extensions.manager.processor.UnregisterExtensionsProcessor;
     65import net.sf.basedb.util.extensions.xml.ExtensionPointFilter;
    6566
    6667/**
     
    118119  private static boolean initialised = false;
    119120 
    120   // The registry that holds information about installed extensions
     121  // The main extensions manager, registry and settings
     122  private static ExtensionsManager manager;
    121123  private static Registry registry;
    122  
    123   // The main extensions manager
    124   private static ExtensionsManager manager;
    125  
    126   // The directory where extension files are located
    127   //private static ExtensionsDirectory extensionsDir;
    128  
    129   // Settings
    130124  private static Settings settings;
    131125 
     
    144138    if (initialised) return;
    145139    log.info("Initialising extensions controller");
    146     //extensionsDir = directory;
    147140    servletContext = context;
    148141   
    149     // Create registry
     142    // Hook into core manager and registry
    150143    manager = Application.getExtensionsManager();
    151     registry = Application.getExtensionsManager().getRegistry();
     144    registry = manager.getRegistry();
     145    settings = manager.getSettings();
    152146   
    153147    // Register some extension points programmatically. This
     
    157151    EditUtil.registerExtensionPoints(registry); // TabControls
    158152   
     153    // Add default web-client extension points and extensions
    159154    manager.addURI(URI.create(ExtensionsControl.class.getResource("/web-extensions.xml").toString()));
    160155
    161     // Load settings
    162     File settingsFile = new File(Config.getConfigDirectory(), "settings.xml");
    163     settings = new Settings(settingsFile);
    164     //extensionsDir.addIgnore(settingsFile);
    165    
    166156    // Install extensions
    167     //XmlLoader loader = new XmlLoader();
    168157    lastScanResults = new ProcessResults(false, false);
    169158   
    170     // Filter that only load web extension points
    171     //loader.setFilter(new ExtensionPointFilter("net\\.sf\\.basedb\\.clients\\.web\\..*"));
    172 
    173     /*
    174     final VariableConverter variableConverter = new VariableConverter();
    175     variableConverter.setVariable("ROOT", servletContext.getContextPath());
    176     variableConverter.setVariable("HOME", null);
    177     variableConverter.setVariable("SERVLET_HOME", null);   
    178     final PathConverter pathConverter = new PathConverter(servletContext.getContextPath(), null);
    179 
    180     loader.addValueConverter(variableConverter);
    181     loader.addValueConverter(pathConverter);
    182     */
    183 
    184     /*
    185     manager.processFiles(new RegisterExtensionsProcessor(loader, false, lastScanResults)
    186     {
    187 
    188       @Override
    189       public void processFile(ExtensionsManager manager,
    190           WriteableExtensionsFile xtFile)
    191       {
    192         String homePath = servletContext.getContextPath() + RESOURCES_URL + "/" + xtFile.getExtensionsFile().getName();
    193         //String servletHomePath = getServletsUrl(extFile);
    194         variableConverter.setVariable("HOME", homePath);
    195         //variableConverter.setVariable("SERVLET_HOME", servletHomePath);
    196         pathConverter.setHome(homePath);
    197 
    198         super.processFile(manager, xtFile);
    199       }
    200     });
    201     */
    202 //    manager.processFiles(new ExtractResourcesProcessor(new java.io.File(servletContext.getRealPath(RESOURCES_URL)), false, Pattern.compile("resources/(.*)"), "$1", lastScanResults));
    203     //lastScanResults = new ScanResults(true, false);
    204     /*
    205     lastScanResults = extensionsDir.installAndUpdateExtensions(registry,
    206       servletContext, false, false);
    207     */
    208    
     159    // Initial scan
    209160    scan(true, false);
    210 
    211161    initialised = true;
    212162   
    213     Services.init(registry, settings);
     163    Services.init();
    214164    log.info("Extensions controller initialised successfully");
    215165  }
     
    225175    Services.close();
    226176    registry = null;
    227     //extensionsDir = null;
    228     settings = null;
    229177    servletContext = null;
    230178    lastScanResults = null;
     
    234182 
    235183 
    236   private static synchronized ProcessResults scan(boolean initialScan, boolean forceUpdate)
     184  private static ProcessResults scan(boolean initialScan, boolean forceUpdate)
    237185  {
    238186    String rootPath = servletContext.getContextPath();
     
    251199    int numRegistered = 0;
    252200   
    253     if (!initialScan)
    254     {
    255       // 1. Process files that has been deleted
    256       DeletedFilter deleted = new DeletedFilter();
     201    synchronized (manager)
     202    {
     203      if (!initialScan)
     204      {
     205        // 1. Process files that has been deleted
     206        DeletedFilter deleted = new DeletedFilter();
     207       
     208        // 1a. Remove resources extracted from JAR files
     209        DeleteResourcesProcessor deleteResources = new DeleteResourcesProcessor(resourceDir, results);
     210        manager.processFiles(deleteResources, deleted);
     211       
     212        // 1b. Unregister all extensions from deleted files
     213        UnregisterExtensionsProcessor unregister = new UnregisterExtensionsProcessor(results);
     214        manager.processFiles(unregister, deleted);
     215        numUnregistered = unregister.getNumUnregistered();
     216      }
    257217     
    258       // 1a. Remove resources extracted from JAR files
    259       DeleteResourcesProcessor deleteResources = new DeleteResourcesProcessor(resourceDir, results);
    260       manager.processFiles(deleteResources, deleted);
     218      // 2. Update the manager with new and modified files
     219      manager.scanForNewAndUpdated();
     220      numNewFiles = manager.getNumNew();
     221      numModifiedFiles = manager.getNumModified();
     222      numDeletedFiles = manager.getNumDeleted();
    261223     
    262       // 1b. Unregister all extensions from deleted files
    263       UnregisterExtensionsProcessor unregister = new UnregisterExtensionsProcessor(results);
    264       manager.processFiles(unregister, deleted);
    265       numUnregistered = unregister.getNumUnregistered();
    266     }
    267    
    268     // 2. Update the manager with new and modified files
    269     manager.scanForNewAndUpdated();
    270     numNewFiles = manager.getNumNew();
    271     numModifiedFiles = manager.getNumModified();
    272     numDeletedFiles = manager.getNumDeleted();
    273    
    274     if (initialScan || numNewFiles > 0 || numModifiedFiles > 0 || forceUpdate)
    275     {
    276       // Process files that are valid and new/updated (unless forceUpdate=true)
    277       ValidAndNewOrModifiedFilter valid = new ValidAndNewOrModifiedFilter(initialScan || forceUpdate);
     224      if (initialScan || numNewFiles > 0 || numModifiedFiles > 0 || forceUpdate)
     225      {
     226        // Process files that are valid and new/updated (unless forceUpdate=true)
     227        ValidAndNewOrModifiedFilter valid = new ValidAndNewOrModifiedFilter(initialScan || forceUpdate);
     228       
     229        // 3. Load extension definitions
     230        WebClientRegisterExtensionsProcessor registerExtensions =
     231          new WebClientRegisterExtensionsProcessor(rootPath, rootPath + RESOURCES_URL, rootPath + SERVLET_URL, results);
     232        registerExtensions.setForceUpdate(forceUpdate);
     233        if (initialScan)
     234        {
     235          // Filter that only load web extension points
     236          registerExtensions.getXmlLoader().setFilter(new ExtensionPointFilter("net\\.sf\\.basedb\\.clients\\.web\\..*"));
     237        }
     238        manager.processFiles(registerExtensions, valid);
     239
     240        // 4. Extract web resources
     241        ExtractResourcesProcessor extractResources = new ExtractResourcesProcessor(resourceDir, Pattern.compile("resources/(.*)"), "$1", results);
     242        extractResources.setForceOverwrite(forceUpdate);
     243        manager.processFiles(extractResources, valid);
     244
     245        // 5. Servlets
     246        LoadServletsProcessor loadServlets = new LoadServletsProcessor(servletContext, results);
     247        manager.processFiles(loadServlets, valid);
     248       
     249        // 6. Actual registration of all extensions
     250        registerExtensions.finalizeRegistration(manager);
     251        numRegistered = registerExtensions.getNumRegistered();
     252      }
    278253     
    279       // 3. Load extension definitions
    280       WebClientRegisterExtensionsProcessor registerExtensions =
    281         new WebClientRegisterExtensionsProcessor(rootPath, rootPath + RESOURCES_URL, rootPath + SERVLET_URL, results);
    282       registerExtensions.setForceUpdate(forceUpdate);
    283       manager.processFiles(registerExtensions, valid);
    284 
    285       // 4. Extract web resources
    286       ExtractResourcesProcessor extractResources = new ExtractResourcesProcessor(resourceDir, Pattern.compile("resources/(.*)"), "$1", results);
    287       extractResources.setForceOverwrite(forceUpdate);
    288       manager.processFiles(extractResources, valid);
    289 
    290       // 5. Servlets
    291      
    292       // 6. Actual registration of all extensions
    293       registerExtensions.finalizeRegistration(manager);
    294       numRegistered = registerExtensions.getNumRegistered();
    295     }
    296    
    297     // Reset the 'last modifed' status of all files and generated summary per file
    298     manager.processFiles(new SetFileStatusProcessor(results));
    299     results.setEnded();
     254      // Reset the 'last modifed' status of all files and generated summary per file
     255      manager.processFiles(new SetFileStatusProcessor(results));
     256      results.setEnded();
     257    }
    300258   
    301259    // Generate summary message, etc.
     
    422380  public static String getHomeUrl(String extensionId)
    423381  {
    424     return null;
    425     //return file == null ? null : extensionsDir.getResourcesUrl(file);
     382    ExtensionsFile xtFile = manager.getFileByObjectKey(new ExtensionKey(extensionId));
     383    return xtFile == null ? null : servletContext.getContextPath() + RESOURCES_URL + "/" + xtFile.getName();
    426384  }
    427385 
    428386  /**
    429387    Get the base URL for servlets in the extension with the given ID. The
    430     URL is a local absolute UTL, eg. it includes the full path but not the
     388    URL is a local absolute URL, eg. it includes the full path but not the
    431389    protocol, server or port. The URL is usually something like:
    432390    <p>
     
    446404  public static String getServletUrl(String extensionId, String servletName)
    447405  {
    448     //ExtensionsFile file = extensionsDir.getFileByExtensionId(extensionId);
     406    ExtensionsFile xtFile = manager.getFileByObjectKey(new ExtensionKey(extensionId));
    449407    String servletPath = null;
    450     /*
    451     if (file != null)
    452     {
    453       servletPath = extensionsDir.getServletsUrl(file) + "/" + servletName;
    454     }
    455     */
     408    if (xtFile != null)
     409    {
     410      servletPath = servletContext.getContextPath() + SERVLET_URL + "/" + xtFile.getName() + "/" + servletName;
     411    }
    456412    return servletPath;
    457413  }
     
    521477  /**
    522478    Get the results of the last scan (manual or automatic).
    523     @return A {@link ScanResults} object, or null if no scan
     479    @return A {@link ProcessResults} object, or null if no scan
    524480      has taken place
    525481  */
     
    701657 
    702658  /**
    703     Get information about the file a given extension or extension
    704     point is defined in.
    705     @param extensionId The ID of an extension or extension point
    706     @return Information about the file the extension is defined in,
    707       or null if no extension with the given ID is found
     659    Find out which file the given object is defined in.
     660   
     661    @param key An object key
     662    @return Information about the file, or null if
     663      the object can't be found
    708664  */
    709665  public ExtensionsFile getFileByObjectKey(ObjectKey key)
     
    716672    If no file with the given name is found or if that file isn't an
    717673    extensions file, nothing is done.
    718     @param filename The filename which contains the extensions
     674    @param fileuri The fileuri which contains the extensions
    719675    @param enable TRUE to enable, FALSE to disable
    720676  */
    721   public void enableAllInFile(String filename, boolean enable)
    722   {
    723     checkPermission(Permission.WRITE, "File[" + filename + "]");
    724     /*
    725     ExtensionsFile file = null; //getFile(filename);
     677  public void enableAllInFile(String fileuri, boolean enable)
     678  {
     679    checkPermission(Permission.WRITE, "File[" + fileuri + "]");
     680
     681    ExtensionsFile file = getFile(fileuri);
    726682    if (file == null)
    727683    {
    728       log.warn("File '" + filename + "' is not an extensions file");
     684      log.warn("File '" + fileuri + "' is not an extensions file");
    729685      return;
    730686    }
    731687   
    732     Iterator<ExtensionPoint<?>> itp = file.getExtensionPoints();
    733     while (itp.hasNext())
    734     {
    735       ExtensionPoint<?> ep = itp.next();
     688    for (ExtensionPoint ep : file.getObjectsOfClass(ExtensionPoint.class))
     689    {
    736690      if (!enable) registry.handleEvent(BEFORE_DISABLE, ep, null);
    737691      settings.enableExtensionPoint(ep.getId(), enable);
     
    739693    }
    740694
    741     Iterator<Extension<?>> itx = file.getExtensions();
    742     while (itx.hasNext())
    743     {
    744       Extension<?> ext = itx.next();
     695    for (Extension ext : file.getObjectsOfClass(Extension.class))
     696    {
    745697      ExtensionPoint ep = getExtensionPoint(ext.getExtends());
    746698      if (!enable) registry.handleEvent(BEFORE_DISABLE, ep, ext);
     
    748700      if (enable) registry.handleEvent(AFTER_ENABLE, ep, ext);
    749701    }
    750     */
    751702  }
    752703 
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/service/Services.java

    r4618 r5606  
    2323
    2424import net.sf.basedb.clients.web.extensions.ExtensionsControl;
    25 import net.sf.basedb.clients.web.extensions.Settings;
     25import net.sf.basedb.core.Application;
    2626import net.sf.basedb.util.extensions.Extension;
    2727import net.sf.basedb.util.extensions.ExtensionsFilter;
    2828import net.sf.basedb.util.extensions.ExtensionsInvoker;
    29 import net.sf.basedb.util.extensions.Registry;
    3029import net.sf.basedb.util.extensions.SingleExtensionFilter;
    3130import net.sf.basedb.util.extensions.events.ExtensionPointEventFilter;
     31import net.sf.basedb.util.extensions.manager.ExtensionsManager;
    3232
    3333/**
     
    4747 
    4848  private static boolean initialised;
    49   private static Settings settings;
    5049 
    5150  /**
     
    5352    is started up.
    5453  */
    55   public static synchronized void init(Registry registry, Settings s)
     54  public static synchronized void init()
    5655  {
    5756    if (initialised) return;
    5857    log.info("Initialising services");
    59     settings = s;
     58    ExtensionsManager manager = Application.getExtensionsManager();
    6059    ExtensionsInvoker<ServiceControllerAction> invoker = getInvoker(null);
    6160    invoker.render(new StartServiceRenderer());
    62     registry.registerEventHandler(
    63         new ServicesEventHandler(settings),
     61    manager.getRegistry().registerEventHandler(
     62        new ServicesEventHandler(),
    6463        new ExtensionPointEventFilter(EXTENSION_POINT_ID));
    6564    log.info("Initialising services done");
     
    7776    ExtensionsInvoker<ServiceControllerAction> invoker = getInvoker(null);
    7877    invoker.render(new StopServiceRenderer());
    79     settings = null;
    8078    initialised = false;
    8179    log.info("Closing all services done");
     
    114112  {
    115113    ExtensionsFilter filter = extension == null ?
    116         settings : new SingleExtensionFilter(extension.getId());
     114        Application.getExtensionsManager().getSettings() : new SingleExtensionFilter(extension.getId());
    117115    ExtensionsInvoker<?> invoker = ExtensionsControl.useExtensions(null, filter, EXTENSION_POINT_ID);
    118116    invoker.setClearErrors(true);
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/service/ServicesEventHandler.java

    r4512 r5606  
    2323
    2424import net.sf.basedb.clients.web.extensions.ExtensionsControl;
    25 import net.sf.basedb.clients.web.extensions.Settings;
     25import net.sf.basedb.core.Application;
    2626import net.sf.basedb.util.extensions.Extension;
    2727import net.sf.basedb.util.extensions.ExtensionPoint;
    2828import net.sf.basedb.util.extensions.events.EventHandler;
    2929import net.sf.basedb.util.extensions.events.EventType;
     30import net.sf.basedb.util.extensions.manager.Settings;
    3031
    3132/**
     
    4445    org.apache.log4j.LogManager.getLogger("net.sf.basedb.clients.web.extensions.service.ServicesEventHandler");
    4546
    46   private Settings settings;
     47  private final Settings settings;
    4748 
    48   public ServicesEventHandler(Settings settings)
     49  public ServicesEventHandler()
    4950  {
    50     this.settings = settings;
     51    this.settings = Application.getExtensionsManager().getSettings();
    5152  }
    5253 
  • trunk/src/clients/web/net/sf/basedb/clients/web/servlet/ExtensionsServlet.java

    r5601 r5606  
    2121package net.sf.basedb.clients.web.servlet;
    2222
    23 import java.io.File;
    2423import java.io.IOException;
    2524import java.util.regex.Matcher;
     
    3433
    3534import net.sf.basedb.clients.web.extensions.ExtensionsControl;
    36 import net.sf.basedb.clients.web.extensions.ExtensionsDirectory;
    37 import net.sf.basedb.clients.web.extensions.ExtensionsFile;
    3835import net.sf.basedb.clients.web.extensions.RequestWrapper;
    3936import net.sf.basedb.clients.web.extensions.ServletWrapper;
     37import net.sf.basedb.clients.web.extensions.ServletWrapperKey;
    4038import net.sf.basedb.util.Values;
     39import net.sf.basedb.util.extensions.manager.ExtensionsFile;
    4140
    4241/**
     
    7473    ServletConfig cfg = getServletConfig();
    7574    ServletContext context = cfg.getServletContext();
    76     /*
    77     File extensionsDir = new File(context.getRealPath(ExtensionsControl.EXTENSIONS_URL));
    78     File resourcesDir = new File(context.getRealPath(ExtensionsControl.RESOURCES_URL));
    79     String rootUrl = context.getContextPath();
    80    
    81     ExtensionsDirectory extensions = new ExtensionsDirectory(
    82         extensionsDir, resourcesDir, rootUrl, rootUrl + ExtensionsControl.RESOURCES_URL);
    83     */
    8475    ExtensionsControl.init(context);
    8576  }
     
    134125
    135126    ExtensionsControl ec = ExtensionsControl.get(null);
    136     ExtensionsFile file = null; //ec.getFile(jarName);
     127    ServletWrapperKey servletKey = new ServletWrapperKey(jarName, servletName);
     128    ExtensionsFile file = ec.getFileByObjectKey(servletKey);
    137129    if (file == null)
    138130    {
     
    146138    }
    147139 
    148     ServletWrapper wrapper = file.getServlet(servletName);
     140    ServletWrapper wrapper = file.getObjectForKey(servletKey);
    149141    if (wrapper == null)
    150142    {
  • trunk/src/core/net/sf/basedb/core/Application.java

    r5605 r5606  
    536536        // TODO -- should this be moved to a utility class? Probably...
    537537        Registry xtRegistry = new Registry();
    538         xtManager = new ExtensionsManager(xtRegistry);
     538        java.io.File xtSettings = new java.io.File(pluginsDirectory, "settings.xml");
     539        xtManager = new ExtensionsManager(xtRegistry, xtSettings);
    539540       
    540541        // Add core extension points and extensions
  • trunk/src/core/net/sf/basedb/util/extensions/Registry.java

    r5599 r5606  
    5252  @version 2.7
    5353  @base.modified $Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $
    54   @see net.sf.basedb.clients.web.extensions.ExtensionsDirectory
    5554*/
    5655public class Registry
  • trunk/src/core/net/sf/basedb/util/extensions/manager/ExtensionKey.java

    r5602 r5606  
    6060 
    6161  /*
     62    From the ObjectKey interface
     63    ----------------------------
     64  */
     65  @Override
     66  public String toDescription()
     67  {
     68    return "Extension '" + id + "'";
     69  }
     70  // -----------------------------
     71 
     72  /*
    6273    From the Object class
    6374    ---------------------
  • trunk/src/core/net/sf/basedb/util/extensions/manager/ExtensionPointKey.java

    r5602 r5606  
    6060 
    6161  /*
     62    From the ObjectKey interface
     63    ----------------------------
     64  */
     65  @Override
     66  public String toDescription()
     67  {
     68    return "Extension point '" + id + "'";
     69  }
     70  // -----------------------------
     71
     72  /*
    6273    From the Object class
    6374    ---------------------
  • trunk/src/core/net/sf/basedb/util/extensions/manager/ExtensionsFile.java

    r5605 r5606  
    689689    {
    690690      checkClosed();
     691      xtFile.manager.registerObject(key, this.xtFile);
    691692      xtFile.allObjects.put(key, obj);
    692       xtFile.manager.registerObject(key, this.xtFile);
    693693    }
    694694   
     
    703703      checkClosed();
    704704      xtFile.allObjects.remove(key);
    705       xtFile.manager.unregisterObject(key);
     705      xtFile.manager.unregisterObject(key, this.xtFile);
    706706    }
    707707   
  • trunk/src/core/net/sf/basedb/util/extensions/manager/ExtensionsManager.java

    r5605 r5606  
    3636import java.util.TreeMap;
    3737
     38import net.sf.basedb.core.ItemAlreadyExistsException;
    3839import net.sf.basedb.util.RegexpFileFilter;
    3940import net.sf.basedb.util.extensions.Registry;
     
    5657    org.apache.log4j.LogManager.getLogger("net.sf.basedb.util.extensions.manager.ExtensionsManager");
    5758
     59  // Main registry for extensions
    5860  private final Registry registry;
    59 
     61  // Settings file
     62  private final Settings settings;
    6063  // Manually added ignore files
    6164  private final Set<File> ignore;
     
    6568  private final Map<URI, ExtensionsFile> xtFiles;
    6669  // Map objects to the file they are defined in. The key is a unique object id.
    67   private final Map<ObjectKey, ExtensionsFile> installedObjects;
     70  private final Map<ObjectKey<?>, ExtensionsFile> installedObjects;
    6871 
    6972  private int numNew;
     
    7881    @param registry
    7982  */
    80   public ExtensionsManager(Registry registry)
     83  public ExtensionsManager(Registry registry, File settingsFile)
    8184  {
    8285    this.registry = registry;
     86    this.settings = new Settings(this, settingsFile);
    8387    this.ignore = new HashSet<File>();
    8488    this.directories = new HashSet<File>();
    8589    this.xtFiles = new TreeMap<URI, ExtensionsFile>(new JarFirstURIComparator());
    86     this.installedObjects = new HashMap<ObjectKey, ExtensionsFile>();
     90    this.installedObjects = new HashMap<ObjectKey<?>, ExtensionsFile>();
     91    addIgnore(settingsFile);
    8792  }
    8893 
     
    9499  {
    95100    return registry;
     101  }
     102 
     103  /**
     104    Get the settings for the extension manager.
     105  */
     106  public Settings getSettings()
     107  {
     108    return settings;
    96109  }
    97110 
     
    103116    @see #removeIgnore(File)
    104117  */
    105   public void addIgnore(File file)
     118  public synchronized void addIgnore(File file)
    106119  {
    107120    if (file == null) return;
     
    114127    @see #addIgnore(File)
    115128  */
    116   public void removeIgnore(File file)
     129  public synchronized void removeIgnore(File file)
    117130  {
    118131    if (file == null) return;
     
    130143      not previously known to the manager
    131144  */
    132   public int addDirectory(File dir)
     145  public synchronized int addDirectory(File dir)
    133146  {
    134147    if (dir == null) throw new NullPointerException("dir");
     
    147160    @return The extension file object representing the added file
    148161  */
    149   public ExtensionsFile addFile(File file)
     162  public synchronized ExtensionsFile addFile(File file)
    150163  {
    151164    if (file == null) throw new NullPointerException("file");
     
    168181    @return The extension file object representing the added uri
    169182  */
    170   public ExtensionsFile addURI(URI uri)
     183  public synchronized ExtensionsFile addURI(URI uri)
    171184  {
    172185    if (uri == null) throw new NullPointerException("uri");
     
    175188    return xtFile;
    176189  }
    177 
    178   /*
    179   public void removeFile(ExtensionsFile xtFile)
    180   {
    181     xtFiles.remove(xtFile.getURI());
    182     //ignore.remove(xtFile);
    183     Iterator<ExtensionsFile> it = installedObjects.values().iterator();
    184     while (it.hasNext())
    185     {
    186       if (it.next().equals(xtFile)) it.remove();
    187     }
    188   }
    189   */
    190190 
    191191  private void addExtensionsFile(ExtensionsFile xtFile)
     
    206206    @return The number of new + modified files that was found
    207207  */
    208   public int scanForNewAndUpdated()
     208  public synchronized int scanForNewAndUpdated()
    209209  {
    210210    numNew = 0;
     
    371371      or null if no object is found for the given key
    372372  */
    373   public ExtensionsFile getFileByObjectKey(ObjectKey key)
     373  public ExtensionsFile getFileByObjectKey(ObjectKey<?> key)
    374374  {
    375375    return installedObjects.get(key);
     
    380380   
    381381    @param key The object key
    382     @param xtFile The extensions file
    383   */
    384   void registerObject(ObjectKey key, ExtensionsFile xtFile)
    385   {
    386     installedObjects.put(key, xtFile);
    387   }
    388  
    389   /**
    390     Unregister an object.
     382    @param xtFile The extensions file the object is defined in
     383  */
     384  void registerObject(ObjectKey<?> key, ExtensionsFile xtFile)
     385  {
     386    ExtensionsFile xtOther = installedObjects.get(key);
     387    if (xtOther == null)
     388    {
     389      installedObjects.put(key, xtFile);
     390    }
     391    else
     392    {
     393      throw new ItemAlreadyExistsException(key.toDescription() + " is defined in '" + xtOther.getName() + "'");
     394    }
     395  }
     396 
     397  /**
     398    Unregister an object. The given extensions file must match
     399    be equal to the one that registered the object, otherwise
     400    the unregistration is ignored.
     401   
    391402    @param key The object key
    392   */
    393   void unregisterObject(ObjectKey key)
    394   {
    395     installedObjects.remove(key);
     403    @param xtFile The extensions file the object is defined in
     404  */
     405  void unregisterObject(ObjectKey<?> key, ExtensionsFile xtFile)
     406  {
     407    if (xtFile.equals(installedObjects.get(key)))
     408    {
     409      installedObjects.remove(key);
     410    }
    396411  }
    397412 
     
    408423  }
    409424 
     425  /**
     426    Process all know file with the given processer.
     427    @param processor A processor implementation, null is not allowed
     428  */
    410429  public void processFiles(ExtensionsFileProcessor processor)
    411430  {
     
    420439      limit which files are sent to the processor
    421440  */
    422   public void processFiles(ExtensionsFileProcessor processor, Filter<ExtensionsFile> filter)
     441  public synchronized void processFiles(ExtensionsFileProcessor processor, Filter<ExtensionsFile> filter)
    423442  {
    424443    if (processor == null) throw new NullPointerException("processor");
     
    479498  }
    480499 
     500  /**
     501    Compare URI:s so that 'jar:' scheme always are listed first. This means
     502    that the core defintion files are always displayed before any external
     503    extensions.
     504  */
    481505  public static class JarFirstURIComparator
    482506    implements Comparator<URI>
  • trunk/src/core/net/sf/basedb/util/extensions/manager/FactoryParametersKey.java

    r5602 r5606  
    5858 
    5959  /*
     60    From the ObjectKey interface
     61    ----------------------------
     62  */
     63  @Override
     64  public String toDescription()
     65  {
     66    return "Factory '" + factory + "'";
     67  }
     68  // -----------------------------
     69
     70 
     71  /*
    6072    From the Object class
    6173    ---------------------
  • trunk/src/core/net/sf/basedb/util/extensions/manager/ObjectKey.java

    r5602 r5606  
    3232  <p>
    3333 
    34   This interface doesn't have any methods. It is up to the
    35   actual implementations to decide what actually makes up
    36   a key that can be used to identify an object. Implementors
     34  It is up to the actual implementations to decide what actually
     35  makes up a key that can be used to identify an object. Implementors
    3736  of this interface should implement <code>equals()</code> and
    3837  <code>hashCode()</code> methods to only match with it's
     
    4746*/
    4847public interface ObjectKey<O>
    49 {}
     48{
     49  /**
     50    Get a string description of the key that is suitable for use
     51    in (error) messages to users.
     52  */
     53  public String toDescription();
     54}
  • trunk/src/core/net/sf/basedb/util/extensions/manager/Settings.java

    r5605 r5606  
    2020  along with BASE. If not, see <http://www.gnu.org/licenses/>.
    2121*/
    22 package net.sf.basedb.clients.web.extensions;
     22package net.sf.basedb.util.extensions.manager;
    2323
    2424import java.io.BufferedInputStream;
     
    4040/**
    4141  Class for keeping settings for the extensions system. Settings
    42   are kept in the file <code>WEB-INF/extensions/settings.xml</code>.
     42  are kept in the <code>settings.xml</code> file in the plug-ins
     43  directory.
    4344  <p>
    4445
     
    6465{
    6566 
    66   //private static final String AUTO_INSTALL = "auto-install";
    67 
    68   //private final ExtensionsDirectory directory;
    6967  private final File file;
     68  private final ExtensionsManager manager;
    7069  private boolean hasChanged;
    7170  private Presets presets;
     
    7877    it will be created if {@link #save()} is called. The settings file
    7978    must be an XML file that can be read by the {@link Presets} class.
    80     @param file The file to load/save settings in
     79    @param file The file to load/save settings in. If null, settings only are
     80      kept in memory and are lost when the server is shutdown.
    8181  */
    82   public Settings(File file)
     82  Settings(ExtensionsManager manager, File file)
    8383  {
    84 //    this.directory = directory;
     84    this.manager = manager;
    8585    this.file = file;
    8686    this.presets = new Presets();
    87     if (file.exists())
     87    if (file != null && file.isFile())
    8888    {
    8989      try
     
    112112  {
    113113    if (extensionPoint == null) return false;
    114     //ExtensionsFile extFile = directory.getFileByExtensionId(extensionPoint.getId());
    115     //if (extFile != null && (extFile.hasError() || !extFile.isValid())) return false;
     114    ExtensionsFile xtFile = manager.getFileByObjectKey(new ExtensionPointKey(extensionPoint));
     115    if (xtFile != null && (xtFile.hasError() || !xtFile.isValid())) return false;
    116116    return disabledExtensionPoints.getSetting(extensionPoint.getId()) == null;
    117117  }
     
    121121  {
    122122    if (extension == null) return false;
    123     //ExtensionsFile extFile = directory.getFileByExtensionId(extension.getId());
    124     //if (extFile != null && (extFile.hasError() || !extFile.isValid())) return false;
     123    ExtensionsFile xtFile = manager.getFileByObjectKey(new ExtensionKey(extension));
     124    if (xtFile != null && (xtFile.hasError() || !xtFile.isValid())) return false;
    125125    return disabledExtensions.getSetting(extension.getId()) == null;
    126126  }
     
    155155  public synchronized void save()
    156156  {
    157     if (!hasChanged) return;
     157    if (!hasChanged || file == null) return;
    158158    try
    159159    {
     
    166166      throw new RuntimeException(ex);
    167167    }
    168     hasChanged = true;
     168    hasChanged = false;
    169169  }
    170170}
  • trunk/src/core/net/sf/basedb/util/extensions/manager/processor/RegisterExtensionsProcessor.java

    r5605 r5606  
    2727
    2828import net.sf.basedb.util.FileUtil;
    29 import net.sf.basedb.util.extensions.Action;
    3029import net.sf.basedb.util.extensions.Extension;
    3130import net.sf.basedb.util.extensions.ExtensionPoint;
     
    122121      FileData data = new FileData();
    123122      data.writeableFile = wFile;
    124       data.extensionPoints = new ArrayList<ExtensionPoint>(loader.getExtensionPoints());
    125       data.extensions = new ArrayList<Extension>(loader.getExtensions());
     123      data.extensionPoints = new ArrayList<ExtensionPoint<?>>(loader.getExtensionPoints());
     124      data.extensions = new ArrayList<Extension<?>>(loader.getExtensions());
    126125      numFiles++;
    127126      log.info("Loaded " + data.extensionPoints.size() + "/" + data.extensions.size() +
     
    309308        {
    310309          results.addErrorMessage(xtFile,
    311             "Could not register extension points: " + ex.getMessage());
     310            "Could not register extension point(s): " + ex.getMessage());
    312311        }
    313312        log.error("Could not register extension points from file: " + xtFile, ex);
     
    350349        {
    351350          results.addErrorMessage(xtFile,
    352             "Could not register extension points: " + ex.getMessage());
     351            "Could not register extension(s): " + ex.getMessage());
    353352        }
    354353        log.error("Could not register extension points from file: " + xtFile, ex);
     
    402401  {
    403402    int numRegistered = 0;
    404     for (ExtensionPoint<Action> ep : data.extensionPoints)
     403    for (ExtensionPoint<?> ep : data.extensionPoints)
    405404    {
    406405      if (forceUpdate || !registry.extensionPointIsRegistered(ep.getId()))
     
    441440  {
    442441    int numRegistered = 0;
    443     for (Extension<Action> ext : data.extensions)
     442    for (Extension<?> ext : data.extensions)
    444443    {
    445444      if (forceUpdate || !registry.extensionIsRegistered(ext.getId()))
     
    503502  {
    504503    WriteableExtensionsFile writeableFile;
    505     List<Extension> extensions;
    506     List<ExtensionPoint> extensionPoints;
     504    List<Extension<?>> extensions;
     505    List<ExtensionPoint<?>> extensionPoints;
    507506  }
    508507
  • trunk/src/core/net/sf/basedb/util/uri/ConnectionManagerUtil.java

    r5599 r5606  
    3737import net.sf.basedb.util.extensions.Registry;
    3838import net.sf.basedb.util.extensions.SingleExtensionFilter;
     39import net.sf.basedb.util.extensions.manager.ExtensionsManager;
    3940
    4041/**
     
    200201  private static ExtensionsInvoker<ConnectionManagerFactory> getInvoker(ClientContext context, ExtensionsFilter filter)
    201202  {
    202     Registry registry = Application.getExtensionsManager().getRegistry();
     203    ExtensionsManager manager = Application.getExtensionsManager();
     204    if (filter == null) filter = manager.getSettings();
     205    Registry registry = manager.getRegistry();
    203206    return (ExtensionsInvoker<ConnectionManagerFactory>)registry.useExtensions(context, filter, EXTENSION_POINT_ID);
    204207  }
  • trunk/www/admin/extensions/details.jsp

    r5603 r5606  
    147147  function enableFile(enable)
    148148  {
    149     window.parent.frames['tree'].setChildIcons('<%=HTML.javaScriptEncode(fileuri)%>', enable);
     149    window.parent.frames['tree'].setChildIcons('<%=HTML.javaScriptEncode(file != null ? file.getName() : "")%>', enable);
    150150    var url = 'index.jsp?ID=<%=ID%>&cmd=EnableFile';
    151151    url += '&fileuri=<%=HTML.urlEncode(fileuri)%>';
  • trunk/www/admin/extensions/index.jsp

    r5601 r5606  
    8484  {
    8585    dc = sc.newDbControl();
    86     String filename = request.getParameter("filename");
     86    String fileuri = request.getParameter("fileuri");
    8787    boolean enable = Values.getBoolean(request.getParameter("enable"));
    8888    ExtensionsControl ec = ExtensionsControl.get(dc);
    89     ec.enableAllInFile(filename, enable);
     89    ec.enableAllInFile(fileuri, enable);
    9090    ec.saveSettings();
    91     redirect = "details.jsp?ID=" + ID + "&filename=" + HTML.urlEncode(filename);
     91    redirect = "details.jsp?ID=" + ID + "&fileuri=" + HTML.urlEncode(fileuri);
    9292  }
    9393  else if ("ManualScan".equals(cmd))
Note: See TracChangeset for help on using the changeset viewer.