<commit_before>/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2010, Red Hat Middleware LLC, and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.jca.codegenerator;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Set;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;


/**
 * Code generator main class
 * 
 * @author <NAME>
 * @version $Revision: $
 */
public class Main
{
   private static final int SUCCESS = 0;
   private static final int ERROR = 1;
   private static final int OTHER = 2;

   /** ResourceBundle */
   private static ResourceBundle rb = ResourceBundle.getBundle("codegenerator", Locale.getDefault());
   
   /**
    * Code generator stand alone tool
    * 
    * @param args command line arguments
    */
   public static void main(String[] args)
   {
      String outputDir = "out"; //default output directory
      String defxml = null;
      int arg = 0;

      if (args.length > 0)
      {
         while (args.length > arg + 1)
         {
            if (args[arg].startsWith("-"))
            {
               if (args[arg].equals("-o"))
               {
                  arg++;
                  if (arg >= args.length)
                  {
                     usage();
                     System.exit(OTHER);
                  }
                  outputDir = args[arg];
               }
               else if (args[arg].equals("-f"))
               {
                  arg++;
                  if (arg >= args.length)
                  {
                     usage();
                     System.exit(OTHER);
                  }
                  defxml = args[arg];
               }
            } 
            else
            {
               usage();
               System.exit(OTHER);
            }
            arg++;
         }
      }
      try 
      {
         File out = new File(outputDir);
         Utils.recursiveDelete(out);

         Definition def = null;
         
         if (defxml == null)
            def = inputFromCommandLine();
         else
            def = inputFromXml(defxml);
         
         if (def == null)
            System.exit(ERROR);
         
         def.setOutputDir(outputDir);

         Profile profile;
         if (def.getVersion().equals("1.7"))
         {
            profile = new JCA17Profile();
         }
         else if (def.getVersion().equals("1.6"))
         {
            profile = new JCA16Profile();
         }
         else if (def.getVersion().equals("1.5"))
         {
            profile = new JCA15Profile();
         }
         else
         {
            profile = new JCA10Profile();
         }
         profile.generate(def);
         
         if (def.getBuild().equals("ant"))
            copyAllJars(outputDir);
         
         System.out.println(rb.getString("code.wrote"));
         System.exit(SUCCESS);
      }
      catch (IOException e)
      {
         e.printStackTrace();
      }
      catch (JAXBException e)
      {
         e.printStackTrace();
      }
   }
   
   /**
    * input from xml file
    * 
    * @param defxml definition xml file
    * @throws IOException ioException
    * @throws JAXBException jaxb exception
    * @return Definition definition from input
    */
   private static Definition inputFromXml(String defxml) throws IOException, JAXBException
   {
      JAXBContext context = JAXBContext.newInstance("org.jboss.jca.codegenerator");
      Unmarshaller unmarshaller = context.createUnmarshaller();
      Definition def = (Definition)unmarshaller.unmarshal(new File(defxml));
      //System.out.println(def.getVersion());

      return def;
   }

   /**
    * input from command line 
    * 
    * @throws IOException ioException
    * @return Definition definition from input
    */
   private static Definition inputFromCommandLine() throws IOException
   {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      Definition def = new Definition();
      Set<String> classes = new HashSet<String>();
      
      //profile version
      String version = null;
      do
      {
         System.out.print(rb.getString("profile.version") + " " + 
            rb.getString("profile.version.values") + " [1.7]: ");
         version = in.readLine();
         if (version == null || version.equals(""))
            version = "1.7";
      }
      while (!version.equals("1.7") || (version.equals("1.6") || version.equals("1.5") || version.equals("1.0")));
      
      def.setVersion(version);
      
      //by default, support outbound, but not inbound
      def.setSupportOutbound(true);
      def.setSupportInbound(false);<commit_msg>[JBJCA-1016] fix bug about wrong '(' logic<commit_after>/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2010, Red Hat Middleware LLC, and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.jca.codegenerator;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Set;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;


/**
 * Code generator main class
 * 
 * @author <NAME>
 * @version $Revision: $
 */
public class Main
{
   private static final int SUCCESS = 0;
   private static final int ERROR = 1;
   private static final int OTHER = 2;

   /** ResourceBundle */
   private static ResourceBundle rb = ResourceBundle.getBundle("codegenerator", Locale.getDefault());
   
   /**
    * Code generator stand alone tool
    * 
    * @param args command line arguments
    */
   public static void main(String[] args)
   {
      String outputDir = "out"; //default output directory
      String defxml = null;
      int arg = 0;

      if (args.length > 0)
      {
         while (args.length > arg + 1)
         {
            if (args[arg].startsWith("-"))
            {
               if (args[arg].equals("-o"))
               {
                  arg++;
                  if (arg >= args.length)
                  {
                     usage();
                     System.exit(OTHER);
                  }
                  outputDir = args[arg];
               }
               else if (args[arg].equals("-f"))
               {
                  arg++;
                  if (arg >= args.length)
                  {
                     usage();
                     System.exit(OTHER);
                  }
                  defxml = args[arg];
               }
            } 
            else
            {
               usage();
               System.exit(OTHER);
            }
            arg++;
         }
      }
      try 
      {
         File out = new File(outputDir);
         Utils.recursiveDelete(out);

         Definition def = null;
         
         if (defxml == null)
            def = inputFromCommandLine();
         else
            def = inputFromXml(defxml);
         
         if (def == null)
            System.exit(ERROR);
         
         def.setOutputDir(outputDir);

         Profile profile;
         if (def.getVersion().equals("1.7"))
         {
            profile = new JCA17Profile();
         }
         else if (def.getVersion().equals("1.6"))
         {
            profile = new JCA16Profile();
         }
         else if (def.getVersion().equals("1.5"))
         {
            profile = new JCA15Profile();
         }
         else
         {
            profile = new JCA10Profile();
         }
         profile.generate(def);
         
         if (def.getBuild().equals("ant"))
            copyAllJars(outputDir);
         
         System.out.println(rb.getString("code.wrote"));
         System.exit(SUCCESS);
      }
      catch (IOException e)
      {
         e.printStackTrace();
      }
      catch (JAXBException e)
      {
         e.printStackTrace();
      }
   }
   
   /**
    * input from xml file
    * 
    * @param defxml definition xml file
    * @throws IOException ioException
    * @throws JAXBException jaxb exception
    * @return Definition definition from input
    */
   private static Definition inputFromXml(String defxml) throws IOException, JAXBException
   {
      JAXBContext context = JAXBContext.newInstance("org.jboss.jca.codegenerator");
      Unmarshaller unmarshaller = context.createUnmarshaller();
      Definition def = (Definition)unmarshaller.unmarshal(new File(defxml));
      //System.out.println(def.getVersion());

      return def;
   }

   /**
    * input from command line 
    * 
    * @throws IOException ioException
    * @return Definition definition from input
    */
   private static Definition inputFromCommandLine() throws IOException
   {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      Definition def = new Definition();
      Set<String> classes = new HashSet<String>();
      
      //profile version
      String version = null;
      do
      {
         System.out.print(rb.getString("profile.version") + " " + 
            rb.getString("profile.version.values") + " [1.7]: ");
         version = in.readLine();
         if (version == null || version.equals(""))
            version = "1.7";
      }
      while (!(version.equals("1.7") || version.equals("1.6") || version.equals("1.5") || version.equals("1.0")));
      
      def.setVersion(version);
      
      //by default, support outbound, but not inbound
      def.setSupportOutbound(true);
      def.setSupportInbound(false);
{'fraction_non_alphanumeric': 0.10611402528162353, 'fraction_numerical': 0.008771175509502106, 'mean_word_length': 1.871604938271605, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 24}, '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': '3522442', 'n_tokens_mistral': 3167, 'n_tokens_neox': 3059, 'n_words': 896}