List of usage examples for com.google.common.base Preconditions checkArgument
public static void checkArgument(boolean expression, @Nullable Object errorMessage)
From source file:org.xdi.oxd.license.validator.LicenseValidatorExecutor.java
/** * Required by Docker Edition.// w ww . j av a2 s . c om * * @param args args * @throws IOException */ public static void main(String[] args) throws IOException { System.out.println("Validator expects: " + ARGUMENTS_MESSAGE); Preconditions.checkArgument(args.length == 6, "Please specify arguments for program as following: " + ARGUMENTS_MESSAGE); String license = args[0]; String publicKey = args[1]; String publicPassword = args[2]; String licensePassword = args[3]; String product = args[4]; String currentDate = args[5]; LicenseContent licenseContent = LicenseValidator.validate(publicKey, publicPassword, licensePassword, license, Product.fromValue(product), new Date(Long.parseLong(currentDate))); System.out.println(Jackson.asJsonSilently(licenseContent)); }
From source file:me.bramhaag.discordselfbot.Main.java
public static void main(String[] args) { Preconditions.checkArgument(args.length == 1, "Please specify a token"); try {/*from www .ja v a2 s .co m*/ bot = new Bot(args[0]); } catch (FileNotFoundException | LoginException | RateLimitedException | InterruptedException e) { e.printStackTrace(); } }
From source file:pt.up.fe.specs.eclipse.Utilities.RunAnt.java
public static void main(String[] args) { SpecsSystem.programStandardInit();/*w ww . j a v a2s . c o m*/ // System.out.println("HELLO"); // System.out.println("ANT java.home: " + System.getProperty("java.home")); // System.out.println("JAVA_HOME ENV:" + System.getenv("JAVA_HOME")); Preconditions.checkArgument(args.length > 0, "Expected at least one argument, the ant file"); File antFile = SpecsIo.existingFile(args[0]); String target = null; if (args.length > 1) { target = args[1]; } DeployUtils.runAnt(antFile, target); }
From source file:org.apache.kylin.common.util.SparkEntry.java
public static void main(String[] args) throws Exception { System.out.println("SparkEntry args:" + StringUtils.join(args, " ")); Preconditions.checkArgument(args.length >= 2, "-className is required"); Preconditions.checkArgument(args[0].equals("-className"), "-className is required"); final String className = args[1]; final Object o = Class.<AbstractApplication>forName(className).newInstance(); Preconditions.checkArgument(o instanceof AbstractApplication, className + " is not a subClass of AbstractSparkApplication"); String[] appArgs = new String[args.length - 2]; for (int i = 2; i < args.length; i++) { appArgs[i - 2] = args[i];//from w w w.jav a 2 s. com } AbstractApplication abstractApplication = (AbstractApplication) o; abstractApplication.execute(appArgs); }
From source file:org.apache.mahout.classifier.sgd.PrintResourceOrFile.java
public static void main(String[] args) throws Exception { Preconditions.checkArgument(args.length == 1, "Must have a single argument that names a file or resource."); BufferedReader in = TrainLogistic.open(args[0]); try {/*from ww w.j ava2 s .co m*/ String line; while ((line = in.readLine()) != null) { System.out.println(line); } } finally { Closeables.close(in, true); } }
From source file:org.opendaylight.protocol.pcep.testtool.PCCMock.java
public static void main(final String[] args) throws InterruptedException, ExecutionException { Preconditions.checkArgument(args.length > 0, "Host and port of server must be provided."); final List<PCEPCapability> caps = new ArrayList<>(); final PCEPSessionProposalFactory proposal = new BasePCEPSessionProposalFactory((short) 120, (short) 30, caps);/*from www . j ava 2 s . c o m*/ final PCEPSessionNegotiatorFactory snf = new DefaultPCEPSessionNegotiatorFactory(proposal, 0); final HostAndPort serverHostAndPort = HostAndPort.fromString(args[0]); final InetSocketAddress serverAddr = new InetSocketAddress(serverHostAndPort.getHostText(), serverHostAndPort.getPortOrDefault(12345)); final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0); try (final PCCDispatcherImpl pccDispatcher = new PCCDispatcherImpl( ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry())) { pccDispatcher.createClient(serverAddr, -1, new PCEPSessionListenerFactory() { @Override public PCEPSessionListener getSessionListener() { return new SimpleSessionListener(); } }, snf, null, clientAddr).get(); } }
From source file:com.emo.ananas.app.App.java
public static void main(String[] args) throws InterruptedException { final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); Config config = ConfigFactory.load(); Preconditions.checkArgument(config.hasPath("emailer"), "expected an 'emailer' object in config"); final Config emailerConfig = config.getConfig("emailer"); Preconditions.checkArgument(emailerConfig.hasPath("smtp"), "expected emailer.smtp in config"); EmailSenderConfig emailSenderConfig = new EmailSenderConfig(emailerConfig.getString("smtp")); Preconditions.checkArgument(config.hasPath("reports"), "expected reports object in config"); final Config reportsConfig = config.getConfig("reports"); Preconditions.checkArgument(reportsConfig.hasPath("actives"), "expected reports.actives with array of active declared reports in config"); final List<String> activeReports = reportsConfig.getStringList("actives"); final DataSourceFactory factory = new DataSourceFactory(config.getConfig("datasources")); for (final String activeReport : activeReports) { Preconditions.checkArgument(reportsConfig.hasPath(activeReport), "expected reports." + activeReport + " in config, because it is declared in actives report list"); }// www.j a v a 2s .c o m scheduler.initialize(); for (final String activeReport : activeReports) { final Config reportConfig = reportsConfig.getConfig(activeReport); final CronConfig cronConfig = new CronConfig(reportConfig); final EmailConfig emailConfig = new EmailConfig(reportConfig); final BaseConfig dataSource = new BaseConfig(reportConfig, factory); final QueryConfig queryConfig = new QueryConfig(reportConfig, dataSource.dataSource()); final Report report = new Report(activeReport, scheduler, emailSenderConfig, emailConfig, cronConfig, queryConfig); report.schedule(); } while (true) { Thread.sleep(60000); } }
From source file:webindex.data.Configure.java
public static void main(String[] args) throws Exception { if (args.length != 2) { log.error("Usage: Configure <webindexConfigPath> <fluoAppProps>"); System.exit(1);//from w ww .j a v a 2s. c o m } WebIndexConfig webIndexConfig = WebIndexConfig.load(args[0]); String appPropsPath = args[1]; Preconditions.checkArgument(new File(appPropsPath).exists(), "File does not exist: " + appPropsPath); FluoConfiguration fluoConfig = new FluoConfiguration(new File(webIndexConfig.getConnPropsPath())); fluoConfig.load(new File(appPropsPath)); IndexEnv env = new IndexEnv(webIndexConfig, fluoConfig); env.initAccumuloIndexTable(); FluoConfiguration appConfig = new FluoConfiguration(); env.configureApplication(fluoConfig, appConfig); Iterator<String> iter = appConfig.getKeys(); try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(appPropsPath, true)))) { while (iter.hasNext()) { String key = iter.next(); out.println(key + " = " + appConfig.getRawString(key)); } } }
From source file:org.b1.pack.cli.Main.java
public static void main(String[] args) throws Exception { boolean debugMode = Boolean.getBoolean(Main.class.getName() + ".debug"); try {/*from w w w. ja v a2s .c o m*/ long startTime = System.currentTimeMillis(); ArgSet argSet = new ArgSet(args); String command = argSet.getCommand(); if (argSet.isHelp()) { printHelp(); Preconditions.checkArgument(command == null, "Command ignored"); } else { Preconditions.checkNotNull(command, "No command"); Preconditions.checkNotNull(COMAND_MAP.get(command), "Invalid command: %s", command).execute(argSet); } if (debugMode) { System.out.println("Executed in " + (System.currentTimeMillis() - startTime) + " ms."); } } catch (Exception e) { printError(e); if (debugMode) { throw e; } else { System.exit(1); } } }
From source file:org.apache.kylin.engine.streaming.diagnose.StreamingLogAnalyzer.java
public static void main(String[] args) { int errorFileCount = 0; List<Long> ellapsedTimes = Lists.newArrayList(); String patternStr = "(\\d{2}/\\d{2}/\\d{2} \\d{2}:\\d{2}:\\d{2})"; Pattern pattern = Pattern.compile(patternStr); SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); format.setTimeZone(TimeZone.getTimeZone("GMT")); // NOTE: this must be GMT to calculate epoch date correctly Preconditions.checkArgument(args.length == 1, "Usage: StreamingLogsAnalyser streaming_logs_folder"); for (File file : FileUtils.listFiles(new File(args[0]), new String[] { "log" }, false)) { System.out.println("Processing file " + file.toString()); long startTime = 0; long endTime = 0; try {/* w w w .j a v a2 s . c o m*/ List<String> contents = Files.readAllLines(file.toPath(), Charset.defaultCharset()); for (int i = 0; i < contents.size(); ++i) { Matcher m = pattern.matcher(contents.get(i)); if (m.find()) { startTime = format.parse("20" + m.group(1)).getTime(); break; } } for (int i = contents.size() - 1; i >= 0; --i) { Matcher m = pattern.matcher(contents.get(i)); if (m.find()) { endTime = format.parse("20" + m.group(1)).getTime(); break; } } if (startTime == 0 || endTime == 0) { throw new RuntimeException("start time or end time is not found"); } if (endTime - startTime < 60000) { System.out.println("Warning: this job took less than one minute!!!! " + file.toString()); } ellapsedTimes.add(endTime - startTime); } catch (Exception e) { System.out.println("Exception when processing log file " + file.toString()); System.out.println(e); errorFileCount++; } } System.out.println("Totally error files count " + errorFileCount); System.out.println("Totally normal files processed " + ellapsedTimes.size()); long sum = 0; for (Long x : ellapsedTimes) { sum += x; } System.out.println("Avg build time " + (sum / ellapsedTimes.size())); }