jvanzyl     2002/11/24 09:57:45

  Modified:    src/java/org/apache/maven/app Maven.java
  Log:
  refactoring
  
  Revision  Changes    Path
  1.137     +87 -298   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.136
  retrieving revision 1.137
  diff -u -r1.136 -r1.137
  --- Maven.java        15 Nov 2002 19:47:26 -0000      1.136
  +++ Maven.java        24 Nov 2002 17:57:45 -0000      1.137
  @@ -81,7 +81,6 @@
   import org.apache.commons.jelly.expression.ConstantExpression;
   import org.apache.commons.jelly.expression.Expression;
   import org.apache.commons.jelly.expression.jexl.JexlExpressionFactory;
  -import org.apache.commons.jelly.tags.ant.JellyPropsHandler;
   import org.apache.commons.jelly.tags.ant.AntTagLibrary;
   import org.apache.commons.jelly.tags.jeez.JeezTagLibrary;
   import org.apache.commons.jelly.tags.werkz.JellyBuildListener;
  @@ -90,13 +89,15 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  +import org.apache.maven.CreateDependencyClasspath;
   import org.apache.maven.MavenConstants;
   import org.apache.maven.MavenUtils;
   import org.apache.maven.jelly.MavenJellyContext;
  +import org.apache.maven.jelly.JellyPropsHandler;
  +import org.apache.maven.jelly.JellyUtils;
   import org.apache.maven.jelly.tags.MavenJeezTagLibrary;
   import org.apache.maven.jelly.tags.project.MavenTagLibrary;
   import org.apache.maven.project.Project;
  -import org.apache.maven.util.JellyUtils;
   
   import org.apache.tools.ant.DemuxOutputStream;
   
  @@ -158,12 +159,12 @@
       // C L A S S  M E M B E R S
       // ------------------------------------------------------------
   
  +    /** Instances of Maven objects. Used by the reactor. */
  +    private static final Stack INSTANCES = new Stack();
  +    
       /** Log. */
       private static final Log log = LogFactory.getLog(Maven.class);
       
  -    /** Instances of Maven objects. Used by the reactor. */
  -    private static final Stack INSTANCES = new Stack();
  -
       // ------------------------------------------------------------
       // I N S T A N C E  M E M B E R S
       // ------------------------------------------------------------
  @@ -281,7 +282,16 @@
        */
       private GrantProject getAntProject()
       {
  -        return this.antProject;
  +        return antProject;
  +    }
  +
  +    /** Retrieve the Ant project.
  +     *
  +     *  @return The ant project.
  +     */
  +    private void setAntProject(GrantProject antProject)
  +    {
  +        this.antProject = antProject;
       }
   
       /** Retrieve the Ant project.
  @@ -290,7 +300,7 @@
        */
       public org.apache.tools.ant.Project getBaseAntProject()
       {
  -        return this.antProject;
  +        return antProject;
       }
   
       /**
  @@ -299,7 +309,7 @@
        */
       public com.werken.werkz.Project getWerkzProject()
       {
  -        return this.werkzProject;
  +        return werkzProject;
       }
   
       /** Set the project directory.
  @@ -385,13 +395,19 @@
           }            
       }        
   
  +    /** Set the context. */
  +    public void setContext(MavenJellyContext jellyContext)
  +    {
  +        this.jellyContext = jellyContext;
  +    }        
  +
       /** Retrieve the Jelly context.
        *
        *  @return The Jelly context.
        */
  -    private MavenJellyContext getJellyContext()
  +    public MavenJellyContext getContext()
       {
  -        return this.jellyContext;
  +        return jellyContext;
       }
   
       /** Retrieve the XML execution output sink.
  @@ -471,41 +487,14 @@
        * @return The value of the property or <code>null</code>
        *          if the property has not been set.
        */
  -    public String getProperty(String name)
  -    {
  -        Object val = getJellyContext().getVariable(name);
  -
  -        if (val == null)
  -        {
  -            return null;
  -        }
  -
  -        if (val instanceof CompositeExpression)
  -        {
  -            val = ((CompositeExpression) val).evaluate(getJellyContext());
  -        }
  -
  -        return val.toString();
  -    }
  -    
  -    /**
  -     * Set a string property in the jelly context.
  -     *
  -     * @param name Name of property.
  -     * @param value Value of property.
  -     */
  -    public void setProperty(String name, String value)
  -    {
  -        setVariable( name, value );
  -    }
  -
  +     
       /** Retrieve all property names.
        *
        * @return an Iterator over the current property names in this context
        */
       public Iterator getPropertyNames()
       {
  -        return getJellyContext().getVariableNames();
  +        return getContext().getVariableNames();
       }
       
       /**
  @@ -516,7 +505,7 @@
        */
       public void setVariable(String name, Object value)
       {
  -        getJellyContext().setVariable( name, value );
  +        getContext().setVariable( name, value );
       }
   
       /**
  @@ -524,105 +513,34 @@
        */
       public Object getVariable(String key)
       {
  -        return getJellyContext().getVariable(key);
  +        return getContext().getVariable(key);
       }        
   
       // ------------------------------------------------------------
       // I M P L E M E N T A T I O N
       // ------------------------------------------------------------
   
  -    /** 
  -     *  Load the properties chain.
  -     *
  -     *  <p>
  -     *  This loads properties files with the following priority:
  -     *  </p>
  -     *  
  -     *  <ol>
  -     *    <li>driver.properties from the maven.jar</li>
  -     *    <li>$PROJECT/project.properties</li>
  -     *    <li>$PROJECT/build.properties</li>
  -     *    <li>$HOME/build.properties</li>
  -     *  </ol>
  -     *
  -     * In addition System properties are loaded after the above chain
  -     * of properties files is processed.
  -     *
  -     * The last definition of a property wins.
  -     */
  -    private void loadProperties()
  -    {
  -        File props = null;
  -        
  -        InputStream is = 
Maven.class.getClassLoader().getResourceAsStream(MavenConstants.DRIVER_PROPERTIES);
  -        loadProperties(is);
  -
  -        props = new File( getDir(), "project.properties" );
  -        loadProperties(props);
  -          
  -        props = new File( getDir(), "build.properties" );
  -        loadProperties(props);
  -
  -        props = new File( System.getProperty("user.home"), "build.properties" );
  -        loadProperties(props);
  -        
  -        // System properties specified on the CLI with the -D option take
  -        // precedence and will override any values that have been previously
  -        // set in any of the properties files processed above.
  -        for (Iterator i = System.getProperties().keySet().iterator(); i.hasNext();)
  -        {
  -            String property = (String) i.next();
  -            setProperty(property, System.getProperty(property));
  -        }
  -    }
  -    
       /** Initialize Jelly.
        */
  -    public void initializeJelly() 
  +    public void initializeJelly()
  +        throws Exception
       {
  -        if (jellyContext != null)
  -        {
  -            return;
  -        }
  -        try
  -        {
  -            jellyContext = new MavenJellyContext();
  -            
  -            initializeJellyVariables();
  -        }
  -        catch (MalformedURLException e)
  +        getContext().setVariable(MavenConstants.MAVEN_OBJECT, this);
  +        getContext().setVariable(MavenConstants.WERKZ_PROJECT, getWerkzProject());
  +
  +        if (hasProjectBuildFile())
           {
  -            // this really should not occur...
  -            e.printStackTrace();
  +            getContext().setVariable(MavenConstants.MAVEN_BUILD_FILE_URL,
  +                                     getProjectBuildFile().toURL());
           }
  -    }
   
  -    /** Initialize common core <code>JellyContext</code> variables.
  -     *
  -     *  <p>
  -     *  Adds the following variables to the <code>JellyContext</code>.
  -     *
  -     *  <ul>
  -     *    <li>maven.home</li>
  -     *    <li>maven.project.buildFile.url</li>
  -     *  </ul>
  -     *  </p>
  -     *
  -     *  @throws MalformedURLException If the project's <code>maven.xml</code>
  -     *          is somehow (probably impossibly) a malformed URL.
  -     */
  -    private void initializeJellyVariables() throws MalformedURLException
  -    {
  -        getJellyContext().setVariable(MavenConstants.MAVEN_OBJECT, this);
  -        getJellyContext().setVariable(MavenConstants.MAVEN_HOME, getMavenHome());
  +        JellyBuildListener listener = new JellyBuildListener( output );
   
  -        getJellyContext().setVariable(MavenConstants.WERKZ_PROJECT, 
getWerkzProject());
  +        listener.isDebug( isDebug );
  +        listener.setEmacsMode( emacsMode );
  +        
  +        getAntProject().addBuildListener( listener );
   
  -        if (hasProjectBuildFile())
  -        {
  -            getJellyContext().setVariable(MavenConstants.MAVEN_BUILD_FILE_URL,
  -                                          getProjectBuildFile().toURL());
  -        }
       }
   
       /** Initialize the core <code>jeez</code> Jelly tag library.
  @@ -631,37 +549,36 @@
       {
           JeezTagLibrary jeezTagLib = new MavenJeezTagLibrary();
   
  -        getJellyContext().registerTagLibrary("jelly:jeez", jeezTagLib);
  -        getJellyContext().registerTagLibrary("", jeezTagLib);
  -        getJellyContext().registerTagLibrary("jelly:maven", new MavenTagLibrary());
  +        getContext().registerTagLibrary("jelly:jeez", jeezTagLib);
  +        getContext().registerTagLibrary("", jeezTagLib);
  +        getContext().registerTagLibrary("jelly:maven", new MavenTagLibrary());
   
  -        AntTagLibrary.setProject( getJellyContext(), getAntProject() );
  +        AntTagLibrary.setProject( getContext(), getAntProject() );
       }
   
  -    /** Initialize Ant.
  -     */
  +    /** Initialize Ant. */
       private void initializeAnt()
       {
  -        this.antProject = new GrantProject();
  +        setAntProject(new GrantProject());
   
  -        this.antProject.setPropsHandler(new JellyPropsHandler(getJellyContext()));
  +        getAntProject().setPropsHandler(new JellyPropsHandler(getContext()));
   
  -        getJellyContext().setAntProject(antProject);
  -
  -        antProject.init();
  -        antProject.setBaseDir(getDir());
  -        antProject.getBaseDir();
  +        getContext().setVariable(MavenConstants.MAVEN_ANT_PROJECT, antProject);
  +        
  +        getAntProject().init();
  +        getAntProject().setBaseDir(getDir());
  +        getAntProject().getBaseDir();
   
           PrintStream demuxOut = 
  -            new PrintStream(new DemuxOutputStream(antProject, false));
  +            new PrintStream(new DemuxOutputStream(getAntProject(), false));
   
           PrintStream demuxErr = 
  -            new PrintStream(new DemuxOutputStream(antProject, true));
  +            new PrintStream(new DemuxOutputStream(getAntProject(), true));
   
           System.setOut(demuxOut);
           System.setErr(demuxErr);
   
  -        getJellyContext().setVariable( MavenConstants.MAVEN_ANT_PROJECT, antProject 
);
  +        getContext().setVariable( MavenConstants.MAVEN_ANT_PROJECT, antProject );
       }
   
       /** Perform pre-build initialization.
  @@ -672,31 +589,25 @@
       public void runtimeInitialization() 
           throws Exception
       {
  -        initializeJelly();
  +    
           initializeAnt();
  -        initializeJellyListener();        
  +        initializeJelly();
           initializeTagLibs();
  -        loadProperties();
           initializeDriver();
  +        
  +        // Create the dependency classpath for this plugin so that the
  +        // values can be made available in the plugin.jelly script.
  +        CreateDependencyClasspath cdc = new CreateDependencyClasspath();
  +        cdc.setRefid("maven.dependency.classpath");
  +        cdc.setMavenProject(getProject());
  +        cdc.setContext(getContext());
  +        cdc.execute();
  +        
           createProjectVerifier();
           initializePlugins();
           loadProjectBuildFile();
       }
  -    
  -    /**
  -     * Initialize the Jelly listening used for the build.
  -     */
  -    private void initializeJellyListener()
  -        throws Exception
  -    {
  -        JellyBuildListener listener = new JellyBuildListener( output );
  -
  -        this.isDebug = isDebug;
  -        listener.isDebug( isDebug );
  -        listener.setEmacsMode( emacsMode );
  -        getAntProject().addBuildListener( listener );
  -    }
  -    
  +        
       /** Return an InputStream found in the classpath. Used
        *  specifically to find resources stored in the maven.jar
        */
  @@ -711,15 +622,16 @@
        *
        * @throws Exception when any error occurs
        */
  -    private void initializeDriver() throws Exception
  +    private void initializeDriver() 
  +        throws Exception
       {
  -        getJellyContext().setVariable(MavenConstants.MAVEN_POM, getProject());
  +        getContext().setVariable(MavenConstants.MAVEN_POM, getProject());
   
           InputStream driverInputStream = getResourceAsStream(DRIVER_SCRIPT_NAME);
   
           JellyUtils.runScript(driverInputStream,
                                null,
  -                             getJellyContext(),
  +                             getContext(),
                                getXMLOutput());
       }
   
  @@ -728,24 +640,25 @@
        *  @throws Exception If an error occurs while initializing
        *          any plugin.
        */
  -    private void initializePlugins() throws Exception
  +    private void initializePlugins() 
  +        throws Exception
       {
           pluginManager.setMavenHome(getMavenHome());
           pluginManager.setAntProject(getAntProject());
  -        pluginManager.setJellyContext(getJellyContext());
  +        pluginManager.setJellyContext(getContext());
           pluginManager.setXMLOutput(getXMLOutput());
           pluginManager.setProjectVerifier(getProjectVerifier());
           pluginManager.initializePlugins();
       }
   
  -     /**
  +    /**
        * Create project verifier
        */
       private ProjectVerifier createProjectVerifier()
           throws Exception
       {
           projectVerifier = new ProjectVerifier();
  -        projectVerifier.setContext(getJellyContext());
  +        projectVerifier.setContext(getContext());
           Boolean online = (Boolean)getVariable(MavenConstants.ONLINE);
           
           if (online != null && !online.booleanValue())
  @@ -770,13 +683,14 @@
        *
        *  @throws Exception If an error occurs.
        */
  -    public void attainGoals() throws Exception
  +    public void attainGoals() 
  +        throws Exception
       {
           try
           {
               INSTANCES.push( this );
               
  -            JellyContext context = getJellyContext();
  +            JellyContext context = getContext();
   
               context.setVariable(MavenConstants.MAVEN_GOALS, getGoalNames());
               
  @@ -866,138 +780,13 @@
           }
       }
   
  -    /** Load the specified properties file into the aggregate
  -     *  properties.
  -     *
  -     *  @param propsFile The properties file to load.
  -     */
  -    private void loadProperties(File propsFile)
  -    {
  -        if (!propsFile.exists())
  -        {
  -            log.debug("No properties file: " + propsFile);
  -        }
  -        else
  -        {
  -            log.debug("Properties file: " + propsFile);
  -        }
  -        
  -        try
  -        {
  -            loadProperties(new FileInputStream(propsFile));
  -        }
  -        catch (Exception e)
  -        {
  -            // ignore
  -        }
  -    }        
  -
  -    /** Load the specified properties file into the aggregate
  -     *  properties.
  -     *
  -     *  @param propsFile The properties file to load.
  -     */
  -    private void loadProperties(InputStream in)
  -    {
  -        try
  -        {
  -            Properties props = new Properties();
  -
  -            props.load(in);
  -
  -            integrateProps(props);
  -        }
  -        catch (IOException e)
  -        {
  -            // ignore
  -        }
  -        finally
  -        {
  -            try
  -            {
  -                if (in != null)
  -                {
  -                    in.close();
  -                }
  -            }
  -            catch (IOException e)
  -            {
  -                // ignore
  -            }
  -        }
  -    }
  -
  -    /**
  -     * Add the specified properties to the
  -     * {@link #getJellyContext() jelly context} where previously
  -     * defined values are overwritten with newer values.
  -     *
  -     * @param props the {@link Properties} to add
  -     */
  -    private void integrateProps(Properties props)
  -    {
  -        if (props == null)
  -        {
  -            return;
  -        }
  -
  -        JellyContext context = getJellyContext();
  -
  -        Enumeration propNames = props.propertyNames();
  -
  -        String eachName = null;
  -        String propText = null;
  -        Object propVal  = null;
  -
  -        JexlExpressionFactory factory = new JexlExpressionFactory();
  -
  -        while (propNames.hasMoreElements())
  -        {
  -            eachName = (String) propNames.nextElement();
  +    // The only thing using this now is the dvsl bean and xdoc base project
  +    // task. Get rid of this when the jsl stuff is finished. jvz.
   
  -            propText = props.getProperty(eachName);
  -            
  -            log.debug(eachName + " -> " + propText);
  -            
  -            try
  -            {
  -                Expression expr = CompositeExpression.parse(propText, factory);
  -
  -                if (expr != null)
  -                {
  -                    if (expr instanceof ConstantExpression)
  -                    {
  -                        // lets unwrap a constant text and discard the Expression 
object
  -                        propVal = expr.evaluate(context);
  -                    }
  -                    else 
  -                    {
  -                        propVal = expr;
  -                    }
  -                }
  -                else
  -                {
  -                    propVal = propText;
  -                }
  -                
  -                context.setVariable(eachName,propVal);
  -            }
  -            catch (Exception e)
  -            {
  -                e.printStackTrace();
  -            }
  -        }
  -    }
  -
  -    // ------------------------------------------------------------
  -    // C L A S S  M E T H O D S
  -    // ------------------------------------------------------------
  -    
  -    /**
  -     * Get the Maven instance.
  -     */
  +    /** Get the Maven instance. */
       public static Maven getInstance()
       {
           return (Maven) INSTANCES.peek();
       }
  +
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to