@Test public void testRailsGoatControllerParser() { File f = new File(RAILSGOAT_SOURCE_LOCATION); assert(f.exists()); assert(f.isDirectory()); railsControllers = (List<RailsController>) RailsControllerParser.parse(f); checkControllers(RAILSGOAT_CONTROLLERS); checkController("Users", RAILSGOAT_USERS_CONTROLLER); checkController("Messages",RAILSGOAT_MESSAGES_CONTROLLER); }
public static Collection parse(@Nonnull File rootFile) { if (!rootFile.exists() || !rootFile.isDirectory()) { LOG.error("Root file not found or is not directory. Exiting."); return null; } File ctrlDir = new File(rootFile,"app/controllers"); if (!ctrlDir.exists() || !ctrlDir.isDirectory()) { LOG.error("{rootFile}/app/controllers/ not found or is not directory. Exiting."); return null; } Collection<File> rubyFiles = (Collection<File>) FileUtils.listFiles(ctrlDir, new WildcardFileFilter("*_controller.rb"), TrueFileFilter.INSTANCE); RailsControllerParser parser = new RailsControllerParser(); parser.modelMap = RailsModelParser.parse(rootFile); parser.railsControllers = list(); for (File rubyFile : rubyFiles) { parser._continue = true; parser.tokenQueue = new ArrayDeque<String>(); parser.currentRailsController = null; parser.currentCtrlMethod = null; parser.currentParamName = null; EventBasedTokenizerRunner.runRails(rubyFile, parser); if (parser.currentRailsController != null && parser.currentCtrlMethod != null && parser.currentCtrlMethod.getMethodName() != null) { parser.currentRailsController.addControllerMethod(parser.currentCtrlMethod); } if (parser.currentRailsController != null && parser.currentRailsController.getControllerMethods() != null && parser.currentRailsController.getControllerMethods().size() > 0) { parser.currentRailsController.setControllerFile(rubyFile); parser.railsControllers.add(parser.currentRailsController); } } return parser.railsControllers; }
RailsControllerParser implements EventBasedTokenizer { public static Collection parse(@Nonnull File rootFile) { if (!rootFile.exists() || !rootFile.isDirectory()) { LOG.error("Root file not found or is not directory. Exiting."); return null; } File ctrlDir = new File(rootFile,"app/controllers"); if (!ctrlDir.exists() || !ctrlDir.isDirectory()) { LOG.error("{rootFile}/app/controllers/ not found or is not directory. Exiting."); return null; } Collection<File> rubyFiles = (Collection<File>) FileUtils.listFiles(ctrlDir, new WildcardFileFilter("*_controller.rb"), TrueFileFilter.INSTANCE); RailsControllerParser parser = new RailsControllerParser(); parser.modelMap = RailsModelParser.parse(rootFile); parser.railsControllers = list(); for (File rubyFile : rubyFiles) { parser._continue = true; parser.tokenQueue = new ArrayDeque<String>(); parser.currentRailsController = null; parser.currentCtrlMethod = null; parser.currentParamName = null; EventBasedTokenizerRunner.runRails(rubyFile, parser); if (parser.currentRailsController != null && parser.currentCtrlMethod != null && parser.currentCtrlMethod.getMethodName() != null) { parser.currentRailsController.addControllerMethod(parser.currentCtrlMethod); } if (parser.currentRailsController != null && parser.currentRailsController.getControllerMethods() != null && parser.currentRailsController.getControllerMethods().size() > 0) { parser.currentRailsController.setControllerFile(rubyFile); parser.railsControllers.add(parser.currentRailsController); } } return parser.railsControllers; } }
RailsControllerParser implements EventBasedTokenizer { public static Collection parse(@Nonnull File rootFile) { if (!rootFile.exists() || !rootFile.isDirectory()) { LOG.error("Root file not found or is not directory. Exiting."); return null; } File ctrlDir = new File(rootFile,"app/controllers"); if (!ctrlDir.exists() || !ctrlDir.isDirectory()) { LOG.error("{rootFile}/app/controllers/ not found or is not directory. Exiting."); return null; } Collection<File> rubyFiles = (Collection<File>) FileUtils.listFiles(ctrlDir, new WildcardFileFilter("*_controller.rb"), TrueFileFilter.INSTANCE); RailsControllerParser parser = new RailsControllerParser(); parser.modelMap = RailsModelParser.parse(rootFile); parser.railsControllers = list(); for (File rubyFile : rubyFiles) { parser._continue = true; parser.tokenQueue = new ArrayDeque<String>(); parser.currentRailsController = null; parser.currentCtrlMethod = null; parser.currentParamName = null; EventBasedTokenizerRunner.runRails(rubyFile, parser); if (parser.currentRailsController != null && parser.currentCtrlMethod != null && parser.currentCtrlMethod.getMethodName() != null) { parser.currentRailsController.addControllerMethod(parser.currentCtrlMethod); } if (parser.currentRailsController != null && parser.currentRailsController.getControllerMethods() != null && parser.currentRailsController.getControllerMethods().size() > 0) { parser.currentRailsController.setControllerFile(rubyFile); parser.railsControllers.add(parser.currentRailsController); } } return parser.railsControllers; }  }
RailsControllerParser implements EventBasedTokenizer { public static Collection parse(@Nonnull File rootFile) { if (!rootFile.exists() || !rootFile.isDirectory()) { LOG.error("Root file not found or is not directory. Exiting."); return null; } File ctrlDir = new File(rootFile,"app/controllers"); if (!ctrlDir.exists() || !ctrlDir.isDirectory()) { LOG.error("{rootFile}/app/controllers/ not found or is not directory. Exiting."); return null; } Collection<File> rubyFiles = (Collection<File>) FileUtils.listFiles(ctrlDir, new WildcardFileFilter("*_controller.rb"), TrueFileFilter.INSTANCE); RailsControllerParser parser = new RailsControllerParser(); parser.modelMap = RailsModelParser.parse(rootFile); parser.railsControllers = list(); for (File rubyFile : rubyFiles) { parser._continue = true; parser.tokenQueue = new ArrayDeque<String>(); parser.currentRailsController = null; parser.currentCtrlMethod = null; parser.currentParamName = null; EventBasedTokenizerRunner.runRails(rubyFile, parser); if (parser.currentRailsController != null && parser.currentCtrlMethod != null && parser.currentCtrlMethod.getMethodName() != null) { parser.currentRailsController.addControllerMethod(parser.currentCtrlMethod); } if (parser.currentRailsController != null && parser.currentRailsController.getControllerMethods() != null && parser.currentRailsController.getControllerMethods().size() > 0) { parser.currentRailsController.setControllerFile(rubyFile); parser.railsControllers.add(parser.currentRailsController); } } return parser.railsControllers; }  static Collection parse(@Nonnull File rootFile); @Override boolean shouldContinue(); @Override void processToken(int type, int lineNumber, String stringValue); }
RailsControllerParser implements EventBasedTokenizer { public static Collection parse(@Nonnull File rootFile) { if (!rootFile.exists() || !rootFile.isDirectory()) { LOG.error("Root file not found or is not directory. Exiting."); return null; } File ctrlDir = new File(rootFile,"app/controllers"); if (!ctrlDir.exists() || !ctrlDir.isDirectory()) { LOG.error("{rootFile}/app/controllers/ not found or is not directory. Exiting."); return null; } Collection<File> rubyFiles = (Collection<File>) FileUtils.listFiles(ctrlDir, new WildcardFileFilter("*_controller.rb"), TrueFileFilter.INSTANCE); RailsControllerParser parser = new RailsControllerParser(); parser.modelMap = RailsModelParser.parse(rootFile); parser.railsControllers = list(); for (File rubyFile : rubyFiles) { parser._continue = true; parser.tokenQueue = new ArrayDeque<String>(); parser.currentRailsController = null; parser.currentCtrlMethod = null; parser.currentParamName = null; EventBasedTokenizerRunner.runRails(rubyFile, parser); if (parser.currentRailsController != null && parser.currentCtrlMethod != null && parser.currentCtrlMethod.getMethodName() != null) { parser.currentRailsController.addControllerMethod(parser.currentCtrlMethod); } if (parser.currentRailsController != null && parser.currentRailsController.getControllerMethods() != null && parser.currentRailsController.getControllerMethods().size() > 0) { parser.currentRailsController.setControllerFile(rubyFile); parser.railsControllers.add(parser.currentRailsController); } } return parser.railsControllers; }  static Collection parse(@Nonnull File rootFile); @Override boolean shouldContinue(); @Override void processToken(int type, int lineNumber, String stringValue);  }