Author: xavier
Date: Sat Oct 27 07:32:24 2007
New Revision: 589116

URL: http://svn.apache.org/viewvc?rev=589116&view=rev
Log:
IMPROVEMENT: Adding option 'cp', which makes it possible for main to be loaded 
from file (IVY-543) (thanks to Tjeerd Verhagen)

Modified:
    incubator/ivy/core/trunk/CHANGES.txt
    incubator/ivy/core/trunk/src/java/org/apache/ivy/Main.java

Modified: incubator/ivy/core/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/CHANGES.txt?rev=589116&r1=589115&r2=589116&view=diff
==============================================================================
--- incubator/ivy/core/trunk/CHANGES.txt (original)
+++ incubator/ivy/core/trunk/CHANGES.txt Sat Oct 27 07:32:24 2007
@@ -65,6 +65,7 @@
 - FIX: Resolving dynamic version fails when using multiple patterns if only 
one pattern find a revision and others don't (IVY-602)
 - FIX: Invalid character in IvyRetrieveTest causing most tests to fail 
(IVY-604)
 
+- IMPROVEMENT: Adding option 'cp', which makes it possible for main to be 
loaded from file (IVY-543) (thanks to Tjeerd Verhagen)
 - IMPROVEMENT: BasicURLHandler should use method=head for getURLInfo (IVY-611) 
(thanks to Jim Bonanno)
 - IMPROVEMENT: artifactproperty should not overwrite the existing properties 
(IVY-587)
 - IMPROVEMENT: Support *(private) and *(public) in the confs parameter of the 
resolve (IVY-588)

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/Main.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/Main.java?rev=589116&r1=589115&r2=589116&view=diff
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/Main.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/Main.java Sat Oct 27 
07:32:24 2007
@@ -23,6 +23,7 @@
 import java.io.PrintWriter;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
@@ -32,6 +33,7 @@
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.StringTokenizer;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
@@ -120,6 +122,8 @@
             "the main class to runtime process").create("main");
         Option args = 
OptionBuilder.withArgName("args").hasArgs().withDescription(
             "the arguments to runtime process").create("args");
+        Option cp = OptionBuilder.withArgName("cp").hasArg().withDescription(
+            "extra classpath, used only in combination with option 
main").create("cp");
 
         Options options = new Options();
 
@@ -152,6 +156,7 @@
         options.addOption(passwd);
         options.addOption(main);
         options.addOption(args);
+        options.addOption(cp);
 
         return options;
     }
@@ -265,6 +270,9 @@
                 }
             }
             if (line.hasOption("main")) {
+                // check if the option cp has been set
+                List fileList = getExtraClasspathFileList(line);
+
                 // merge -args and left over args
                 String[] fargs = line.getOptionValues("args");
                 if (fargs == null) {
@@ -278,7 +286,7 @@
                 System.arraycopy(fargs, 0, params, 0, fargs.length);
                 System.arraycopy(extra, 0, params, fargs.length, extra.length);
                 // invoke with given main class and merged params
-                invoke(ivy, cache, md, confs, line.getOptionValue("main"), 
params);
+                invoke(ivy, cache, md, confs, fileList, 
line.getOptionValue("main"), params);
             }
         } catch (ParseException exp) {
             // oops, something went wrong
@@ -288,6 +296,28 @@
         }
     }
 
+    private static List getExtraClasspathFileList(CommandLine line) {
+        List fileList = null;
+        if (line.hasOption("cp")) {
+            fileList = new ArrayList();
+            String[] cpArray = line.getOptionValues("cp");
+            for (int index = 0; index < cpArray.length; index++) {
+                StringTokenizer tokenizer = new 
StringTokenizer(cpArray[index], 
+                    System.getProperty("path.separator"));
+                while (tokenizer.hasMoreTokens()) {
+                    String token = tokenizer.nextToken();
+                    File file = new File(token);
+                    if (file.exists()) {
+                        fileList.add(file);
+                    } else {
+                        Message.warn("The extra classpath '" + file + "' does 
not exist.");
+                    }
+                }
+            }
+        }
+        return fileList;
+    }
+
     private static IvySettings initSettings(CommandLine line, Options options, 
Ivy ivy) 
             throws java.text.ParseException, IOException {
         IvySettings settings = ivy.getSettings();
@@ -370,9 +400,21 @@
     }
 
     private static void invoke(Ivy ivy, File cache, ModuleDescriptor md, 
String[] confs,
-            String mainclass, String[] args) {
+            List fileList, String mainclass, String[] args) {
         List urls = new ArrayList();
 
+        // Add option cp (extra classpath) urls
+        if (fileList != null && fileList.size() > 0) {
+            for (Iterator iter = fileList.iterator(); iter.hasNext();) {
+                File file = (File) iter.next();
+                try {
+                    urls.add(file.toURL());
+                } catch (MalformedURLException e) {
+                    // Should not happen, just ignore.
+                } 
+            }
+        }
+        
         try {
             Collection all = new LinkedHashSet();
             CacheManager cacheMgr = ivy.getCacheManager(cache);


Reply via email to