src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/local/LocalDebianSoftwareExtractor.java
File was removed.
src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/local/Log.java
File was removed.
src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/local/Test.java
File was removed.
src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/CommandManager.java
File was removed.
src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/Engine2.java
File was removed.
src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/LocalCLI.java
File was removed.
src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/ReadJSON.java
File was removed.
request
File was removed.
src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/absolute/Engine.java Diff Switch to unified view
src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/local/CLI.java Diff Switch to unified view
src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/local/CommandManager.java Diff Switch to unified view
src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/remote/DebianSoftwareExtractor.java Diff Switch to unified view
src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/CLI.java Diff Switch to unified view
src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/cli/CLI.java to src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/local/LocalCLI.java
--- a/src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/cli/CLI.java +++ b/src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/local/LocalCLI.java @@ -16,78 +16,51 @@ * See the License for the specific language governing permissions and limitation under the License. */ -package net.timbusproject.extractors.modules.debiansoftwareextractor.cli; +package net.timbusproject.extractors.modules.debiansoftwareextractor.local; -import com.jcraft.jsch.JSchException; -import net.timbusproject.extractors.modules.debiansoftwareextractor.Engine; -import net.timbusproject.extractors.modules.debiansoftwareextractor.ReadJSON; -import net.timbusproject.extractors.modules.debiansoftwareextractor.SSHManager; -import org.apache.commons.cli.*; -import org.apache.commons.cli.ParseException; import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; import java.io.IOException; -import java.text.*; -import java.util.Scanner; +import java.text.ParseException; -public class CLI { - public static void main(String... args) throws ParseException, IOException, JSONException, JSchException, java.text.ParseException { - final Options options = new Options(); - final CommandLineParser parser = new PosixParser(); - //Available options - options.addOption("e", "extract", true, "[user@]hostname]"); - options.addOption("h", "help", false, "Prints this help message"); - final CommandLine line = parser.parse(options, args); +public class LocalCLI { - //Print help if there are no arguments - checkOptions(options, line); + public static void main(String[] args) throws IOException, JSONException { + try { + CommandManager commandManager = new CommandManager(); + JSONArray array; - if (line.hasOption("h")) { - printHelp(options); - } - - String extract = getOption("e", line); - if (extract.isEmpty()) { -// printHelp(options); - } else { - String[] split = extract.split("@"); - String user = "", fqdn = ""; - //user@hostname - if (split.length == 2) { - user = split[0]; - fqdn = split[1]; - Scanner scanner = new Scanner(System.in); - System.out.println("Please write your pass: "); - String pass = scanner.nextLine(); - SSHManager manager = new SSHManager(user, pass, fqdn, "", ""); - - Engine engine = new Engine(); - JSONArray jsonArray = engine.run(manager); - System.out.print(jsonArray.toString(2)); + array = commandManager.run(true); + if (args.length > 0) { + File f; + if (args[0].equals("y")) + f = new File("extraction.json"); + else + f = new File(args[0]); + BufferedWriter fileWriter = new BufferedWriter(new FileWriter(f)); + fileWriter.write(array.toString(2)); + fileWriter.close(); + if (args.length > 1) { + String command; + if (args[1].equals("y")) + command = "java -jar local-deb-software-converter-1.0-SNAPSHOT.jar"; + else + command = "java -jar " + args[1]; + if (args.length > 2){ + command = command + " " + args[2]; + if(args.length > 3) + command = command + " " + args[3]; + } + commandManager.doCommand(command); + } } - System.exit(0); + } catch (ParseException e) { + e.printStackTrace(); } } +} - public static String getOption(String option, CommandLine line) { - if (line.hasOption(option)) { - return line.getOptionValue(option); - } - - return ""; - } - - public static void checkOptions(Options options, CommandLine line) { - HelpFormatter formatter = new HelpFormatter(); - if (line.getOptions().length == 0) - formatter.printHelp("launch", options); - - } - - private static void printHelp(Options options) { - HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp("launch", options); - System.exit(0); - } -}
src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/local/CLOption.java to src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/absolute/ReadJSON.java
--- a/src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/local/CLOption.java +++ b/src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/absolute/ReadJSON.java @@ -1,135 +1,43 @@ -package net.timbusproject.extractors.modules.debiansoftwareextractor.local; +/** + * Copyright (c) 2013, Caixa Magica Software Lda (CMS). + * The work has been developed in the TIMBUS Project and the above-mentioned are Members of the TIMBUS Consortium. + * TIMBUS is supported by the European Union under the 7th Framework Programme for research and technological + * development and demonstration activities (FP7/2007-2013) under grant agreement no. 269940. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including without + * limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTIBITLY, or FITNESS FOR A PARTICULAR + * PURPOSE. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, + * unless required by applicable law or agreed to in writing, shall any Contributor be liable for damages, including + * any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this + * License or out of the use or inability to use the Work. + * See the License for the specific language governing permissions and limitation under the License. + */ +package net.timbusproject.extractors.modules.debiansoftwareextractor.absolute; -import org.apache.commons.cli.Option; +import org.apache.commons.io.IOUtils; +import org.codehaus.jettison.json.JSONArray; +import org.codehaus.jettison.json.JSONException; -/** - * Created with IntelliJ IDEA. - * User: jorge - * Date: 1/7/14 - * Time: 3:42 PM - * To change this template use File | Settings | File Templates. - */ -class CLOption { +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.StringWriter; - private final Option option; - private final String defaultValue; - private String title; +public class ReadJSON { - private CLOption(Option option) { - this(option, null); + private JSONArray jsonArray; + + public ReadJSON(String path) throws IOException, JSONException { + StringWriter writer = new StringWriter(); + IOUtils.copy(new FileInputStream(new File(path)), writer); + this.jsonArray = new JSONArray(writer.toString()); } - private CLOption(Option option, String defaultValue) { - this.option = option; - this.defaultValue = defaultValue; + public JSONArray getJsonArray() { + return jsonArray; } - static CLOption buildOption(Option option) { - return new CLOption(option); - } - - static CLOption buildOption(Option option, String argName) { - option.setArgName(argName); - return new CLOption(option); - } - - static CLOption buildOption(Option option, Class type) { - option.setType(type); - return new CLOption(option); - } - - static CLOption buildOption(Option option, String argName, Class type) { - option.setArgName(argName); - option.setType(type); - return new CLOption(option); - } - - static CLOption buildOption(Option option, String argName, Class type, String defaultValue) { - option.setArgName(argName); - option.setType(type); - return new CLOption(option, defaultValue); - } - - CLOption setTitle(String title) { - this.title = title; - return this; - } - - String getDefaultValue() { - return defaultValue; - } - - String getTitle() { - return title; - } - - Option getOption() { - return option; - } - - - - - - - - - - - - -/* - public CLOption(String opt, String description) throws IllegalArgumentException { - super(opt, description); - } - - public CLOption(String opt, boolean hasArg, String description) throws IllegalArgumentException { - super(opt, hasArg, description); - } - - public CLOption(String opt, boolean hasArg, String description, Class type) throws IllegalArgumentException { - super(opt, hasArg, description); - setType(type); - } - - public CLOption(String opt, String longOpt, boolean hasArg, String description) throws IllegalArgumentException { - super(opt, longOpt, hasArg, description); - } - - public CLOption(String opt, String longOpt, boolean hasArg, String description, Class type) throws IllegalArgumentException { - super(opt, longOpt, hasArg, description); - setType(type); - } - - public CLOption(String opt, String longOpt, boolean hasArg, String description, String argName) throws IllegalArgumentException { - super(opt, longOpt, hasArg, description); - setArgName(argName); - } - - public CLOption(String opt, String longOpt, boolean hasArg, String description, String argName, Class type) throws IllegalArgumentException { - this(opt, longOpt, hasArg, description, argName); - setType(type); - } - - public CLOption(String opt, String longOpt, boolean hasArg, String description, int args) throws IllegalArgumentException { - super(opt, longOpt, hasArg, description); - setArgs(args); - } - - public CLOption(String opt, String longOpt, boolean hasArg, String description, int args, Class type) throws IllegalArgumentException { - this(opt, longOpt, hasArg, description, args); - setType(type); - } - - public CLOption(String opt, String longOpt, boolean hasArg, String description, String argName, int args) throws IllegalArgumentException { - this(opt, longOpt, hasArg, description, argName); - setArgs(args); - } - - public CLOption(String opt, String longOpt, boolean hasArg, String description, String argName, int args, Class type) throws IllegalArgumentException { - this(opt, longOpt, hasArg, description, argName, args); - setType(type); - } -*/ - }
src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/local/CommonsEngine2.java to src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/absolute/Engine2.java
--- a/src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/local/CommonsEngine2.java +++ b/src/main/java/net/timbusproject/extractors/modules/debiansoftwareextractor/absolute/Engine2.java @@ -1,234 +1,224 @@ -package net.timbusproject.extractors.modules.debiansoftwareextractor.local; +package net.timbusproject.extractors.modules.debiansoftwareextractor.absolute; import com.jcraft.jsch.JSchException; -import net.timbusproject.extractors.core.Endpoint; -import net.timbusproject.extractors.modules.debiansoftwareextractor.absolute.Engine; -import net.timbusproject.extractors.modules.debiansoftwareextractor.absolute.SSHManager; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.ParseException; import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import java.io.*; -import java.util.*; -import java.util.regex.Pattern; - -/** - * Created with IntelliJ IDEA. - * User: jorge - * Date: 12/17/13 - * Time: 5:36 PM - * To change this template use File | Settings | File Templates. - */ -public class CommonsEngine2 { - - private final CLI cmd = new CLI(); - private final JSONObject request = new JSONObject(); - private JSONObject response; - // private final OutputStream out; - private final Log log; - Engine engine = new Engine(); - - public CommonsEngine2(String... args) throws IOException, ParseException, JSONException, JSchException, java.text.ParseException { - this(args, null); - } - - public CommonsEngine2(String[] args, OutputStream out) throws IOException, ParseException, JSONException, JSchException, java.text.ParseException { - response = new JSONObject(); - setOptions(); - OutputStream o = null; -// cmd.parse(args); - try { - o = parse(args); - } catch (ParseException e) { - Log.out(System.out, true, true, e.getMessage()); - } - log = new Log(o != null ? o : out); - printHelp(); - execute(); - } - - private void execute() throws IOException, JSONException, JSchException, java.text.ParseException { - String result = ""; - if(!cmd.hasOption("l") && !cmd.hasOption("s") && !cmd.hasOption("o") && !cmd.hasOption("j")) - printUsage(System.out); - if (cmd.hasOption("l")) { - boolean show = false; - if (cmd.hasOption("s")) - show = true; - result = engine.run(show).toString(); - } - if (cmd.hasOption("j")) { - StringBuilder request = new StringBuilder(); - String currentLine; - BufferedReader fileReader = new BufferedReader(new FileReader(new File(cmd.getOptionValue("j")))); - while ((currentLine = fileReader.readLine()) != null) - request.append(currentLine); - fileReader.close(); - JSONObject jsonObject = new JSONObject(request.toString()); - SSHManager manager = new SSHManager( - jsonObject.optString("user"), - jsonObject.optString("password"), - jsonObject.optString("fqdn"), - jsonObject.optString("knownHosts"), - jsonObject.has("port") ? Integer.parseInt(jsonObject.getString("port")) : Endpoint.DEFAULT_SSH_PORT, - jsonObject.optString("privateKey")); - result = engine.run(manager).toString(); - if(cmd.hasOption("s")) - System.out.println(result); - } - if (cmd.hasOption("o")) - if (result != "") { - engine.writeToFile(cmd.getOptionValue("o"), result); - } - } - - public boolean printHelp() throws IOException { - if (cmd.getParsedOptions() == null) - printUsage(System.out); - else if (cmd.hasOption("h")) - printUsage(System.out); - else - return false; - return true; - } - - public boolean confirmInput() throws IOException, ParseException { - Hashtable<String, List<Object>> table = new Hashtable<>(); - for (Option option : cmd.getParsedOptions()) { - String title = cmd.getOptionTitle(option); - if (!table.containsKey(title)) - table.put(title, new ArrayList<>()); - table.get(title).add(cmd.getParsedValue(option)); - } -/* - String[] values = inputToArray(cmd.getParsedValues()); - Log.out(System.out, true, "Your input was:"); - Log.out(System.out, true, values); -*/ - List<String> list = new ArrayList<>(); - list.add("Your input was:"); - for (Map.Entry<String, List<Object>> entry : table.entrySet()) { - list.add(formatString(4, cmd.getOptionsTab(), ':', entry.getKey(), String.valueOf(entry.getValue()).replaceAll("\\[|\\]", ""))); - } - Log.out(System.out, true, list.toArray(new String[list.size()])); - Log.out(System.out, "Proceed using this information? [y/n] "); - switch (new Scanner(System.in).nextLine().trim().toLowerCase()) { - case "y": - case "": - list.add(""); - log.out(true, list.toArray(new String[list.size()])); - Log.out(System.out, true, ""); - return true; - } - return false; - } - -/* - private String[] inputToArray(Hashtable<String, List<Object>> table) { - List<String> list = new ArrayList<>(); - for (Map.Entry<String, List<Object>> entry : table.entrySet()) { - list.add(formatString(4, cmd.getOptionsTab(), ':', entry.getKey(), String.valueOf(entry.getValue()).replaceAll("\\[|\\]", ""))); - } - return list.toArray(new String[list.size()]); - } -*/ - - public boolean convert() throws JSONException, IOException, ParseException { +import java.text.ParseException; +import java.util.LinkedList; +import java.util.Scanner; + +public class Engine2 { + + public JSONArray run(SSHManager instance) throws JSchException, IOException, JSONException { + String dpkgStatus = "less /var/lib/dpkg/status"; + String result; + if (instance != null) { + instance.connect(); + result = instance.sendCommand(dpkgStatus); + } else + result = doLocalCommand(dpkgStatus); + + StringBuilder stringBuilder = new StringBuilder(result); + Scanner scanner = new Scanner(stringBuilder.toString()); + LinkedList<String> packgeList = buildList(scanner); + JSONArray array = parseList(packgeList); + + // printList(packgeList); + + writeToFile(array.toString(2)); + if (instance != null) + instance.close(); + + return array; + } + + public JSONArray run() throws ParseException, JSchException, JSONException, IOException { + return run(null); + } + + public String doLocalCommand(String command) throws IOException { + StringBuilder outputBuffer = new StringBuilder(); + InputStream commandOutput; + ProcessBuilder processBuilder = new ProcessBuilder("/bin/sh", "-c", command); + Process p = processBuilder.start(); + commandOutput = p.getInputStream(); + + int readByte = commandOutput.read(); + while (readByte != 0xffffffff) { + outputBuffer.append((char) readByte); + readByte = commandOutput.read(); + } + commandOutput.close(); + p.destroy(); + return outputBuffer.toString(); + } + + + private void printList(LinkedList<String> packgeList) throws IOException { + StringBuilder stringBuilder = new StringBuilder(); + for (String str : packgeList) + stringBuilder.append(str); + + writeToFile(stringBuilder.toString()); + + } + + private JSONArray parseList(LinkedList<String> packgeList) throws JSONException { + + JSONArray array = new JSONArray(); + for (String str : packgeList) { + array.put(parser(str)); + } + return array; + } + + private void writeToFile(String result) throws IOException { + File file = new File("intel-extraction.json"); + if (file.exists()) + file.createNewFile(); + + FileWriter fileWriter = new FileWriter(file.getAbsoluteFile()); + BufferedWriter bufWriter = new BufferedWriter(fileWriter); + bufWriter.write(result); + bufWriter.close(); + + } + + private LinkedList<String> buildList(Scanner scanner) { + LinkedList<String> linkedList = new LinkedList<>(); + StringBuilder stringBuilder = new StringBuilder(); + String tmp; + while (scanner.hasNextLine()) { + tmp = scanner.nextLine(); + stringBuilder.append(tmp + "\n"); + + if (tmp.isEmpty()) { + linkedList.add(stringBuilder.toString()); + stringBuilder = new StringBuilder(); + } + } + return linkedList; + } + + + public JSONObject parser(String pkg) throws JSONException { + Scanner scanner = new Scanner(pkg); + JSONObject jsonObject = new JSONObject(); + String key = ""; + while (scanner.hasNextLine()) { + String tmp = ""; + + if (scanner.hasNext()) + tmp = scanner.next(); + + if (tmp.endsWith(":")) { + key = tmp.replace(':', ' ').trim(); + } + + switch (key.toLowerCase()) { + case "conffiles": + getConffiles(scanner, jsonObject, tmp, key); + break; + + // fields with | + case "pre-depends": + case "recommends": + case "suggests": + case "depends": + // fields without | + case "provides": + case "conflicts": + case "replaces": + JSONArray jsonArrayAnd = getDepends(scanner); + jsonObject.put(key, jsonArrayAnd); + break; + default: + if (scanner.hasNextLine()) + jsonObject.put(key, scanner.nextLine().trim()); + break; + } + + } + return jsonObject; + } + + private JSONArray getDepends(Scanner scanner) throws JSONException { + String[] depends = scanner.nextLine().trim().split(","); + // main array + JSONArray jsonArrayAnd = new JSONArray(); + for (String s : depends) { + JSONArray jsonArrayOr = new JSONArray(); + + if (s.contains("|")) { + JSONArray result = orDependency(s); + jsonArrayOr.put(result); +// System.out.println("Result " + result.toString()); + } else { + String[] temp = s.trim().split(" "); + JSONObject jsonDependency = new JSONObject(); + for (String pkgOr : temp) { + String[] split = pkgOr.trim().split(" "); + for (String string : split) { + if (string.contains("(")) { + jsonDependency.put("Comparator", string.replace("(", "")); + } else if (string.contains(")")) { + jsonDependency.put("Version", string.replace(")", "")); + } else if (string.length() > 0) { + jsonDependency.put("Package", string.trim()); + } +// System.out.println("STRING" + string); + } + } + jsonArrayOr.put(jsonDependency); + } + if (jsonArrayOr.length() == 1) + jsonArrayAnd.put(jsonArrayOr.get(0)); + else + jsonArrayAnd.put(jsonArrayOr); + } + return jsonArrayAnd; + } + + private JSONArray orDependency(String s) throws JSONException { + String[] temp = s.trim().split("\\|"); + JSONArray orDependencies = new JSONArray(); + for (String pkgOr : temp) { + JSONObject jsonDependency = new JSONObject(); + String[] split = pkgOr.trim().split(" "); + for (String string : split) { + if (string.contains("(")) { + jsonDependency.put("Comparator", string.replace("(", "")); + } else if (string.contains(")")) { + jsonDependency.put("Version", string.replace(")", "")); + } else if (string.length() > 0) { + jsonDependency.put("Package", string.trim()); + } + } + orDependencies.put(jsonDependency); + } + return orDependencies; + } + + + private void getConffiles(Scanner scanner, JSONObject jsonObject, String tmp, String key) throws JSONException { JSONArray jsonArray = new JSONArray(); - for (Object o : cmd.getAllParsedValues("f")) { - if (!(o instanceof File) || !((File) o).isFile()) { - Log.out(System.out, true, true, "Invalid file" + (o != null ? ": " + o : ".")); - return false; - } - Scanner scanner = new Scanner((File) o); - JSONObject jsonObject = new JSONObject(); - while (scanner.hasNextLine()) { - Map.Entry<String, String> entry = new AbstractMap.SimpleImmutableEntry<>( - scanner.findInLine(Pattern.compile("[\\p{L}|\\p{N}]+")), - scanner.nextLine().substring(1).trim() - ); - if (entry.getValue() != null && entry.getValue().length() > 0) - jsonObject.put(entry.getKey(), entry.getValue()); - } - jsonArray.put(jsonObject); - } - request.put("extractions", jsonArray); - return true; - } - - public void printRequest() throws JSONException, IOException { - log.out(true, request.toString(2)); - Log.out(System.out, true, "Input generated."); - } - - /*public StatusLine submit() throws IOException, JSONException { - HttpPost post = new HttpPost("/api/extract"); - post.setHeader("Content-Type", "application/json"); - post.setEntity(new StringEntity(request.toString())); - HttpResponse httpResponse = new DefaultHttpClient().execute(post); - - if (httpResponse.getFirstHeader("Content-Type").getValue().equals("application/json")) { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - httpResponse.getEntity().writeTo(stream); - response = new JSONObject(new String(stream.toByteArray())); - } - return httpResponse.getStatusLine(); - }*/ - - public void printResponse() throws JSONException, IOException { - log.out(true, response.toString(2)); - } - - private void setOptions() { - cmd.addOption( - CLOption.buildOption(new Option("h", "help", false, "print help")), - CLOption.buildOption(new Option("l", "local-extraction", false, "Do local extraction")), - CLOption.buildOption(new Option("s", "show-extraction", false, "Show extraction in stdout")), - CLOption.buildOption(new Option("f", "text-file", true, "load request from text file"), "path-to-file", File.class).setTitle("Text files"), - CLOption.buildOption(new Option("j", "json-file", true, "load request from json file"), "path-to-file", File.class).setTitle("JSON files"), - CLOption.buildOption(new Option("o", "out", true, "file to save output to"), "path-to-file", File.class).setTitle("Output file") - ); - } - - private OutputStream parse(String[] args) throws ParseException, FileNotFoundException { - try { - cmd.parse(args); - if (cmd.hasOption("o")) - return new FileOutputStream((File) cmd.getParsedValue("o")); - } catch (ParseException e) { - throw new ParseException(e.getMessage() + "\n"); - } - return null; - } - - private Properties readManifest() throws IOException { - Properties manifest = new Properties(); - Scanner scan = new Scanner(getClass().getClassLoader().getResourceAsStream("META-INF/MANIFEST.MF")); - manifest.setProperty("title", - scan.findWithinHorizon(Pattern.compile("Implementation-Title:", Pattern.CASE_INSENSITIVE), 0) != null - ? scan.nextLine().trim() - : "Context Population CLI"); - scan.reset(); - manifest.setProperty("version", - scan.findWithinHorizon(Pattern.compile("Implementation-Version:", Pattern.CASE_INSENSITIVE), 0) != null - ? scan.nextLine().trim() - : "0.0.1-SNAPSHOT"); - return manifest; - } - - private void printUsage(OutputStream out) throws IOException { - Properties mf = readManifest(); - new HelpFormatter().printHelp(new PrintWriter(out, true), 120, "extraction", "", cmd.getOptions(), 2, 4, - "\nRunning version " + mf.getProperty("version") + " of the " + mf.getProperty("title") + ".", true); - } - - private String formatString(int indentation, int tabSize, char separator, String string1, String string2) { - return (indentation > 0 ? String.format("%" + indentation + "s", ' ') : "") + string1 + - (separator != '\0' ? separator : "") - + (tabSize > 0 ? String.format("%" + Math.max(tabSize - string1.length(), 1) + "s", ' ') : "") + string2; - } - + JSONObject jsonObject1 = new JSONObject(); + String line = ""; + if (scanner.hasNextLine()) + line = scanner.nextLine().trim(); + + if (!tmp.contains(key)) { + jsonObject1.put("file", tmp); + jsonObject1.put("hash", line); + jsonArray.put(jsonObject1); + if (jsonObject.has(key)) { + jsonObject.getJSONArray(key).put(jsonObject1); + } else { + jsonObject.put(key, jsonArray); + } + } + } }