[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.guitar.commands;
|
---|
[205] | 16 |
|
---|
| 17 | import java.io.File;
|
---|
[425] | 18 | import java.io.FilenameFilter;
|
---|
[205] | 19 | import java.util.Collection;
|
---|
| 20 | import java.util.LinkedList;
|
---|
| 21 | import java.util.List;
|
---|
[639] | 22 | import java.util.logging.Level;
|
---|
[205] | 23 |
|
---|
[922] | 24 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
| 25 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 26 | import de.ugoe.cs.autoquest.plugin.guitar.GUITARTestCaseParser;
|
---|
[205] | 27 | import de.ugoe.cs.util.console.Command;
|
---|
| 28 | import de.ugoe.cs.util.console.Console;
|
---|
[667] | 29 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
[205] | 30 |
|
---|
[206] | 31 | /**
|
---|
| 32 | * <p>
|
---|
| 33 | * Command to load a set of sequences from a set of GUITAR test cases.
|
---|
| 34 | * </p>
|
---|
| 35 | *
|
---|
| 36 | * @author Steffen Herbold
|
---|
| 37 | * @version 1.0
|
---|
| 38 | */
|
---|
[205] | 39 | public class CMDefgTestCasesToSequences implements Command {
|
---|
| 40 |
|
---|
[206] | 41 | /*
|
---|
| 42 | * (non-Javadoc)
|
---|
| 43 | *
|
---|
| 44 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 45 | */
|
---|
[205] | 46 | @Override
|
---|
| 47 | public void run(List<Object> parameters) {
|
---|
| 48 | String foldername;
|
---|
[227] | 49 | String sequencesName;
|
---|
| 50 | String efgFileName = null;
|
---|
[205] | 51 | try {
|
---|
| 52 | foldername = (String) parameters.get(0);
|
---|
[227] | 53 | sequencesName = (String) parameters.get(1);
|
---|
| 54 | if (parameters.size() >= 3) {
|
---|
| 55 | efgFileName = (String) parameters.get(2);
|
---|
[205] | 56 | }
|
---|
| 57 | } catch (Exception e) {
|
---|
[766] | 58 | throw new IllegalArgumentException();
|
---|
[205] | 59 | }
|
---|
[206] | 60 |
|
---|
[205] | 61 | File folder = new File(foldername);
|
---|
[425] | 62 |
|
---|
| 63 | File[] testcaseFiles = folder.listFiles( new FilenameFilter() {
|
---|
| 64 | @Override
|
---|
| 65 | public boolean accept(File dir, String name) {
|
---|
| 66 | return name.endsWith(".tst");
|
---|
| 67 | }
|
---|
| 68 | });
|
---|
[556] | 69 | Collection<List<Event>> sequences = new LinkedList<List<Event>>();
|
---|
[227] | 70 | GUITARTestCaseParser parser;
|
---|
| 71 | if (efgFileName == null) {
|
---|
| 72 | parser = new GUITARTestCaseParser();
|
---|
| 73 | } else {
|
---|
| 74 | parser = new GUITARTestCaseParser(efgFileName);
|
---|
| 75 | }
|
---|
[2232] | 76 |
|
---|
| 77 | if (testcaseFiles != null) {
|
---|
| 78 | for (File testcaseFile : testcaseFiles) {
|
---|
| 79 | Console.traceln(Level.INFO, "Loading from file "
|
---|
| 80 | + testcaseFile.getAbsolutePath());
|
---|
| 81 | sequences.add(parser.parseTestCaseFile(testcaseFile));
|
---|
| 82 | }
|
---|
[205] | 83 | }
|
---|
[2232] | 84 |
|
---|
[205] | 85 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
|
---|
[244] | 86 | CommandHelpers.dataOverwritten(sequencesName);
|
---|
[205] | 87 | }
|
---|
[206] | 88 |
|
---|
[205] | 89 | }
|
---|
| 90 |
|
---|
[206] | 91 | /*
|
---|
| 92 | * (non-Javadoc)
|
---|
| 93 | *
|
---|
| 94 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 95 | */
|
---|
[205] | 96 | @Override
|
---|
[664] | 97 | public String help() {
|
---|
[728] | 98 | return "efgTestCasesToSequences <directory> <sequencesName> {<guiFileName>}";
|
---|
[205] | 99 | }
|
---|
| 100 |
|
---|
| 101 | }
|
---|