View Javadoc
1   package com.github.searls.jasmine.io.scripts;
2   
3   import com.github.searls.jasmine.io.ScansDirectory;
4   import com.github.searls.jasmine.model.ScriptSearch;
5   
6   import java.io.File;
7   import java.util.ArrayList;
8   import java.util.List;
9   
10  public class FindsScriptLocationsInDirectory {
11  
12    private final ScansDirectory scansDirectory;
13    private final ConvertsFileToUriString convertsFileToUriString;
14  
15    public FindsScriptLocationsInDirectory(ScansDirectory scansDirectory,
16                                           ConvertsFileToUriString convertsFileToUriString) {
17      this.scansDirectory = scansDirectory;
18      this.convertsFileToUriString = convertsFileToUriString;
19    }
20  
21    public FindsScriptLocationsInDirectory() {
22      this(new ScansDirectory(), new ConvertsFileToUriString());
23    }
24  
25    public List<String> find(ScriptSearch search) {
26      List<String> scriptLocations = new ArrayList<String>();
27      if (search.getDirectory().canRead()) {
28        for (String script : scansDirectory.scan(search.getDirectory(), search.getIncludes(), search.getExcludes())) {
29          scriptLocations.add(convertsFileToUriString.convert(new File(search.getDirectory(), script)));
30        }
31      }
32      return scriptLocations;
33    }
34  }