geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject cvs commit: incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/cli Main.java
Date Mon, 25 Aug 2003 16:07:45 GMT
jdillon     2003/08/25 09:07:45

  Modified:    modules/twiddle/src/java/org/apache/geronimo/twiddle
                        Twiddle.java
               modules/twiddle/src/java/org/apache/geronimo/twiddle/cli
                        Main.java
  Log:
   o Moved home dir and URL accessors to Twiddle
  
  Revision  Changes    Path
  1.9       +51 -1     incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/Twiddle.java
  
  Index: Twiddle.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/Twiddle.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Twiddle.java	25 Aug 2003 15:49:13 -0000	1.8
  +++ Twiddle.java	25 Aug 2003 16:07:45 -0000	1.9
  @@ -57,7 +57,11 @@
   package org.apache.geronimo.twiddle;
   
   import java.net.URL;
  +import java.net.URLDecoder;
  +import java.net.MalformedURLException;
   
  +import java.io.File;
  +import java.io.IOException;
   import java.io.StringWriter;
   import java.io.PrintWriter;
   
  @@ -89,6 +93,8 @@
    */
   public class Twiddle
   {
  +    public static final String TWIDDLE_HOME = "twiddle.home";
  +    
       private static final Log log = LogFactory.getLog(Twiddle.class);
       
       /** The input/output context. */
  @@ -230,5 +236,49 @@
           out.flush();
           
           return writer.toString();
  +    }
  +    
  +    /**
  +     * Get the <em>Twiddle</em> home directory
  +     *
  +     * @return The <em>Twiddle</em> home directory
  +     *
  +     * @throws RuntimeException     Unable to determine home dir.
  +     */
  +    public static File getHomeDir()
  +    {
  +        // Determine what our home directory is
  +        String temp = System.getProperty(TWIDDLE_HOME);
  +        if (temp == null) {
  +            String path = Twiddle.class.getProtectionDomain().getCodeSource().getLocation().getFile();
  +            try {
  +                path = URLDecoder.decode(path, "UTF-8");
  +                //
  +                // jason: home dir is expected to be lib/..
  +                //
  +                temp = new File(path).getParentFile().getParentFile().getCanonicalPath();
  +            }
  +            catch (IOException e) {
  +                throw new RuntimeException("Unable to determine home dir", e);
  +            }
  +        }
  +        return new File(temp);
  +    }
  +    
  +    /**
  +     * Get the <em>Twiddle</em> home URL
  +     *
  +     * @return The <em>Twiddle</em> home URL
  +     *
  +     * @throws RuntimeException     Unable to determine home URL.
  +     */
  +    public static URL getHomeURL()
  +    {
  +        try {
  +            return getHomeDir().toURL();
  +        }
  +        catch (MalformedURLException e) {
  +            throw new RuntimeException("Unable to determine home URL", e);
  +        }
       }
   }
  
  
  
  1.10      +2 -13     incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/cli/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/cli/Main.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Main.java	25 Aug 2003 15:49:13 -0000	1.9
  +++ Main.java	25 Aug 2003 16:07:45 -0000	1.10
  @@ -56,12 +56,10 @@
   
   package org.apache.geronimo.twiddle.cli;
   
  -import java.io.File;
   import java.io.PrintWriter;
   import java.io.OutputStreamWriter;
   
   import java.net.URL;
  -import java.net.URLDecoder;
   
   import com.werken.classworlds.ClassWorld;
   
  @@ -189,19 +187,10 @@
           // Process command-line options
           args = processCommandLine(args);
           
  -        // Determine what our home directory is
  -        String temp = System.getProperty("twiddle.home");
  -        if (temp == null) {
  -            String path = Main.class.getProtectionDomain().getCodeSource().getLocation().getFile();
  -            path = URLDecoder.decode(path, "UTF-8");
  -            temp = new File(path).getParentFile().getParentFile().getCanonicalPath();
  -        }
  -        File homeDir = new File(temp);
  -        URL homeURL = homeDir.toURL();
  +        URL homeURL = Twiddle.getHomeURL();
           URL configURL = new URL(homeURL, filename);
           
           if (log.isDebugEnabled()) {
  -            log.debug("Home directory: " + homeDir);
               log.debug("Home URL: " + homeURL);
               log.debug("Configuration URL: " + configURL);
           }
  
  
  

Mime
View raw message