1 package com.github.searls.jasmine.io.scripts;
2
3 import com.github.searls.jasmine.collections.CollectionHelper;
4
5 import java.io.File;
6 import java.util.ArrayList;
7 import java.util.List;
8
9 public class ResolvesLocationOfPreloadSources {
10
11 private CollectionHelper collectionHelper = new CollectionHelper();
12 private ConvertsFileToUriString convertsFileToUriString = new ConvertsFileToUriString();
13
14 public List<String> resolve(List<String> preloadSources, File sourceDir, File specDir) {
15 List<String> sources = new ArrayList<String>();
16 for (String source : collectionHelper.list(preloadSources)) {
17 if (fileCouldNotBeAdded(new File(sourceDir, source), sources)
18 && fileCouldNotBeAdded(new File(specDir, source), sources)
19 && fileCouldNotBeAdded(new File(source), sources)) {
20 sources.add(source);
21 }
22 }
23 return sources;
24 }
25
26 private boolean fileCouldNotBeAdded(File file, List<String> sourcePaths) {
27 boolean canAdd = file.exists();
28 if (canAdd) {
29 sourcePaths.add(convertsFileToUriString.convert(file));
30 }
31 return !canAdd;
32 }
33
34 }