Changeset 7231


Ignore:
Timestamp:
Nov 16, 2016, 12:57:05 PM (5 years ago)
Author:
Nicklas Nordborg
Message:

References #2042: Add support for ignoring an extension or other file in the extensions directory

Ignored files are now saved in the Settings so that they are remembered after a server restart.

The ExtensionsManager can now be used for listing the ignored files.

Location:
trunk/src/core/net/sf/basedb/util/extensions/manager
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/util/extensions/manager/ExtensionsManager.java

    r6898 r7231  
    3535import java.util.Set;
    3636import java.util.TreeMap;
     37import java.util.TreeSet;
    3738
    3839import net.sf.basedb.core.ItemAlreadyExistsException;
     
    7677  private int numUnmodified;
    7778  private int numDeleted;
     79  private int numIgnored;
    7880 
    7981  /**
     
    8890    this.registry = registry;
    8991    this.settings = new Settings(this, settingsFile);
    90     this.ignore = new HashSet<File>();
     92    this.ignore = new TreeSet<File>(settings.getIgnoredFiles());
    9193    this.directories = new HashSet<File>();
    9294    this.xtFiles = new TreeMap<URI, ExtensionsFile>(new JarFirstURIComparator());
     
    141143  {
    142144    if (file == null) return;
    143     ignore.add(file);
     145    if (ignore.add(file))
     146    {
     147      settings.setIgnoredFile(file, true);
     148      removeFile(file);
     149    }
    144150  }
    145151 
     
    152158  {
    153159    if (file == null) return;
    154     ignore.remove(file);
    155   }
    156 
     160    if (ignore.remove(file))
     161    {
     162      settings.setIgnoredFile(file, false);
     163    }
     164  }
     165
     166  /**
     167    Get all ignored files.
     168   
     169    @param onlyInManagedDirectory TRUE to only look for files that
     170      are located in a managed directory
     171    @since 3.10
     172  */
     173  public List<File> getIgnoredFiles(boolean onlyInManagedDirectory)
     174  {
     175    // Create a copy, or the iterator will fail if new
     176    // files are added by another thread
     177    List<File> copy = new ArrayList<File>(ignore.size());
     178    if (onlyInManagedDirectory)
     179    {
     180      for (File f : ignore)
     181      {
     182        if (directories.contains(f.getParentFile())) copy.add(f);
     183      }
     184    }
     185    else
     186    {
     187      copy.addAll(ignore);
     188    }
     189    return copy;
     190  }
     191 
    157192  /**
    158193    Add a directory to this manager. The directory will be monitored
     
    190225    ExtensionsFile xtFile = new ExtensionsFile(this, file);
    191226    addExtensionsFile(xtFile);
     227    ignore.remove(file);
    192228    return xtFile;
    193229  }
     
    260296    numDeleted = 0;
    261297    numUnmodified = 0;
     298    numIgnored = 0;
    262299   
    263300    // 1. Check and count all known files
     
    337374 
    338375  /**
     376    Get the number of ignored files that was found in the last
     377    call to {@link #scanForChanges()}.
     378    @since 3.10
     379  */
     380  public int getNumIgnored()
     381  {
     382    return numIgnored;
     383  }
     384 
     385  /**
    339386    Scan the given directory and add files that are new.
    340387    @param dir The directory to scan
     
    363410        {
    364411          log.debug("File '" + file + "' is ignored.");
     412          numIgnored++;
    365413          continue; // with the next file
    366414        }
     
    417465        {
    418466          log.debug("File '" + file + "' is ignored.");
     467          numIgnored++;
    419468          continue; // with the next file
    420469        }
  • trunk/src/core/net/sf/basedb/util/extensions/manager/Settings.java

    r6875 r7231  
    7474  private Preset settings;
    7575  private Preset installedFiles;
     76  private Preset ignoredFiles;
    7677  private Preset disabledExtensions;
    7778  private Preset disabledExtensionPoints;
     
    104105    this.settings = presets.getDefault();
    105106    this.installedFiles = presets.getPreset("installed-files");
     107    this.ignoredFiles = presets.getPreset("ignored-files");
    106108    this.disabledExtensionPoints = presets.getPreset("disabled-extension-points");
    107109    this.disabledExtensions = presets.getPreset("disabled-extensions");
     
    245247 
    246248  /**
     249    Check if the given file is marked as ignored.
     250    @since 3.10
     251  */
     252  public boolean isIgnoredFile(File file)
     253  {
     254    return Values.getBoolean(ignoredFiles.getSetting(file.getAbsolutePath()));
     255  }
     256 
     257  /**
     258    Mark the given file as ignored/not ignored by the extension system.
     259    @since 3.10
     260  */
     261  public void setIgnoredFile(File file, boolean ignore)
     262  {
     263    if (file == null) return;
     264    hasChanged = true;
     265    ignoredFiles.setSetting(file.getAbsolutePath(), ignore ? "1" :  null);
     266  }
     267 
     268  /**
     269    Get a list with all files that are ignored.
     270    @since 3.10
     271  */
     272  public List<File> getIgnoredFiles()
     273  {
     274    List<String> paths = ignoredFiles.getKeys();
     275    List<File> files = new ArrayList<File>(paths.size());
     276    for (String path : paths)
     277    {
     278      files.add(new File(path));
     279    }
     280    return files;
     281  }
     282 
     283  /**
    247284    Save the settings to disk. If the settings has not been
    248285    changed the file is not written.
Note: See TracChangeset for help on using the changeset viewer.