[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>
|
---|
| 27 | * TODO comment
|
---|
| 28 | * </p>
|
---|
| 29 | *
|
---|
| 30 | * @author Patrick Harms
|
---|
| 31 | * @version 1.0
|
---|
| 32 | */
|
---|
| 33 | public 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 | }
|
---|