/** Check if there are any errors. */ public boolean hasErrors() { return getDiagCollector().hasErrors(); }
/** Check if there are any errors. */ public boolean hasErrors() { return getDiagCollector().hasErrors(); }
/** * Report any errors and exit if there were some. */ protected void onErrorsExit() { if (getDiagCollector().hasErrors()) { reportDiag(); System.exit(1); } }
/** * Report any errors and exit if there were some. */ protected void onErrorsExit() { if (getDiagCollector().hasErrors()) { reportDiag(); System.exit(1); } }
/** * Runs the tool. Returns a non-zero exit code on errors. */ public int run() { // Run tool specific code. if (!getDiagCollector().hasErrors()) { try { process(); } catch (Exception e) { getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unexpected exception:%n%s", Throwables.getStackTraceAsString(e))); } } reportDiag(); return getDiagCollector().hasErrors() ? 1 : 0; }
/** * Runs the tool. Returns a non-zero exit code on errors. */ public int run() { // Run tool specific code. if (!getDiagCollector().hasErrors()) { try { process(); } catch (Exception e) { getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unexpected exception:%n%s", Throwables.getStackTraceAsString(e))); } } reportDiag(); return getDiagCollector().hasErrors() ? 1 : 0; }
/** Sets up the model configs, attaching to the model. */ public static void setupModelConfigs(Model model, Set<FileWrapper> files) { DiagCollector diagCollector = model.getDiagReporter().getDiagCollector(); ImmutableList.Builder<ConfigSource> builder = ImmutableList.builder(); for (FileWrapper file : files) { ConfigSource message = getConfigSourceFromFile(diagCollector, file.getFilename(), file.getFileContents()); if (message != null) { builder.add(message); } } if (diagCollector.hasErrors()) { return; } model.setConfigSources(builder.build()); } }
/** Sets up the model configs, attaching to the model. */ public static void setupModelConfigs(Model model, Set<FileWrapper> files) { DiagCollector diagCollector = model.getDiagReporter().getDiagCollector(); ImmutableList.Builder<ConfigSource> builder = ImmutableList.builder(); for (FileWrapper file : files) { ConfigSource message = getConfigSourceFromFile(diagCollector, file.getFilename(), file.getFileContents()); if (message != null) { builder.add(message); } } if (diagCollector.hasErrors()) { return; } model.setConfigSources(builder.build()); } }
/** Creates {@link com.google.api.Service} from Swagger Objects, and returns it. */ public Service createServiceConfig() throws OpenApiConversionException { new TopLevelBuilder() .setTopLevelFields(openApis.get(0).serviceBuilder(), openApis, serviceName); try { buildService(openApis); } catch (Exception ex) { aggregateAllDiagnostics(openApis); // If the openApi files have known errors, regardless of any exceptions that have been // generated while parsing them, we log and swallow the exception so that we can respond with // the errors that we've already generated. if (diagCollector.hasErrors()) { return null; } throw ex; } aggregateAllDiagnostics(openApis); if (diagCollector.hasErrors()) { return null; } List<Service.Builder> serviceBuilders = Lists.newArrayList(); for (OpenApiFile openApiFile : openApis) { serviceBuilders.add(openApiFile.serviceBuilder()); } return ServiceNormalizer.normalizeService( new ServiceMerger().merge(serviceBuilders), diagCollector, additionalConfigs); }
ExtensionPool userExtensionPool = parseExtensionDescriptor(options, registry, diagCollector); if (diagCollector.hasErrors()) { return ModelBuildResult.create(null, diagCollector); userExtensionPool, diagCollector); if (diagCollector.hasErrors()) { return ModelBuildResult.create(null, diagCollector); if (diagCollector.hasErrors()) { return ModelBuildResult.create(null, diagCollector);
private void checkNoErrors() { if (model.getDiagReporter().getDiagCollector().hasErrors()) { Assert.fail( "Errors: " + Joiner.on("\n").join(model.getDiagReporter().getDiagCollector().getDiags())); } StageValidator.assertStages(ImmutableList.<Key<?>>of(Resolved.KEY, Merged.KEY), model); }
/** * Run a test for the given file base name(s). Collects all .proto and .yaml files with the given * base name (i.e. baseName.proto or baseName.yaml), constructs model, and calls {@link #run()}. * Post that, prints diags and the result of the run to the baseline. */ protected void test() throws Exception { DiagCollector diagCollector = new BoundedDiagCollector(); // Run test specific logic. Object result = run(); if (!diagCollector.hasErrors() && result != null) { // Output the result depending on its type. if (result instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) result; for (Map.Entry<String, Object> entry : map.entrySet()) { testOutput().printf("============== file: %s ==============%n", entry.getKey()); testOutput().println(displayValue(entry.getValue())); } } else { testOutput().println(displayValue(result)); } } }
@Test public void resolvesOkFromProtoc() { Model testApi = Model.create(descriptors); testApi.registerProcessor(new Resolver()); Truth.assertThat(testApi.establishStage(Resolved.KEY)).isTrue(); Truth.assertThat(testApi.getDiagReporter().getDiagCollector().hasErrors()).isFalse(); StageValidator.assertStages(ImmutableList.<Key<?>>of(Resolved.KEY), testApi); }
/** * Merges configurations from all the additionalConfigs and returns a normalized {@link Service} * instance. */ public static Service normalizeService( Service service, DiagCollector diagCollector, List<FileWrapper> additionalConfigs) { Model model = createModel(service, additionalConfigs); model.establishStage(Normalized.KEY); for (Diag diag : model.getDiagReporter().getDiagCollector().getDiags()) { diagCollector.addDiag(diag); } if (model.getDiagReporter().getDiagCollector().hasErrors()) { return null; } return model.getNormalizedConfig(); }
/** * Merges configurations from all the additionalConfigs and returns a normalized {@link Service} * instance. */ public static Service normalizeService( Service service, DiagCollector diagCollector, List<FileWrapper> additionalConfigs) { Model model = createModel(service, additionalConfigs); model.establishStage(Normalized.KEY); for (Diag diag : model.getDiagReporter().getDiagCollector().getDiags()) { diagCollector.addDiag(diag); } if (model.getDiagReporter().getDiagCollector().hasErrors()) { return null; } return model.getNormalizedConfig(); }
private void assertError(final String phrase) { Assert.assertTrue(model.getDiagReporter().getDiagCollector().hasErrors()); Assert.assertTrue( Iterators.any( model.getDiagReporter().getDiagCollector().getDiags().iterator(), new Predicate<Diag>() { @Override public boolean apply(Diag diag) { return diag.getKind() == Kind.ERROR && diag.toString().contains(phrase); } })); }
@Override protected Object run() throws Exception { if (suppressAllWarnings) { model.getDiagReporter().getDiagSuppressor().suppressAllWarningsUnder(model); } // Establish stage. model.establishStage(Normalized.KEY); if (model.getDiagReporter().getDiagCollector().hasErrors()) { return null; } Service service = model.getNormalizedConfig(); return toBaselineString(service); }
@BeforeClass public static void setupClass() { TestDataLocator locator = TestDataLocator.create(GoGapicSurfaceTransformerTest.class); model = CodegenTestUtil.readModel( locator, tempDir, new String[] {"myproto.proto", "singleservice.proto"}, new String[] {"myproto.yaml"}); for (Interface apiInterface : model.getSymbolTable().getInterfaces()) { if (apiInterface.getSimpleName().equals("Gopher")) { GoGapicSurfaceTransformerTest.apiInterface = apiInterface; break; } } ConfigProto configProto = CodegenTestUtil.readConfig( model.getDiagReporter().getDiagCollector(), locator, new String[] {"myproto_gapic.yaml"}); productConfig = GapicProductConfig.create(model, configProto, TargetLanguage.GO); if (model.getDiagReporter().getDiagCollector().hasErrors()) { throw new IllegalStateException( model.getDiagReporter().getDiagCollector().getDiags().toString()); } }
@Test public void resolvesOkWithPartialNames() { // Modify the descriptor. Protoc generates full names, and // we want to check whether we can also deal with partial names. FileDescriptorSet.Builder builder = descriptors.toBuilder(); builder .getFileBuilder(0) .getMessageTypeBuilder(0) .getFieldBuilder(1) // required N n .setTypeName("N"); Model testApi = Model.create(builder.build()); testApi.registerProcessor(new Resolver()); Truth.assertThat(testApi.establishStage(Resolved.KEY)).isTrue(); Truth.assertThat(testApi.getDiagReporter().getDiagCollector().hasErrors()).isFalse(); }
@Test public void missingConfigSchemaVersion() { TestDataLocator locator = TestDataLocator.create(GapicConfigProducerTest.class); locator.addTestDataSource(CodegenTestUtil.class, "testsrc/common"); locator.addTestDataSource(CodegenTestUtil.class, "testsrc/libraryproto"); model = CodegenTestUtil.readModel( locator, tempDir, new String[] {"myproto.proto"}, new String[] {"myproto.yaml"}); ConfigProto configProto = CodegenTestUtil.readConfig( model.getDiagReporter().getDiagCollector(), locator, new String[] {"missing_config_schema_version.yaml"}); productConfig = GapicProductConfig.create(model, configProto, null, null, TargetLanguage.JAVA); Diag expectedError = Diag.error( SimpleLocation.TOPLEVEL, "config_schema_version field is required in GAPIC yaml."); assertThat(model.getDiagReporter().getDiagCollector().hasErrors()).isTrue(); assertThat(model.getDiagReporter().getDiagCollector().getDiags()).contains(expectedError); } }