jvanzyl     2002/11/13 22:33:56

  Modified:    src/java/org/apache/maven MavenConstants.java
                        MavenUtils.java
               src/java/org/apache/maven/app App.java Maven.java
  Log:
  o Adding another Map merging method which takes an array of Maps.
  o Put in the functionality to merge all the required properties
    from the CLI wrapper and create a context from the resultant
    values but not activated yet. More testing first.
  
  Revision  Changes    Path
  1.9       +4 -1      
jakarta-turbine-maven/src/java/org/apache/maven/MavenConstants.java
  
  Index: MavenConstants.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/MavenConstants.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- MavenConstants.java       13 Nov 2002 17:47:37 -0000      1.8
  +++ MavenConstants.java       14 Nov 2002 06:33:52 -0000      1.9
  @@ -116,4 +116,7 @@
   
       /** Snapshot JAR signifier tag. */
       public static final String SNAPSHOT_JAR_SIGNIFIER = "SNAPSHOT.jar";
  +
  +    /** Driver properties */
  +    public static final String DRIVER_PROPERTIES = "driver.properties";
   }
  
  
  
  1.60      +27 -2     jakarta-turbine-maven/src/java/org/apache/maven/MavenUtils.java
  
  Index: MavenUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/MavenUtils.java,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- MavenUtils.java   14 Nov 2002 04:12:32 -0000      1.59
  +++ MavenUtils.java   14 Nov 2002 06:33:52 -0000      1.60
  @@ -483,7 +483,7 @@
   
           return factory.newSAXParser().getXMLReader();
       }
  -    
  +
       /**
        * Take a dominant and recessive Map and merge the key:value
        * pairs where the recessive Map may add key:value pairs to the dominant
  @@ -525,6 +525,31 @@
           }
           
           return dominantMap;
  +    }
  +
  +    public static Map mergeMaps(Map[] maps)
  +    {
  +        Map result = null;
  +        
  +        if (maps.length == 0)
  +        {
  +            result = null;
  +        }
  +        else if (maps.length == 1)
  +        {
  +            result = maps[0];
  +        }
  +        else
  +        {
  +            result = mergeMaps(maps[0], maps[1]);
  +            
  +            for (int i = 2; i < maps.length; i++)
  +            {
  +                result = mergeMaps(result, maps[i]);
  +            }
  +        }
  +        
  +        return result;
       }
   
       // ------------------------------------------------------------
  
  
  
  1.32      +111 -2    jakarta-turbine-maven/src/java/org/apache/maven/app/App.java
  
  Index: App.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/app/App.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- App.java  13 Nov 2002 01:49:36 -0000      1.31
  +++ App.java  14 Nov 2002 06:33:56 -0000      1.32
  @@ -57,7 +57,9 @@
    */
   
   import java.io.File;
  +import java.io.FileInputStream;
   import java.io.IOException;
  +import java.io.InputStream;
   import java.io.OutputStreamWriter;
   import java.io.PrintStream;
   import java.io.Writer;
  @@ -70,6 +72,8 @@
   import java.util.Date;
   import java.util.Iterator;
   import java.util.List;
  +import java.util.Map;
  +import java.util.Properties;
   import java.util.Set;
   import java.util.StringTokenizer;
   
  @@ -83,6 +87,7 @@
   
   import org.apache.maven.MavenConstants;
   import org.apache.maven.MavenUtils;
  +import org.apache.maven.jelly.MavenJellyContext;
   import org.apache.maven.project.Project;
   
   import com.werken.werkz.Goal;
  @@ -173,7 +178,10 @@
   
       /** Jelly's underlying writer. */
       private Writer writer;
  -    
  +
  +    /** Descriptor directory. */
  +    private File descriptorDirectory;
  +
       /** Constructor. */
       public App(Maven maven)
       {
  @@ -186,6 +194,18 @@
           return this.maven;
       }
   
  +    /** Set the descriptor directory. */
  +    public void setDescriptorDirectory(File descriptorDirectory)
  +    {
  +        this.descriptorDirectory = descriptorDirectory;
  +    }
  +    
  +    /** Get the descriptor directory. */
  +    public File getDescriptorDirectory()
  +    {
  +        return descriptorDirectory;
  +    }        
  +
       /** Get the CLI parser. */
       protected CommandLine getCli()
       {
  @@ -216,6 +236,7 @@
               if (file != null) 
               {
                   getMaven().setDir(file.getParentFile());
  +                setDescriptorDirectory(file.getParentFile());
                   initializeProject(file);
               }
               else 
  @@ -228,10 +249,12 @@
   
           if (getCli().hasOption("d"))
           {
  +            setDescriptorDirectory(new File(getCli().getOptionValue("d")));
               getMaven().setDir(new File(getCli().getOptionValue("d")));
           }
           else if (!getCli().hasOption("f"))
           {
  +            setDescriptorDirectory(new File(System.getProperty("user.dir")));
               getMaven().setDir(new File(System.getProperty("user.dir")));
           }
   
  @@ -920,6 +943,92 @@
           }
   
           return (min > 0 ? min + " minutes" : " ") + secs + " seconds";
  +    }
  +
  +    // ------------------------------------------------------------
  +    // P R O P E R T I E S  M E T H O D S
  +    // ------------------------------------------------------------
  +
  +    /**
  +     * Process properties in dominant order.
  +     */
  +    private MavenJellyContext createMavenJellyContext()
  +    {
  +        // We are listing the properties in the dominant order.
  +
  +        Properties systemProperties = System.getProperties();
  +    
  +        Properties userBuildProperties = loadProperties(
  +            new File( System.getProperty("user.home"), "build.properties" ));
  +        
  +        Properties projectBuildProperties = loadProperties(
  +            new File( getDescriptorDirectory(), "build.properties" ));
  +        
  +        Properties projectProperties = loadProperties(
  +            new File( getDescriptorDirectory(), "project.properties" ));
  +
  +        Properties driverProperties = loadProperties(
  +            App.class.getClassLoader().getResourceAsStream(
  +                MavenConstants.DRIVER_PROPERTIES));
  +
  +        Map result = MavenUtils.mergeMaps( new Map[]
  +        {
  +            systemProperties,
  +            userBuildProperties,
  +            projectBuildProperties,
  +            projectProperties,
  +            driverProperties
  +        });
  +            
  +
  +        MavenJellyContext context = new MavenJellyContext();
  +        context.setVariables(result);
  +        
  +        return context;
  +    }
  +
  +    private Properties loadProperties(File file)
  +    {
  +        try
  +        {
  +            return loadProperties(new FileInputStream(file));
  +        }
  +        catch(Exception e)
  +        {
  +            // ignore
  +        }
  +        
  +        return null;
  +    }
  +
  +    private Properties loadProperties(InputStream is)
  +    {
  +        try
  +        {
  +            Properties properties = new Properties();
  +            properties.load(is);
  +            return properties;
  +        }
  +        catch (IOException e)
  +        {
  +            // ignore
  +        }
  +        finally
  +        {
  +            try
  +            {
  +                if (is != null)
  +                {
  +                    is.close();
  +                }
  +            }
  +            catch (IOException e)
  +            {
  +                // ignore
  +            }
  +        }
  +        
  +        return null;
       }
   
       public static void main(String[] args)
  
  
  
  1.134     +3 -6      jakarta-turbine-maven/src/java/org/apache/maven/app/Maven.java
  
  Index: Maven.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/app/Maven.java,v
  retrieving revision 1.133
  retrieving revision 1.134
  diff -u -r1.133 -r1.134
  --- Maven.java        14 Nov 2002 04:12:35 -0000      1.133
  +++ Maven.java        14 Nov 2002 06:33:56 -0000      1.134
  @@ -151,9 +151,6 @@
       /** Initialization jellyscript name. */
       public static final String DRIVER_SCRIPT_NAME = "driver.jelly";
   
  -    /** Driver properties */
  -    public static final String DRIVER_PROPERTIES = "driver.properties";
  -
       /** The current Maven version id */
       public static final String APP_VERSION = "1.0-beta-8";
   
  @@ -557,8 +554,8 @@
       {
           File props = null;
           
  -        InputStream is = 
Maven.class.getClassLoader().getResourceAsStream(DRIVER_PROPERTIES);
  -        loadProperties(is);
  +        //InputStream is = 
Maven.class.getClassLoader().getResourceAsStream(DRIVER_PROPERTIES);
  +        //loadProperties(is);
   
           props = new File( getDir(), "project.properties" );
           loadProperties(props);
  
  
  

--
To unsubscribe, e-mail:   <mailto:turbine-maven-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:turbine-maven-dev-help@;jakarta.apache.org>

Reply via email to