public void loadDiffableReaders() { List<Class<? extends DiffableReader>> drClasses = new PluginManager<DiffableReader>(DiffableReader.class).getPlugins(); logger.info("Loading diffable modules:"); for (Class<? extends DiffableReader> drClass : drClasses) { logger.info("\t" + drClass.getSimpleName()); try { DiffableReader dr = drClass.newInstance(); readers.put(dr.getName(), dr); } catch (InstantiationException e) { throw new ReviewedStingException( "Unable to instantiate module '" + drClass.getSimpleName() + "'"); } catch (IllegalAccessException e) { throw new ReviewedStingException( "Illegal access error when trying to instantiate '" + drClass.getSimpleName() + "'"); } } }
public DiffElement createDiffableFromFile(File file, int maxElementsToRead) { DiffableReader reader = findReaderForFile(file); if (reader == null) throw new UserException("Unsupported file type: " + file); else return reader.readFromFile(file, maxElementsToRead); }
/** * Returns a reader appropriate for this file, or null if no such reader exists * * @param file * @return */ public DiffableReader findReaderForFile(File file) { for (DiffableReader reader : readers.values()) if (reader.canRead(file)) return reader; return null; }