MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / run

Method run

src/main/java/fieldbox/Copy.java:22–89  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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();

Callers 7

iFunction · 0.45
XbFunction · 0.45
runFunction · 0.45
saveAsNewFileMethod · 0.45
mainMethod · 0.45
engineevalMethod · 0.45
middleMethod · 0.45

Calls 15

getStringMethod · 0.95
newFieldFileMethod · 0.95
newFieldBoxMethod · 0.95
filenameForMethod · 0.80
getDefaultDirectoryMethod · 0.80
collectMethod · 0.80
asListMethod · 0.80
existsMethod · 0.80
getNameMethod · 0.45
mapMethod · 0.45
streamMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected