1 | package de.ugoe.cs.eventbench.efg.commands;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.security.InvalidParameterException;
|
---|
5 | import java.util.Collection;
|
---|
6 | import java.util.LinkedList;
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import de.ugoe.cs.eventbench.CommandHelpers;
|
---|
10 | import de.ugoe.cs.eventbench.data.Event;
|
---|
11 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
12 | import de.ugoe.cs.eventbench.efg.GUITARTestCaseParser;
|
---|
13 | import de.ugoe.cs.util.console.Command;
|
---|
14 | import de.ugoe.cs.util.console.Console;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * <p>
|
---|
18 | * Command to load a set of sequences from a set of GUITAR test cases.
|
---|
19 | * </p>
|
---|
20 | *
|
---|
21 | * @author Steffen Herbold
|
---|
22 | * @version 1.0
|
---|
23 | */
|
---|
24 | public class CMDefgTestCasesToSequences implements Command {
|
---|
25 |
|
---|
26 | /*
|
---|
27 | * (non-Javadoc)
|
---|
28 | *
|
---|
29 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
30 | */
|
---|
31 | @Override
|
---|
32 | public void run(List<Object> parameters) {
|
---|
33 | String foldername;
|
---|
34 | String sequencesName;
|
---|
35 | String efgFileName = null;
|
---|
36 | try {
|
---|
37 | foldername = (String) parameters.get(0);
|
---|
38 | sequencesName = (String) parameters.get(1);
|
---|
39 | if (parameters.size() >= 3) {
|
---|
40 | efgFileName = (String) parameters.get(2);
|
---|
41 | }
|
---|
42 | } catch (Exception e) {
|
---|
43 | throw new InvalidParameterException();
|
---|
44 | }
|
---|
45 |
|
---|
46 | File folder = new File(foldername);
|
---|
47 | // TODO would be more robust with filter
|
---|
48 | File[] testcaseFiles = folder.listFiles();
|
---|
49 | Collection<List<Event<?>>> sequences = new LinkedList<List<Event<?>>>();
|
---|
50 | GUITARTestCaseParser parser;
|
---|
51 | if (efgFileName == null) {
|
---|
52 | parser = new GUITARTestCaseParser();
|
---|
53 | } else {
|
---|
54 | parser = new GUITARTestCaseParser(efgFileName);
|
---|
55 | }
|
---|
56 | for (File testcaseFile : testcaseFiles) {
|
---|
57 | Console.traceln("Loading from file "
|
---|
58 | + testcaseFile.getAbsolutePath());
|
---|
59 | sequences.add(parser.parseTestCaseFile(testcaseFile));
|
---|
60 | }
|
---|
61 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
|
---|
62 | CommandHelpers.dataOverwritten(sequencesName);
|
---|
63 | }
|
---|
64 |
|
---|
65 | }
|
---|
66 |
|
---|
67 | /*
|
---|
68 | * (non-Javadoc)
|
---|
69 | *
|
---|
70 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
71 | */
|
---|
72 | @Override
|
---|
73 | public void help() {
|
---|
74 | Console.println("Usage: efgTestCasesToSequences <folder> <sequencesName> {<efgFileName>}");
|
---|
75 | }
|
---|
76 |
|
---|
77 | }
|
---|