@Test public void testParseCommandLine() throws Exception{ String user_dir = System.getProperty("user.dir"); File file = new File(user_dir); String bin_path = Paths.get(user_dir, "src","test","resources","sample_dep").toString(); String classPrefix = "org.tudelft"; File outputDir = Paths.get(user_dir, "target", "generated-models").toFile(); String[] prop = { "-" + CommandLineParameters.PROJECT_CP_OPT, bin_path, "-" + CommandLineParameters.PROJECT_PREFIX, classPrefix, "-" + CommandLineParameters.OUTPUT_FOLDER, outputDir.getAbsolutePath() }; ModelGeneration main = new ModelGeneration(); main.parseCommandLine(prop); assertThat(outputDir, anExistingDirectory()); assertThat(outputDir.list(), arrayWithSize(greaterThan(0))); }
public void parseCommandLine(String[] args) throws IOException { Options options = CommandLineParameters.getCommandLineOptions(); CommandLine commands = parseCommands(args, options); if(commands.hasOption(HELP_OPT)) { printHelpMessage(options); } else if(commands.hasOption(PROJECT_CP_OPT)) { String cp = commands.getOptionValue(PROJECT_CP_OPT); List<String> classPathEntries = ClassPaths.getClassPathEntries(cp); CallSequenceCollector callSequenceCollector = new CallSequenceCollector(classPathEntries.toArray(new String[classPathEntries.size()])); String outputFolder = commands.hasOption(OUTPUT_FOLDER) ? commands.getOptionValue(OUTPUT_FOLDER) : "generated_results"; List<String> involvedObejcts = new ArrayList<>(); if(commands.hasOption(CRASHES)) { Gson gson = new Gson(); ArrayList<String> crashes = gson.fromJson(commands.getOptionValue(CRASHES), ArrayList.class); LogReader logReader = new LogReader(crashes); involvedObejcts = logReader.collectInvolvedObjects(); } else if(commands.hasOption(LIST_CLASSES)) { File listClasses = new File(commands.getOptionValue(LIST_CLASSES)); involvedObejcts = Files.readAllLines(listClasses.toPath()); } if(commands.hasOption(PROJECT_PREFIX) ^ commands.hasOption(PROJECT_PACKAGE)) { if(commands.hasOption(PROJECT_PREFIX)) { callSequenceCollector.collect(commands.getOptionValue(PROJECT_PREFIX), outputFolder, involvedObejcts, true); } else { callSequenceCollector.collect(commands.getOptionValue(PROJECT_PACKAGE), outputFolder, involvedObejcts, false); } ModelGenerator modelGenerator = new ModelGenerator(); try { modelGenerator.generate(CallSequencesPoolManager.getInstance().getPool(), Paths.get(outputFolder, "models").toString()); } catch(SessionBuildException e) { LOG.error("Exception while building a session to learn the model!", e); } } else { LOG.error("Either project prefix or project package name should be passed as an input. For more " + "information, use -" + HELP_OPT); } } else { LOG.error("Project classpath should be passed as an input. For more information -> help"); } }
ModelGeneration { public void parseCommandLine(String[] args) throws IOException { Options options = CommandLineParameters.getCommandLineOptions(); CommandLine commands = parseCommands(args, options); if(commands.hasOption(HELP_OPT)) { printHelpMessage(options); } else if(commands.hasOption(PROJECT_CP_OPT)) { String cp = commands.getOptionValue(PROJECT_CP_OPT); List<String> classPathEntries = ClassPaths.getClassPathEntries(cp); CallSequenceCollector callSequenceCollector = new CallSequenceCollector(classPathEntries.toArray(new String[classPathEntries.size()])); String outputFolder = commands.hasOption(OUTPUT_FOLDER) ? commands.getOptionValue(OUTPUT_FOLDER) : "generated_results"; List<String> involvedObejcts = new ArrayList<>(); if(commands.hasOption(CRASHES)) { Gson gson = new Gson(); ArrayList<String> crashes = gson.fromJson(commands.getOptionValue(CRASHES), ArrayList.class); LogReader logReader = new LogReader(crashes); involvedObejcts = logReader.collectInvolvedObjects(); } else if(commands.hasOption(LIST_CLASSES)) { File listClasses = new File(commands.getOptionValue(LIST_CLASSES)); involvedObejcts = Files.readAllLines(listClasses.toPath()); } if(commands.hasOption(PROJECT_PREFIX) ^ commands.hasOption(PROJECT_PACKAGE)) { if(commands.hasOption(PROJECT_PREFIX)) { callSequenceCollector.collect(commands.getOptionValue(PROJECT_PREFIX), outputFolder, involvedObejcts, true); } else { callSequenceCollector.collect(commands.getOptionValue(PROJECT_PACKAGE), outputFolder, involvedObejcts, false); } ModelGenerator modelGenerator = new ModelGenerator(); try { modelGenerator.generate(CallSequencesPoolManager.getInstance().getPool(), Paths.get(outputFolder, "models").toString()); } catch(SessionBuildException e) { LOG.error("Exception while building a session to learn the model!", e); } } else { LOG.error("Either project prefix or project package name should be passed as an input. For more " + "information, use -" + HELP_OPT); } } else { LOG.error("Project classpath should be passed as an input. For more information -> help"); } } }
ModelGeneration { public void parseCommandLine(String[] args) throws IOException { Options options = CommandLineParameters.getCommandLineOptions(); CommandLine commands = parseCommands(args, options); if(commands.hasOption(HELP_OPT)) { printHelpMessage(options); } else if(commands.hasOption(PROJECT_CP_OPT)) { String cp = commands.getOptionValue(PROJECT_CP_OPT); List<String> classPathEntries = ClassPaths.getClassPathEntries(cp); CallSequenceCollector callSequenceCollector = new CallSequenceCollector(classPathEntries.toArray(new String[classPathEntries.size()])); String outputFolder = commands.hasOption(OUTPUT_FOLDER) ? commands.getOptionValue(OUTPUT_FOLDER) : "generated_results"; List<String> involvedObejcts = new ArrayList<>(); if(commands.hasOption(CRASHES)) { Gson gson = new Gson(); ArrayList<String> crashes = gson.fromJson(commands.getOptionValue(CRASHES), ArrayList.class); LogReader logReader = new LogReader(crashes); involvedObejcts = logReader.collectInvolvedObjects(); } else if(commands.hasOption(LIST_CLASSES)) { File listClasses = new File(commands.getOptionValue(LIST_CLASSES)); involvedObejcts = Files.readAllLines(listClasses.toPath()); } if(commands.hasOption(PROJECT_PREFIX) ^ commands.hasOption(PROJECT_PACKAGE)) { if(commands.hasOption(PROJECT_PREFIX)) { callSequenceCollector.collect(commands.getOptionValue(PROJECT_PREFIX), outputFolder, involvedObejcts, true); } else { callSequenceCollector.collect(commands.getOptionValue(PROJECT_PACKAGE), outputFolder, involvedObejcts, false); } ModelGenerator modelGenerator = new ModelGenerator(); try { modelGenerator.generate(CallSequencesPoolManager.getInstance().getPool(), Paths.get(outputFolder, "models").toString()); } catch(SessionBuildException e) { LOG.error("Exception while building a session to learn the model!", e); } } else { LOG.error("Either project prefix or project package name should be passed as an input. For more " + "information, use -" + HELP_OPT); } } else { LOG.error("Project classpath should be passed as an input. For more information -> help"); } }  }
ModelGeneration { public void parseCommandLine(String[] args) throws IOException { Options options = CommandLineParameters.getCommandLineOptions(); CommandLine commands = parseCommands(args, options); if(commands.hasOption(HELP_OPT)) { printHelpMessage(options); } else if(commands.hasOption(PROJECT_CP_OPT)) { String cp = commands.getOptionValue(PROJECT_CP_OPT); List<String> classPathEntries = ClassPaths.getClassPathEntries(cp); CallSequenceCollector callSequenceCollector = new CallSequenceCollector(classPathEntries.toArray(new String[classPathEntries.size()])); String outputFolder = commands.hasOption(OUTPUT_FOLDER) ? commands.getOptionValue(OUTPUT_FOLDER) : "generated_results"; List<String> involvedObejcts = new ArrayList<>(); if(commands.hasOption(CRASHES)) { Gson gson = new Gson(); ArrayList<String> crashes = gson.fromJson(commands.getOptionValue(CRASHES), ArrayList.class); LogReader logReader = new LogReader(crashes); involvedObejcts = logReader.collectInvolvedObjects(); } else if(commands.hasOption(LIST_CLASSES)) { File listClasses = new File(commands.getOptionValue(LIST_CLASSES)); involvedObejcts = Files.readAllLines(listClasses.toPath()); } if(commands.hasOption(PROJECT_PREFIX) ^ commands.hasOption(PROJECT_PACKAGE)) { if(commands.hasOption(PROJECT_PREFIX)) { callSequenceCollector.collect(commands.getOptionValue(PROJECT_PREFIX), outputFolder, involvedObejcts, true); } else { callSequenceCollector.collect(commands.getOptionValue(PROJECT_PACKAGE), outputFolder, involvedObejcts, false); } ModelGenerator modelGenerator = new ModelGenerator(); try { modelGenerator.generate(CallSequencesPoolManager.getInstance().getPool(), Paths.get(outputFolder, "models").toString()); } catch(SessionBuildException e) { LOG.error("Exception while building a session to learn the model!", e); } } else { LOG.error("Either project prefix or project package name should be passed as an input. For more " + "information, use -" + HELP_OPT); } } else { LOG.error("Project classpath should be passed as an input. For more information -> help"); } }  @SuppressWarnings("checkstyle:systemexit") static void main(String[] args); void parseCommandLine(String[] args); }
ModelGeneration { public void parseCommandLine(String[] args) throws IOException { Options options = CommandLineParameters.getCommandLineOptions(); CommandLine commands = parseCommands(args, options); if(commands.hasOption(HELP_OPT)) { printHelpMessage(options); } else if(commands.hasOption(PROJECT_CP_OPT)) { String cp = commands.getOptionValue(PROJECT_CP_OPT); List<String> classPathEntries = ClassPaths.getClassPathEntries(cp); CallSequenceCollector callSequenceCollector = new CallSequenceCollector(classPathEntries.toArray(new String[classPathEntries.size()])); String outputFolder = commands.hasOption(OUTPUT_FOLDER) ? commands.getOptionValue(OUTPUT_FOLDER) : "generated_results"; List<String> involvedObejcts = new ArrayList<>(); if(commands.hasOption(CRASHES)) { Gson gson = new Gson(); ArrayList<String> crashes = gson.fromJson(commands.getOptionValue(CRASHES), ArrayList.class); LogReader logReader = new LogReader(crashes); involvedObejcts = logReader.collectInvolvedObjects(); } else if(commands.hasOption(LIST_CLASSES)) { File listClasses = new File(commands.getOptionValue(LIST_CLASSES)); involvedObejcts = Files.readAllLines(listClasses.toPath()); } if(commands.hasOption(PROJECT_PREFIX) ^ commands.hasOption(PROJECT_PACKAGE)) { if(commands.hasOption(PROJECT_PREFIX)) { callSequenceCollector.collect(commands.getOptionValue(PROJECT_PREFIX), outputFolder, involvedObejcts, true); } else { callSequenceCollector.collect(commands.getOptionValue(PROJECT_PACKAGE), outputFolder, involvedObejcts, false); } ModelGenerator modelGenerator = new ModelGenerator(); try { modelGenerator.generate(CallSequencesPoolManager.getInstance().getPool(), Paths.get(outputFolder, "models").toString()); } catch(SessionBuildException e) { LOG.error("Exception while building a session to learn the model!", e); } } else { LOG.error("Either project prefix or project package name should be passed as an input. For more " + "information, use -" + HELP_OPT); } } else { LOG.error("Project classpath should be passed as an input. For more information -> help"); } }  @SuppressWarnings("checkstyle:systemexit") static void main(String[] args); void parseCommandLine(String[] args);  }