@Test public void testWithSomeParameters() { String[] args = new String[]{ "eu.dnetlib.iis.common.java.DummyProcess", "-Iperson=hdfs: "-Idocument=hdfs: "-Omerged=hdfs: "-SclassName=java.util.String"}; CmdLineParserForProcessConstruction cmdLineParser = new CmdLineParserForProcessConstruction(); CommandLine cmdLine = CmdLineParser.parse(args); Process actual = cmdLineParser.run(cmdLine); assertEquals(DummyProcess.class, actual.getClass()); }
public Process run(CommandLine cmdLine){ String[] args = cmdLine.getArgs(); if(args.length != 1){ throw new CmdLineParserException("The name of the class has "+ "to be specified as the first agrument"); } String className = args[0]; String[] constructorParams = cmdLine.getOptionValues( CmdLineParser.constructorPrefix); if(constructorParams == null){ constructorParams = new String[0]; } try { Class<?> processClass = Class.forName(className); Constructor<?> processConstructor = null; if(constructorParams.length == 0){ try{ processConstructor = processClass.getConstructor(); return (Process) processConstructor.newInstance(); } catch(NoSuchMethodException ex){ } } processConstructor = processClass.getConstructor(String[].class); return (Process) processConstructor.newInstance( (Object)constructorParams); } catch (Exception e) { throw new CmdLineParserException(String.format( "Problem while creating class \"%s\"", className), e); } }
CmdLineParserForProcessConstruction { public Process run(CommandLine cmdLine){ String[] args = cmdLine.getArgs(); if(args.length != 1){ throw new CmdLineParserException("The name of the class has "+ "to be specified as the first agrument"); } String className = args[0]; String[] constructorParams = cmdLine.getOptionValues( CmdLineParser.constructorPrefix); if(constructorParams == null){ constructorParams = new String[0]; } try { Class<?> processClass = Class.forName(className); Constructor<?> processConstructor = null; if(constructorParams.length == 0){ try{ processConstructor = processClass.getConstructor(); return (Process) processConstructor.newInstance(); } catch(NoSuchMethodException ex){ } } processConstructor = processClass.getConstructor(String[].class); return (Process) processConstructor.newInstance( (Object)constructorParams); } catch (Exception e) { throw new CmdLineParserException(String.format( "Problem while creating class \"%s\"", className), e); } } }
CmdLineParserForProcessConstruction { public Process run(CommandLine cmdLine){ String[] args = cmdLine.getArgs(); if(args.length != 1){ throw new CmdLineParserException("The name of the class has "+ "to be specified as the first agrument"); } String className = args[0]; String[] constructorParams = cmdLine.getOptionValues( CmdLineParser.constructorPrefix); if(constructorParams == null){ constructorParams = new String[0]; } try { Class<?> processClass = Class.forName(className); Constructor<?> processConstructor = null; if(constructorParams.length == 0){ try{ processConstructor = processClass.getConstructor(); return (Process) processConstructor.newInstance(); } catch(NoSuchMethodException ex){ } } processConstructor = processClass.getConstructor(String[].class); return (Process) processConstructor.newInstance( (Object)constructorParams); } catch (Exception e) { throw new CmdLineParserException(String.format( "Problem while creating class \"%s\"", className), e); } }  }
CmdLineParserForProcessConstruction { public Process run(CommandLine cmdLine){ String[] args = cmdLine.getArgs(); if(args.length != 1){ throw new CmdLineParserException("The name of the class has "+ "to be specified as the first agrument"); } String className = args[0]; String[] constructorParams = cmdLine.getOptionValues( CmdLineParser.constructorPrefix); if(constructorParams == null){ constructorParams = new String[0]; } try { Class<?> processClass = Class.forName(className); Constructor<?> processConstructor = null; if(constructorParams.length == 0){ try{ processConstructor = processClass.getConstructor(); return (Process) processConstructor.newInstance(); } catch(NoSuchMethodException ex){ } } processConstructor = processClass.getConstructor(String[].class); return (Process) processConstructor.newInstance( (Object)constructorParams); } catch (Exception e) { throw new CmdLineParserException(String.format( "Problem while creating class \"%s\"", className), e); } }  Process run(CommandLine cmdLine); }
CmdLineParserForProcessConstruction { public Process run(CommandLine cmdLine){ String[] args = cmdLine.getArgs(); if(args.length != 1){ throw new CmdLineParserException("The name of the class has "+ "to be specified as the first agrument"); } String className = args[0]; String[] constructorParams = cmdLine.getOptionValues( CmdLineParser.constructorPrefix); if(constructorParams == null){ constructorParams = new String[0]; } try { Class<?> processClass = Class.forName(className); Constructor<?> processConstructor = null; if(constructorParams.length == 0){ try{ processConstructor = processClass.getConstructor(); return (Process) processConstructor.newInstance(); } catch(NoSuchMethodException ex){ } } processConstructor = processClass.getConstructor(String[].class); return (Process) processConstructor.newInstance( (Object)constructorParams); } catch (Exception e) { throw new CmdLineParserException(String.format( "Problem while creating class \"%s\"", className), e); } }  Process run(CommandLine cmdLine);  }