List of usage examples for com.google.common.base Preconditions checkNotNull
public static <T> T checkNotNull(T reference)
From source file:com.google.errorprone.bugpatterns.testdata.ProtoFieldPreconditionsCheckNotNullPositiveCases.java
public static void main(String[] args) { TestProtoMessage message = TestProtoMessage.newBuilder().build(); // BUG: Diagnostic contains: check is redundant // remove this line Preconditions.checkNotNull(message.getMessage()); // BUG: Diagnostic contains: check is redundant // remove this line Preconditions.checkNotNull(message.getMultiFieldList()); // BUG: Diagnostic contains: check is redundant // remove this line Preconditions.checkNotNull(message.getMessage(), new Object()); // BUG: Diagnostic contains: check is redundant // remove this line Preconditions.checkNotNull(message.getMultiFieldList(), new Object()); // BUG: Diagnostic contains: check is redundant // remove this line Preconditions.checkNotNull(message.getMessage(), "%s", new Object()); // BUG: Diagnostic contains: check is redundant // remove this line Preconditions.checkNotNull(message.getMultiFieldList(), "%s", new Object()); // BUG: Diagnostic contains: fieldMessage = message.getMessage(); TestFieldProtoMessage fieldMessage = Preconditions.checkNotNull(message.getMessage()); // BUG: Diagnostic contains: fieldMessage2 = message.getMessage() TestFieldProtoMessage fieldMessage2 = Preconditions.checkNotNull(message.getMessage(), "Msg"); // BUG: Diagnostic contains: message.getMessage().toString(); Preconditions.checkNotNull(message.getMessage()).toString(); // BUG: Diagnostic contains: message.getMessage().toString(); Preconditions.checkNotNull(message.getMessage(), "Message").toString(); }
From source file:com.linkedin.pinot.perf.DictionaryDumper.java
public static void main(String[] args) throws Exception { if (args.length != 3) { System.err.println(// w ww. j a v a 2s. c o m "Usage: DictionaryDumper <segmentDirectory> <dimensionName> <comma-separated dictionaryIds>"); System.exit(1); } File[] indexDirs = new File(args[0]).listFiles(); Preconditions.checkNotNull(indexDirs); for (File indexDir : indexDirs) { System.out.println("Loading " + indexDir.getName()); ImmutableSegment immutableSegment = ImmutableSegmentLoader.load(indexDir, ReadMode.heap); ImmutableDictionaryReader colDictionary = immutableSegment.getDictionary(args[1]); List<String> strIdList = Arrays.asList(args[2].split(",")); for (String strId : strIdList) { int id = Integer.valueOf(strId); String s = colDictionary.getStringValue(id); System.out.println(String.format("%d -> %s", id, s)); } } }
From source file:com.google.devtools.build.android.idlclass.IdlClass.java
public static void main(String[] args) throws IOException { OptionsParser optionsParser = OptionsParser.newOptionsParser(IdlClassOptions.class); optionsParser.parseAndExitUponError(args); IdlClassOptions options = optionsParser.getOptions(IdlClassOptions.class); Preconditions.checkNotNull(options.manifestProto); Preconditions.checkNotNull(options.classJar); Preconditions.checkNotNull(options.outputClassJar); Preconditions.checkNotNull(options.outputSourceJar); Preconditions.checkNotNull(options.tempDir); List<Path> idlSources = Lists.newArrayList(); for (String idlSource : optionsParser.getResidue()) { idlSources.add(Paths.get(idlSource)); }/*from ww w . j a va2s .c o m*/ Manifest manifest = readManifest(options.manifestProto); writeClassJar(options, idlSources, manifest); writeSourceJar(options, idlSources, manifest); }
From source file:com.google.cloud.security.scanner.servlets.LiveStateCheckerRunner.java
/** * Main function for the runner.//from w ww. j a v a 2s .com * @param args The args this program was called with. * @throws IOException Thrown if there's an error reading from one of the APIs. */ public static void main(String[] args) throws IOException { String org = System.getenv("POLICY_SCANNER_ORG_NAME"); String inputRepositoryUrl = System.getenv("POLICY_SCANNER_INPUT_REPOSITORY_URL"); String sinkUrl = System.getenv("POLICY_SCANNER_SINK_URL"); String dataflowTmpBucket = System.getenv("POLICY_SCANNER_DATAFLOW_TMP_BUCKET"); String stagingLocation = "gs://" + dataflowTmpBucket + "/dataflow_tmp"; Preconditions.checkNotNull(org); Preconditions.checkNotNull(inputRepositoryUrl); Preconditions.checkNotNull(sinkUrl); Preconditions.checkNotNull(dataflowTmpBucket); GCSFilesSource source; try { source = new GCSFilesSource(inputRepositoryUrl, org); } catch (GeneralSecurityException e) { throw new IOException("SecurityException: Cannot create GCSFileSource"); } PipelineOptions options; if (CloudUtil.willExecuteOnCloud()) { options = getCloudExecutionOptions(stagingLocation); } else { options = getLocalExecutionOptions(); } new OnDemandLiveStateChecker(options, source) .attachSink(TextIO.Write.named("Write messages to GCS").to(sinkUrl)).run(); }
From source file:com.pinterest.terrapin.hadoop.S3Uploader.java
public static void main(String[] args) { TerrapinUploaderOptions uploaderOptions = TerrapinUploaderOptions.initFromSystemProperties(); uploaderOptions.validate();/*from w ww. j ava 2 s .c om*/ String s3Bucket = System.getProperties().getProperty("terrapin.s3bucket"); String s3Prefix = System.getProperties().getProperty("terrapin.s3key_prefix"); Preconditions.checkNotNull(s3Bucket); Preconditions.checkNotNull(s3Prefix); try { new S3Uploader(uploaderOptions, s3Bucket, s3Prefix).upload(uploaderOptions.terrapinCluster, uploaderOptions.terrapinFileSet, uploaderOptions.loadOptions); } catch (Exception e) { LOG.error("Upload FAILED.", e); System.exit(1); } // We need to force an exit since some of the netty threads instantiated as part // of the process are not daemon threads. System.exit(0); }
From source file:com.google.devtools.build.android.AndroidResourceParsingAction.java
public static void main(String[] args) throws Exception { OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class); optionsParser.parseAndExitUponError(args); Options options = optionsParser.getOptions(Options.class); Preconditions.checkNotNull(options.primaryData); Preconditions.checkNotNull(options.output); final Stopwatch timer = Stopwatch.createStarted(); ParsedAndroidData parsedPrimary = ParsedAndroidData.from(options.primaryData); logger.fine(String.format("Walked XML tree at %dms", timer.elapsed(TimeUnit.MILLISECONDS))); UnwrittenMergedAndroidData unwrittenData = UnwrittenMergedAndroidData.of(null, parsedPrimary, ParsedAndroidData.from(ImmutableList.<DependencyAndroidData>of())); AndroidDataSerializer serializer = AndroidDataSerializer.create(); unwrittenData.serializeTo(serializer); serializer.flushTo(options.output);// w w w. j a va 2s . c om logger.fine(String.format("Finished parse + serialize in %dms", timer.elapsed(TimeUnit.MILLISECONDS))); }
From source file:com.google.devtools.build.android.AndroidCompiledResourceMergingAction.java
public static void main(String[] args) throws Exception { final Stopwatch timer = Stopwatch.createStarted(); OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class, AaptConfigOptions.class); optionsParser.enableParamsFileSupport(new ShellQuotedParamsFilePreProcessor(FileSystems.getDefault())); optionsParser.parseAndExitUponError(args); AaptConfigOptions aaptConfigOptions = optionsParser.getOptions(AaptConfigOptions.class); Options options = optionsParser.getOptions(Options.class); Preconditions.checkNotNull(options.primaryData); Preconditions.checkNotNull(options.primaryManifest); Preconditions.checkNotNull(options.manifestOutput); Preconditions.checkNotNull(options.classJarOutput); try (ScopedTemporaryDirectory scopedTmp = new ScopedTemporaryDirectory("android_resource_merge_tmp"); ExecutorServiceCloser executorService = ExecutorServiceCloser.createWithFixedPoolOf(15)) { Path tmp = scopedTmp.getPath(); Path generatedSources = tmp.resolve("generated_resources"); Path processedManifest = tmp.resolve("manifest-processed/AndroidManifest.xml"); logger.fine(String.format("Setup finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS))); String packageForR = options.packageForR; if (packageForR == null) { packageForR = Strings/* ww w .j av a 2 s . c om*/ .nullToEmpty(VariantConfiguration.getManifestPackage(options.primaryManifest.toFile())); } AndroidResourceClassWriter resourceClassWriter = AndroidResourceClassWriter .createWith(aaptConfigOptions.androidJar, generatedSources, packageForR); resourceClassWriter.setIncludeClassFile(true); resourceClassWriter.setIncludeJavaFile(false); AndroidResourceMerger.mergeCompiledData(options.primaryData, options.primaryManifest, options.directData, options.transitiveData, resourceClassWriter, options.throwOnResourceConflict, executorService); logger.fine(String.format("Merging finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS))); AndroidResourceOutputs.createClassJar(generatedSources, options.classJarOutput, options.targetLabel, options.injectingRuleKind); logger.fine(String.format("Create classJar finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS))); // Until enough users with manifest placeholders migrate to the new manifest merger, // we need to replace ${applicationId} and ${packageName} with options.packageForR to make // the manifests compatible with the old manifest merger. processedManifest = AndroidManifestProcessor.with(stdLogger).processLibraryManifest(options.packageForR, options.primaryManifest, processedManifest); Files.createDirectories(options.manifestOutput.getParent()); Files.copy(processedManifest, options.manifestOutput); } catch (MergeConflictException e) { logger.log(Level.SEVERE, e.getMessage()); System.exit(1); } catch (MergingException e) { logger.log(Level.SEVERE, "Error during merging resources", e); throw e; } catch (AndroidManifestProcessor.ManifestProcessingException e) { System.exit(1); } catch (Exception e) { logger.log(Level.SEVERE, "Unexpected", e); throw e; } logger.fine(String.format("Resources merged in %sms", timer.elapsed(TimeUnit.MILLISECONDS))); }
From source file:org.apache.kylin.engine.streaming.cli.MonitorCLI.java
public static void main(String[] args) { Preconditions.checkArgument(args[0].equals("monitor")); int i = 1;// w ww.j ava2s.co m List<String> receivers = null; String host = null; String tableName = null; String authorization = null; String cubeName = null; String projectName = "default"; while (i < args.length) { String argName = args[i]; switch (argName) { case "-receivers": receivers = Lists.newArrayList(StringUtils.split(args[++i], ";")); break; case "-host": host = args[++i]; break; case "-tableName": tableName = args[++i]; break; case "-authorization": authorization = args[++i]; break; case "-cubeName": cubeName = args[++i]; break; case "-projectName": projectName = args[++i]; break; default: throw new RuntimeException("invalid argName:" + argName); } i++; } Preconditions.checkArgument(receivers != null && receivers.size() > 0); final StreamingMonitor streamingMonitor = new StreamingMonitor(); if (tableName != null) { logger.info(String.format("check query tableName:%s host:%s receivers:%s", tableName, host, StringUtils.join(receivers, ";"))); Preconditions.checkNotNull(host); Preconditions.checkNotNull(authorization); Preconditions.checkNotNull(tableName); streamingMonitor.checkCountAll(receivers, host, authorization, projectName, tableName); } if (cubeName != null) { logger.info(String.format("check cube cubeName:%s receivers:%s", cubeName, StringUtils.join(receivers, ";"))); streamingMonitor.checkCube(receivers, cubeName, host); } System.exit(0); }
From source file:com.pinterest.terrapin.hadoop.HdfsUploader.java
public static void main(String[] args) { TerrapinUploaderOptions uploaderOptions = TerrapinUploaderOptions.initFromSystemProperties(); uploaderOptions.validate();// w w w. j a v a 2 s .c om String hdfsDir = System.getProperties().getProperty("terrapin.hdfs_dir"); Preconditions.checkNotNull(hdfsDir); try { new HdfsUploader(uploaderOptions, hdfsDir).upload(uploaderOptions.terrapinCluster, uploaderOptions.terrapinFileSet, uploaderOptions.loadOptions); } catch (Exception e) { LOG.error("Upload FAILED.", e); System.exit(1); } // We need to force an exit since some of the netty threads instantiated as part // of the process are not daemon threads. System.exit(0); }
From source file:org.apache.streams.elasticsearch.example.MongoElasticsearchIndex.java
public static void main(String[] args) { LOGGER.info(StreamsConfigurator.config.toString()); Config reindex = StreamsConfigurator.config.getConfig("reindex"); Config source = reindex.getConfig("source"); Config destination = reindex.getConfig("destination"); MongoConfiguration mongoConfiguration = null; try {/*from www . j ava2 s . co m*/ mongoConfiguration = mapper.readValue(source.root().render(ConfigRenderOptions.concise()), MongoConfiguration.class); } catch (Exception e) { e.printStackTrace(); return; } Preconditions.checkNotNull(mongoConfiguration); ElasticsearchWriterConfiguration elasticsearchConfiguration; try { elasticsearchConfiguration = mapper.readValue(destination.root().render(ConfigRenderOptions.concise()), ElasticsearchWriterConfiguration.class); } catch (Exception e) { e.printStackTrace(); return; } Preconditions.checkNotNull(elasticsearchConfiguration); MongoPersistReader mongoPersistReader = new MongoPersistReader(mongoConfiguration); ElasticsearchPersistWriter elasticsearchPersistWriter = new ElasticsearchPersistWriter( elasticsearchConfiguration); StreamBuilder builder = new LocalStreamBuilder(1000); builder.newPerpetualStream(MongoPersistReader.STREAMS_ID, mongoPersistReader); builder.addStreamsPersistWriter(ElasticsearchPersistWriter.STREAMS_ID, elasticsearchPersistWriter, 1, MongoPersistReader.STREAMS_ID); builder.start(); }