// Path: gtfs-validator-json/src/main/java/com/conveyal/gtfs/validator/json/backends/FileSystemFeedBackend.java
// public class FileSystemFeedBackend implements FeedBackend {
// 	
// 	/**
// 	 * Get the feed at path feedId on the file system. This is trivial but allows for compatibility
// 	 * with more complicated backends.
// 	 * @param feedId The path the feed
// 	 * @return a file object referring to the feed
// 	 */
// 	public File getFeed(String feedId) {
// 		return new File(feedId);
// 	}
// }
// 
// Path: gtfs-validator-json/src/main/java/com/conveyal/gtfs/validator/json/serialization/JsonSerializer.java
// public class JsonSerializer extends Serializer {
// 	private ObjectMapper mapper;
// 	private ObjectWriter writer;
// 
// 	
// 	/**
// 	 * Create a JSON serializer for these validation results.
// 	 * @param results
// 	 */
// 	public JsonSerializer (FeedValidationResultSet results) {
// 		super(results);
// 		mapper = new ObjectMapper();
// 		mapper.addMixInAnnotations(Rectangle2D.class, Rectangle2DMixIn.class);
// 		SimpleModule deser = new SimpleModule();
// 		deser.addDeserializer(Rectangle2D.class, new Rectangle2DDeserializer());
// 		mapper.registerModule(deser);
// 		SimpleFilterProvider filters = new SimpleFilterProvider();
// 		filters.addFilter("bbox", SimpleBeanPropertyFilter.filterOutAllExcept("west", "east", "south", "north"));
// 		writer = mapper.writer(filters);
// 	}
// 	
// 	/**
// 	 * Serialize to JSON
// 	 * @return a string containing the serialized JSON
// 	 */
// 	public Object serialize() throws JsonProcessingException {
// 		return writer.writeValueAsString(results);
// 	}
// 
// 	/**
// 	 * Serialize to JSON and write to file.
// 	 * @param file the file to write the JSON to
// 	 */
// 	public void serializeToFile(File file) throws JsonGenerationException, JsonMappingException, IOException {
// 		writer.writeValue(file, results);
// 	}
// }


import java.io.File;
import java.io.IOException;
import com.conveyal.gtfs.validator.json.backends.FileSystemFeedBackend;
import com.conveyal.gtfs.validator.json.serialization.JsonSerializer;
package com.conveyal.gtfs.validator.json;



public class JsonValidatorMain {

    /**
     * Take an input GTFS and an output file and write JSON to that output file summarizing validation of the GTFS.
     * @param args
     */
    public static void main(String[] args) throws Exception {
        if (args.length < 2) {
            System.err.println("usage: java -Xmx[several]G input_gtfs.zip [other_gtfs.zip third_gtfs.zip . . .] output_file.json");
            return;
        }

        // We use a file system backend because we're not doing anything fancy, just reading local GTFS
        FileSystemFeedBackend backend = new FileSystemFeedBackend();
        
        // Since we're processing multiple feeds (potentially), use a FeedValidationResultSet to save the output
        FeedValidationResultSet results = new FeedValidationResultSet();
        
        // default name is directory name
        results.name = new File(args[0]).getAbsoluteFile().getParentFile().getName();
        
        // loop over all arguments except the last (which is the name of the JSON file)
        // TODO: throw all feeds in a queue and run as many threads as we have cores to do the validation
        // not exactly urgent, since for all of New York State this takes only a few minutes on my laptop
        for (int i = 0; i < args.length - 1; i++) {
            File input = backend.getFeed(args[i]);
            System.err.println("Processing feed " + input.getName());
            FeedProcessor processor = new FeedProcessor(input);
            try {
                processor.run();
            } catch (IOException e) {
                e.printStackTrace();
                System.err.println("Unable to access input GTFS " + input.getPath() + ". Does the file exist and do I have permission to read it?");
                return;
            }

            results.add(processor.getOutput());
        }
        
// Path: gtfs-validator-json/src/main/java/com/conveyal/gtfs/validator/json/backends/FileSystemFeedBackend.java
// public class FileSystemFeedBackend implements FeedBackend {
// 	
// 	/**
// 	 * Get the feed at path feedId on the file system. This is trivial but allows for compatibility
// 	 * with more complicated backends.
// 	 * @param feedId The path the feed
// 	 * @return a file object referring to the feed
// 	 */
// 	public File getFeed(String feedId) {
// 		return new File(feedId);
// 	}
// }
// 
// Path: gtfs-validator-json/src/main/java/com/conveyal/gtfs/validator/json/serialization/JsonSerializer.java
// public class JsonSerializer extends Serializer {
// 	private ObjectMapper mapper;
// 	private ObjectWriter writer;
// 
// 	
// 	/**
// 	 * Create a JSON serializer for these validation results.
// 	 * @param results
// 	 */
// 	public JsonSerializer (FeedValidationResultSet results) {
// 		super(results);
// 		mapper = new ObjectMapper();
// 		mapper.addMixInAnnotations(Rectangle2D.class, Rectangle2DMixIn.class);
// 		SimpleModule deser = new SimpleModule();
// 		deser.addDeserializer(Rectangle2D.class, new Rectangle2DDeserializer());
// 		mapper.registerModule(deser);
// 		SimpleFilterProvider filters = new SimpleFilterProvider();
// 		filters.addFilter("bbox", SimpleBeanPropertyFilter.filterOutAllExcept("west", "east", "south", "north"));
// 		writer = mapper.writer(filters);
// 	}
// 	
// 	/**
// 	 * Serialize to JSON
// 	 * @return a string containing the serialized JSON
// 	 */
// 	public Object serialize() throws JsonProcessingException {
// 		return writer.writeValueAsString(results);
// 	}
// 
// 	/**
// 	 * Serialize to JSON and write to file.
// 	 * @param file the file to write the JSON to
// 	 */
// 	public void serializeToFile(File file) throws JsonGenerationException, JsonMappingException, IOException {
// 		writer.writeValue(file, results);
// 	}
// }


// Path: gtfs-validator-json/src/main/java/com/conveyal/gtfs/validator/json/JsonValidatorMain.java
import java.io.File;
import java.io.IOException;
import com.conveyal.gtfs.validator.json.backends.FileSystemFeedBackend;
import com.conveyal.gtfs.validator.json.serialization.JsonSerializer;

package com.conveyal.gtfs.validator.json;



public class JsonValidatorMain {

    /**
     * Take an input GTFS and an output file and write JSON to that output file summarizing validation of the GTFS.
     * @param args
     */
    public static void main(String[] args) throws Exception {
        if (args.length < 2) {
            System.err.println("usage: java -Xmx[several]G input_gtfs.zip [other_gtfs.zip third_gtfs.zip . . .] output_file.json");
            return;
        }

        // We use a file system backend because we're not doing anything fancy, just reading local GTFS
        FileSystemFeedBackend backend = new FileSystemFeedBackend();
        
        // Since we're processing multiple feeds (potentially), use a FeedValidationResultSet to save the output
        FeedValidationResultSet results = new FeedValidationResultSet();
        
        // default name is directory name
        results.name = new File(args[0]).getAbsoluteFile().getParentFile().getName();
        
        // loop over all arguments except the last (which is the name of the JSON file)
        // TODO: throw all feeds in a queue and run as many threads as we have cores to do the validation
        // not exactly urgent, since for all of New York State this takes only a few minutes on my laptop
        for (int i = 0; i < args.length - 1; i++) {
            File input = backend.getFeed(args[i]);
            System.err.println("Processing feed " + input.getName());
            FeedProcessor processor = new FeedProcessor(input);
            try {
                processor.run();
            } catch (IOException e) {
                e.printStackTrace();
                System.err.println("Unable to access input GTFS " + input.getPath() + ". Does the file exist and do I have permission to read it?");
                return;
            }

            results.add(processor.getOutput());
        }
        
        JsonSerializer serializer = new JsonSerializer(results);