jvanzyl 2002/12/30 23:04:31 Added: src/java/org/apache/maven MavenSession.java Log: refactoring. update to follow Revision Changes Path 1.1 jakarta-turbine-maven/src/java/org/apache/maven/MavenSession.java Index: MavenSession.java =================================================================== package org.apache.maven; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache MavenSession" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache MavenSession", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ==================================================================== */ import org.apache.maven.jelly.MavenJellyContext; import org.apache.maven.plugin.PluginManager; import org.apache.maven.project.Project; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Set; /** * This class should represent the single place to access everything that * MavenSession provides and control any options provided by MavenSession. Currently * this is not entirely the case: there are bits of logic that need to * be moved out of App.java and some code that needs to be shuffled * between the PluginManager and MavenSession proper. * * @author <a href="mailto:[EMAIL PROTECTED]">bob mcwhirter</a> * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * * @version $Id: MavenSession.java,v 1.1 2002/12/31 07:04:31 jvanzyl Exp $ * * @todo Filter the MavenSession version number into a Java constant that will change * during compilation. */ // This is the mediator and main point of entry for the guts of maven. public class MavenSession extends AbstractMavenComponent { // ------------------------------------------------------------ // C O N S T A N T S // ------------------------------------------------------------ /** Filename of project-specific maven buildfile. */ public static final String PROJECT_BUILD_FILE_NAME = "maven.xml"; /** Tag for build start goal. */ public static final String BUILD_START_GOAL = "build:start"; /** Tag for build end goal. */ public static final String BUILD_END_GOAL = "build:end"; /** Initialization jellyscript name. */ public static final String DRIVER_SCRIPT_NAME = "driver.jelly"; /** The current MavenSession version id */ public static final String APP_VERSION = "1.0-beta-8"; // ------------------------------------------------------------ // C L A S S M E M B E R S // ------------------------------------------------------------ private MavenJellyContext rootContext; private static File rootDescriptorFile; private Project rootProject; private PluginManager pluginManager; // ------------------------------------------------------------ // I N S T A N C E M E M B E R S // ------------------------------------------------------------ /** List of string goal names on the command-line. */ private List goalNames; // ------------------------------------------------------------ // C O N S T R U C T O R S // ------------------------------------------------------------ /** Default Constructor. */ public MavenSession() { goalNames = new ArrayList(); pluginManager = new PluginManager( this ); //goalNames.add( BUILD_START_GOAL ); } // ------------------------------------------------------------ // A C C E S S O R S // ------------------------------------------------------------ public void setRootContext( MavenJellyContext rootContext ) { this.rootContext = rootContext; } public MavenJellyContext getRootContext() { return rootContext; } public static void setRootDescriptorFile( File descriptorFile ) { rootDescriptorFile = descriptorFile; } public static File getRootDescriptorFile() { return rootDescriptorFile; } public void setRootProject( Project rootProject ) { this.rootProject = rootProject; } public Project getRootProject() { return rootProject; } public void setPluginManager( PluginManager pluginManager ) { this.pluginManager = pluginManager; } public PluginManager getPluginManager() { return pluginManager; } /** Retrieve the list of goal names. * * @return The list of goal names. */ public List getGoalNames() { return this.goalNames; } /** * Add a single goal to the list of goals to attain. * * @param goalName Goal to attain. */ public void addGoalName( String goalName ) { this.goalNames.add( goalName ); } /** * Add a list of goals to attain. * * @param goalNames List of goals to attain. */ public void addGoalNames( List goalNames ) { this.goalNames.addAll( goalNames ); } /** * Clear the goal list. */ public void clearGoalNames() { for ( int i = 0; i < goalNames.size(); i++ ) { goalNames.remove( i ); } } // ------------------------------------------------------------ // I M P L E M E N T A T I O N // ------------------------------------------------------------ /** Perform pre-build initialization. * * @throws Exception If an error occurs while performing * runtime initialization. */ public void initialize() throws Exception { initializePluginManager(); initializeRootProject(); } public void prepForGoal( String goalName, Project project ) throws Exception { getPluginManager().prepForGoal( goalName, project ); } public boolean isPluginManagerInitialized() { return getPluginManager().isInitialized(); } public Set getAllGoalNames() { return getPluginManager().getGoalNames(); } public String getGoalDescription( String goalName) { return getPluginManager().getGoalDescription( goalName ); } // end of public interface /** Initialize all plugins. * * @throws Exception If an error occurs while initializing * any plugin. */ private void initializePluginManager() throws Exception { getPluginManager().initialize(); } /** * Load the mavenSession project descriptor. * * @throws Exception If there is an error while * reading the project descriptor. */ private void initializeRootProject() throws Exception { File descriptorFile = getRootDescriptorFile(); // THIS NEEDS TO BE SET getRootContext().setMavenSession( this ); if ( descriptorFile.exists() ) { if ( descriptorFile.length() == 0 ) { throw new Exception( MavenUtils.getMessage( "empty.descriptor.error", descriptorFile.getName() ) ); } // Now we want to use the root context as the parent context because // it has all the global values needed by all projects. The root context // created within MavenUtils.getProject(f) is almost identical to the root context // because in both cases they are created with MavenUtils.createContext(d) // but the root context has addition values set from from values based // on options present on the command line. setRootProject( MavenUtils.getProject( descriptorFile, getRootContext() ) ); } else { // A type of null pattern. We don't really have a root project per se // but want the rest of the system to believe there is for consistency // in the rest of the code. Project globalProject = new Project(); globalProject.setId( "Global Project" ); globalProject.setContext( getRootContext() ); setRootProject( globalProject ); } getRootProject().setGoalNames( getGoalNames() ); } public void attainGoals() throws UnknownGoalException, Exception { getPluginManager().attainGoals( getRootProject() ); } public void attainGoals( Project project ) throws UnknownGoalException, Exception { getPluginManager().attainGoals( project ); } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
