From d986011cb54b2911a85da7d54e5d35eb2531c688 Mon Sep 17 00:00:00 2001 From: Amr Abed Date: Thu, 29 Nov 2018 04:56:54 +0200 Subject: [PATCH] Migrate from Commons CLI to picocli --- .travis.yml | 9 ++ analyzer/BoSC.java | 21 ---- analyzer/Database.java | 106 ----------------- analyzer/aggregate/Aggregator.java | 21 ---- analyzer/compare/Comparator.java | 20 ---- build.gradle | 21 ++-- {analyzer/data => data}/ambari-0 | 0 {analyzer/data => data}/ambari-1 | 0 {analyzer/data => data}/ambari-1-2 | 0 {analyzer/data => data}/ambari-2 | 0 src/main/java/edu/vt/rhids/Main.java | 107 +++++++++++++++++- .../java/edu/vt/rhids/common/Database.java | 3 +- src/main/java/edu/vt/rhids/input/BoSC.java | 6 +- .../edu/vt/rhids/input/SyscallParser.java | 8 +- .../java/edu/vt/rhids/main/Classifier.java | 11 +- .../java/edu/vt/rhids/main/Parameters.java | 74 +++++------- src/main/java/edu/vt/rhids/main/RHIDS.java | 71 +----------- 17 files changed, 172 insertions(+), 306 deletions(-) delete mode 100644 analyzer/BoSC.java delete mode 100644 analyzer/Database.java delete mode 100644 analyzer/aggregate/Aggregator.java delete mode 100644 analyzer/compare/Comparator.java rename {analyzer/data => data}/ambari-0 (100%) rename {analyzer/data => data}/ambari-1 (100%) rename {analyzer/data => data}/ambari-1-2 (100%) rename {analyzer/data => data}/ambari-2 (100%) diff --git a/.travis.yml b/.travis.yml index 2569719..81b4945 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,3 +7,12 @@ addons: script: - sonar-scanner + +deploy: + provider: releases + api_key: + secure: ebHVnn5fwJZ32s79Df099gM5nsF9QJ/KMpQbBEJo4kwRqDEW6dP0f28MrkJSdq337oOI6/uIdvB+Umko0uZ4wMxyX5NyXXfC4H1FZ+0OpdS+ksueguatAP3Wvhng3bse8UBxeMKekQNwRlK3MS+igLOQJrSxyyzchXgj+vWwm4TiheTIY/0I1JrQv/B/VW5EusVDl6WZosc1q2XF0qhtBT5ytHwVTZN9/4KwtFA8e2dyuX+aHyJdfTjSpXkByJtgBepHdAQ4dL3ZyYifBLChSfYoQlbzxwbl0kNTmsnnvcjO4rqjGwBbZrGufgIigr+w9klMzih/90TRo6MFRQo2vc2wUHhSYmAGc2H+RQjR2gPAsHrHizotJg4mWq/KhXGoT1jp5reKfwKnq4giQ0TWI6eE14y1IDDPygQuQNCY6b7UNdbCLhBfEnjdMmDvOhuyx2FmsP2czeDmlL1U99bwz2AcbWTo/AkiW0b4tzQ+Eml8esPOdSu5Fgf9mcdzfirqYCtbzXxxsJXLXdzJNbfOD8N99xdK/kqNcDaIPM+rBSNTsuGk66k+m+QCIGznAG5goCnbD9RU0T2NT/qewi7LLEV31/KaKVoGzULjxhwLmcbBHxsxGBGNTt+6fJLxTUEfce3G6t8PAv2BeCw5Z1MQ/gw9AWwp6tcnLJXfmcM5rB4= + file: "build/libs/rhids-*.jar" + skip_cleanup: true + on: + tags: true \ No newline at end of file diff --git a/analyzer/BoSC.java b/analyzer/BoSC.java deleted file mode 100644 index 913b661..0000000 --- a/analyzer/BoSC.java +++ /dev/null @@ -1,21 +0,0 @@ -package analyzer; - -import java.util.ArrayList; - -/** - * Bag of System Calls - * - * @author AmrAbed - */ -public class BoSC extends ArrayList { - private static final long serialVersionUID = 1L; - - public BoSC(String string) { - string = string.replace("[", ""); - string = string.replace("]", ""); - - for (String value : string.split(",")) { - add(Byte.parseByte(value.trim())); - } - } -} diff --git a/analyzer/Database.java b/analyzer/Database.java deleted file mode 100644 index ac2d40d..0000000 --- a/analyzer/Database.java +++ /dev/null @@ -1,106 +0,0 @@ -package analyzer; - -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.PrintStream; -import java.util.HashMap; - -/** - * Normal-behavior Database - * - * @author AmrAbed - */ -public class Database extends HashMap { - private static final long serialVersionUID = 1L; - - /** - * Create normal-behavior database from a dump file - * - * @param filePath path to the dump file - * @throws IOException - */ - public Database(String filePath) throws IOException { - if (filePath != null) { - try (final BufferedReader reader = new BufferedReader(new FileReader(filePath))) { - String line; - while ((line = reader.readLine()) != null) { - final String[] words = line.split("\t"); - put(new BoSC(words[0]), Long.parseLong(words[1])); - } - } finally { - reader.close(); - } - } - } - - public void add(BoSC bosc) { - if (bosc == null) { - return; - } - - if (containsKey(bosc)) { - replace(bosc, get(bosc) + 1); - } else { - put(bosc, 1L); - } - } - - public void commit(Database change) { - for (BoSC bosc : change.keySet()) { - long value = change.get(bosc); - if (this.containsKey(bosc)) { - value += this.get(bosc); - } - this.put(bosc, value); - } - } - - private double getNorm() { - double norm = 0; - for (BoSC bosc : keySet()) { - long val = get(bosc); - norm += val * val; - } - return Math.sqrt(norm); - } - - public double calculateSimilarity(Database other) { - if (this.isEmpty() || other.isEmpty()) { - return 0; - } - - double dot = 0; - double norm1 = this.getNorm(); - double norm2 = other.getNorm(); - for (BoSC bosc : keySet()) { - if (other.containsKey(bosc)) { - long value1 = other.get(bosc); - long value2 = this.get(bosc); - dot += value1 * value2; - } - } - return dot / (norm1 * norm2); - } - - public void dump(String file) throws FileNotFoundException { - try (PrintStream out = new PrintStream(file)) { - for (BoSC bosc : keySet()) { - out.println(bosc + "\t" + get(bosc)); - } - } - } - - @Override - public String toString() { - final StringBuilder output = new StringBuilder(); - for (Entry entry : entrySet()) { - output.append(entry.getKey()); - output.append(" => "); - output.append(entry.getValue()); - output.append('\n'); - } - return output.toString(); - } -} diff --git a/analyzer/aggregate/Aggregator.java b/analyzer/aggregate/Aggregator.java deleted file mode 100644 index 239f64f..0000000 --- a/analyzer/aggregate/Aggregator.java +++ /dev/null @@ -1,21 +0,0 @@ -package analyzer.aggregate; - -import java.util.logging.Logger; -import java.util.logging.Level; - -import analyzer.Database; - -public class Aggregator { - public static void main(String[] args) { - try { - final Database db1 = new Database(args[0]); - final Database db2 = new Database(args[1]); - - db1.commit(db2); - db1.dump(args[2]); - - } catch (Exception e) { - Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString()); - } - } -} diff --git a/analyzer/compare/Comparator.java b/analyzer/compare/Comparator.java deleted file mode 100644 index 8e1d354..0000000 --- a/analyzer/compare/Comparator.java +++ /dev/null @@ -1,20 +0,0 @@ -package analyzer.compare; - -import java.util.logging.Logger; -import java.util.logging.Level; - -import analyzer.Database; - -public class Comparator { - public static void main(String[] args) { - try { - final Database db1 = new Database(args[0]); - final Database db2 = new Database(args[1]); - final double similarity = db1.calculateSimilarity(db2); - Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.INFO, () -> "Similaity: " + similarity); - - } catch (Exception e) { - Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString()); - } - } -} \ No newline at end of file diff --git a/build.gradle b/build.gradle index b80884f..31c57fb 100644 --- a/build.gradle +++ b/build.gradle @@ -1,24 +1,29 @@ apply plugin: 'java' apply plugin: 'application' -mainClassName = 'edu.vt.rhids.main.RHIDS' +mainClassName = 'edu.vt.rhids.Main' sourceCompatibility = 1.8 -version = '0.1' +version = '0.2' task createJar(type: Jar) { - manifest { - attributes 'Implementation-Title': 'RHIDS', - 'Main-Class': mainClassName + manifest { + attributes 'Implementation-Title': 'rhids', + 'Main-Class': mainClassName } baseName = project.name - from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } + from { configurations.extralibs.collect { it.isDirectory() ? it : zipTree(it) } } with jar } +configurations { + extralibs +} + repositories { mavenCentral() } dependencies { - implementation 'commons-cli:commons-cli:1.2' -} + implementation 'info.picocli:picocli:3.8.0' + extralibs 'info.picocli:picocli:3.8.0' +} \ No newline at end of file diff --git a/analyzer/data/ambari-0 b/data/ambari-0 similarity index 100% rename from analyzer/data/ambari-0 rename to data/ambari-0 diff --git a/analyzer/data/ambari-1 b/data/ambari-1 similarity index 100% rename from analyzer/data/ambari-1 rename to data/ambari-1 diff --git a/analyzer/data/ambari-1-2 b/data/ambari-1-2 similarity index 100% rename from analyzer/data/ambari-1-2 rename to data/ambari-1-2 diff --git a/analyzer/data/ambari-2 b/data/ambari-2 similarity index 100% rename from analyzer/data/ambari-2 rename to data/ambari-2 diff --git a/src/main/java/edu/vt/rhids/Main.java b/src/main/java/edu/vt/rhids/Main.java index 1327238..711cf8e 100644 --- a/src/main/java/edu/vt/rhids/Main.java +++ b/src/main/java/edu/vt/rhids/Main.java @@ -1,13 +1,114 @@ package edu.vt.rhids; +import edu.vt.rhids.common.Database; +import edu.vt.rhids.main.Parameters; import edu.vt.rhids.main.RHIDS; +import edu.vt.rhids.output.Summary; import edu.vt.rhids.util.Logger; +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Help.Visibility; +import picocli.CommandLine.Option; -public class Main { +import java.util.concurrent.Callable; - public static final RHIDS rhids = RHIDS.getInstance(); +@Command(name = "rhids", version = "0.2", + description = "Resilient Host-based Intrusion Detection System for Docker Containers", + subcommands = { + CommandLine.HelpCommand.class, + Main.Classifier.class, + Main.Aggregator.class, + Main.Comparator.class + }) +@SuppressWarnings("unused") +public class Main implements Runnable { + + @Option(names = {"-V", "--version"}, description = "Print version information and exit", versionHelp = true) + boolean isVersionRequested; + + @Option(names = {"-h", "--help"}, description = "Print this help message and exit", usageHelp = true) + boolean isHelpRequested; public static void main(String[] args) { - Logger.log(rhids.run(args), Logger.Verbosity.NONE); + new CommandLine(new Main()).parseWithHandler(new CommandLine.RunFirst(), args); + } + + @Override + public void run() { + CommandLine.usage(this, System.out); + } + + @Command(name = "classify", description = "Train & test classifier using an input trace file", + sortOptions = false, mixinStandardHelpOptions = true) + public static class Classifier implements Callable { + @Option(names = {"-i", "--input-file"}, paramLabel = "", + description = "Input file path", required = true) + String inputFile; + @Option(names = {"-b", "--database-file"}, paramLabel = "", + description = "File to read database from") + String databaseFile; + @Option(names = {"-o", "--output-file"}, description = "Output file path", paramLabel = "", required = true) + String outputFile; + @Option(names = {"-e", "--epoch-size"}, description = "Range for epoch size", + paramLabel = "", converter = Parameters.IntegerRange.class, + defaultValue = "2500:2500:50000", showDefaultValue = Visibility.ALWAYS) + Parameters.IntegerRange epochSizeRange; + @Option(names = {"-t", "--train-threshold"}, description = "Range for training threshold", + paramLabel = "", converter = Parameters.FloatRange.class, + defaultValue = "0.9f:0.001f:1f", showDefaultValue = Visibility.ALWAYS) + Parameters.FloatRange trainThresholdRange; + @Option(names = {"-d", "--detection-threshold"}, description = "Range for detection threshold", + paramLabel = "", converter = Parameters.IntegerRange.class, + defaultValue = "5:5:200", showDefaultValue = Visibility.ALWAYS) + Parameters.IntegerRange testThresholdRange; + @Option(names = {"-v", "--verbosity"}, description = "Verbose level", + defaultValue = "0", showDefaultValue = Visibility.ALWAYS) + int verbosity; + + @Override + public Summary call() throws Exception { + Logger.setHandler(outputFile); + Logger.setLevel(verbosity); + final Parameters parameters = new Parameters(inputFile, databaseFile, epochSizeRange, trainThresholdRange, testThresholdRange); + Summary summary = RHIDS.getInstance().run(parameters); + Logger.log(summary, Logger.Verbosity.LOW); + return summary; + } + } + + @Command(name = "aggregate", description = "Aggregate two database files into one", + mixinStandardHelpOptions = true) + public static class Aggregator implements Callable { + @CommandLine.Parameters(index = "0", description = "dump file for first database") + String file1; + @CommandLine.Parameters(index = "1", description = "dump file for second database") + String file2; + @CommandLine.Parameters(index = "2", description = "output dump file of aggregate database") + String output; + + @Override + public Void call() throws Exception { + final Database db1 = new Database(file1); + db1.commit(new Database(file2)); + db1.dump(output); + return null; + } + } + + @Command(name = "compare", description = "Calculate similarity matrix between two database files", mixinStandardHelpOptions = true) + public static class Comparator implements Callable { + @CommandLine.Parameters(description = "dump file for first database") + String file1; + @CommandLine.Parameters(description = "dump file for second database") + String file2; + + @Override + public Double call() throws Exception { + final Database db1 = new Database(file1); + final Database db2 = new Database(file2); + final double similarity = db1.calculateSimilarity(db2); + Logger.log("Similarity: " + similarity, Logger.Verbosity.LOW); + return similarity; + } } } \ No newline at end of file diff --git a/src/main/java/edu/vt/rhids/common/Database.java b/src/main/java/edu/vt/rhids/common/Database.java index 65130ff..e85f11b 100644 --- a/src/main/java/edu/vt/rhids/common/Database.java +++ b/src/main/java/edu/vt/rhids/common/Database.java @@ -82,8 +82,7 @@ public double calculateSimilarity(Database other) { return dot / (norm1 * norm2); } - public void dump(String id) throws FileNotFoundException { - final String file = "/var/log/rhids/db-" + id + ".dump"; + public void dump(String file) throws FileNotFoundException { try (PrintStream out = new PrintStream(file)) { Logger.log("Dumping database to " + file, Verbosity.MEDIUM); for (Entry entry : entrySet()) { diff --git a/src/main/java/edu/vt/rhids/input/BoSC.java b/src/main/java/edu/vt/rhids/input/BoSC.java index a6ef95c..85e5de2 100644 --- a/src/main/java/edu/vt/rhids/input/BoSC.java +++ b/src/main/java/edu/vt/rhids/input/BoSC.java @@ -1,6 +1,6 @@ package edu.vt.rhids.input; -import edu.vt.rhids.Main; +import edu.vt.rhids.main.RHIDS; import java.util.ArrayList; import java.util.Collections; @@ -14,9 +14,9 @@ public class BoSC extends ArrayList { private static final long serialVersionUID = 1L; BoSC(Window window) { - super(Collections.nCopies(Main.rhids.getIndexMap().size() + 1, (byte) 0)); + super(Collections.nCopies(RHIDS.getInstance().getIndexMap().size() + 1, (byte) 0)); for (String syscall : window) { - int index = Main.rhids.getIndexMap().get(syscall); + int index = RHIDS.getInstance().getIndexMap().get(syscall); Byte count = get(index); set(index, ++count); } diff --git a/src/main/java/edu/vt/rhids/input/SyscallParser.java b/src/main/java/edu/vt/rhids/input/SyscallParser.java index cb7c012..c06cb3d 100644 --- a/src/main/java/edu/vt/rhids/input/SyscallParser.java +++ b/src/main/java/edu/vt/rhids/input/SyscallParser.java @@ -1,6 +1,6 @@ package edu.vt.rhids.input; -import edu.vt.rhids.Main; +import edu.vt.rhids.main.RHIDS; import java.io.BufferedReader; import java.io.IOException; @@ -22,19 +22,19 @@ public static String parse(BufferedReader reader) throws IOException { Matcher matcher = Pattern.compile("STOP TRAINING").matcher(line); if (matcher.find()) { - Main.rhids.setDoneTraining(true); + RHIDS.getInstance().setDoneTraining(true); return parse(reader); } matcher = Pattern.compile("START ATTACK").matcher(line); if (matcher.find()) { - Main.rhids.setUnderAttack(true); + RHIDS.getInstance().setUnderAttack(true); return parse(reader); } matcher = Pattern.compile("END ATTACK").matcher(line); if (matcher.find()) { - Main.rhids.setUnderAttack(false); + RHIDS.getInstance().setUnderAttack(false); return parse(reader); } diff --git a/src/main/java/edu/vt/rhids/main/Classifier.java b/src/main/java/edu/vt/rhids/main/Classifier.java index c497ae0..44fa91e 100644 --- a/src/main/java/edu/vt/rhids/main/Classifier.java +++ b/src/main/java/edu/vt/rhids/main/Classifier.java @@ -1,6 +1,5 @@ package edu.vt.rhids.main; -import edu.vt.rhids.Main; import edu.vt.rhids.common.Database; import edu.vt.rhids.common.SimilarityVector; import edu.vt.rhids.input.BoSC; @@ -37,7 +36,7 @@ boolean trainUnconditionally() throws IOException { BoSC bosc; String syscall; - while (Main.rhids.isTrainingActive()) { + while (RHIDS.getInstance().isTrainingActive()) { for (int i = 0; i < stats.getEpochSize(); i++) { if ((syscall = SyscallParser.parse(reader)) != null) { bosc = window.slide(syscall).getBoSC(); @@ -46,14 +45,14 @@ boolean trainUnconditionally() throws IOException { } else { // Failed to train using input file Logger.signal("Training failed", Verbosity.LOW); - db.dump(String.valueOf(stats.getEpochSize())); + db.dump("/var/log/rhids/db-" + String.valueOf(stats.getEpochSize()) + ".dump"); return false; } } Logger.log("Epoch " + stats.getTotalEpochs() + ": Database size is " + db.size(), Verbosity.MEDIUM); stats.incrementTrainingEpochs(); } - db.dump(String.valueOf(stats.getEpochSize())); + db.dump("/var/log/rhids/db-" + String.valueOf(stats.getEpochSize()) + ".dump"); return true; } @@ -64,7 +63,7 @@ public boolean train() throws IOException { Database lastEpochChange = new Database(null); String syscall; - while (Main.rhids.isTrainingActive()) { + while (RHIDS.getInstance().isTrainingActive()) { Logger.log("\nEpoch " + stats.getTotalEpochs(), Verbosity.MEDIUM); final Database currentEpochChange = new Database(null); for (int i = 0; i < stats.getEpochSize(); i++) { @@ -105,7 +104,7 @@ void test() throws IOException { for (int i = 0; i < stats.getEpochSize(); i++) { if ((syscall = SyscallParser.parse(reader)) != null) { - if (Main.rhids.isUnderAttack()) { + if (RHIDS.getInstance().isUnderAttack()) { isAnomalousEpoch = true; } final BoSC bosc = window.slide(syscall).getBoSC(); diff --git a/src/main/java/edu/vt/rhids/main/Parameters.java b/src/main/java/edu/vt/rhids/main/Parameters.java index 4b8a1ab..99c7849 100644 --- a/src/main/java/edu/vt/rhids/main/Parameters.java +++ b/src/main/java/edu/vt/rhids/main/Parameters.java @@ -1,44 +1,23 @@ package edu.vt.rhids.main; import edu.vt.rhids.util.Logger; +import picocli.CommandLine; -class Parameters { - // You can update default RHIDS ranges here - static final IntegerRange DEFAULT_EPOCH_SIZE = new IntegerRange(2500, 2500, 50000); +public class Parameters { private static final String PARSE_FAILED = "Parsing failed: invalid range"; - static final FloatRange DEFAULT_TRAIN_THRESHOLD = new FloatRange(0.9f, 0.001f, 1f); - static final IntegerRange DEFAULT_TEST_THRESHOLD = new IntegerRange(5, 5, 200); + + final String inputFile; + final String databaseFile; final IntegerRange epochSize; final FloatRange trainThreshold; final IntegerRange testThreshold; - String inputFile; - String databaseFile; - - Parameters() { - epochSize = DEFAULT_EPOCH_SIZE; - trainThreshold = DEFAULT_TRAIN_THRESHOLD; - testThreshold = DEFAULT_TEST_THRESHOLD; - } - - void setNormalFilePath(String normalFilePath) { - this.inputFile = normalFilePath; - } - - void setDatabaseFilePath(String databaseFile) { + public Parameters(String inputFile, String databaseFile, IntegerRange epochSize, FloatRange trainThreshold, IntegerRange testThreshold) { + this.inputFile = inputFile; this.databaseFile = databaseFile; - } - - void setEpochSize(String range) { - this.epochSize.set(range); - } - - void setTrainThreshold(String range) { - this.trainThreshold.set(range); - } - - void setTestThreshold(String range) { - this.testThreshold.set(range); + this.epochSize = epochSize; + this.trainThreshold = trainThreshold; + this.testThreshold = testThreshold; } @Override @@ -49,18 +28,18 @@ public String toString() { "\nTest-threshold range: " + testThreshold; } - public static class IntegerRange { + public static class IntegerRange implements CommandLine.ITypeConverter { int min; int step; int max; - private IntegerRange(int min, int step, int max) { - this.min = min; - this.step = step; - this.max = max; + + // Needed for picocli instantitation + @SuppressWarnings("unused") + public IntegerRange() { } - private void set(String range) { + IntegerRange(String range) { if (range == null) { return; } @@ -87,20 +66,24 @@ private void set(String range) { public String toString() { return "[" + min + ((max == min) ? "" : ":" + step + ":" + max) + "]"; } + + @Override + public IntegerRange convert(String value) { + return new IntegerRange(value); + } } - public static class FloatRange { + public static class FloatRange implements CommandLine.ITypeConverter { float min; float step; float max; - private FloatRange(float min, float step, float max) { - this.min = min; - this.step = step; - this.max = max; + // Needed for picocli instantitation + @SuppressWarnings("unused") + public FloatRange() { } - private void set(String range) { + FloatRange(String range) { if (range == null) { return; } @@ -127,5 +110,10 @@ private void set(String range) { public String toString() { return "[" + min + ((max == min) ? "" : ":" + step + ":" + max) + "]"; } + + @Override + public FloatRange convert(String value) { + return new FloatRange(value); + } } } \ No newline at end of file diff --git a/src/main/java/edu/vt/rhids/main/RHIDS.java b/src/main/java/edu/vt/rhids/main/RHIDS.java index 4d44bdd..f4674ef 100644 --- a/src/main/java/edu/vt/rhids/main/RHIDS.java +++ b/src/main/java/edu/vt/rhids/main/RHIDS.java @@ -5,13 +5,10 @@ import edu.vt.rhids.output.Summary; import edu.vt.rhids.util.Logger; import edu.vt.rhids.util.Logger.Verbosity; -import org.apache.commons.cli.*; import java.io.BufferedReader; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; -import java.util.List; /** * Resilient Host-based Intrusion Detection System @@ -19,9 +16,6 @@ * @author AmrAbed */ public class RHIDS { - private static final String OUTPUT_FILE = "output-file"; - private static final String DB_FILE = "database-file"; - private static final String VERBOSE = "verbose"; private static RHIDS instance = null; private boolean isUnderAttack; @@ -36,8 +30,7 @@ public static RHIDS getInstance() { return instance; } - public List run(String[] args) { - final Parameters p = parseArguments(args); + public Summary run(Parameters p) { Logger.log(p, Verbosity.NONE); final Summary summary = new Summary(); try { @@ -78,66 +71,6 @@ public List run(String[] args) { return summary; } - private Parameters parseArguments(String[] args) { - final Parameters parameters = new Parameters(); - final Options options = createOptions(); - - try { - CommandLine command = new BasicParser().parse(options, args); - - if (command.hasOption("help")) { - new HelpFormatter().printHelp("RHIDS", options); - System.exit(0); - } - - if (command.hasOption(VERBOSE)) { - Logger.setLevel(Integer.parseInt(command.getOptionValue(VERBOSE))); - } - - if (command.hasOption(OUTPUT_FILE)) { - Logger.setHandler(command.getOptionValue(OUTPUT_FILE)); - } - - if (command.hasOption(DB_FILE)) { - parameters.setDatabaseFilePath(command.getOptionValue(DB_FILE)); - } - - parameters.setNormalFilePath(command.getOptionValue("input-file")); - parameters.setEpochSize(command.getOptionValue("epoch-size")); - parameters.setTrainThreshold(command.getOptionValue("train-threshold")); - parameters.setTestThreshold(command.getOptionValue("detection-threshold")); - } catch (ParseException | FileNotFoundException e) { - Logger.log("Parsing failed: " + e.getMessage(), Verbosity.NONE); - System.exit(-1); - } - - return parameters; - } - - private Options createOptions() { - - final Options options = new Options(); - - final OptionGroup group = new OptionGroup(); - group.addOption(new Option("h", "help", false, "Print this help message")); - group.addOption(new Option("i", "input-file", true, "Input file path")); - group.setRequired(true); - - options.addOptionGroup(group); - - options.addOption("b", DB_FILE, true, "File to read database from"); - options.addOption("e", "epoch-size", true, "Range for epoch size (default " + Parameters.DEFAULT_EPOCH_SIZE - + ")"); - options.addOption("t", "train-threshold", true, "Range for training threshold (default " - + Parameters.DEFAULT_TRAIN_THRESHOLD + ")"); - options.addOption("d", "detection-threshold", true, "Range for detection threshold (default " - + Parameters.DEFAULT_TEST_THRESHOLD + ")"); - options.addOption("v", VERBOSE, true, "Verbose level (default 0)"); - options.addOption("o", OUTPUT_FILE, true, "Output file path"); - - return options; - } - public IndexMap getIndexMap() { return indexMap; } @@ -157,4 +90,4 @@ boolean isTrainingActive() { public void setDoneTraining(boolean doneTraining) { this.isDoneTraining = doneTraining; } -} +} \ No newline at end of file