View Javadoc
1   package com.atlassian.plugin.loaders;
2   
3   import com.atlassian.plugin.PluginException;
4   import com.atlassian.plugin.loaders.classloading.DeploymentUnit;
5   import com.atlassian.plugin.loaders.classloading.Scanner;
6   
7   import java.io.File;
8   import java.util.ArrayList;
9   import java.util.Collection;
10  import java.util.Collections;
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      private final Collection<File> files;
18      private transient Collection<DeploymentUnit> units;
19  
20      public FileListScanner(final Collection<File> files) {
21          this.files = new ArrayList<>(files);
22      }
23  
24      public Collection<DeploymentUnit> scan() {
25          if (units != null) {
26              return Collections.emptyList();
27          }
28  
29          units = new ArrayList<>();
30          for (final File file : files) {
31              units.add(new DeploymentUnit(file));
32          }
33  
34          return units;
35      }
36  
37      public Collection<DeploymentUnit> getDeploymentUnits() {
38          return Collections.unmodifiableCollection(units);
39      }
40  
41      public void reset() {
42          units = null;
43      }
44  
45      public void remove(final DeploymentUnit unit) throws PluginException {
46          throw new PluginException("Cannot remove files in a file-list scanner: " + unit.getPath());
47      }
48  }