werken 2002/06/13 18:52:58 Modified: src/java/org/apache/maven/app Maven.java Log: Comments, for [EMAIL PROTECTED] and all the other lovely people. Revision Changes Path 1.2 +224 -15 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.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Maven.java 13 Jun 2002 21:37:33 -0000 1.1 +++ Maven.java 14 Jun 2002 01:52:58 -0000 1.2 @@ -1,8 +1,64 @@ - package org.apache.maven.app; +/* ==================================================================== + * 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 Maven" 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 Maven", 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.MavenUtils; +import org.apache.maven.project.Project; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.cli.Options; @@ -26,95 +82,185 @@ import java.util.Properties; import java.util.Enumeration; +/** Command-line entry-point to maven. + * + * @author <a href="mailto:[EMAIL PROTECTED]">bob mcwhirter</a> + */ public class Maven { - private final static Log log = LogFactory.getLog( Maven.class ); - + /** Filename of project-specific maven buildfile. */ public static final String PROJECT_BUILD_FILE_NAME = "build.maven"; + + /** Filename of project descriptor. */ public static final String PROJECT_DESCRIPTOR_FILE_NAME = "project.xml"; + /** Jelly entrypoint script name. */ public static final String MAVEN_DRIVER_FILE_NAME = "driver.jelly"; + /** Log. */ + private final static Log log = LogFactory.getLog( Maven.class ); + + /** CLI options. */ private Options options; + + /** Parsed command-line. */ private CommandLine cli; + /** ${maven.home}/ directory. */ private File mavenHome; + + /** ${maven.home}/bin/ directory. */ private File mavenBin; + /** Project directory. */ private File dir; + + /** ${basedir}/project.xml file. */ private File projectFile; + + /** ${basedir}/build.maven file (or null). */ private File projectBuildFile; + /** List of string goal names on the command-line. */ private List goalNames; + /** Aggregate properties. */ private Properties properties; - private org.apache.maven.project.Project mavenProject; + /** Maven project. */ + private Project mavenProject; + /** Jelly conext. */ private JellyContext jellyContext; + /** Construct. + */ public Maven() { this.properties = new Properties(); } + /** Set the project descriptor file. + * + * @param projectFile The project descriptor file. + */ public void setProjectFile(File projectFile) { this.projectFile = projectFile; } + /** Retrieve the project descriptor file. + * + * @return The project descriptor file. + */ public File getProjectFile() { return this.projectFile; } + /** Set the project-specific build file. + * + * @see #hasProjectBuildFile + * + * @param projectBuildFile The project-specific build file. + */ public void setProjectBuildFile(File projectBuildFile) { this.projectBuildFile = projectBuildFile; } + /** Retrieve the project-specific build file. + * + * @return The project-specific build file if + * one exists, otherwise <code>null</code>. + */ public File getProjectBuildFile() { return this.projectBuildFile; } + /** Determine if the project has a project-specific + * build file. + * + * @see #getProjectBuildFile + * + * @return <code>true</code> if a project-specific + * build file exists, otherwise <code>false</code>. + */ public boolean hasProjectBuildFile() { return (this.projectBuildFile != null); } - public org.apache.maven.project.Project getMavenProject() { + /** Retrieve the Maven project. + * + * @return The maven project. + */ + Project getMavenProject() { return this.mavenProject; } + /** Set the project directory. + * + * @param dir The project directory. + */ public void setDir(File dir) { this.dir = dir; } + /** Retrieve the project directory. + * + * @return The project directory. + */ + public File getDir() { + if ( this.dir == null ) { + this.dir = new File( System.getProperty( "user.dir" ) ); + } + + return this.dir; + } + + + /** Set the ${maven.home} directory. + * + * @param mavenHome The ${maven.home} directory. + */ public void setMavenHome(File mavenHome) { this.mavenHome = mavenHome; this.mavenBin = new File( mavenHome, "bin" ); } + /** Retrieve the ${maven.home} directory. + * + * @return The ${maven.home} directory. + */ public File getMavenHome() { return this.mavenHome; } + /** Retrieve the ${maven.home}/bin directory. + * + * @return The ${maven.home}/bin directory. + */ public File getMavenBin() { return this.mavenBin; } - public File getDir() { - if ( this.dir == null ) { - this.dir = new File( System.getProperty( "user.dir" ) ); - } - - return this.dir; - } - + /** Retrieve the list of goal names. + * + * @return The list of goal names. + */ public List getGoalNames() { return this.goalNames; } + /** Retrieve aggregated properties. + * + * @return Aggregated properties. + */ public Properties getProperties() { return this.properties; } + /** Produce a string representation, suitable for debugging. + * + * @return A debug string. + */ public String toString() { return "[Maven: mavenHome=" + getMavenHome() + "; dir=" + getDir() @@ -124,6 +270,10 @@ + "]"; } + /** Initialize the driver given command-line arguments. + * + * @param args The command-line arguments. + */ public void initialize(String[] args) throws Exception { setMavenHome( new File( System.getProperty( "maven.home" ) ) ); @@ -145,10 +295,18 @@ // run(); } + /** Retrieve the Jelly context. + * + * @return The Jelly context. + */ JellyContext getJellyContext() { return this.jellyContext; } + /** Initialize Jelly. + * + * @throws Exception If an error occurs. + */ void initializeJelly() throws Exception { this.jellyContext = new MavenJellyContext( getMavenBin().toURL() ); @@ -185,6 +343,10 @@ } } + /** Initialize Ant. + * + * @param context The Jelly context. + */ MavenAntProject initializeAntProject(JellyContext context) { MavenAntProject antProject = new MavenAntProject( context ); @@ -193,6 +355,10 @@ return antProject; } + /** Run maven. + * + * @throws Exception If an error occurs. + */ void run() throws Exception { Writer writer = new BufferedWriter(new OutputStreamWriter(System.out)); @@ -207,7 +373,11 @@ writer.close(); } - public Script compileScript() throws Exception { + /** Compile the first Jelly driver script. + * + * @return The compiled script. + */ + Script compileScript() throws Exception { XMLParser parser = new XMLParser(); parser.setContext( getJellyContext() ); @@ -221,12 +391,21 @@ return script; } + + /** Display help information on the console. + */ public void displayHelp() { HelpFormatter format = new HelpFormatter(); format.printHelp( "maven [options] [gaol [goal2 [goal3] ...]]", "Options:", this.options, "\n" ); } + /** Parse the command-line. + * + * @param args The command-line arguments. + * + * @throws ParseException If an error occurs during parsing. + */ void parseCommandLine(String[] args) throws ParseException { this.options = new Options(); @@ -246,10 +425,16 @@ this.cli = this.options.parse( args ); } + /** Retrieve the parsed command-line. + * + * @return The parsed command-line. + */ CommandLine getCli() { return this.cli; } + /** Process the command-line. + */ void processCommandLine() { CommandLine cli = getCli(); @@ -280,10 +465,25 @@ this.goalNames = cli.getArgList(); } + /** Load the maven project descriptor. + * + * @throws Exception If an error occurs whilst loading. + */ void loadMavenProject() throws Exception { this.mavenProject = MavenUtils.getProject( getProjectFile() ); } + /** Load the properties chain. + * + * <p> + * This loads properties files with the following priority: + * <ol> + * <li>$PROJECT/build.properties</li> + * <li>$HOME/build.properties</li> + * <li>$PROJECT/project.properties</li> + * <li>--system properties--</li> + * </ol> + */ void loadPropertiesChain() { Enumeration propNames = System.getProperties().propertyNames(); @@ -318,6 +518,11 @@ } + /** Load the specified properties file into the aggregate + * properties. + * + * @param propsFile The properties file to load. + */ void loadProps(File propsFile) { if ( ! propsFile.exists() ) { @@ -345,6 +550,10 @@ } + /** Run maven. + * + * @param args The command-line arguments. + */ public static void main(String[] args) { // log.info( "maven: intelligent projects" ); @@ -361,7 +570,7 @@ return; } - org.apache.maven.project.Project mavenProject = maven.getMavenProject(); + Project mavenProject = maven.getMavenProject(); System.out.println( "project-directory: " + maven.getDir() );
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
