1 | package de.ugoe.cs.quest.plugin.jfc.commands;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.List;
|
---|
6 | import java.util.logging.Level;
|
---|
7 |
|
---|
8 | import de.ugoe.cs.quest.CommandHelpers;
|
---|
9 | import de.ugoe.cs.quest.eventcore.Event;
|
---|
10 | import de.ugoe.cs.quest.eventcore.guimodel.GUIModel;
|
---|
11 | import de.ugoe.cs.quest.plugin.jfc.JFCLogParser;
|
---|
12 | import de.ugoe.cs.util.console.Command;
|
---|
13 | import de.ugoe.cs.util.console.Console;
|
---|
14 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * <p>
|
---|
18 | * Command that tries to parse all files in a folder as if they were log files generated by the
|
---|
19 | * JFCMonitor. The result is one set of sequences for all files (not one set of sequences for each
|
---|
20 | * file!).
|
---|
21 | * </p>
|
---|
22 | *
|
---|
23 | * @author Steffen Herbold
|
---|
24 | * @version 1.0
|
---|
25 | */
|
---|
26 | public class CMDparseDirJFC implements Command {
|
---|
27 |
|
---|
28 | /*
|
---|
29 | * (non-Javadoc)
|
---|
30 | *
|
---|
31 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
32 | */
|
---|
33 | @Override
|
---|
34 | public void run(List<Object> parameters) {
|
---|
35 | String path;
|
---|
36 | String sequencesName = "sequences";
|
---|
37 |
|
---|
38 | try {
|
---|
39 | path = (String) parameters.get(0);
|
---|
40 | if (parameters.size() >= 2) {
|
---|
41 | sequencesName = (String) parameters.get(1);
|
---|
42 | }
|
---|
43 | }
|
---|
44 | catch (Exception e) {
|
---|
45 | throw new IllegalArgumentException();
|
---|
46 | }
|
---|
47 |
|
---|
48 | File folder = new File(path);
|
---|
49 | if (!folder.isDirectory()) {
|
---|
50 | Console.printerrln(path + " is not a directory");
|
---|
51 | return;
|
---|
52 | }
|
---|
53 |
|
---|
54 | JFCLogParser parser = new JFCLogParser();
|
---|
55 |
|
---|
56 | String absolutPath = folder.getAbsolutePath();
|
---|
57 | for (String filename : folder.list()) {
|
---|
58 | String source = absolutPath + "/" + filename;
|
---|
59 | Console.traceln(Level.INFO, "Processing file: " + source);
|
---|
60 |
|
---|
61 | parser.parseFile(source);
|
---|
62 | }
|
---|
63 |
|
---|
64 | Collection<List<Event>> sequences = parser.getSequences();
|
---|
65 |
|
---|
66 | GUIModel targets = parser.getGuiModel();
|
---|
67 |
|
---|
68 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
|
---|
69 | CommandHelpers.dataOverwritten(sequencesName);
|
---|
70 | }
|
---|
71 |
|
---|
72 | if (GlobalDataContainer.getInstance().addData(sequencesName + "_targets", targets)) {
|
---|
73 | CommandHelpers.dataOverwritten(sequencesName + "_targets");
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | /*
|
---|
78 | * (non-Javadoc)
|
---|
79 | *
|
---|
80 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
81 | */
|
---|
82 | @Override
|
---|
83 | public String help() {
|
---|
84 | return "parseDirJFC <directory> {<sequencesName>}";
|
---|
85 | }
|
---|
86 |
|
---|
87 | }
|
---|