@Test public void testRailsGoatModelParser() { File f = new File(RAILSGOAT_SOURCE_LOCATION); assert(f.exists()); assert(f.isDirectory()); System.err.println("parsing "+f.getAbsolutePath() ); Map modelMap = RailsModelParser.parse(f); System.err.println( System.lineSeparator() + "Parse done." + System.lineSeparator()); compareModels(RAILSGOAT_MODELS, modelMap); }
public static Map parse(@Nonnull File rootFile) { if (!rootFile.exists() || !rootFile.isDirectory()) { LOG.error("Root file not found or is not directory. Exiting."); return null; } File modelDir = new File(rootFile,"app/models"); if (!modelDir.exists() || !modelDir.isDirectory()) { LOG.error("{rootFile}/app/models/ not found or is not directory. Exiting."); return null; } String[] rubyExtension = new String[] { "rb" }; Collection<File> rubyFiles = (Collection<File>) FileUtils.listFiles(modelDir, rubyExtension, true); RailsModelParser parser = new RailsModelParser(); for (File rubyFile : rubyFiles) { parser.modelName = ""; parser.modelAttributes = new ArrayList<String>(); EventBasedTokenizerRunner.runRails(rubyFile, parser); if (!parser.modelName.isEmpty()) { parser.models.put(parser.modelName, parser.modelAttributes); } } return parser.models; }
RailsModelParser implements EventBasedTokenizer { public static Map parse(@Nonnull File rootFile) { if (!rootFile.exists() || !rootFile.isDirectory()) { LOG.error("Root file not found or is not directory. Exiting."); return null; } File modelDir = new File(rootFile,"app/models"); if (!modelDir.exists() || !modelDir.isDirectory()) { LOG.error("{rootFile}/app/models/ not found or is not directory. Exiting."); return null; } String[] rubyExtension = new String[] { "rb" }; Collection<File> rubyFiles = (Collection<File>) FileUtils.listFiles(modelDir, rubyExtension, true); RailsModelParser parser = new RailsModelParser(); for (File rubyFile : rubyFiles) { parser.modelName = ""; parser.modelAttributes = new ArrayList<String>(); EventBasedTokenizerRunner.runRails(rubyFile, parser); if (!parser.modelName.isEmpty()) { parser.models.put(parser.modelName, parser.modelAttributes); } } return parser.models; } }
RailsModelParser implements EventBasedTokenizer { public static Map parse(@Nonnull File rootFile) { if (!rootFile.exists() || !rootFile.isDirectory()) { LOG.error("Root file not found or is not directory. Exiting."); return null; } File modelDir = new File(rootFile,"app/models"); if (!modelDir.exists() || !modelDir.isDirectory()) { LOG.error("{rootFile}/app/models/ not found or is not directory. Exiting."); return null; } String[] rubyExtension = new String[] { "rb" }; Collection<File> rubyFiles = (Collection<File>) FileUtils.listFiles(modelDir, rubyExtension, true); RailsModelParser parser = new RailsModelParser(); for (File rubyFile : rubyFiles) { parser.modelName = ""; parser.modelAttributes = new ArrayList<String>(); EventBasedTokenizerRunner.runRails(rubyFile, parser); if (!parser.modelName.isEmpty()) { parser.models.put(parser.modelName, parser.modelAttributes); } } return parser.models; }  }
RailsModelParser implements EventBasedTokenizer { public static Map parse(@Nonnull File rootFile) { if (!rootFile.exists() || !rootFile.isDirectory()) { LOG.error("Root file not found or is not directory. Exiting."); return null; } File modelDir = new File(rootFile,"app/models"); if (!modelDir.exists() || !modelDir.isDirectory()) { LOG.error("{rootFile}/app/models/ not found or is not directory. Exiting."); return null; } String[] rubyExtension = new String[] { "rb" }; Collection<File> rubyFiles = (Collection<File>) FileUtils.listFiles(modelDir, rubyExtension, true); RailsModelParser parser = new RailsModelParser(); for (File rubyFile : rubyFiles) { parser.modelName = ""; parser.modelAttributes = new ArrayList<String>(); EventBasedTokenizerRunner.runRails(rubyFile, parser); if (!parser.modelName.isEmpty()) { parser.models.put(parser.modelName, parser.modelAttributes); } } return parser.models; }  static Map parse(@Nonnull File rootFile); @Override boolean shouldContinue(); @Override void processToken(int type, int lineNumber, String stringValue); }
RailsModelParser implements EventBasedTokenizer { public static Map parse(@Nonnull File rootFile) { if (!rootFile.exists() || !rootFile.isDirectory()) { LOG.error("Root file not found or is not directory. Exiting."); return null; } File modelDir = new File(rootFile,"app/models"); if (!modelDir.exists() || !modelDir.isDirectory()) { LOG.error("{rootFile}/app/models/ not found or is not directory. Exiting."); return null; } String[] rubyExtension = new String[] { "rb" }; Collection<File> rubyFiles = (Collection<File>) FileUtils.listFiles(modelDir, rubyExtension, true); RailsModelParser parser = new RailsModelParser(); for (File rubyFile : rubyFiles) { parser.modelName = ""; parser.modelAttributes = new ArrayList<String>(); EventBasedTokenizerRunner.runRails(rubyFile, parser); if (!parser.modelName.isEmpty()) { parser.models.put(parser.modelName, parser.modelAttributes); } } return parser.models; }  static Map parse(@Nonnull File rootFile); @Override boolean shouldContinue(); @Override void processToken(int type, int lineNumber, String stringValue);  }