[927] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
| 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
| 14 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.plugin.jfc.commands;
|
---|
[573] | 16 |
|
---|
| 17 | import java.io.File;
|
---|
| 18 | import java.util.Collection;
|
---|
| 19 | import java.util.List;
|
---|
[639] | 20 | import java.util.logging.Level;
|
---|
[573] | 21 |
|
---|
[922] | 22 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
| 23 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 24 | import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel;
|
---|
[1037] | 25 | import de.ugoe.cs.autoquest.plugin.jfc.JFCSimplifiedLogParser;
|
---|
[573] | 26 | import de.ugoe.cs.util.console.Command;
|
---|
| 27 | import de.ugoe.cs.util.console.Console;
|
---|
[667] | 28 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
[573] | 29 |
|
---|
| 30 | /**
|
---|
| 31 | * <p>
|
---|
| 32 | * Command that tries to parse all files in a folder as if they were log files generated by the
|
---|
| 33 | * JFCMonitor. The result is one set of sequences for all files (not one set of sequences for each
|
---|
| 34 | * file!).
|
---|
| 35 | * </p>
|
---|
| 36 | *
|
---|
| 37 | * @author Steffen Herbold
|
---|
| 38 | * @version 1.0
|
---|
| 39 | */
|
---|
| 40 | public class CMDparseDirJFC implements Command {
|
---|
| 41 |
|
---|
| 42 | /*
|
---|
| 43 | * (non-Javadoc)
|
---|
| 44 | *
|
---|
| 45 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 46 | */
|
---|
| 47 | @Override
|
---|
| 48 | public void run(List<Object> parameters) {
|
---|
| 49 | String path;
|
---|
| 50 | String sequencesName = "sequences";
|
---|
| 51 |
|
---|
| 52 | try {
|
---|
| 53 | path = (String) parameters.get(0);
|
---|
| 54 | if (parameters.size() >= 2) {
|
---|
| 55 | sequencesName = (String) parameters.get(1);
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | catch (Exception e) {
|
---|
[766] | 59 | throw new IllegalArgumentException();
|
---|
[573] | 60 | }
|
---|
| 61 |
|
---|
| 62 | File folder = new File(path);
|
---|
| 63 | if (!folder.isDirectory()) {
|
---|
| 64 | Console.printerrln(path + " is not a directory");
|
---|
| 65 | return;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[1037] | 68 | JFCSimplifiedLogParser parser = new JFCSimplifiedLogParser();
|
---|
[573] | 69 |
|
---|
| 70 | String absolutPath = folder.getAbsolutePath();
|
---|
| 71 | for (String filename : folder.list()) {
|
---|
[1178] | 72 | String source = absolutPath + File.separator + filename;
|
---|
[639] | 73 | Console.traceln(Level.INFO, "Processing file: " + source);
|
---|
[573] | 74 |
|
---|
[1179] | 75 | try {
|
---|
| 76 | parser.parseFile(source);
|
---|
| 77 | }
|
---|
| 78 | catch (Exception e) {
|
---|
| 79 | Console.printerrln("Could not parse " + source + ": " + e.getMessage());
|
---|
| 80 | }
|
---|
[573] | 81 | }
|
---|
| 82 |
|
---|
| 83 | Collection<List<Event>> sequences = parser.getSequences();
|
---|
[752] | 84 |
|
---|
| 85 | GUIModel targets = parser.getGuiModel();
|
---|
[573] | 86 |
|
---|
| 87 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
|
---|
| 88 | CommandHelpers.dataOverwritten(sequencesName);
|
---|
| 89 | }
|
---|
[752] | 90 |
|
---|
| 91 | if (GlobalDataContainer.getInstance().addData(sequencesName + "_targets", targets)) {
|
---|
| 92 | CommandHelpers.dataOverwritten(sequencesName + "_targets");
|
---|
| 93 | }
|
---|
[573] | 94 | }
|
---|
| 95 |
|
---|
| 96 | /*
|
---|
| 97 | * (non-Javadoc)
|
---|
| 98 | *
|
---|
| 99 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 100 | */
|
---|
| 101 | @Override
|
---|
[664] | 102 | public String help() {
|
---|
[728] | 103 | return "parseDirJFC <directory> {<sequencesName>}";
|
---|
[573] | 104 | }
|
---|
| 105 |
|
---|
| 106 | }
|
---|