List of usage examples for org.apache.commons.cli CommandLine getOptionValues
public String[] getOptionValues(char opt)
From source file:com.cws.esolutions.core.main.NetworkUtility.java
public static final void main(final String[] args) { final String methodName = NetworkUtility.CNAME + "#main(final String[] args)"; if (DEBUG) {/*from w w w. ja v a2 s . c om*/ DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", (Object) args); } if (args.length == 0) { new HelpFormatter().printHelp(NetworkUtility.CNAME, options, true); return; } try { CommandLineParser parser = new PosixParser(); CommandLine commandLine = parser.parse(options, args); if (DEBUG) { DEBUGGER.debug("CommandLineParser parser: {}", parser); DEBUGGER.debug("CommandLine commandLine: {}", commandLine); } String coreConfiguration = (StringUtils.isBlank(System.getProperty("coreConfigFile"))) ? NetworkUtility.CORE_SVC_CONFIG : System.getProperty("coreConfigFile"); String securityConfiguration = (StringUtils.isBlank(System.getProperty("secConfigFile"))) ? NetworkUtility.CORE_LOG_CONFIG : System.getProperty("secConfigFile"); String coreLogging = (StringUtils.isBlank(System.getProperty("coreLogConfig"))) ? NetworkUtility.SEC_SVC_CONFIG : System.getProperty("coreLogConfig"); String securityLogging = (StringUtils.isBlank(System.getProperty("secLogConfig"))) ? NetworkUtility.SEC_LOG_CONFIG : System.getProperty("secLogConfig"); if (DEBUG) { DEBUGGER.debug("String coreConfiguration: {}", coreConfiguration); DEBUGGER.debug("String securityConfiguration: {}", securityConfiguration); DEBUGGER.debug("String coreLogging: {}", coreLogging); DEBUGGER.debug("String securityLogging: {}", securityLogging); } SecurityServiceInitializer.initializeService(securityConfiguration, securityLogging, false); CoreServiceInitializer.initializeService(coreConfiguration, coreLogging, false, true); final CoreConfigurationData coreConfigData = NetworkUtility.appBean.getConfigData(); final SecurityConfigurationData secConfigData = NetworkUtility.secBean.getConfigData(); if (DEBUG) { DEBUGGER.debug("CoreConfigurationData coreConfigData: {}", coreConfigData); DEBUGGER.debug("SecurityConfigurationData secConfig: {}", secConfigData); } if (commandLine.hasOption("ssh")) { if (!(commandLine.hasOption("hostname")) || (!(StringUtils.isBlank(commandLine.getOptionValue("hostname"))))) { throw new CoreServiceException("No target host was provided. Unable to process request."); } else if (!(commandLine.hasOption("username")) && (StringUtils.isBlank(commandLine.getOptionValue("username")))) { throw new CoreServiceException("No username was provided. Using default."); } // NetworkUtils.executeSshConnection(commandLine.getOptionValue("hostname"), commandList); } else if (commandLine.hasOption("http")) { if (!(commandLine.hasOption("hostname")) || (!(StringUtils.isBlank(commandLine.getOptionValue("hostname"))))) { throw new CoreServiceException("No target host was provided. Unable to process request."); } else if (!(commandLine.hasOption("method")) && (StringUtils.isBlank(commandLine.getOptionValue("method")))) { throw new CoreServiceException("No HTTP method was provided. Unable to process request."); } NetworkUtils.executeHttpConnection(new URL(commandLine.getOptionValue("hostname")), commandLine.getOptionValue("method")); } else if (commandLine.hasOption("copyFiles")) { if (!(commandLine.hasOption("hostname")) || (StringUtils.isBlank(commandLine.getOptionValue("hostname")))) { throw new CoreServiceException("No target host was provided. Unable to process request."); } else if (!(commandLine.hasOption("sourceFile")) && (StringUtils.isBlank(commandLine.getOptionValue("sourceFile")))) { throw new CoreServiceException("No source file(s) were provided. Unable to process request."); } else if (!(commandLine.hasOption("targetFile")) && (StringUtils.isBlank(commandLine.getOptionValue("targetFile")))) { throw new CoreServiceException("No target file(s) were provided. Unable to process request."); } List<String> filesToTransfer = new ArrayList<String>( Arrays.asList(commandLine.getOptionValues("sourceFile"))); List<String> filesToCreate = new ArrayList<String>( Arrays.asList(commandLine.getOptionValues("targetFile"))); if (DEBUG) { DEBUGGER.debug("List<String> filesToTransfer: {}", filesToTransfer); DEBUGGER.debug("List<String> filesToCreate: {}", filesToCreate); } if (commandLine.hasOption("withSSH")) { for (String fileName : filesToTransfer) { if (DEBUG) { DEBUGGER.debug("String fileName: {}", fileName); } NetworkUtils.executeSftpTransfer(fileName, filesToCreate.get(filesToTransfer.indexOf(fileName)), commandLine.getOptionValue("hostname"), FileUtils.getFile(fileName).exists()); } } else if (commandLine.hasOption("withFTP")) { if ((commandLine.hasOption("withSSL")) && (Boolean.valueOf(commandLine.getOptionValue("withSSL")))) { // ftp/s } // NetworkUtils.executeFtpConnection(sourceFile, targetFile, targetHost, isUpload); } } } catch (ParseException px) { ERROR_RECORDER.error(px.getMessage(), px); System.err.println("An error occurred during processing: " + px.getMessage()); } catch (SecurityException sx) { ERROR_RECORDER.error(sx.getMessage(), sx); System.err.println("An error occurred during processing: " + sx.getMessage()); } catch (SecurityServiceException ssx) { ERROR_RECORDER.error(ssx.getMessage(), ssx); System.err.println("An error occurred during processing: " + ssx.getMessage()); } catch (CoreServiceException csx) { ERROR_RECORDER.error(csx.getMessage(), csx); System.err.println("An error occurred during processing: " + csx.getMessage()); } catch (MalformedURLException mux) { ERROR_RECORDER.error(mux.getMessage(), mux); System.err.println("An error occurred during processing: " + mux.getMessage()); } }
From source file:DcmQR.java
@SuppressWarnings("unchecked") public static void main(String[] args) { CommandLine cl = parse(args); DcmQR dcmqr = new DcmQR(); final List<String> argList = cl.getArgList(); String remoteAE = argList.get(0); String[] calledAETAddress = split(remoteAE, '@'); dcmqr.setCalledAET(calledAETAddress[0], cl.hasOption("reuseassoc")); if (calledAETAddress[1] == null) { dcmqr.setRemoteHost("127.0.0.1"); dcmqr.setRemotePort(104);/*from w w w . java2 s . c o m*/ } else { String[] hostPort = split(calledAETAddress[1], ':'); dcmqr.setRemoteHost(hostPort[0]); dcmqr.setRemotePort(toPort(hostPort[1])); } if (cl.hasOption("L")) { String localAE = cl.getOptionValue("L"); String[] localPort = split(localAE, ':'); if (localPort[1] != null) { dcmqr.setLocalPort(toPort(localPort[1])); } String[] callingAETHost = split(localPort[0], '@'); dcmqr.setCalling(callingAETHost[0]); if (callingAETHost[1] != null) { dcmqr.setLocalHost(callingAETHost[1]); } } if (cl.hasOption("username")) { String username = cl.getOptionValue("username"); UserIdentity userId; if (cl.hasOption("passcode")) { String passcode = cl.getOptionValue("passcode"); userId = new UserIdentity.UsernamePasscode(username, passcode.toCharArray()); } else { userId = new UserIdentity.Username(username); } userId.setPositiveResponseRequested(cl.hasOption("uidnegrsp")); dcmqr.setUserIdentity(userId); } if (cl.hasOption("connectTO")) dcmqr.setConnectTimeout(parseInt(cl.getOptionValue("connectTO"), "illegal argument of option -connectTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("reaper")) dcmqr.setAssociationReaperPeriod(parseInt(cl.getOptionValue("reaper"), "illegal argument of option -reaper", 1, Integer.MAX_VALUE)); if (cl.hasOption("cfindrspTO")) dcmqr.setDimseRspTimeout(parseInt(cl.getOptionValue("cfindrspTO"), "illegal argument of option -cfindrspTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("cmoverspTO")) dcmqr.setRetrieveRspTimeout(parseInt(cl.getOptionValue("cmoverspTO"), "illegal argument of option -cmoverspTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("cgetrspTO")) dcmqr.setRetrieveRspTimeout(parseInt(cl.getOptionValue("cgetrspTO"), "illegal argument of option -cgetrspTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("acceptTO")) dcmqr.setAcceptTimeout(parseInt(cl.getOptionValue("acceptTO"), "illegal argument of option -acceptTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("releaseTO")) dcmqr.setReleaseTimeout(parseInt(cl.getOptionValue("releaseTO"), "illegal argument of option -releaseTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("soclosedelay")) dcmqr.setSocketCloseDelay(parseInt(cl.getOptionValue("soclosedelay"), "illegal argument of option -soclosedelay", 1, 10000)); if (cl.hasOption("rcvpdulen")) dcmqr.setMaxPDULengthReceive( parseInt(cl.getOptionValue("rcvpdulen"), "illegal argument of option -rcvpdulen", 1, 10000) * KB); if (cl.hasOption("sndpdulen")) dcmqr.setMaxPDULengthSend( parseInt(cl.getOptionValue("sndpdulen"), "illegal argument of option -sndpdulen", 1, 10000) * KB); if (cl.hasOption("sosndbuf")) dcmqr.setSendBufferSize( parseInt(cl.getOptionValue("sosndbuf"), "illegal argument of option -sosndbuf", 1, 10000) * KB); if (cl.hasOption("sorcvbuf")) dcmqr.setReceiveBufferSize( parseInt(cl.getOptionValue("sorcvbuf"), "illegal argument of option -sorcvbuf", 1, 10000) * KB); if (cl.hasOption("filebuf")) dcmqr.setFileBufferSize( parseInt(cl.getOptionValue("filebuf"), "illegal argument of option -filebuf", 1, 10000) * KB); dcmqr.setPackPDV(!cl.hasOption("pdv1")); dcmqr.setTcpNoDelay(!cl.hasOption("tcpdelay")); dcmqr.setMaxOpsInvoked(cl.hasOption("async") ? parseInt(cl.getOptionValue("async"), "illegal argument of option -async", 0, 0xffff) : 1); dcmqr.setMaxOpsPerformed(cl.hasOption("cstoreasync") ? parseInt(cl.getOptionValue("cstoreasync"), "illegal argument of option -cstoreasync", 0, 0xffff) : 0); if (cl.hasOption("C")) dcmqr.setCancelAfter( parseInt(cl.getOptionValue("C"), "illegal argument of option -C", 1, Integer.MAX_VALUE)); if (cl.hasOption("lowprior")) dcmqr.setPriority(CommandUtils.LOW); if (cl.hasOption("highprior")) dcmqr.setPriority(CommandUtils.HIGH); if (cl.hasOption("cstore")) { String[] storeTCs = cl.getOptionValues("cstore"); for (String storeTC : storeTCs) { String cuid; String[] tsuids; int colon = storeTC.indexOf(':'); if (colon == -1) { cuid = storeTC; tsuids = DEF_TS; } else { cuid = storeTC.substring(0, colon); String ts = storeTC.substring(colon + 1); try { tsuids = TS.valueOf(ts).uids; } catch (IllegalArgumentException e) { tsuids = ts.split(","); } } try { cuid = CUID.valueOf(cuid).uid; } catch (IllegalArgumentException e) { // assume cuid already contains UID } dcmqr.addStoreTransferCapability(cuid, tsuids); } if (cl.hasOption("cstoredest")) dcmqr.setStoreDestination(cl.getOptionValue("cstoredest")); } dcmqr.setCGet(cl.hasOption("cget")); if (cl.hasOption("cmove")) dcmqr.setMoveDest(cl.getOptionValue("cmove")); if (cl.hasOption("evalRetrieveAET")) dcmqr.setEvalRetrieveAET(true); if (cl.hasOption("P")) dcmqr.setQueryLevel(QueryRetrieveLevel.PATIENT); else if (cl.hasOption("S")) dcmqr.setQueryLevel(QueryRetrieveLevel.SERIES); else if (cl.hasOption("I")) dcmqr.setQueryLevel(QueryRetrieveLevel.IMAGE); else dcmqr.setQueryLevel(QueryRetrieveLevel.STUDY); if (cl.hasOption("noextneg")) dcmqr.setNoExtNegotiation(true); if (cl.hasOption("rel")) dcmqr.setRelationQR(true); if (cl.hasOption("datetime")) dcmqr.setDateTimeMatching(true); if (cl.hasOption("fuzzy")) dcmqr.setFuzzySemanticPersonNameMatching(true); if (!cl.hasOption("P")) { if (cl.hasOption("retall")) dcmqr.addPrivate(UID.PrivateStudyRootQueryRetrieveInformationModelFIND); if (cl.hasOption("blocked")) dcmqr.addPrivate(UID.PrivateBlockedStudyRootQueryRetrieveInformationModelFIND); if (cl.hasOption("vmf")) dcmqr.addPrivate(UID.PrivateVirtualMultiframeStudyRootQueryRetrieveInformationModelFIND); } if (cl.hasOption("q")) { String[] matchingKeys = cl.getOptionValues("q"); for (int i = 1; i < matchingKeys.length; i++, i++) dcmqr.addMatchingKey(Tag.toTagPath(matchingKeys[i - 1]), matchingKeys[i]); } if (cl.hasOption("r")) { String[] returnKeys = cl.getOptionValues("r"); for (int i = 0; i < returnKeys.length; i++) dcmqr.addReturnKey(Tag.toTagPath(returnKeys[i])); } dcmqr.configureTransferCapability(cl.hasOption("ivrle")); int repeat = cl.hasOption("repeat") ? parseInt(cl.getOptionValue("repeat"), "illegal argument of option -repeat", 1, Integer.MAX_VALUE) : 0; int interval = cl.hasOption("repeatdelay") ? parseInt(cl.getOptionValue("repeatdelay"), "illegal argument of option -repeatdelay", 1, Integer.MAX_VALUE) : 0; boolean closeAssoc = cl.hasOption("closeassoc"); if (cl.hasOption("tls")) { String cipher = cl.getOptionValue("tls"); if ("NULL".equalsIgnoreCase(cipher)) { dcmqr.setTlsWithoutEncyrption(); } else if ("3DES".equalsIgnoreCase(cipher)) { dcmqr.setTls3DES_EDE_CBC(); } else if ("AES".equalsIgnoreCase(cipher)) { dcmqr.setTlsAES_128_CBC(); } else { exit("Invalid parameter for option -tls: " + cipher); } if (cl.hasOption("nossl2")) { dcmqr.disableSSLv2Hello(); } dcmqr.setTlsNeedClientAuth(!cl.hasOption("noclientauth")); if (cl.hasOption("keystore")) { dcmqr.setKeyStoreURL(cl.getOptionValue("keystore")); } if (cl.hasOption("keystorepw")) { dcmqr.setKeyStorePassword(cl.getOptionValue("keystorepw")); } if (cl.hasOption("keypw")) { dcmqr.setKeyPassword(cl.getOptionValue("keypw")); } if (cl.hasOption("truststore")) { dcmqr.setTrustStoreURL(cl.getOptionValue("truststore")); } if (cl.hasOption("truststorepw")) { dcmqr.setTrustStorePassword(cl.getOptionValue("truststorepw")); } long t1 = System.currentTimeMillis(); try { dcmqr.initTLS(); } catch (Exception e) { System.err.println("ERROR: Failed to initialize TLS context:" + e.getMessage()); System.exit(2); } long t2 = System.currentTimeMillis(); LOG.info("Initialize TLS context in {} s", Float.valueOf((t2 - t1) / 1000f)); } try { dcmqr.start(); } catch (Exception e) { System.err.println( "ERROR: Failed to start server for receiving " + "requested objects:" + e.getMessage()); System.exit(2); } try { long t1 = System.currentTimeMillis(); try { dcmqr.open(); } catch (Exception e) { LOG.error("Failed to establish association:", e); System.exit(2); } long t2 = System.currentTimeMillis(); LOG.info("Connected to {} in {} s", remoteAE, Float.valueOf((t2 - t1) / 1000f)); for (;;) { List<DicomObject> result = dcmqr.query(); long t3 = System.currentTimeMillis(); LOG.info("Received {} matching entries in {} s", Integer.valueOf(result.size()), Float.valueOf((t3 - t2) / 1000f)); if (dcmqr.isCMove() || dcmqr.isCGet()) { if (dcmqr.isCMove()) dcmqr.move(result); else dcmqr.get(result); long t4 = System.currentTimeMillis(); LOG.info("Retrieved {} objects (warning: {}, failed: {}) in {}s", new Object[] { Integer.valueOf(dcmqr.getTotalRetrieved()), Integer.valueOf(dcmqr.getWarning()), Integer.valueOf(dcmqr.getFailed()), Float.valueOf((t4 - t3) / 1000f) }); } if (repeat == 0 || closeAssoc) { try { dcmqr.close(); } catch (InterruptedException e) { LOG.error(e.getMessage(), e); } LOG.info("Released connection to {}", remoteAE); } if (repeat-- == 0) break; Thread.sleep(interval); long t4 = System.currentTimeMillis(); dcmqr.open(); t2 = System.currentTimeMillis(); LOG.info("Reconnect or reuse connection to {} in {} s", remoteAE, Float.valueOf((t2 - t4) / 1000f)); } } catch (IOException e) { LOG.error(e.getMessage(), e); } catch (InterruptedException e) { LOG.error(e.getMessage(), e); } catch (ConfigurationException e) { LOG.error(e.getMessage(), e); } finally { dcmqr.stop(); } }
From source file:mod.org.dcm4che2.tool.DcmQR.java
@SuppressWarnings("unchecked") public static void main(String[] args) { CommandLine cl = parse(args); DcmQR dcmqr = new DcmQR(cl.hasOption("device") ? cl.getOptionValue("device") : "DCMQR"); final List<String> argList = cl.getArgList(); String remoteAE = argList.get(0); String[] calledAETAddress = split(remoteAE, '@'); dcmqr.setCalledAET(calledAETAddress[0], cl.hasOption("reuseassoc")); if (calledAETAddress[1] == null) { dcmqr.setRemoteHost("127.0.0.1"); dcmqr.setRemotePort(104);/* w w w . ja va2 s . com*/ } else { String[] hostPort = split(calledAETAddress[1], ':'); dcmqr.setRemoteHost(hostPort[0]); dcmqr.setRemotePort(toPort(hostPort[1])); } if (cl.hasOption("L")) { String localAE = cl.getOptionValue("L"); String[] localPort = split(localAE, ':'); if (localPort[1] != null) { dcmqr.setLocalPort(toPort(localPort[1])); } String[] callingAETHost = split(localPort[0], '@'); dcmqr.setCalling(callingAETHost[0]); if (callingAETHost[1] != null) { dcmqr.setLocalHost(callingAETHost[1]); } } if (cl.hasOption("username")) { String username = cl.getOptionValue("username"); UserIdentity userId; if (cl.hasOption("passcode")) { String passcode = cl.getOptionValue("passcode"); userId = new UserIdentity.UsernamePasscode(username, passcode.toCharArray()); } else { userId = new UserIdentity.Username(username); } userId.setPositiveResponseRequested(cl.hasOption("uidnegrsp")); dcmqr.setUserIdentity(userId); } if (cl.hasOption("connectTO")) dcmqr.setConnectTimeout(parseInt(cl.getOptionValue("connectTO"), "illegal argument of option -connectTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("reaper")) dcmqr.setAssociationReaperPeriod(parseInt(cl.getOptionValue("reaper"), "illegal argument of option -reaper", 1, Integer.MAX_VALUE)); if (cl.hasOption("cfindrspTO")) dcmqr.setDimseRspTimeout(parseInt(cl.getOptionValue("cfindrspTO"), "illegal argument of option -cfindrspTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("cmoverspTO")) dcmqr.setRetrieveRspTimeout(parseInt(cl.getOptionValue("cmoverspTO"), "illegal argument of option -cmoverspTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("cgetrspTO")) dcmqr.setRetrieveRspTimeout(parseInt(cl.getOptionValue("cgetrspTO"), "illegal argument of option -cgetrspTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("acceptTO")) dcmqr.setAcceptTimeout(parseInt(cl.getOptionValue("acceptTO"), "illegal argument of option -acceptTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("releaseTO")) dcmqr.setReleaseTimeout(parseInt(cl.getOptionValue("releaseTO"), "illegal argument of option -releaseTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("soclosedelay")) dcmqr.setSocketCloseDelay(parseInt(cl.getOptionValue("soclosedelay"), "illegal argument of option -soclosedelay", 1, 10000)); if (cl.hasOption("rcvpdulen")) dcmqr.setMaxPDULengthReceive( parseInt(cl.getOptionValue("rcvpdulen"), "illegal argument of option -rcvpdulen", 1, 10000) * KB); if (cl.hasOption("sndpdulen")) dcmqr.setMaxPDULengthSend( parseInt(cl.getOptionValue("sndpdulen"), "illegal argument of option -sndpdulen", 1, 10000) * KB); if (cl.hasOption("sosndbuf")) dcmqr.setSendBufferSize( parseInt(cl.getOptionValue("sosndbuf"), "illegal argument of option -sosndbuf", 1, 10000) * KB); if (cl.hasOption("sorcvbuf")) dcmqr.setReceiveBufferSize( parseInt(cl.getOptionValue("sorcvbuf"), "illegal argument of option -sorcvbuf", 1, 10000) * KB); if (cl.hasOption("filebuf")) dcmqr.setFileBufferSize( parseInt(cl.getOptionValue("filebuf"), "illegal argument of option -filebuf", 1, 10000) * KB); dcmqr.setPackPDV(!cl.hasOption("pdv1")); dcmqr.setTcpNoDelay(!cl.hasOption("tcpdelay")); dcmqr.setMaxOpsInvoked(cl.hasOption("async") ? parseInt(cl.getOptionValue("async"), "illegal argument of option -async", 0, 0xffff) : 1); dcmqr.setMaxOpsPerformed(cl.hasOption("cstoreasync") ? parseInt(cl.getOptionValue("cstoreasync"), "illegal argument of option -cstoreasync", 0, 0xffff) : 0); if (cl.hasOption("C")) dcmqr.setCancelAfter( parseInt(cl.getOptionValue("C"), "illegal argument of option -C", 1, Integer.MAX_VALUE)); if (cl.hasOption("lowprior")) dcmqr.setPriority(CommandUtils.LOW); if (cl.hasOption("highprior")) dcmqr.setPriority(CommandUtils.HIGH); if (cl.hasOption("cstore")) { String[] storeTCs = cl.getOptionValues("cstore"); for (String storeTC : storeTCs) { String cuid; String[] tsuids; int colon = storeTC.indexOf(':'); if (colon == -1) { cuid = storeTC; tsuids = DEF_TS; } else { cuid = storeTC.substring(0, colon); String ts = storeTC.substring(colon + 1); try { tsuids = TS.valueOf(ts).uids; } catch (IllegalArgumentException e) { tsuids = ts.split(","); } } try { cuid = CUID.valueOf(cuid).uid; } catch (IllegalArgumentException e) { // assume cuid already contains UID } dcmqr.addStoreTransferCapability(cuid, tsuids); } if (cl.hasOption("cstoredest")) dcmqr.setStoreDestination(cl.getOptionValue("cstoredest")); } dcmqr.setCFind(!cl.hasOption("nocfind")); dcmqr.setCGet(cl.hasOption("cget")); if (cl.hasOption("cmove")) dcmqr.setMoveDest(cl.getOptionValue("cmove")); if (cl.hasOption("evalRetrieveAET")) dcmqr.setEvalRetrieveAET(true); dcmqr.setQueryLevel(cl.hasOption("P") ? QueryRetrieveLevel.PATIENT : cl.hasOption("S") ? QueryRetrieveLevel.SERIES : cl.hasOption("I") ? QueryRetrieveLevel.IMAGE : QueryRetrieveLevel.STUDY); if (cl.hasOption("noextneg")) dcmqr.setNoExtNegotiation(true); if (cl.hasOption("rel")) dcmqr.setRelationQR(true); if (cl.hasOption("datetime")) dcmqr.setDateTimeMatching(true); if (cl.hasOption("fuzzy")) dcmqr.setFuzzySemanticPersonNameMatching(true); if (!cl.hasOption("P")) { if (cl.hasOption("retall")) dcmqr.addPrivate(UID.PrivateStudyRootQueryRetrieveInformationModelFIND); if (cl.hasOption("blocked")) dcmqr.addPrivate(UID.PrivateBlockedStudyRootQueryRetrieveInformationModelFIND); if (cl.hasOption("vmf")) dcmqr.addPrivate(UID.PrivateVirtualMultiframeStudyRootQueryRetrieveInformationModelFIND); } if (cl.hasOption("cfind")) { String[] cuids = cl.getOptionValues("cfind"); for (int i = 0; i < cuids.length; i++) dcmqr.addPrivate(cuids[i]); } if (!cl.hasOption("nodefret")) dcmqr.addDefReturnKeys(); if (cl.hasOption("r")) { String[] returnKeys = cl.getOptionValues("r"); for (int i = 0; i < returnKeys.length; i++) dcmqr.addReturnKey(Tag.toTagPath(returnKeys[i])); } if (cl.hasOption("q")) { String[] matchingKeys = cl.getOptionValues("q"); for (int i = 1; i < matchingKeys.length; i++, i++) dcmqr.addMatchingKey(Tag.toTagPath(matchingKeys[i - 1]), matchingKeys[i]); } dcmqr.configureTransferCapability(cl.hasOption("ivrle")); int repeat = cl.hasOption("repeat") ? parseInt(cl.getOptionValue("repeat"), "illegal argument of option -repeat", 1, Integer.MAX_VALUE) : 0; int interval = cl.hasOption("repeatdelay") ? parseInt(cl.getOptionValue("repeatdelay"), "illegal argument of option -repeatdelay", 1, Integer.MAX_VALUE) : 0; boolean closeAssoc = cl.hasOption("closeassoc"); if (cl.hasOption("tls")) { String cipher = cl.getOptionValue("tls"); if ("NULL".equalsIgnoreCase(cipher)) { dcmqr.setTlsWithoutEncyrption(); } else if ("3DES".equalsIgnoreCase(cipher)) { dcmqr.setTls3DES_EDE_CBC(); } else if ("AES".equalsIgnoreCase(cipher)) { dcmqr.setTlsAES_128_CBC(); } else { exit("Invalid parameter for option -tls: " + cipher); } if (cl.hasOption("tls1")) { dcmqr.setTlsProtocol(TLS1); } else if (cl.hasOption("ssl3")) { dcmqr.setTlsProtocol(SSL3); } else if (cl.hasOption("no_tls1")) { dcmqr.setTlsProtocol(NO_TLS1); } else if (cl.hasOption("no_ssl3")) { dcmqr.setTlsProtocol(NO_SSL3); } else if (cl.hasOption("no_ssl2")) { dcmqr.setTlsProtocol(NO_SSL2); } dcmqr.setTlsNeedClientAuth(!cl.hasOption("noclientauth")); if (cl.hasOption("keystore")) { dcmqr.setKeyStoreURL(cl.getOptionValue("keystore")); } if (cl.hasOption("keystorepw")) { dcmqr.setKeyStorePassword(cl.getOptionValue("keystorepw")); } if (cl.hasOption("keypw")) { dcmqr.setKeyPassword(cl.getOptionValue("keypw")); } if (cl.hasOption("truststore")) { dcmqr.setTrustStoreURL(cl.getOptionValue("truststore")); } if (cl.hasOption("truststorepw")) { dcmqr.setTrustStorePassword(cl.getOptionValue("truststorepw")); } long t1 = System.currentTimeMillis(); try { dcmqr.initTLS(); } catch (Exception e) { System.err.println("ERROR: Failed to initialize TLS context:" + e.getMessage()); System.exit(2); } long t2 = System.currentTimeMillis(); LOG.info("Initialize TLS context in {} s", Float.valueOf((t2 - t1) / 1000f)); } try { dcmqr.start(); } catch (Exception e) { System.err.println( "ERROR: Failed to start server for receiving " + "requested objects:" + e.getMessage()); System.exit(2); } try { long t1 = System.currentTimeMillis(); try { dcmqr.open(); } catch (Exception e) { LOG.error("Failed to establish association:", e); System.exit(2); } long t2 = System.currentTimeMillis(); LOG.info("Connected to {} in {} s", remoteAE, Float.valueOf((t2 - t1) / 1000f)); for (;;) { List<DicomObject> result; if (dcmqr.isCFind()) { result = dcmqr.query(); long t3 = System.currentTimeMillis(); LOG.info("Received {} matching entries in {} s", Integer.valueOf(result.size()), Float.valueOf((t3 - t2) / 1000f)); t2 = t3; } else { result = Collections.singletonList(dcmqr.getKeys()); } if (dcmqr.isCMove() || dcmqr.isCGet()) { if (dcmqr.isCMove()) dcmqr.move(result); else dcmqr.get(result); long t4 = System.currentTimeMillis(); LOG.info("Retrieved {} objects (warning: {}, failed: {}) in {}s", new Object[] { Integer.valueOf(dcmqr.getTotalRetrieved()), Integer.valueOf(dcmqr.getWarning()), Integer.valueOf(dcmqr.getFailed()), Float.valueOf((t4 - t2) / 1000f) }); } if (repeat == 0 || closeAssoc) { try { dcmqr.close(); } catch (InterruptedException e) { LOG.error(e.getMessage(), e); } LOG.info("Released connection to {}", remoteAE); } if (repeat-- == 0) break; Thread.sleep(interval); long t4 = System.currentTimeMillis(); dcmqr.open(); t2 = System.currentTimeMillis(); LOG.info("Reconnect or reuse connection to {} in {} s", remoteAE, Float.valueOf((t2 - t4) / 1000f)); } } catch (IOException e) { LOG.error(e.getMessage(), e); } catch (InterruptedException e) { LOG.error(e.getMessage(), e); } catch (ConfigurationException e) { LOG.error(e.getMessage(), e); } finally { dcmqr.stop(); } }
From source file:edu.uthscsa.ric.papaya.builder.Builder.java
public static void main(final String[] args) { final Builder builder = new Builder(); // process command line final CommandLine cli = builder.createCLI(args); builder.setUseSample(cli.hasOption(ARG_SAMPLE)); builder.setUseAtlas(cli.hasOption(ARG_ATLAS)); builder.setLocal(cli.hasOption(ARG_LOCAL)); builder.setPrintHelp(cli.hasOption(ARG_HELP)); builder.setUseImages(cli.hasOption(ARG_IMAGE)); builder.setSingleFile(cli.hasOption(ARG_SINGLE)); builder.setUseParamFile(cli.hasOption(ARG_PARAM_FILE)); builder.setUseTitle(cli.hasOption(ARG_TITLE)); // print help, if necessary if (builder.isPrintHelp()) { builder.printHelp();//from w w w .j a va2s .co m return; } // find project root directory if (cli.hasOption(ARG_ROOT)) { try { builder.projectDir = (new File(cli.getOptionValue(ARG_ROOT))).getCanonicalFile(); } catch (final IOException ex) { System.err.println("Problem finding root directory. Reason: " + ex.getMessage()); } } if (builder.projectDir == null) { builder.projectDir = new File(System.getProperty("user.dir")); } // clean output dir final File outputDir = new File(builder.projectDir + "/" + OUTPUT_DIR); System.out.println("Cleaning output directory..."); try { builder.cleanOutputDir(outputDir); } catch (final IOException ex) { System.err.println("Problem cleaning build directory. Reason: " + ex.getMessage()); } if (builder.isLocal()) { System.out.println("Building for local usage..."); } // write JS final File compressedFileJs = new File(outputDir, OUTPUT_JS_FILENAME); // build properties try { final File buildFile = new File(builder.projectDir + "/" + BUILD_PROP_FILE); builder.readBuildProperties(buildFile); builder.buildNumber++; // increment build number builder.writeBuildProperties(compressedFileJs, true); builder.writeBuildProperties(buildFile, false); } catch (final IOException ex) { System.err.println("Problem handling build properties. Reason: " + ex.getMessage()); } String htmlParameters = null; if (builder.isUseParamFile()) { final String paramFileArg = cli.getOptionValue(ARG_PARAM_FILE); if (paramFileArg != null) { try { System.out.println("Including parameters..."); final String parameters = FileUtils.readFileToString(new File(paramFileArg), "UTF-8"); htmlParameters = "var params = " + parameters + ";"; } catch (final IOException ex) { System.err.println("Problem reading parameters file! " + ex.getMessage()); } } } String title = null; if (builder.isUseTitle()) { String str = cli.getOptionValue(ARG_TITLE); if (str != null) { str = str.trim(); str = str.replace("\"", ""); str = str.replace("'", ""); if (str.length() > 0) { title = str; System.out.println("Using title: " + title); } } } try { final JSONArray loadableImages = new JSONArray(); // sample image if (builder.isUseSample()) { System.out.println("Including sample image..."); final File sampleFile = new File(builder.projectDir + "/" + SAMPLE_IMAGE_NII_FILE); final String filename = Utilities .replaceNonAlphanumericCharacters(Utilities.removeNiftiExtensions(sampleFile.getName())); if (builder.isLocal()) { loadableImages.put(new JSONObject("{\"nicename\":\"Sample Image\",\"name\":\"" + filename + "\",\"encode\":\"" + filename + "\"}")); final String sampleEncoded = Utilities.encodeImageFile(sampleFile); FileUtils.writeStringToFile(compressedFileJs, "var " + filename + "= \"" + sampleEncoded + "\";\n", "UTF-8", true); } else { loadableImages.put(new JSONObject("{\"nicename\":\"Sample Image\",\"name\":\"" + filename + "\",\"url\":\"" + SAMPLE_IMAGE_NII_FILE + "\"}")); FileUtils.copyFile(sampleFile, new File(outputDir + "/" + SAMPLE_IMAGE_NII_FILE)); } } // atlas if (builder.isUseAtlas()) { Atlas atlas = null; try { String atlasArg = cli.getOptionValue(ARG_ATLAS); if (atlasArg == null) { atlasArg = (builder.projectDir + "/" + SAMPLE_DEFAULT_ATLAS_FILE); } final File atlasXmlFile = new File(atlasArg); System.out.println("Including atlas " + atlasXmlFile); atlas = new Atlas(atlasXmlFile); final File atlasJavaScriptFile = atlas.createAtlas(builder.isLocal()); System.out.println("Using atlas image file " + atlas.getImageFile()); if (builder.isLocal()) { loadableImages.put( new JSONObject("{\"nicename\":\"Atlas\",\"name\":\"" + atlas.getImageFileNewName() + "\",\"encode\":\"" + atlas.getImageFileNewName() + "\",\"hide\":true}")); } else { final File atlasImageFile = atlas.getImageFile(); final String atlasPath = "data/" + atlasImageFile.getName(); loadableImages.put(new JSONObject("{\"nicename\":\"Atlas\",\"name\":\"" + atlas.getImageFileNewName() + "\",\"url\":\"" + atlasPath + "\",\"hide\":true}")); FileUtils.copyFile(atlasImageFile, new File(outputDir + "/" + atlasPath)); } builder.writeFile(atlasJavaScriptFile, compressedFileJs); } catch (final IOException ex) { System.err.println("Problem finding atlas file. Reason: " + ex.getMessage()); } } // additional images if (builder.isUseImages()) { final String[] imageArgs = cli.getOptionValues(ARG_IMAGE); if (imageArgs != null) { for (final String imageArg : imageArgs) { final File file = new File(imageArg); System.out.println("Including image " + file); final String filename = Utilities .replaceNonAlphanumericCharacters(Utilities.removeNiftiExtensions(file.getName())); if (builder.isLocal()) { loadableImages.put(new JSONObject( "{\"nicename\":\"" + Utilities.removeNiftiExtensions(file.getName()) + "\",\"name\":\"" + filename + "\",\"encode\":\"" + filename + "\"}")); final String sampleEncoded = Utilities.encodeImageFile(file); FileUtils.writeStringToFile(compressedFileJs, "var " + filename + "= \"" + sampleEncoded + "\";\n", "UTF-8", true); } else { final String filePath = "data/" + file.getName(); loadableImages.put(new JSONObject( "{\"nicename\":\"" + Utilities.removeNiftiExtensions(file.getName()) + "\",\"name\":\"" + filename + "\",\"url\":\"" + filePath + "\"}")); FileUtils.copyFile(file, new File(outputDir + "/" + filePath)); } } } } File tempFileJs = null; try { tempFileJs = builder.createTempFile(); } catch (final IOException ex) { System.err.println("Problem creating temp write file. Reason: " + ex.getMessage()); } // write image refs FileUtils.writeStringToFile(tempFileJs, "var " + PAPAYA_LOADABLE_IMAGES + " = " + loadableImages.toString() + ";\n", "UTF-8", true); // compress JS tempFileJs = builder.concatenateFiles(JS_FILES, "js", tempFileJs); System.out.println("Compressing JavaScript... "); FileUtils.writeStringToFile(compressedFileJs, "\n", "UTF-8", true); builder.compressJavaScript(tempFileJs, compressedFileJs, new YuiCompressorOptions()); //tempFileJs.deleteOnExit(); } catch (final IOException ex) { System.err.println("Problem concatenating JavaScript. Reason: " + ex.getMessage()); } // compress CSS final File compressedFileCss = new File(outputDir, OUTPUT_CSS_FILENAME); try { final File concatFile = builder.concatenateFiles(CSS_FILES, "css", null); System.out.println("Compressing CSS... "); builder.compressCSS(concatFile, compressedFileCss, new YuiCompressorOptions()); concatFile.deleteOnExit(); } catch (final IOException ex) { System.err.println("Problem concatenating CSS. Reason: " + ex.getMessage()); } // write HTML try { System.out.println("Writing HTML... "); if (builder.singleFile) { builder.writeHtml(outputDir, compressedFileJs, compressedFileCss, htmlParameters, title); } else { builder.writeHtml(outputDir, htmlParameters, title); } } catch (final IOException ex) { System.err.println("Problem writing HTML. Reason: " + ex.getMessage()); } System.out.println("Done! Output files located at " + outputDir); }
From source file:at.ac.tuwien.inso.subcat.miner.MinerRunner.java
public static void main(String[] args) { Options options = new Options(); options.addOption("h", "help", false, "Show this options"); options.addOption("m", "miner-help", false, "Show miner specific options"); options.addOption("d", "db", true, "The database to process (required)"); options.addOption("p", "project", true, "The project ID to process"); options.addOption("P", "list-projects", false, "List all registered projects"); options.addOption("v", "verbose", false, "Show details"); options.addOption(null, "bug-repo", true, "Bug Repository URL"); options.addOption(null, "bug-product", true, "Bug Product Name"); options.addOption(null, "bug-tracker", true, "Bug Tracker name (e.g. bugzilla)"); options.addOption(null, "bug-account", true, "Bug account name"); options.addOption(null, "bug-passwd", true, "Bug account password"); options.addOption(null, "bug-enable-untrusted", false, "Accept untrusted certificates"); options.addOption(null, "bug-threads", true, "Thread count used in bug miners"); options.addOption(null, "bug-cooldown-time", true, "Bug cooldown time"); options.addOption(null, "bug-miner-option", true, "Bug miner specific option. Format: <option-name>:value"); options.addOption(null, "bug-update", false, "Mine all changes since the last run"); options.getOption("bug-miner-option").setArgs(Option.UNLIMITED_VALUES); options.addOption(null, "src-path", true, "Local source repository path"); options.addOption(null, "src-remote", true, "Remote address"); options.addOption(null, "src-passwd", true, "Source repository account password"); options.addOption(null, "src-account", true, "Source repository account name"); options.addOption(null, "src-miner-option", true, "Source miner specific option. Format: <option-name>:value"); options.getOption("src-miner-option").setArgs(Option.UNLIMITED_VALUES); final Reporter reporter = new Reporter(true); reporter.startTimer();//from w ww. j a va 2 s .c o m boolean printTraces = false; Settings settings = new Settings(); ModelPool pool = null; CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("postprocessor", options); return; } if (cmd.hasOption("miner-help")) { init(); for (MetaData meta : registeredMiner) { System.out.println(meta.name()); for (Entry<String, ParamType> opt : meta.getSpecificParams().entrySet()) { System.out.println(" - " + opt.getKey() + " (" + opt.getValue() + ")"); } } return; } if (cmd.hasOption("db") == false) { reporter.error("miner", "Option --db is required"); reporter.printSummary(); return; } printTraces = cmd.hasOption("verbose"); pool = new ModelPool(cmd.getOptionValue("db"), 2); if (cmd.hasOption("list-projects")) { Model model = pool.getModel(); for (Project proj : model.getProjects()) { System.out.println(" " + proj.getId() + ": " + proj.getDate()); } model.close(); return; } Project project; Model model = pool.getModel(); boolean hasSrcInfos = false; boolean hasBugInfos = false; if (cmd.hasOption("project")) { try { int projId = Integer.parseInt(cmd.getOptionValue("project")); project = model.getProject(projId); } catch (NumberFormatException e) { reporter.error("post-processor", "Invalid project ID"); reporter.printSummary(); return; } if (project == null) { reporter.error("post-processor", "Invalid project ID"); reporter.printSummary(); return; } List<String> flags = model.getFlags(project); hasBugInfos = flags.contains(Model.FLAG_BUG_INFO); hasSrcInfos = flags.contains(Model.FLAG_SRC_INFO); } else { project = model.addProject(new Date(), null, settings.bugTrackerName, settings.bugRepository, settings.bugProductName, null); } model.close(); // // Source Repository Mining: // settings.srcLocalPath = cmd.getOptionValue("src-path"); settings.srcRemote = cmd.getOptionValue("src-remote"); settings.srcRemotePw = cmd.getOptionValue("src-passwd"); settings.srcRemoteUser = cmd.getOptionValue("src-account"); if (settings.srcRemotePw == null || settings.srcRemoteUser == null) { if (settings.srcRemotePw != null) { reporter.error("miner", "--src-passwd should only be used in combination with --src-account"); reporter.printSummary(); return; } else if (settings.srcRemoteUser != null) { reporter.error("miner", "--src-account should only be used in combination with --src-passwd"); reporter.printSummary(); return; } } if (settings.srcRemoteUser != null && settings.srcRemote == null) { reporter.error("miner", "--src-account should only be used in combination with --src-remote"); reporter.printSummary(); return; } if (settings.srcLocalPath != null && hasSrcInfos) { reporter.error("miner", "Source repository updates are not supported yet."); reporter.printSummary(true); return; } // // Bug Repository Mining: // settings.bugRepository = cmd.getOptionValue("bug-repo"); settings.bugProductName = cmd.getOptionValue("bug-product"); settings.bugTrackerName = cmd.getOptionValue("bug-tracker"); settings.bugEnableUntrustedCertificates = cmd.hasOption("bug-enable-untrusted"); settings.bugLoginUser = cmd.getOptionValue("bug-account"); settings.bugLoginPw = cmd.getOptionValue("bug-passwd"); settings.bugUpdate = cmd.hasOption("bug-update"); boolean includeBugs = false; if (settings.bugUpdate) { if (project.getBugTracker() == null || project.getDomain() == null) { reporter.error("miner", "flag --bug-update is requires previously mined bugs. Use --bug-repository, --bug-product and --bug-tracker."); reporter.printSummary(true); return; } if (settings.bugTrackerName != null) { reporter.warning("miner", "flag --bug-tracker without effect"); } if (settings.bugProductName != null) { reporter.warning("miner", "flag --bug-product without effect"); } if (settings.bugRepository != null) { reporter.warning("miner", "flag --bug-repository without effect"); } settings.bugTrackerName = project.getBugTracker(); settings.bugProductName = project.getProduct(); settings.bugRepository = project.getDomain(); includeBugs = true; } else if (settings.bugRepository != null && settings.bugProductName != null && settings.bugTrackerName != null) { if (hasBugInfos == false) { // The user is trying to append bug tracker information to a existing project. } else if (!settings.bugTrackerName.equalsIgnoreCase(project.getBugTracker()) || !settings.bugProductName.equalsIgnoreCase(project.getProduct()) || !settings.bugRepository.equalsIgnoreCase(project.getDomain())) { reporter.error("miner", "There are already previously mined bugs for this project. Use --bug-update to update the database."); reporter.printSummary(true); return; } if (settings.bugRepository == null) { reporter.error("miner", "flag --bug-repository is required"); reporter.printSummary(true); return; } if (settings.bugProductName == null) { reporter.error("miner", "flag --bug-product is required"); reporter.printSummary(true); return; } includeBugs = true; } if (includeBugs) { if (settings.bugLoginPw == null || settings.bugLoginUser == null) { if (settings.bugLoginPw != null) { reporter.error("miner", "--bug-passwd should only be used in combination with --bug-account"); reporter.printSummary(); return; } else if (settings.bugLoginUser != null) { reporter.error("miner", "--bug-account should only be used in combination with --bug-passwd"); reporter.printSummary(); return; } } if (cmd.hasOption("bug-threads")) { try { settings.bugThreads = Integer.parseInt(cmd.getOptionValue("bug-threads")); } catch (Exception e) { reporter.error("miner", "--bug-threads: Invalid parameter type"); reporter.printSummary(); return; } } if (cmd.hasOption("bug-cooldown-time")) { try { settings.bugCooldownTime = Integer.parseInt(cmd.getOptionValue("bug-cooldown-time")); } catch (Exception e) { reporter.error("miner", "--bug-cooldown-time: Invalid parameter type"); reporter.printSummary(); return; } } if (cmd.hasOption("bug-miner-option")) { for (String str : cmd.getOptionValues("bug-miner-option")) { addSpecificParameter(settings.bugSpecificParams, str); } } if (cmd.hasOption("src-miner-option")) { for (String str : cmd.getOptionValues("src-miner-option")) { addSpecificParameter(settings.srcSpecificParams, str); } } } else { if (settings.bugLoginPw != null) { reporter.error("miner", "--bug-passwd should only be used in combination with --bug-account"); reporter.printSummary(); return; } if (settings.bugLoginUser != null) { reporter.error("miner", "--bug-account should only be used in combination with --bug-account"); reporter.printSummary(); return; } if (settings.bugRepository != null) { reporter.error("miner", "--bug-repo should only be used in combination with --bug-product and --bug-tracker"); reporter.printSummary(); return; } if (settings.bugProductName != null) { reporter.error("miner", "--bug-product should only be used in combination with --bug-repo and --bug-tracker"); reporter.printSummary(); return; } if (settings.bugTrackerName != null) { reporter.error("miner", "--bug-tracker should only be used in combination with --bug-repo and --bug-product"); reporter.printSummary(); return; } if (settings.bugEnableUntrustedCertificates) { reporter.error("miner", "--bug-enable-untrusted should only be used in combination with --bug-repo, --bug-tracker and --bug-product"); reporter.printSummary(); return; } if (settings.bugUpdate) { reporter.error("miner", "--bug-update should only be used in combination with --bug-repo, --bug-tracker and --bug-product"); reporter.printSummary(); return; } if (cmd.hasOption("bug-threads")) { reporter.error("miner", "--bug-threads should only be used in combination with --bug-repo, --bug-tracker and --bug-product"); reporter.printSummary(); return; } if (cmd.hasOption("bug-cooldown-time")) { reporter.error("miner", "--bug-cooldown-time should only be used in combination with --bug-repo, --bug-tracker and --bug-product"); reporter.printSummary(); return; } if (cmd.hasOption("bug-miner-option")) { reporter.error("miner", "--bug-miner-option should only be used in combination with --bug-repo, --bug-tracker and --bug-product"); reporter.printSummary(); return; } } // // Run: // MinerRunner runner = new MinerRunner(pool, project, settings, reporter); if (cmd.hasOption("verbose")) { runner.addListener(new MinerListener() { private Map<Miner, Integer> totals = new HashMap<Miner, Integer>(); @Override public void start(Miner miner) { } @Override public void end(Miner miner) { } @Override public void stop(Miner miner) { } @Override public void tasksTotal(Miner miner, int count) { totals.put(miner, count); } @Override public void tasksProcessed(Miner miner, int processed) { Integer total = totals.get(miner); reporter.note(miner.getName(), "status: " + processed + "/" + ((total == null) ? "0" : total)); } }); } runner.run(); } catch (ParameterException e) { reporter.error(e.getMiner().getName(), e.getMessage()); } catch (ParseException e) { reporter.error("miner", "Parsing failed: " + e.getMessage()); if (printTraces == true) { e.printStackTrace(); } } catch (ClassNotFoundException e) { reporter.error("miner", "Failed to create a database connection: " + e.getMessage()); if (printTraces == true) { e.printStackTrace(); } } catch (SQLException e) { reporter.error("miner", "Failed to create a database connection: " + e.getMessage()); if (printTraces == true) { e.printStackTrace(); } } catch (MinerException e) { reporter.error("miner", "Mining Error: " + e.getMessage()); if (printTraces == true) { e.printStackTrace(); } } finally { if (pool != null) { pool.close(); } } reporter.printSummary(true); }
From source file:com.linkedin.python.importer.ImporterCLI.java
public static Map<String, String> buildSubstitutionMap(CommandLine line) { Map<String, String> sub = new LinkedHashMap<>(); if (line.hasOption("replace")) { Arrays.asList(line.getOptionValues("replace")).forEach(it -> { System.out.println(it); String[] split = it.split("="); sub.put(split[0], split[1]); });/*from w ww.j a v a2 s . co m*/ } return sub; }
From source file:net.openhft.chronicle.queue.ChronicleReaderMain.java
private static void configureReader(final ChronicleReader chronicleReader, final CommandLine commandLine) { if (commandLine.hasOption('i')) { stream(commandLine.getOptionValues('i')).forEach(chronicleReader::withInclusionRegex); }/*from w ww . ja v a2 s. c o m*/ if (commandLine.hasOption('e')) { stream(commandLine.getOptionValues('e')).forEach(chronicleReader::withExclusionRegex); } if (commandLine.hasOption('f')) { chronicleReader.tail(); } if (commandLine.hasOption('m')) { chronicleReader.historyRecords(Long.parseLong(commandLine.getOptionValue('m'))); } if (commandLine.hasOption('n')) { chronicleReader.withStartIndex(Long.decode(commandLine.getOptionValue('n'))); } if (commandLine.hasOption('r')) { chronicleReader.asMethodReader(); } if (commandLine.hasOption('w')) { chronicleReader.withWireType(WireType.valueOf(commandLine.getOptionValue('w'))); } if (commandLine.hasOption('s')) { chronicleReader.suppressDisplayIndex(); } }
From source file:hrytsenko.csv.Args.java
private static String[] getValues(CommandLine line, String option) { return line.hasOption(option) ? line.getOptionValues(option) : new String[0]; }
From source file:de.topobyte.utilities.apache.commons.cli.parsing.ArgumentHelper.java
public static List<StringOption> getStrings(CommandLine line, String option) { String[] values = line.getOptionValues(option); if (values == null) { return new ArrayList<>(); }// www .j a v a 2 s . c o m List<StringOption> options = new ArrayList<>(); for (String value : values) { options.add(new StringOption(true, value)); } return options; }
From source file:com.heliosdecompiler.helios.Helios.java
public static void handleCommandLine(String[] args, Injector injector) { Options options = new Options(); options.addOption(Option.builder("o").longOpt("open").hasArg().desc("Open a file straight away").build()); try {//from w w w. j av a 2 s .c o m List<File> open = new ArrayList<>(); CommandLineParser parser = new DefaultParser(); CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption("open")) { for (String name : commandLine.getOptionValues("open")) { File file = new File(name); if (file.exists()) { open.add(file); } } } for (File file : open) injector.getInstance(OpenedFileController.class).openFile(file); } catch (ParseException e) { injector.getInstance(MessageHandler.class).handleException(Message.ERROR_UNKNOWN_ERROR.format(), e); } }