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

Last change on this file since 1230 was 1230, checked in by pharms, 11 years ago
  • added support for compressing log files by reducing the redundant occurrence of GUI elements
File size: 2.5 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 * TODO comment
28 * </p>
29 *
30 * @author Patrick Harms
31 * @version 1.0
32 */
33public class CMDcompressHTMLLogFiles implements Command {
34
35    /*
36     * (non-Javadoc)
37     *
38     * @see de.ugoe.cs.util.console.Command#run(java.util.List)
39     */
40    @Override
41    public void run(List<Object> parameters) {
42        String path;
43
44        try {
45            path = (String) parameters.get(0);
46        }
47        catch (Exception e) {
48            throw new IllegalArgumentException("illegal parameters provided: " + e);
49        }
50
51        File directory = new File(path);
52        if (!directory.isDirectory()) {
53            Console.printerrln(path + " is not a directory");
54            return;
55        }
56
57        compressDirectory(directory);
58
59    }
60
61    /**
62     *
63     */
64    private void compressDirectory(File directory) {
65        if (directory.isDirectory()) {
66            File[] children = directory.listFiles();
67            Arrays.sort(children);
68           
69            boolean containsAtLeastOneFile = false;
70            for (File child : children) {
71                compressDirectory(child);
72               
73                containsAtLeastOneFile |= child.isFile();
74            }
75           
76            if (containsAtLeastOneFile) {
77                HTMLLogCompressor compressor = new HTMLLogCompressor();
78                compressor.compressFilesInDirectory(directory);
79            }
80        }
81    }
82
83    /*
84     * (non-Javadoc)
85     *
86     * @see de.ugoe.cs.util.console.Command#help()
87     */
88    @Override
89    public String help() {
90        return "compressHTMLLogFiles <directory>";
91    }
92
93}
Note: See TracBrowser for help on using the repository browser.