[jboss-cvs] JBossAS SVN: r102181 - projects/jboss-jca/trunk/validator/src/main/java/org/jboss/jca/validator.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 9 22:10:22 EST 2010


Author: jeff.zhang
Date: 2010-03-09 22:10:22 -0500 (Tue, 09 Mar 2010)
New Revision: 102181

Modified:
   projects/jboss-jca/trunk/validator/src/main/java/org/jboss/jca/validator/Main.java
Log:
[JBJCA-297] add -classpath flag to validator tool

Modified: projects/jboss-jca/trunk/validator/src/main/java/org/jboss/jca/validator/Main.java
===================================================================
--- projects/jboss-jca/trunk/validator/src/main/java/org/jboss/jca/validator/Main.java	2010-03-10 02:59:19 UTC (rev 102180)
+++ projects/jboss-jca/trunk/validator/src/main/java/org/jboss/jca/validator/Main.java	2010-03-10 03:10:22 UTC (rev 102181)
@@ -62,7 +62,7 @@
    private static final int SUCCESS = 0;
    private static final int FAIL = 1;
    private static final int OTHER = 2;
-   
+
    /**
     * validate
     * @param url The url
@@ -71,6 +71,18 @@
     */
    public static int validate(URL url, String output)
    {
+      return validate(url, output, null);
+   }
+
+   /**
+    * validate
+    * @param url The url
+    * @param output directory of output
+    * @param classpath classpath of including
+    * @return The system exit code
+    */
+   public static int validate(URL url, String output, String[] classpath)
+   {
       if (url == null || !(url.toExternalForm().endsWith(".rar") || url.toExternalForm().endsWith(".rar/")))
          return FAIL;
 
@@ -97,8 +109,25 @@
          }
       
          // Create classloader
+         URL[] allurls;
          URL[] urls = getUrls(root);
-         URLClassLoader cl = SecurityActions.createURLCLassLoader(urls, SecurityActions.getThreadContextClassLoader());
+         if (classpath != null && classpath.length > 0)
+         {
+            List<URL> listUrl = new ArrayList<URL>();
+            for (URL u : urls)
+               listUrl.add(u);
+            for (String jar : classpath)
+            {
+               if (jar.endsWith(".jar"))
+                  listUrl.add(new File(jar).toURI().toURL());
+            }
+            allurls = listUrl.toArray(new URL[listUrl.size()]);
+         }
+         else
+            allurls = urls;
+                  
+         URLClassLoader cl = SecurityActions.createURLCLassLoader(allurls, 
+            SecurityActions.getThreadContextClassLoader());
          SecurityActions.setThreadContextClassLoader(cl);
 
          // Parse metadata
@@ -382,6 +411,7 @@
       boolean quite = false;
       String outputDir = "."; //put report into current directory by default
       int arg = 0;
+      String[] classpath = null;
       
       if (args.length > 0)
       {
@@ -403,6 +433,12 @@
                   }
                   outputDir = args[arg];
                }
+               else if (args[arg].endsWith("classpath"))
+               {
+                  arg++;
+                  classpath = args[arg].split(System.getProperty("path.separator"));
+
+               }
             }
             else
             {
@@ -414,7 +450,7 @@
 
          try
          {
-            int systemExitCode = validate(new File(args[arg]).toURI().toURL(), outputDir);
+            int systemExitCode = validate(new File(args[arg]).toURI().toURL(), outputDir, classpath);
             
             if (!quite && systemExitCode == FAIL)
             {
@@ -422,6 +458,11 @@
             }
             System.exit(systemExitCode);
          }
+         catch (ArrayIndexOutOfBoundsException oe)
+         {
+            usage();
+            System.exit(OTHER);
+         }
          catch (MalformedURLException e)
          {
             e.printStackTrace();
@@ -440,7 +481,7 @@
     */
    private static void usage()
    {
-      System.out.println("Usage: validator [-quite] [-output directory] <file>");
+      System.out.println("Usage: validator [-quite] [-output directory] [-classpath thirdparty.jar] <file>");
    }
 
 




More information about the jboss-cvs-commits mailing list