<commit_before>package org.folio.rest.tools;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.jsonschema2pojo.AnnotationStyle;
import org.raml.jaxrs.codegen.core.Configuration;
import org.raml.jaxrs.codegen.core.Configuration.JaxrsVersion;
import org.raml.jaxrs.codegen.core.GeneratorProxy;
import org.raml.jaxrs.codegen.core.ext.GeneratorExtension;

import org.folio.rest.tools.Raml2Java;

/**
 * @author shale
 *
 */
public class GenerateRunner {

  private static String outputDirectory = null;
  private static String inputDirectory = null;
  private static Configuration configuration = null;
  
  private static final String PACKAGE_DEFAULT = "org.folio.rest.jaxrs";
  private static final String SOURCES_DEFAULT = "/ramls/";
  private static final String RESOURCE_DEFAULT = "/target/classes";

  static final GeneratorProxy generator = new GeneratorProxy();

  public static void main(String args[]) throws Exception{
    
    List<GeneratorExtension> extensions = new ArrayList<>();
    extensions.add(new Raml2Java());
    
    String root = System.getProperties().getProperty("project.basedir");
    
    outputDirectory = root + "/src/main/java/";// + PACKAGE_DEFAULT.replace('.', '/');
    
    String outputDirectoryWithPackage = outputDirectory + PACKAGE_DEFAULT.replace('.', '/');
    
    if(new File(outputDirectoryWithPackage).exists()){
      FileUtils.cleanDirectory(new File(outputDirectoryWithPackage));
    }else{
      new File(outputDirectoryWithPackage).mkdirs();
    }
    
    //String inputDirectory = "C:\\Git\\raml\\circulation\\";
    //String outputDirectory = "C:\\tools\\raml\\raml";
    
    configuration = new Configuration();
    configuration.setJaxrsVersion(JaxrsVersion.JAXRS_2_0);
    configuration.setUseJsr303Annotations(true);
    configuration.setJsonMapper(AnnotationStyle.JACKSON2);
    configuration.setBasePackageName(PACKAGE_DEFAULT);
    configuration.setExtensions(extensions);

    //outputDirectory = System.getProperty("output_directory");
    
/*    if(outputDirectory == null){
      outputDirectory = System.getProperty("java.io.tmpdir");
    }
    
    if(inputDirectory == null){<commit_msg>dirty hack needed to remove old files after renaming<commit_after>package org.folio.rest.tools;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.jsonschema2pojo.AnnotationStyle;
import org.raml.jaxrs.codegen.core.Configuration;
import org.raml.jaxrs.codegen.core.Configuration.JaxrsVersion;
import org.raml.jaxrs.codegen.core.GeneratorProxy;
import org.raml.jaxrs.codegen.core.ext.GeneratorExtension;

import org.folio.rest.tools.Raml2Java;

/**
 * @author shale
 *
 */
public class GenerateRunner {

  private static String outputDirectory = null;
  private static String inputDirectory = null;
  private static Configuration configuration = null;
  
  private static final String PACKAGE_DEFAULT = "org.folio.rest.jaxrs";
  private static final String SOURCES_DEFAULT = "/ramls/";
  private static final String RESOURCE_DEFAULT = "/target/classes";

  static final GeneratorProxy generator = new GeneratorProxy();

  public static void main(String args[]) throws Exception{
    
    List<GeneratorExtension> extensions = new ArrayList<>();
    extensions.add(new Raml2Java());
    
    String root = System.getProperties().getProperty("project.basedir");
    
    outputDirectory = root + "/src/main/java/";// + PACKAGE_DEFAULT.replace('.', '/');
    
    String outputDirectoryWithPackage = outputDirectory + PACKAGE_DEFAULT.replace('.', '/');
    
    try{
      //this is a dirty hack needed when the project was refactored from com.folio to org.folio
      //the old wrong packaged dir is not deleted sine the package_default has changed - this
      //can be removed probably within a month - 9/7/2016
      String tempoutputDirectoryWithPackage = outputDirectory + PACKAGE_DEFAULT.replace('.', '/');
      FileUtils.cleanDirectory(new File(root+"/src/main/java/com/folio"));
    }
    catch(Exception e){}
    
    
    if(new File(outputDirectoryWithPackage).exists()){
      FileUtils.cleanDirectory(new File(outputDirectoryWithPackage));
    }else{
      new File(outputDirectoryWithPackage).mkdirs();
    }
    
    //String inputDirectory = "C:\\Git\\raml\\circulation\\";
    //String outputDirectory = "C:\\tools\\raml\\raml";
    
    configuration = new Configuration();
    configuration.setJaxrsVersion(JaxrsVersion.JAXRS_2_0);
    configuration.setUseJsr303Annotations(true);
    configuration.setJsonMapper(AnnotationStyle.JACKSON2);
    configuration.setBasePackageName(PACKAGE_DEFAULT);
    configuration.setExtensions(extensions);

    //outputDirectory = System.getProperty("output_directory");
    
/*    if(outputDirectory == null){
      outputDirectory = System.getProperty("java.io.tmpdir");
    }
    
    if(inputDirectory == null){
{'fraction_non_alphanumeric': 0.1159898970273946, 'fraction_numerical': 0.004662910433262095, 'mean_word_length': 4.137724550898204, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1569462', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1457, 'n_words': 303}