View Javadoc

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