List of usage examples for org.apache.commons.cli Option setRequired
public void setRequired(boolean required)
From source file:fr.inria.atlanmod.kyanos.benchmarks.Migrator.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input file"); inputOpt.setArgs(1);/*from ww w . j a v a 2 s . c o m*/ inputOpt.setRequired(true); Option outputOpt = OptionBuilder.create(OUT); outputOpt.setArgName("OUTPUT"); outputOpt.setDescription("Output file"); outputOpt.setArgs(1); outputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(IN_EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of input EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); Option outClassOpt = OptionBuilder.create(OUT_EPACKAGE_CLASS); outClassOpt.setArgName("CLASS"); outClassOpt.setDescription("FQN of output EPackage implementation class"); outClassOpt.setArgs(1); outClassOpt.setRequired(true); options.addOption(inputOpt); options.addOption(outputOpt); options.addOption(inClassOpt); options.addOption(outClassOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); URI sourceUri = URI.createFileURI(commandLine.getOptionValue(IN)); URI targetUri = URI.createFileURI(commandLine.getOptionValue(OUT)); Class<?> inClazz = Migrator.class.getClassLoader() .loadClass(commandLine.getOptionValue(IN_EPACKAGE_CLASS)); Class<?> outClazz = Migrator.class.getClassLoader() .loadClass(commandLine.getOptionValue(OUT_EPACKAGE_CLASS)); @SuppressWarnings("unused") EPackage inEPackage = (EPackage) inClazz.getMethod("init").invoke(null); EPackage outEPackage = (EPackage) outClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("zxmi", new XMIResourceFactoryImpl()); Resource sourceResource = resourceSet.getResource(sourceUri, true); Resource targetResource = resourceSet.createResource(targetUri); targetResource.getContents().clear(); LOG.log(Level.INFO, "Start migration"); targetResource.getContents() .add(MigratorUtil.migrate(sourceResource.getContents().get(0), outEPackage)); LOG.log(Level.INFO, "Migration finished"); Map<String, Object> saveOpts = new HashMap<String, Object>(); saveOpts.put(XMIResource.OPTION_ZIP, Boolean.TRUE); LOG.log(Level.INFO, "Start saving"); targetResource.save(saveOpts); LOG.log(Level.INFO, "Saving done"); } catch (ParseException e) { showError(e.toString()); showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { showError(e.toString()); } }
From source file:com.genentech.struchk.sdfNormalizer.java
public static void main(String[] args) { long start = System.currentTimeMillis(); int nMessages = 0; int nErrors = 0; int nStruct = 0; // create command line Options object Options options = new Options(); Option opt = new Option("in", true, "input file [.ism,.sdf,...]"); opt.setRequired(true); options.addOption(opt);/*from w w w .j a v a2 s . c o m*/ opt = new Option("out", true, "output file"); opt.setRequired(true); options.addOption(opt); opt = new Option("mol", true, "molFile used for output: ORIGINAL(def)|NORMALIZED|TAUTOMERIC"); opt.setRequired(false); options.addOption(opt); opt = new Option("shortMessage", false, "Limit message to first 80 characters to conform with sdf file specs."); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { exitWithHelp(options, e.getMessage()); throw new Error(e); // avoid compiler errors } args = cmd.getArgs(); if (args.length != 0) { System.err.print("Unknown options: " + args + "\n\n"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("sdfNormalizer", options); System.exit(1); } String molOpt = cmd.getOptionValue("mol"); OUTMolFormat outMol = OUTMolFormat.ORIGINAL; if (molOpt == null || "original".equalsIgnoreCase(molOpt)) outMol = OUTMolFormat.ORIGINAL; else if ("NORMALIZED".equalsIgnoreCase(molOpt)) outMol = OUTMolFormat.NORMALIZED; else if ("TAUTOMERIC".equalsIgnoreCase(molOpt)) outMol = OUTMolFormat.TAUTOMERIC; else { System.err.printf("Unkown option for -mol: %s\n", molOpt); System.exit(1); } String inFile = cmd.getOptionValue("in"); String outFile = cmd.getOptionValue("out"); boolean limitMessage = cmd.hasOption("shortMessage"); try { oemolistream ifs = new oemolistream(inFile); oemolostream ofs = new oemolostream(outFile); URL cFile = OEStruchk.getResourceURL(OEStruchk.class, "Struchk.xml"); // create OEStruchk from config file OEStruchk strchk = new OEStruchk(cFile, CHECKConfig.ASSIGNStructFlag, false); OEGraphMol mol = new OEGraphMol(); StringBuilder sb = new StringBuilder(2000); while (oechem.OEReadMolecule(ifs, mol)) { if (!strchk.applyRules(mol, null)) nErrors++; switch (outMol) { case NORMALIZED: mol.Clear(); oechem.OEAddMols(mol, strchk.getTransformedMol("parent")); break; case TAUTOMERIC: mol.Clear(); oechem.OEAddMols(mol, strchk.getTransformedMol(null)); break; case ORIGINAL: break; } oechem.OESetSDData(mol, "CTISMILES", strchk.getTransformedIsoSmiles(null)); oechem.OESetSDData(mol, "CTSMILES", strchk.getTransformedSmiles(null)); oechem.OESetSDData(mol, "CISMILES", strchk.getTransformedIsoSmiles("parent")); oechem.OESetSDData(mol, "Strutct_Flag", strchk.getStructureFlag().getName()); List<Message> msgs = strchk.getStructureMessages(null); nMessages += msgs.size(); for (Message msg : msgs) sb.append(String.format("\t%s:%s", msg.getLevel(), msg.getText())); if (limitMessage) sb.setLength(Math.min(sb.length(), 80)); oechem.OESetSDData(mol, "NORM_MESSAGE", sb.toString()); oechem.OEWriteMolecule(ofs, mol); sb.setLength(0); nStruct++; } strchk.delete(); mol.delete(); ifs.close(); ifs.delete(); ofs.close(); ofs.delete(); } catch (Exception e) { throw new Error(e); } finally { System.err.printf("sdfNormalizer: Checked %d structures %d errors, %d messages in %dsec\n", nStruct, nErrors, nMessages, (System.currentTimeMillis() - start) / 1000); } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.KyanosMapQueryClassDeclarationAttributes.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input Kyanos resource directory"); inputOpt.setArgs(1);/* w ww .j a v a2 s.c o m*/ inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); CommandLineParser parser = new PosixParser(); try { PersistenceBackendFactoryRegistry.getFactories().put(NeoMapURI.NEO_MAP_SCHEME, new MapPersistenceBackendFactory()); CommandLine commandLine = parser.parse(options, args); URI uri = NeoMapURI.createNeoMapURI(new File(commandLine.getOptionValue(IN))); Class<?> inClazz = KyanosMapQueryClassDeclarationAttributes.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(NeoMapURI.NEO_MAP_SCHEME, PersistentResourceFactory.eINSTANCE); Resource resource = resourceSet.createResource(uri); Map<String, Object> loadOpts = new HashMap<String, Object>(); resource.load(loadOpts); { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); HashMap<String, EList<NamedElement>> list = JavaQueries.getClassDeclarationAttributes(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result contains {0} elements", list.entrySet().size())); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); } if (resource instanceof PersistentResourceImpl) { PersistentResourceImpl.shutdownWithoutUnload((PersistentResourceImpl) resource); } else { resource.unload(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.KyanosMapQueryRenameAllMethods.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input Kyanos resource directory"); inputOpt.setArgs(1);/*from w ww .j ava 2 s . c o m*/ inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); CommandLineParser parser = new PosixParser(); try { PersistenceBackendFactoryRegistry.getFactories().put(NeoMapURI.NEO_MAP_SCHEME, new MapPersistenceBackendFactory()); CommandLine commandLine = parser.parse(options, args); URI uri = NeoMapURI.createNeoMapURI(new File(commandLine.getOptionValue(IN))); Class<?> inClazz = KyanosMapQueryRenameAllMethods.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(NeoMapURI.NEO_MAP_SCHEME, PersistentResourceFactory.eINSTANCE); Resource resource = resourceSet.createResource(uri); Map<String, Object> loadOpts = new HashMap<String, Object>(); resource.load(loadOpts); String name = UUID.randomUUID().toString(); { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); JavaQueries.renameAllMethods(resource, name); long end = System.currentTimeMillis(); resource.save(Collections.emptyMap()); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); } if (resource instanceof PersistentResourceImpl) { PersistentResourceImpl.shutdownWithoutUnload((PersistentResourceImpl) resource); } else { resource.unload(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.KyanosMapQueryLoop.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input Kyanos resource directory"); inputOpt.setArgs(1);// w ww . j av a 2 s . c o m inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); CommandLineParser parser = new PosixParser(); try { PersistenceBackendFactoryRegistry.getFactories().put(NeoMapURI.NEO_MAP_SCHEME, new MapPersistenceBackendFactory()); CommandLine commandLine = parser.parse(options, args); URI uri = NeoMapURI.createNeoMapURI(new File(commandLine.getOptionValue(IN))); Class<?> inClazz = KyanosMapQueryLoop.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(NeoMapURI.NEO_MAP_SCHEME, PersistentResourceFactory.eINSTANCE); Resource resource = resourceSet.createResource(uri); Map<String, Object> loadOpts = new HashMap<String, Object>(); resource.load(loadOpts); { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); EList<MethodDeclaration> list = JavaQueries.getUnusedMethodsLoop(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result (loops) contains {0} elements", list.size())); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); } if (resource instanceof PersistentResourceImpl) { PersistentResourceImpl.shutdownWithoutUnload((PersistentResourceImpl) resource); } else { resource.unload(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:com.genentech.chemistry.openEye.apps.SDFALogP.java
/** * @param args/*from w w w . ja va 2 s . co m*/ */ public static void main(String... args) throws IOException { // create command line Options object Options options = new Options(); Option opt = new Option(OPT_INFILE, true, "input file oe-supported Use .sdf|.smi to specify the file type."); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_OUTFILE, true, "output file oe-supported. Use .sdf|.smi to specify the file type."); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_SMARTS_FILE, true, "Optional: to overwrite atom type definition file."); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_PRINT_COUNTS, false, "If set the count of each atom type is added to the output file."); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_VALIDATE_ASSIGNMENT, false, "Print warning if no atomtype matches an atom in a candidte molecule."); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_SUPRESS_ZERO, false, "If given atom type counts with count=0 will not be added."); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_NEUTRALIZE, true, "y|n to neutralize molecule if possible (default=y)"); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } String inFile = cmd.getOptionValue(OPT_INFILE); String outFile = cmd.getOptionValue(OPT_OUTFILE); String smartsFile = cmd.getOptionValue(OPT_SMARTS_FILE); boolean outputCount = cmd.hasOption(OPT_PRINT_COUNTS); boolean outputZero = !cmd.hasOption(OPT_SUPRESS_ZERO); boolean neutralize = !"n".equalsIgnoreCase(cmd.getOptionValue(OPT_NEUTRALIZE)); boolean ValidateAssignment = cmd.hasOption(OPT_VALIDATE_ASSIGNMENT); SDFALogP sdfALogP = new SDFALogP(smartsFile, outFile, outputZero, neutralize, ValidateAssignment); sdfALogP.run(inFile, outputCount); sdfALogP.close(); }
From source file:fr.inria.atlanmod.kyanos.benchmarks.MorsaTraverser.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input Kyanos resource directory"); inputOpt.setArgs(1);/*w w w . j av a 2s .c om*/ inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); URI uri = URI.createURI("morsa://" + commandLine.getOptionValue(IN)); Class<?> inClazz = MorsaTraverser.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put("morsa", new MorsaResourceFactoryImpl(new MongoDBMorsaBackendFactory())); Resource resource = resourceSet.createResource(uri); Map<String, Object> loadOpts = new HashMap<String, Object>(); loadOpts.put(IMorsaResource.OPTION_SERVER_URI, "localhost"); loadOpts.put(IMorsaResource.OPTION_MAX_SAVE_CACHE_SIZE, 30000); loadOpts.put(IMorsaResource.OPTION_DEMAND_LOAD, false); // loadOpts.put(IMorsaResource.OPTION_CACHE_POLICY, FIFOEObjectCachePolicy.class.getName()); // loadOpts.put(IMorsaResource.OPTION_MAX_CACHE_SIZE, 30000); // loadOpts.put(IMorsaResource.OPTION_CACHE_FLUSH_FACTOR, 0.3f); // loadOpts.put(IMorsaResource.OPTION_DEMAND_LOAD_STRATEGY, IMorsaResource.OPTION_SINGLE_LOAD_STRATEGY); // loadOpts.put(IMorsaResource.OPTION_DEMAND_LOAD, true); resource.load(loadOpts); LOG.log(Level.INFO, "Start counting"); int count = 0; long begin = System.currentTimeMillis(); for (Iterator<EObject> iterator = resource.getAllContents(); iterator.hasNext(); iterator .next(), count++) ; long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End counting"); LOG.log(Level.INFO, MessageFormat.format("Resource {0} contains {1} elements", uri, count)); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:com.blackducksoftware.tools.nrt.NoticeReportTool.java
/** * @param args/* w w w . j a va 2s . c om*/ * @throws Exception */ public static void main(String[] args) throws Exception { System.out.println("Notice Report Tool for Black Duck Suite"); CommandLineParser parser = new DefaultParser(); options.addOption("h", "help", false, "show help."); Option applicationOption = new Option(NRTConstants.CL_APPLICATION_TYPE, true, "Application type [PROTEX|CODECENTER] (required)"); applicationOption.setRequired(true); options.addOption(applicationOption); Option configFileOption = new Option(NRTConstants.CL_CONFIG_FILE, true, "Location of configuration file (required)"); configFileOption.setRequired(true); options.addOption(configFileOption); Option projectNameOption = new Option(NRTConstants.CL_PROJECT_NAME, true, "Name of Protex project (will override configuration file)"); projectNameOption.setRequired(false); options.addOption(projectNameOption); File configFile = null; APPLICATION applicationType = null; String projectName = null; try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { help(); } // Config File if (cmd.hasOption(NRTConstants.CL_CONFIG_FILE)) { String configFilePath = cmd.getOptionValue(NRTConstants.CL_CONFIG_FILE); log.info("Config file location: " + configFilePath); configFile = new File(configFilePath); if (!configFile.exists()) { log.error("Configuration file does not exist at location: " + configFile); System.exit(-1); } } else { log.error("Must specify configuration file!"); help(); } if (cmd.hasOption(NRTConstants.CL_APPLICATION_TYPE)) { String bdsApplicationType = cmd.getOptionValue(NRTConstants.CL_APPLICATION_TYPE); try { applicationType = APPLICATION.valueOf(bdsApplicationType); } catch (IllegalArgumentException e) { log.error("No such application type recognized: " + bdsApplicationType); help(); } } else { help(); } if (cmd.hasOption(NRTConstants.CL_PROJECT_NAME)) { projectName = cmd.getOptionValue(NRTConstants.CL_PROJECT_NAME); log.info("User specified project name: " + projectName); } NoticeReportProcessor processor = new NoticeReportProcessor(configFile.getAbsolutePath(), applicationType, projectName); try { processor.connect(); } catch (Exception e) { log.error("Connection problems: " + e.getMessage()); throw new Exception(e); } processor.processReport(); } catch (Exception e) { log.error("Error: " + e.getMessage()); help(); } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.ReferencesCounter.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input file"); inputOpt.setArgs(1);/*from www.j a v a 2 s. c om*/ inputOpt.setRequired(true); Option outputOpt = OptionBuilder.create(OUT); outputOpt.setArgName("OUTPUT"); outputOpt.setDescription("Output file"); outputOpt.setArgs(1); outputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(IN_EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of input EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); Option labelOpt = OptionBuilder.create(LABEL); labelOpt.setArgName("LABEL"); labelOpt.setDescription("Label for the data set"); labelOpt.setArgs(1); labelOpt.setRequired(true); options.addOption(inputOpt); options.addOption(outputOpt); options.addOption(inClassOpt); options.addOption(labelOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); URI sourceUri = URI.createFileURI(commandLine.getOptionValue(IN)); Class<?> inClazz = ReferencesCounter.class.getClassLoader() .loadClass(commandLine.getOptionValue(IN_EPACKAGE_CLASS)); @SuppressWarnings("unused") EPackage inEPackage = (EPackage) inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("zxmi", new XMIResourceFactoryImpl()); Resource sourceResource = resourceSet.getResource(sourceUri, true); FileWriter writer = new FileWriter(new File(commandLine.getOptionValue(OUT))); try { writer.write(commandLine.getOptionValue(LABEL)); writer.write("\n"); for (Iterator<EObject> iterator = sourceResource.getAllContents(); iterator.hasNext();) { EObject eObject = iterator.next(); for (EStructuralFeature feature : eObject.eClass().getEAllStructuralFeatures()) { if (feature.isMany() && eObject.eIsSet(feature)) { EList<?> value = (EList<?>) eObject.eGet(feature); // if (value.size() > 10) writer.write(String.format("%d\n", value.size())); } } } } finally { IOUtils.closeQuietly(writer); } } catch (ParseException e) { showError(e.toString()); showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { showError(e.toString()); } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.KyanosMapTraverser.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input Kyanos resource directory"); inputOpt.setArgs(1);/*from ww w. ja v a 2s . c om*/ inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); CommandLineParser parser = new PosixParser(); try { PersistenceBackendFactoryRegistry.getFactories().put(NeoMapURI.NEO_MAP_SCHEME, new MapPersistenceBackendFactory()); CommandLine commandLine = parser.parse(options, args); URI uri = NeoMapURI.createNeoMapURI(new File(commandLine.getOptionValue(IN))); Class<?> inClazz = KyanosMapTraverser.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(NeoMapURI.NEO_MAP_SCHEME, PersistentResourceFactory.eINSTANCE); Resource resource = resourceSet.createResource(uri); Map<String, Object> loadOpts = new HashMap<String, Object>(); resource.load(loadOpts); resource.getContents().get(0); LOG.log(Level.INFO, "Start counting"); int count = 0; long begin = System.currentTimeMillis(); for (Iterator<EObject> iterator = resource.getAllContents(); iterator.hasNext(); iterator .next(), count++) ; long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End counting"); LOG.log(Level.INFO, MessageFormat.format("Resource {0} contains {1} elements", uri, count)); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); if (resource instanceof PersistentResourceImpl) { PersistentResourceImpl.shutdownWithoutUnload((PersistentResourceImpl) resource); } else { resource.unload(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }