@Test public void testDetectFormatEmptyBeatsIgnored() { Settings settings = new Settings(); settings.setIgnoreFilesWithStrings(ImmutableList.of("\n")); assertThat( detectFormat("\n", settings, ConfigurationFormat.UNKNOWN), equalTo(ConfigurationFormat.EMPTY)); assertThat( detectFormat("\n\n\n", settings, ConfigurationFormat.UNKNOWN), equalTo(ConfigurationFormat.EMPTY)); }
@VisibleForTesting static ConfigurationFormat detectFormat( String fileText, Settings settings, ConfigurationFormat format) { Span span = GlobalTracer.get().buildSpan("Detecting file format").start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; if (WHITESPACE_ONLY.matcher(fileText).matches()) { return ConfigurationFormat.EMPTY; } if (settings.ignoreFilesWithStrings().stream().anyMatch(fileText::contains)) { return ConfigurationFormat.IGNORED; } if (format == ConfigurationFormat.UNKNOWN) { return VendorConfigurationFormatDetector.identifyConfigurationFormat(fileText); } return format; } finally { span.finish(); } }
ParseVendorConfigurationJob extends BatfishJob<ParseVendorConfigurationResult> { @VisibleForTesting static ConfigurationFormat detectFormat( String fileText, Settings settings, ConfigurationFormat format) { Span span = GlobalTracer.get().buildSpan("Detecting file format").start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; if (WHITESPACE_ONLY.matcher(fileText).matches()) { return ConfigurationFormat.EMPTY; } if (settings.ignoreFilesWithStrings().stream().anyMatch(fileText::contains)) { return ConfigurationFormat.IGNORED; } if (format == ConfigurationFormat.UNKNOWN) { return VendorConfigurationFormatDetector.identifyConfigurationFormat(fileText); } return format; } finally { span.finish(); } } }
ParseVendorConfigurationJob extends BatfishJob<ParseVendorConfigurationResult> { @VisibleForTesting static ConfigurationFormat detectFormat( String fileText, Settings settings, ConfigurationFormat format) { Span span = GlobalTracer.get().buildSpan("Detecting file format").start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; if (WHITESPACE_ONLY.matcher(fileText).matches()) { return ConfigurationFormat.EMPTY; } if (settings.ignoreFilesWithStrings().stream().anyMatch(fileText::contains)) { return ConfigurationFormat.IGNORED; } if (format == ConfigurationFormat.UNKNOWN) { return VendorConfigurationFormatDetector.identifyConfigurationFormat(fileText); } return format; } finally { span.finish(); } } ParseVendorConfigurationJob(
      Settings settings,
      NetworkSnapshot snapshot,
      String fileText,
      String filename,
      Warnings warnings,
      ConfigurationFormat expectedFormat,
      Multimap<String, String> duplicateHostnames,
      @Nullable SpanContext spanContext); }
ParseVendorConfigurationJob extends BatfishJob<ParseVendorConfigurationResult> { @VisibleForTesting static ConfigurationFormat detectFormat( String fileText, Settings settings, ConfigurationFormat format) { Span span = GlobalTracer.get().buildSpan("Detecting file format").start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; if (WHITESPACE_ONLY.matcher(fileText).matches()) { return ConfigurationFormat.EMPTY; } if (settings.ignoreFilesWithStrings().stream().anyMatch(fileText::contains)) { return ConfigurationFormat.IGNORED; } if (format == ConfigurationFormat.UNKNOWN) { return VendorConfigurationFormatDetector.identifyConfigurationFormat(fileText); } return format; } finally { span.finish(); } } ParseVendorConfigurationJob(
      Settings settings,
      NetworkSnapshot snapshot,
      String fileText,
      String filename,
      Warnings warnings,
      ConfigurationFormat expectedFormat,
      Multimap<String, String> duplicateHostnames,
      @Nullable SpanContext spanContext); @Nonnull ParseResult parse(); ParseVendorConfigurationResult fromResult(ParseResult result, long elapsed); @Override ParseVendorConfigurationResult call(); String getFilename(); String getFileText(); }
ParseVendorConfigurationJob extends BatfishJob<ParseVendorConfigurationResult> { @VisibleForTesting static ConfigurationFormat detectFormat( String fileText, Settings settings, ConfigurationFormat format) { Span span = GlobalTracer.get().buildSpan("Detecting file format").start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; if (WHITESPACE_ONLY.matcher(fileText).matches()) { return ConfigurationFormat.EMPTY; } if (settings.ignoreFilesWithStrings().stream().anyMatch(fileText::contains)) { return ConfigurationFormat.IGNORED; } if (format == ConfigurationFormat.UNKNOWN) { return VendorConfigurationFormatDetector.identifyConfigurationFormat(fileText); } return format; } finally { span.finish(); } } ParseVendorConfigurationJob(
      Settings settings,
      NetworkSnapshot snapshot,
      String fileText,
      String filename,
      Warnings warnings,
      ConfigurationFormat expectedFormat,
      Multimap<String, String> duplicateHostnames,
      @Nullable SpanContext spanContext); @Nonnull ParseResult parse(); ParseVendorConfigurationResult fromResult(ParseResult result, long elapsed); @Override ParseVendorConfigurationResult call(); String getFilename(); String getFileText();  }