()
| 20 | public final IO io = new IO(Options.getDirectory("workspace", () -> System.getProperty("user.home") + "/Documents/FieldWorkspace/")); |
| 21 | |
| 22 | @Override |
| 23 | public void run() { |
| 24 | |
| 25 | String from = Options.getString("file", () -> null); |
| 26 | if (from == null) throw new IllegalArgumentException("-file option can't be null"); |
| 27 | |
| 28 | String to = Options.getString("destination", () -> null); |
| 29 | if (from == null) throw new IllegalArgumentException("-destination option can't be null"); |
| 30 | |
| 31 | |
| 32 | // the file to copy |
| 33 | FileBrowser.FieldFile file = FileBrowser.newFieldFile(io.filenameFor(IO.WORKSPACE+from)); |
| 34 | |
| 35 | // should be recursive! |
| 36 | File[] files = new File(io.getDefaultDirectory()).listFiles(x -> x.getName() |
| 37 | .endsWith(".box")); |
| 38 | |
| 39 | List<FileBrowser.FieldBox> implicated = Arrays.asList(files) |
| 40 | .stream() |
| 41 | .map(x -> FileBrowser.newFieldBox(x, true)) |
| 42 | .filter(x -> x != null) |
| 43 | .filter(x -> file.boxes.contains(x.id)) |
| 44 | .collect(Collectors.toList()); |
| 45 | |
| 46 | List<File> sub = implicated.stream() |
| 47 | .flatMap(x -> x.allText.stream() |
| 48 | .filter(y -> y.contains(IO.WORKSPACE))) |
| 49 | .map(x -> { |
| 50 | String[] pieces = x.trim().split(" "); |
| 51 | String last = ""; |
| 52 | for(int i=1;i<pieces.length;i++) |
| 53 | { |
| 54 | last = last+" "+pieces[i]; |
| 55 | } |
| 56 | last = last.trim(); |
| 57 | last = last.substring(1, last.length() - 1); |
| 58 | return io.filenameFor(last); |
| 59 | }) |
| 60 | .collect(Collectors.toList()); |
| 61 | |
| 62 | LinkedHashSet<File> all = new LinkedHashSet<File>(sub); |
| 63 | all.addAll(implicated.stream() |
| 64 | .map(x -> x.filename) |
| 65 | .collect(Collectors.toList())); |
| 66 | all.add(io.filenameFor(IO.WORKSPACE+from)); |
| 67 | |
| 68 | all.forEach(x -> { |
| 69 | if (!x.exists()) throw new IllegalArgumentException(" box references a file that doesn't exist :"+x); |
| 70 | }); |
| 71 | |
| 72 | if (new File(to).exists()) |
| 73 | throw new IllegalArgumentException(" won't copy into an existing directory"); |
| 74 | |
| 75 | new File(to).mkdirs(); |
| 76 | |
| 77 | all.forEach(x -> { |
| 78 | try { |
| 79 | Path a = x.toPath(); |
no test coverage detected