<commit_before>package org.batfish.job;

import java.io.File;
import java.util.concurrent.Callable;

import org.batfish.main.Batfish;
import org.batfish.main.BatfishException;
import org.batfish.main.BatfishLogger;
import org.batfish.main.ConfigurationFormat;
import org.batfish.main.ParserBatfishException;
import org.batfish.main.Settings;
import org.batfish.main.Warnings;

public class FlattenVendorConfigurationJob implements
      Callable<FlattenVendorConfigurationResult> {

   private String _fileText;

   private File _inputFile;

   private final BatfishLogger _logger;

   private File _outputFile;

   private Settings _settings;

   private Warnings _warnings;

   public FlattenVendorConfigurationJob(Settings settings, String fileText,
         File inputFile, File outputFile, Warnings warnings) {
      _settings = settings;
      _fileText = fileText;
      _inputFile = inputFile;
      _outputFile = outputFile;
      _warnings = warnings;
      _logger = new BatfishLogger(_settings.getLogLevel(),
            _settings.getTimestamp());
   }

   @Override
   public FlattenVendorConfigurationResult call() throws Exception {
      String inputFileAsString = _inputFile.getAbsolutePath();
      ConfigurationFormat format = Format
            .identifyConfigurationFormat(_fileText);

      if (format == ConfigurationFormat.JUNIPER) {
         _logger.debug("Flattening config: \"" + _inputFile.toString()
               + "\"...");
         String flatConfigText = null;
         try {
            flatConfigText = Batfish.flatten(_fileText, _logger, _settings);
         }
         catch (ParserBatfishException e) {
            String error = "Error parsing configuration file: \""
                  + inputFileAsString + "\"";
            return new FlattenVendorConfigurationResult(_logger.getHistory(),
                  new BatfishException(error, e));
         }
         catch (Exception e) {
            String error = "Error post-processing parse tree of configuration file: \""
                  + inputFileAsString + "\"";
            return new FlattenVendorConfigurationResult(_logger.getHistory(),
                  new BatfishException(error, e));
         }
         finally {
            for (String warning : _warnings.getRedFlagWarnings()) {
               _logger.redflag(warning);
            }
            for (String warning : _warnings.getUnimplementedWarnings()) {
               _logger.unimplemented(warning);
            }
            for (String warning : _warnings.getPedanticWarnings()) {
               _logger.pedantic(warning);
            }
         }
         return new FlattenVendorConfigurationResult(_logger.getHistory(),
               _outputFile, flatConfigText);
      }
      else {
         _logger.debug("Skipping: \"" + _inputFile.toString() + "\"\n");
         String flatConfigText = _fileText;
         return new FlattenVendorConfigurationResult(_logger.getHistory(),
               _outputFile, flatConfigText);
      }
   }

}<commit_msg>by default fail to flatten when configuration format is unknown<commit_after>package org.batfish.job;

import java.io.File;
import java.util.concurrent.Callable;

import org.batfish.main.Batfish;
import org.batfish.main.BatfishException;
import org.batfish.main.BatfishLogger;
import org.batfish.main.ConfigurationFormat;
import org.batfish.main.ParserBatfishException;
import org.batfish.main.Settings;
import org.batfish.main.Warnings;

public class FlattenVendorConfigurationJob implements
      Callable<FlattenVendorConfigurationResult> {

   private String _fileText;

   private File _inputFile;

   private final BatfishLogger _logger;

   private File _outputFile;

   private Settings _settings;

   private Warnings _warnings;

   public FlattenVendorConfigurationJob(Settings settings, String fileText,
         File inputFile, File outputFile, Warnings warnings) {
      _settings = settings;
      _fileText = fileText;
      _inputFile = inputFile;
      _outputFile = outputFile;
      _warnings = warnings;
      _logger = new BatfishLogger(_settings.getLogLevel(),
            _settings.getTimestamp());
   }

   @Override
   public FlattenVendorConfigurationResult call() throws Exception {
      String inputFileAsString = _inputFile.getAbsolutePath();
      ConfigurationFormat format = Format
            .identifyConfigurationFormat(_fileText);

      if (format == ConfigurationFormat.JUNIPER) {
         _logger.debug("Flattening config: \"" + _inputFile.toString()
               + "\"...");
         String flatConfigText = null;
         try {
            flatConfigText = Batfish.flatten(_fileText, _logger, _settings);
         }
         catch (ParserBatfishException e) {
            String error = "Error parsing configuration file: \""
                  + inputFileAsString + "\"";
            return new FlattenVendorConfigurationResult(_logger.getHistory(),
                  new BatfishException(error, e));
         }
         catch (Exception e) {
            String error = "Error post-processing parse tree of configuration file: \""
                  + inputFileAsString + "\"";
            return new FlattenVendorConfigurationResult(_logger.getHistory(),
                  new BatfishException(error, e));
         }
         finally {
            for (String warning : _warnings.getRedFlagWarnings()) {
               _logger.redflag(warning);
            }
            for (String warning : _warnings.getUnimplementedWarnings()) {
               _logger.unimplemented(warning);
            }
            for (String warning : _warnings.getPedanticWarnings()) {
               _logger.pedantic(warning);
            }
         }
         return new FlattenVendorConfigurationResult(_logger.getHistory(),
               _outputFile, flatConfigText);
      }
      else if (!_settings.ignoreUnsupported()
            && format == ConfigurationFormat.UNKNOWN) {
         return new FlattenVendorConfigurationResult(_logger.getHistory(),
               new BatfishException("Unknown configuration format for: \""
                     + _inputFile.toString() + "\""));
      }
      else {
         _logger.debug("Skipping: \"" + _inputFile.toString() + "\"\n");
         String flatConfigText = _fileText;
         return new FlattenVendorConfigurationResult(_logger.getHistory(),
               _outputFile, flatConfigText);
      }
   }

}
{'fraction_non_alphanumeric': 0.08876386935458666, 'fraction_numerical': 0.0, 'mean_word_length': 2.514552443712246, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5528936', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1620, 'n_words': 351}