View Javadoc

1   package com.atlassian.plugin.loaders;
2   
3   import com.atlassian.plugin.PluginException;
4   import com.atlassian.plugin.loaders.classloading.DeploymentUnit;
5   
6   import java.io.File;
7   import java.util.ArrayList;
8   import java.util.Collection;
9   import java.util.Collections;
10  
11  /**
12   * A scanner that simply scans a given set of input files.
13   * This scanner will always return the units in the order supplied in the constructor.
14   */
15  public class FileListScanner implements com.atlassian.plugin.loaders.classloading.Scanner
16  {
17      private final Collection<File> files;
18      private transient Collection<DeploymentUnit> units;
19  
20      public FileListScanner(final Collection<File> files)
21      {
22          this.files = new ArrayList<File>(files);
23      }
24  
25      public Collection<DeploymentUnit> scan()
26      {
27          if (units != null) {
28              return Collections.emptyList();
29          }
30  
31          units = new ArrayList<DeploymentUnit>();
32          for (File file : files)
33          {
34              units.add(new DeploymentUnit(file));
35          }
36  
37          return units;
38      }
39  
40      public Collection<DeploymentUnit> getDeploymentUnits()
41      {
42          return Collections.unmodifiableCollection(units);
43      }
44  
45      public void reset()
46      {
47          units = null;
48      }
49  
50      public void remove(final DeploymentUnit unit) throws PluginException
51      {
52          throw new PluginException("Cannot remove files in a file-list scanner: " + unit.getPath());
53      }
54  }