source: trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/commands/CMDcompressHTMLLogFiles.java

Last change on this file was 2232, checked in by pharms, 7 years ago
  • solved some findbugs issues
File size: 3.2 KB
Line 
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
15package de.ugoe.cs.autoquest.plugin.html.commands;
16
17import java.io.File;
18import java.util.Arrays;
19import java.util.List;
20
21import de.ugoe.cs.autoquest.plugin.html.HTMLLogCompressor;
22import de.ugoe.cs.util.console.Command;
23import de.ugoe.cs.util.console.Console;
24
25/**
26 * <p>
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.
33 * </p>
34 *
35 * @author Patrick Harms
36 * @version 1.0
37 */
38public class CMDcompressHTMLLogFiles implements Command {
39
40    /* (non-Javadoc)
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    /**
65     * <p>
66     * convenience method for recursively calling the {@link HTMLLogCompressor} for each directory
67     * </p>
68     *
69     * @param the directory to be traversed
70     */
71    private void compressDirectory(File directory) {
72        if (directory.isDirectory()) {
73            File[] children = directory.listFiles();
74           
75                boolean containsAtLeastOneFile = false;
76            if (children != null) {
77                Arrays.sort(children);
78
79                for (File child : children) {
80                        compressDirectory(child);
81
82                        containsAtLeastOneFile |= child.isFile();
83                }
84            }
85           
86            if (containsAtLeastOneFile) {
87                HTMLLogCompressor compressor = new HTMLLogCompressor();
88                compressor.compressFilesInDirectory(directory);
89            }
90        }
91    }
92
93    /* (non-Javadoc)
94     * @see de.ugoe.cs.util.console.Command#help()
95     */
96    @Override
97    public String help() {
98        return "compressHTMLLogFiles <directory>";
99    }
100
101}
Note: See TracBrowser for help on using the repository browser.