[1230] | 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 |
|
---|
| 15 | package de.ugoe.cs.autoquest.plugin.html.commands;
|
---|
| 16 |
|
---|
| 17 | import java.io.File;
|
---|
| 18 | import java.util.Arrays;
|
---|
| 19 | import java.util.List;
|
---|
| 20 |
|
---|
| 21 | import de.ugoe.cs.autoquest.plugin.html.HTMLLogCompressor;
|
---|
| 22 | import de.ugoe.cs.util.console.Command;
|
---|
| 23 | import de.ugoe.cs.util.console.Console;
|
---|
| 24 |
|
---|
| 25 | /**
|
---|
| 26 | * <p>
|
---|
[1276] | 27 | * This command performs a compression of HTML log files. It traverse a directory structure. All
|
---|
| 28 | * files in the same directory are treated as HTML log files. They are parsed and all GUI elements
|
---|
| 29 | * and events contained in them are dumped into a new log file. No GUI element is dumped more than
|
---|
| 30 | * once. Through this, several log files containing duplicates of GUI elements are condensed to
|
---|
| 31 | * only one. The events are put at the end of the new log file and are sorted based on their time
|
---|
| 32 | * stamp.
|
---|
[1230] | 33 | * </p>
|
---|
| 34 | *
|
---|
| 35 | * @author Patrick Harms
|
---|
| 36 | * @version 1.0
|
---|
| 37 | */
|
---|
| 38 | public class CMDcompressHTMLLogFiles implements Command {
|
---|
| 39 |
|
---|
[1276] | 40 | /* (non-Javadoc)
|
---|
[1230] | 41 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 42 | */
|
---|
| 43 | @Override
|
---|
| 44 | public void run(List<Object> parameters) {
|
---|
| 45 | String path;
|
---|
| 46 |
|
---|
| 47 | try {
|
---|
| 48 | path = (String) parameters.get(0);
|
---|
| 49 | }
|
---|
| 50 | catch (Exception e) {
|
---|
| 51 | throw new IllegalArgumentException("illegal parameters provided: " + e);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | File directory = new File(path);
|
---|
| 55 | if (!directory.isDirectory()) {
|
---|
| 56 | Console.printerrln(path + " is not a directory");
|
---|
| 57 | return;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | compressDirectory(directory);
|
---|
| 61 |
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | /**
|
---|
[1276] | 65 | * <p>
|
---|
| 66 | * convenience method for recursively calling the {@link HTMLLogCompressor} for each directory
|
---|
| 67 | * </p>
|
---|
[1230] | 68 | *
|
---|
[1276] | 69 | * @param the directory to be traversed
|
---|
[1230] | 70 | */
|
---|
| 71 | private void compressDirectory(File directory) {
|
---|
| 72 | if (directory.isDirectory()) {
|
---|
| 73 | File[] children = directory.listFiles();
|
---|
| 74 | Arrays.sort(children);
|
---|
| 75 |
|
---|
| 76 | boolean containsAtLeastOneFile = false;
|
---|
| 77 | for (File child : children) {
|
---|
| 78 | compressDirectory(child);
|
---|
| 79 |
|
---|
| 80 | containsAtLeastOneFile |= child.isFile();
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | if (containsAtLeastOneFile) {
|
---|
| 84 | HTMLLogCompressor compressor = new HTMLLogCompressor();
|
---|
| 85 | compressor.compressFilesInDirectory(directory);
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[1276] | 90 | /* (non-Javadoc)
|
---|
[1230] | 91 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 92 | */
|
---|
| 93 | @Override
|
---|
| 94 | public String help() {
|
---|
| 95 | return "compressHTMLLogFiles <directory>";
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | }
|
---|