Example #1
0
 public static void main(final String... args) throws Throwable {
   new Thread(
           new Runnable() {
             public void run() {
               do {
                 try {
                   char c = (char) System.in.read();
                   if (Character.toUpperCase(c)
                       == Character.toUpperCase(ApplicationSettings.getExitChar())) {
                     FileMonitorFactory.closeAll();
                     System.exit(0);
                   }
                 } catch (IOException e) {
                   throw new RuntimeException(e);
                 }
               } while (true);
             }
           })
       .start();
   Map<ArgumentType, CommandLineArgument> argsMap = new CommandLineArgumentBuilder(args);
   if (argsMap.containsKey(ArgumentType.RUN_KOANS)) {
     FileMonitorFactory.getInstance(
             new File(DirectoryManager.getProdMainDir()), new File(DirectoryManager.getDataFile()))
         .addFileSavedListener(new KoanFileCompileAndRunListener(argsMap));
   }
   new CommandLineArgumentRunner(argsMap).run();
   if (ApplicationSettings.isDebug()) {
     StringBuilder argsBuilder = new StringBuilder();
     int argNumber = 0;
     for (String arg : args) {
       argsBuilder.append("Argument number " + String.valueOf(++argNumber) + ": '" + arg + "'");
     }
     ApplicationUtils.getPresenter().displayMessage(argsBuilder.toString());
   }
 }
 static XmlToPathTransformer getXmlToPathTransformer() {
   if (xmlToPathTransformer == null) {
     try {
       String filename =
           DirectoryManager.injectFileSystemSeparators(
               DirectoryManager.getConfigDir(), ApplicationSettings.getPathXmlFileName());
       File file = new File(filename);
       if (!file.exists()) {
         throw new RuntimeException("No " + filename + " was found at: " + file.getAbsolutePath());
       }
       xmlToPathTransformer = new XmlToPathTransformerImpl(filename, suiteName, koanMethod);
     } catch (FileNotFoundException e) {
       throw new RuntimeException(e);
     }
   }
   return xmlToPathTransformer;
 }
 private int countKoanAnnotationsInJavaFileGivenClassName(String className) {
   String[] lines =
       FileCompiler.getContentsOfJavaFile(DirectoryManager.getSourceDir(), className)
           .split(KoanConstants.EOLS);
   String koanClassSimpleNameWithAnnotationPrefix = '@' + Koan.class.getSimpleName();
   int total = 0;
   for (String line : lines) {
     String trimmedLine = line.trim();
     if (trimmedLine.contains(koanClassSimpleNameWithAnnotationPrefix)
         && !trimmedLine.startsWith("//")
         && !trimmedLine.startsWith("*")
         && !trimmedLine.startsWith("/*")) {
       total++;
     }
   }
   return total;
 }