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