List of usage examples for java.lang String isEmpty
public boolean isEmpty()
From source file:com.k42b3.quantum.Entry.java
public static void main(String[] args) throws Exception { // logging/*from w w w .j av a 2 s . c om*/ Layout layout = new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN); Logger.getLogger("com.k42b3.quantum").addAppender(new WriterAppender(layout, System.out)); // options Options options = new Options(); options.addOption("p", "port", false, "Port for the web server default is 8080"); options.addOption("i", "interval", false, "The interval how often each worker gets triggered in minutes default is 2"); options.addOption("d", "database", false, "Path to the sqlite database default is \"quantum.db\""); options.addOption("l", "log", false, "Defines the log level default is ERROR possible is (ALL, TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF)"); options.addOption("v", "version", false, "Shows the current version"); options.addOption("h", "help", false, "Shows the help"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); // start app Quantum app = new Quantum(); if (cmd.hasOption("p")) { try { int port = Integer.parseInt(cmd.getOptionValue("p")); app.setPort(port); } catch (NumberFormatException e) { Logger.getLogger("com.k42b3.quantum").info("Port must be an integer"); } } if (cmd.hasOption("i")) { try { int pollInterval = Integer.parseInt(cmd.getOptionValue("i")); app.setPollInterval(pollInterval); } catch (NumberFormatException e) { Logger.getLogger("com.k42b3.quantum").info("Interval must be an integer"); } } if (cmd.hasOption("d")) { String dbPath = cmd.getOptionValue("d"); if (!dbPath.isEmpty()) { app.setDbPath(dbPath); } } if (cmd.hasOption("l")) { Logger.getLogger("com.k42b3.quantum").setLevel(Level.toLevel(cmd.getOptionValue("l"))); } else { Logger.getLogger("com.k42b3.quantum").setLevel(Level.ERROR); } if (cmd.hasOption("v")) { System.out.println("Version: " + Quantum.VERSION); System.exit(0); } if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("quantum.jar", options); System.exit(0); } app.run(); }
From source file:dpfmanager.shell.core.util.VersionUtil.java
public static void main(String[] args) { String version = args[0];//from w ww. ja v a 2 s . c o m String baseDir = args[1]; String issPath = baseDir + "/package/windows/DPF Manager.iss"; String rpmPath = baseDir + "/package/linux/DPFManager.old.spec"; String propOutput = baseDir + "/target/classes/version.properties"; try { // Windows iss File issFile = new File(issPath); String issContent = FileUtils.readFileToString(issFile); String newIssContent = replaceLine(StringUtils.split(issContent, '\n'), "AppVersion=", version); if (!newIssContent.isEmpty()) { FileUtils.writeStringToFile(issFile, newIssContent); System.out.println("New version information updated! (iss)"); } // RPM spec File rpmFile = new File(rpmPath); String rpmContent = FileUtils.readFileToString(rpmFile); String newRpmContent = replaceLine(StringUtils.split(rpmContent, '\n'), "Version: ", version); if (!newRpmContent.isEmpty()) { FileUtils.writeStringToFile(rpmFile, newRpmContent); System.out.println("New version information updated! (spec)"); } // Java properties file OutputStream output = new FileOutputStream(propOutput); Properties prop = new Properties(); prop.setProperty("version", version); prop.store(output, "Version autoupdated"); output.close(); System.out.println("New version information updated! (properties)"); } catch (Exception e) { System.out.println("Exception ocurred, no version changed."); e.printStackTrace(); } }
From source file:ddf.lib.OwaspDiffRunner.java
public static void main(String[] args) throws OwaspDiffRunnerException { System.out.println(BEGIN_OWASP_AUDIT); try {/*from w ww .j ava 2 s. co m*/ mavenHome = getMavenHome(); localRepo = getLocalRepo(); String modulesOfChangedPoms = getModulesOfChangedPoms(); if (modulesOfChangedPoms.isEmpty()) { System.out.println("No changed poms."); return; } InvocationRequest request = new DefaultInvocationRequest(); request.setPomFile(new File(PROJECT_ROOT + File.separator + "pom.xml")); request.setBaseDirectory(new File(PROJECT_ROOT)); request.setLocalRepositoryDirectory(new File(localRepo)); request.setGoals( Arrays.asList("dependency-check:check", "--quiet", "-pl", modulesOfChangedPoms, "-Powasp")); invoker.setMavenHome(new File(mavenHome)); System.out.println("-- Maven home: " + mavenHome); System.out.println("-- Local Maven repo: " + localRepo); InvocationResult mavenBuildResult; try { mavenBuildResult = invoker.execute(request); } catch (MavenInvocationException e) { throw new OwaspDiffRunnerException( OwaspDiffRunnerException.UNABLE_TO_RUN_MAVEN + modulesOfChangedPoms, e); } if (mavenBuildResult.getExitCode() != 0) { throw new OwaspDiffRunnerException(OwaspDiffRunnerException.FOUND_VULNERABILITIES); } } finally { System.out.println(END_OWASP_AUDIT); } }
From source file:eu.interedition.collatex.http.Server.java
public static void main(String... args) { try {/* www . ja v a 2s .co m*/ final CommandLine commandLine = new GnuParser().parse(OPTIONS, args); if (commandLine.hasOption("h")) { new HelpFormatter().printHelp("collatex-server [<options> ...]\n", OPTIONS); return; } final Collator collator = new Collator(Integer.parseInt(commandLine.getOptionValue("mpc", "2")), Integer.parseInt(commandLine.getOptionValue("mcs", "0")), commandLine.getOptionValue("dot", null)); final String staticPath = System.getProperty("collatex.static.path", ""); final HttpHandler httpHandler = staticPath.isEmpty() ? new CLStaticHttpHandler(Server.class.getClassLoader(), "/static/") { @Override protected void onMissingResource(Request request, Response response) throws Exception { collator.service(request, response); } } : new StaticHttpHandler(staticPath.replaceAll("/+$", "") + "/") { @Override protected void onMissingResource(Request request, Response response) throws Exception { collator.service(request, response); } }; final NetworkListener httpListener = new NetworkListener("http", "0.0.0.0", Integer.parseInt(commandLine.getOptionValue("p", "7369"))); final CompressionConfig compressionConfig = httpListener.getCompressionConfig(); compressionConfig.setCompressionMode(CompressionConfig.CompressionMode.ON); compressionConfig.setCompressionMinSize(860); // http://webmasters.stackexchange.com/questions/31750/what-is-recommended-minimum-object-size-for-gzip-performance-benefits compressionConfig.setCompressableMimeTypes("application/javascript", "application/json", "application/xml", "text/css", "text/html", "text/javascript", "text/plain", "text/xml"); final HttpServer httpServer = new HttpServer(); httpServer.addListener(httpListener); httpServer.getServerConfiguration().addHttpHandler(httpHandler, commandLine.getOptionValue("cp", "").replaceAll("/+$", "") + "/*"); Runtime.getRuntime().addShutdownHook(new Thread(() -> { if (LOG.isLoggable(Level.INFO)) { LOG.info("Stopping HTTP server"); } httpServer.shutdown(); })); httpServer.start(); Thread.sleep(Long.MAX_VALUE); } catch (Throwable t) { LOG.log(Level.SEVERE, "Error while parsing command line", t); System.exit(1); } }
From source file:it.geosolutions.geobatch.jetty.Start.java
public static void main(String[] args) { Server server = null;/*www . j av a2 s . com*/ SocketConnector conn = null; try { server = new Server(); // TODO pass properties file File properties = null; if (args.length == 1) { String propertiesFileName = args[0]; if (!propertiesFileName.isEmpty()) { properties = new File(propertiesFileName); } } else { properties = new File("src/test/resources/jetty.properties"); } Properties prop = loadProperties(properties); // load properties into system env setSystemProperties(prop); server.setHandler(configureContext(prop)); conn = configureConnection(prop); server.setConnectors(new Connector[] { conn }); server.start(); // use this to test normal stop behavior, that is, to check stuff // that // need to be done on container shutdown (and yes, this will make // jetty stop just after you started it...) // jettyServer.stop(); } catch (Throwable e) { log.error("Could not start the Jetty server: " + e.getMessage(), e); if (server != null) { try { server.stop(); } catch (Exception e1) { log.error("Unable to stop the Jetty server:" + e1.getMessage(), e1); } } if (conn != null) { try { conn.stop(); } catch (Exception e1) { log.error("Unable to stop the connection:" + e1.getMessage(), e1); } } } }
From source file:co.turnus.analysis.pipelining.SimplePipeliningCliLauncher.java
public static void main(String[] args) { try {/*from w w w . j a v a 2 s . co m*/ CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(cliOptions, args); Configuration config = parseCommandLine(cmd); // init models AnalysisActivator.init(); // set logger verbosity if (config.getBoolean(VERBOSE, false)) { TurnusLogger.setLevel(TurnusLevel.ALL); } // load trace project File tDir = new File(config.getString(TRACE_PROJECT)); TraceProject project = TraceProject.load(tDir); SimplePipelining sp = new SimplePipelining(project); sp.setConfiguration(config); SimplePipelingData data = sp.run(); TurnusLogger.info("Storing results..."); File outPath = new File(config.getString(OUTPUT_PATH)); // store the analysis report String uuid = UUID.randomUUID().toString(); File rFile = new File(outPath, uuid + "." + TurnusExtension.REPORT); Report report = DataFactory.eINSTANCE.createReport(); report.setDate(new Date()); report.setComment("Report with only Simple Pipeling results analysis"); report.getDataSet().add(data); EcoreHelper.storeEObject(report, new ResourceSetImpl(), rFile); TurnusLogger.info("TURNUS report stored in " + rFile); // store formatted reports String xlsName = config.getString(XLS, ""); if (!xlsName.isEmpty()) { File xlsFile = new File(outPath, xlsName + ".xls"); new XlsSimplePipeliningDataWriter().write(data, xlsFile); TurnusLogger.info("XLS report stored in " + xlsFile); } TurnusLogger.info("Analysis Done!"); } catch (ParseException e) { TurnusLogger.error(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(SimplePipeliningCliLauncher.class.getSimpleName(), cliOptions); } catch (Exception e) { TurnusLogger.error(e.getMessage()); } }
From source file:com.impetus.ankush.agent.daemon.AnkushAgent.java
/** * The main method./*from w ww . j a v a 2s. c o m*/ * * @param args * the arguments */ public static void main(String[] args) { // taskable file name. String file = System.getProperty(Constant.AGENT_INSTALL_DIR) + "/.ankush/agent/conf/taskable.conf"; // iterate always try { // reading the class name lines from the file List<String> classNames = FileUtils.readLines(new File(file)); // iterate over the class names to start the newly added task. for (String className : classNames) { // if an empty string from the file then continue the loop. if (className.isEmpty()) { continue; } // if not started. if (!objMap.containsKey(className)) { // create taskable object LOGGER.info("Creating " + className + " object."); try { Taskable taskable = ActionFactory.getTaskableObject(className); objMap.put(className, taskable); // call start on object ... taskable.start(); } catch (Exception e) { LOGGER.error("Could not start the " + className + " taskable."); } } } // iterating over the existing tasks to stop if it is removed // from the file. Set<String> existingClassNames = new HashSet<String>(objMap.keySet()); for (String className : existingClassNames) { // if not started. if (!classNames.contains(className)) { // create taskable object LOGGER.info("Removing " + className + " object."); Taskable taskable = objMap.get(className); objMap.remove(className); // call stop on object ... taskable.stop(); } } } catch (Exception e) { LOGGER.error(e.getMessage(), e); } while (true) { try { Thread.sleep(TASK_SEARCH_SLEEP_TIME); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } } }
From source file:edu.cmu.lti.oaqa.knn4qa.apps.BuildInMemFwdIndexApp.java
public static void main(String[] args) { Options options = new Options(); options.addOption(CommonParams.ROOT_DIR_PARAM, null, true, CommonParams.ROOT_DIR_DESC); options.addOption(CommonParams.SUB_DIR_TYPE_PARAM, null, true, CommonParams.SUB_DIR_TYPE_DESC); options.addOption(CommonParams.MAX_NUM_REC_PARAM, null, true, CommonParams.MAX_NUM_REC_DESC); options.addOption(CommonParams.SOLR_FILE_NAME_PARAM, null, true, CommonParams.SOLR_FILE_NAME_DESC); options.addOption(CommonParams.OUT_INDEX_PARAM, null, true, CommonParams.OUT_MINDEX_DESC); options.addOption(EXCLUDE_FIELDS_PARAM, null, true, EXCLUDE_FIELDS_DESC); CommandLineParser parser = new org.apache.commons.cli.GnuParser(); try {/* w w w .j av a 2 s. c o m*/ CommandLine cmd = parser.parse(options, args); String rootDir = null; rootDir = cmd.getOptionValue(CommonParams.ROOT_DIR_PARAM); if (null == rootDir) Usage("Specify: " + CommonParams.ROOT_DIR_DESC, options); String outPrefix = cmd.getOptionValue(CommonParams.OUT_INDEX_PARAM); if (null == outPrefix) Usage("Specify: " + CommonParams.OUT_MINDEX_DESC, options); String subDirTypeList = cmd.getOptionValue(CommonParams.SUB_DIR_TYPE_PARAM); if (null == subDirTypeList || subDirTypeList.isEmpty()) Usage("Specify: " + CommonParams.SUB_DIR_TYPE_DESC, options); String solrFileName = cmd.getOptionValue(CommonParams.SOLR_FILE_NAME_PARAM); if (null == solrFileName) Usage("Specify: " + CommonParams.SOLR_FILE_NAME_DESC, options); int maxNumRec = Integer.MAX_VALUE; String tmp = cmd.getOptionValue(CommonParams.MAX_NUM_REC_PARAM); if (tmp != null) { try { maxNumRec = Integer.parseInt(tmp); if (maxNumRec <= 0) { Usage("The maximum number of records should be a positive integer", options); } } catch (NumberFormatException e) { Usage("The maximum number of records should be a positive integer", options); } } String[] exclFields = new String[0]; tmp = cmd.getOptionValue(EXCLUDE_FIELDS_PARAM); if (null != tmp) { exclFields = tmp.split(","); } String[] subDirs = subDirTypeList.split(","); for (int k = 0; k < FeatureExtractor.mFieldNames.length; ++k) { String field = FeatureExtractor.mFieldsSOLR[k]; String fieldName = FeatureExtractor.mFieldNames[k]; boolean bOk = !StringUtilsLeo.isInArrayNoCase(fieldName, exclFields); if (bOk) System.out.println("Processing field: " + field); else { System.out.println("Skipping field: " + field); continue; } String[] fileNames = new String[subDirs.length]; for (int i = 0; i < fileNames.length; ++i) fileNames[i] = rootDir + "/" + subDirs[i] + "/" + solrFileName; InMemForwardIndex indx = new InMemForwardIndex(field, fileNames, maxNumRec); indx.save(InMemIndexFeatureExtractor.indexFileName(outPrefix, fieldName)); } } catch (ParseException e) { Usage("Cannot parse arguments", options); } catch (Exception e) { e.printStackTrace(); System.err.println("Terminating due to an exception: " + e); System.exit(1); } }
From source file:CommandLineInterpreter.java
/** * Main method, command line input will get parsed here. * * @param args/*from www. j a va 2 s . c o m*/ */ public static void main(String[] args) { // // test-arguments: // args = new String[] { "1.9", "-gui" }; boolean success = false; if (args.length == 1) { String arg = args[0].trim().replaceAll("[-]+", ""); if (arg.equals("help") || arg.equals("h")) printHelp(null); } if (args.length == 0) { printHelp("ONE ARGUMENT NEEDED"); } else { try { boolean guiAlert = false; Float minVersion = null; File resourcesFile = null; // ------------------------------------------------ // // -- // ------------------------------------------------ // final String minJavaVersionArgument = args[0]; if (!minJavaVersionArgument.trim().isEmpty()) { try { minVersion = Float.parseFloat(minJavaVersionArgument); } catch (Exception e) { // do nothing } } if (minVersion == null || minVersion > 2 || minVersion < 1.6) { printHelp("VERSION STRING IS NOT VALID"); } // ------------------------------------------------ // // -- // ------------------------------------------------ // for (int i = 1; i < (args.length <= 3 ? args.length : 3); i++) { final String argument = args[i].trim(); if (argument.equals("-gui")) { guiAlert = true; } else { String resourcesFilePath = argument; if (!resourcesFilePath.isEmpty()) { resourcesFile = new File(resourcesFilePath); if (!resourcesFile.exists() || !resourcesFile.isFile() || !resourcesFile.canRead()) { printHelp("RESOURCES FILE IS NOT VALID\n[" + resourcesFile.getAbsolutePath() + "]"); } } } } // ------------------------------------------------ // // -- // ------------------------------------------------ // success = checkJREVersion(minVersion, guiAlert); if (success && resourcesFile != null) { success = checkResources(resourcesFile, guiAlert); } } catch (Exception e) { success = false; e.printStackTrace(); } } if (!success) { // set error exit code System.exit(1); } }
From source file:edu.cmu.lti.oaqa.knn4qa.apps.CollectionSplitter.java
public static void main(String[] args) { Options options = new Options(); options.addOption("i", null, true, "Input file"); options.addOption("o", null, true, "Output file prefix"); options.addOption("p", null, true, "Comma separated probabilities e.g., 0.1,0.2,0.7."); options.addOption("n", null, true, "Comma separated part names, e.g., dev,test,train"); CommandLineParser parser = new org.apache.commons.cli.GnuParser(); try {/* w ww . java2 s . c o m*/ CommandLine cmd = parser.parse(options, args); InputStream input = null; if (cmd.hasOption("i")) { input = CompressUtils.createInputStream(cmd.getOptionValue("i")); } else { Usage("Specify Input file"); } ArrayList<Double> probs = new ArrayList<Double>(); String[] partNames = null; if (cmd.hasOption("p")) { String parts[] = cmd.getOptionValue("p").split(","); try { double sum = 0; for (String s : parts) { double p = Double.parseDouble(s); if (p <= 0 || p > 1) Usage("All probabilities must be in the range (0,1)"); sum += p; probs.add(p); } if (Math.abs(sum - 1.0) > Float.MIN_NORMAL) { Usage("The sum of probabilities should be equal to 1, but it's: " + sum); } } catch (NumberFormatException e) { Usage("Can't convert some of the probabilities to a floating-point number."); } } else { Usage("Specify part probabilities."); } if (cmd.hasOption("n")) { partNames = cmd.getOptionValue("n").split(","); if (partNames.length != probs.size()) Usage("The number of probabilities is not equal to the number of parts!"); } else { Usage("Specify part names"); } BufferedWriter[] outFiles = new BufferedWriter[partNames.length]; if (cmd.hasOption("o")) { String outPrefix = cmd.getOptionValue("o"); for (int partId = 0; partId < partNames.length; ++partId) { outFiles[partId] = new BufferedWriter(new OutputStreamWriter( CompressUtils.createOutputStream(outPrefix + "_" + partNames[partId] + ".gz"))); } } else { Usage("Specify Output file prefix"); } System.out.println("Using probabilities:"); for (int partId = 0; partId < partNames.length; ++partId) System.out.println(partNames[partId] + " : " + probs.get(partId)); System.out.println("================================================="); XmlIterator inpIter = new XmlIterator(input, YahooAnswersReader.DOCUMENT_TAG); String oneRec = inpIter.readNext(); int docNum = 1; for (; !oneRec.isEmpty(); ++docNum, oneRec = inpIter.readNext()) { double p = Math.random(); if (docNum % 1000 == 0) { System.out.println(String.format("Processed %d documents", docNum)); } BufferedWriter out = null; for (int partId = 0; partId < partNames.length; ++partId) { double pp = probs.get(partId); if (p <= pp || partId + 1 == partNames.length) { out = outFiles[partId]; break; } p -= pp; } oneRec = oneRec.trim() + System.getProperty("line.separator"); out.write(oneRec); } System.out.println(String.format("Processed %d documents", docNum - 1)); // It's important to close all the streams here! for (BufferedWriter f : outFiles) f.close(); } catch (ParseException e) { Usage("Cannot parse arguments"); } catch (Exception e) { System.err.println("Terminating due to an exception: " + e); System.exit(1); } }