public void appendAllDiags(DiagCollector diagCollector) { diags.addAll(diagCollector.getDiags()); errorCount += diagCollector.getErrorCount(); }
/** Check if there are any errors. */ public boolean hasErrors() { return getDiagCollector().hasErrors(); }
/** * 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(); }
@Nullable public static ConfigSource read( DiagCollector collector, List<File> files, Map<String, Message> supportedConfigTypes) { List<String> inputNames = new ArrayList<>(); List<String> inputs = new ArrayList<>(); for (File file : files) { inputNames.add(file.getName()); try { String fileContent = Files.toString(file, Charset.forName("UTF8")); inputs.add(fileContent); } catch (IOException e) { collector.addDiag( Diag.error( SimpleLocation.TOPLEVEL, "Cannot read configuration file '%s': %s", file.getName(), e.getMessage())); } } if (collector.getErrorCount() > 0) { return null; } else { return read(collector, inputNames, inputs, supportedConfigTypes); } } }
/** Sets up the model configs, reading them from Yaml files and attaching to the model. */ public static List<FileWrapper> readModelConfigs( String dataPath, List<String> configs, DiagCollector diagCollector) { List<FileWrapper> files = Lists.newArrayList(); for (String filename : configs) { File file = findDataFile(filename, dataPath); if (file == null) { diagCollector.addDiag( Diag.error(SimpleLocation.TOPLEVEL, "Cannot find configuration file '%s'.", filename)); } else { try { files.add(FileWrapper.from(filename)); } catch (IOException ex) { diagCollector.addDiag( Diag.error( SimpleLocation.TOPLEVEL, "Cannot read input file '%s': %s", filename, ex.getMessage())); } } } if (diagCollector.hasErrors()) { return null; } return files; }
public int getErrorCount() { return diag.getErrorCount(); }
/** Report errors and warnings. */ public static void reportDiags(DiagCollector diagCollector, boolean colored) { for (Diag diag : diagCollector.getDiags()) { System.err.println(diagToString(diag, colored)); } }
private void addError(String message, Object... params) { diagCollector.addDiag( Diag.error(location, "In path template '" + template + "': " + message, params)); hadErrors = true; } }
@Override public int getErrorCount() { return model.getDiagReporter().getDiagCollector().getErrorCount(); }
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); } })); }
/** Report errors and warnings. */ public static void reportDiags(DiagCollector diagCollector, boolean colored) { for (Diag diag : diagCollector.getDiags()) { System.err.println(diagToString(diag, colored)); } }
private void addError(String message, Object... params) { diagCollector.addDiag( Diag.error(location, "In path template '" + template + "': " + message, params)); hadErrors = true; } }
/** Sets up the model configs, reading them from Yaml files and attaching to the model. */ public static List<FileWrapper> readModelConfigs( String dataPath, List<String> configs, DiagCollector diagCollector) { List<FileWrapper> files = Lists.newArrayList(); for (String filename : configs) { File file = findDataFile(filename, dataPath); if (file == null) { diagCollector.addDiag( Diag.error(SimpleLocation.TOPLEVEL, "Cannot find configuration file '%s'.", filename)); } else { try { files.add(FileWrapper.from(filename)); } catch (IOException ex) { diagCollector.addDiag( Diag.error( SimpleLocation.TOPLEVEL, "Cannot read input file '%s': %s", filename, ex.getMessage())); } } } if (diagCollector.hasErrors()) { return null; } return files; }
@Nullable private static ImmutableMap<String, ImmutableList<String>> createRetryCodesDefinitionFromConfigProto( DiagCollector diagCollector, InterfaceConfigProto interfaceConfigProto) { ImmutableMap.Builder<String, ImmutableList<String>> builder = ImmutableMap.builder(); for (RetryCodesDefinitionProto retryDef : interfaceConfigProto.getRetryCodesDefList()) { // Enforce ordering on set for baseline test consistency. Set<String> codes = new TreeSet<>(); for (String codeText : retryDef.getRetryCodesList()) { try { codes.add(String.valueOf(codeText)); } catch (IllegalArgumentException e) { diagCollector.addDiag( Diag.error( SimpleLocation.TOPLEVEL, "status code not found: '%s' (in interface %s)", codeText, interfaceConfigProto.getName())); } } builder.put(retryDef.getName(), ImmutableList.copyOf(codes)); } if (diagCollector.getErrorCount() > 0) { return null; } return builder.build(); }
public void appendAllDiags(DiagCollector diagCollector) { diags.addAll(diagCollector.getDiags()); errorCount += diagCollector.getErrorCount(); }
@Override public int getErrorCount() { return model.getDiagReporter().getDiagCollector().getErrorCount(); }
@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()); } }
/** Check if there are any errors. */ public boolean hasErrors() { return getDiagCollector().hasErrors(); }
/** * 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(); }