werken 2002/06/24 11:33:19
Modified: src/java/org/apache/maven/app GrantPropsHandler.java
Maven.java MavenJellyContext.java
UnknownGoalException.java
Added: src/java/org/apache/maven/app CLIManager.java
JellyUtils.java
Removed: src/java/org/apache/maven/app MavenAntProject.java
Log:
* Massive cleanup of app.Maven (through introduction of new classes).
* Massive cleanup my most of my checkstyle violations, d'ion.
* Start of pulling d'ion's hacks into mine.
Revision Changes Path
1.2 +82 -26
jakarta-turbine-maven/src/java/org/apache/maven/app/GrantPropsHandler.java
Index: GrantPropsHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/app/GrantPropsHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GrantPropsHandler.java 19 Jun 2002 17:21:53 -0000 1.1
+++ GrantPropsHandler.java 24 Jun 2002 18:33:18 -0000 1.2
@@ -56,15 +56,8 @@
* ====================================================================
*/
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.ProjectHelper;
-import org.apache.tools.ant.BuildException;
-import org.apache.commons.jelly.JellyContext;
-import org.apache.tools.ant.DemuxOutputStream;
-import org.apache.commons.jelly.tags.werkz.JellyBuildListener;
import org.apache.commons.grant.PropsHandler;
-import java.io.PrintStream;
import java.util.Hashtable;
/** Implementation of a Commons Grant <code>propsHandler</code>
@@ -78,62 +71,125 @@
private Hashtable props;
/** The JellyContext. */
- MavenJellyContext context;
+ private MavenJellyContext context;
/** Construct with a backing-store <code>JellyContext</code>
*
* @param context The backing-store <code>JellyContext</code>.
*/
- public GrantPropsHandler(MavenJellyContext context) {
+ public GrantPropsHandler(MavenJellyContext context)
+ {
this.context = context;
}
- public void setProperty(String name, String value) {
- context.setScopedVariable( name, value );
+ /** Set an ant property.
+ *
+ * @param name The property name.
+ * @param value The property value.
+ */
+ public void setProperty(String name, String value)
+ {
+ context.setScopedVariable(name,
+ value);
}
- public String getProperty(String name) {
- Object value = context.getScopedVariable( name );
+ /** Retrieve an ant property.
+ *
+ * @param name The property name.
+ *
+ * @return The property value.
+ */
+ public String getProperty(String name)
+ {
+ Object value = context.getScopedVariable(name);
- if ( value == null ) {
+ if (value == null)
+ {
return null;
}
return value.toString();
}
- public void setNewProperty(String name, String value) {
- if ( context.getScopedVariable( name ) == null ) {
- context.setScopedVariable( name, value );
+ /** Set a new ant property.
+ *
+ * <p>
+ * Following the ant spec, this sets a property
+ * only if it has not been previously set. If
+ * the property has already been set, this returns
+ * silently.
+ * </p>
+ *
+ * @param name The property name.
+ * @param value The property value.
+ */
+ public void setNewProperty(String name, String value)
+ {
+ if (context.getScopedVariable(name) == null)
+ {
+ context.setScopedVariable(name,
+ value);
}
}
- public void setUserProperty(String name, String value) {
- context.setScopedVariable( name, value );
+ /** Set an ant user property.
+ *
+ * @param name The property name.
+ * @param value The property value.
+ */
+ public void setUserProperty(String name, String value)
+ {
+ context.setScopedVariable(name,
+ value);
}
- public String getUserProperty(String name) {
- Object value = context.getScopedVariable( name );
+ /** Retrieve an ant user property.
+ *
+ * @param name The property name.
+ *
+ * @return The property value.
+ */
+ public String getUserProperty(String name)
+ {
+ Object value = context.getScopedVariable(name);
- if ( value == null ) {
+ if (value == null)
+ {
return null;
}
return value.toString();
}
- public void setPropertyInternal(String name, String value) {
- if (null != getUserProperty(name) ) {
+ /** Internal ant property-setting implementation.
+ *
+ * @param name The property name.
+ * @param value The property value.
+ */
+ public void setPropertyInternal(String name, String value)
+ {
+ if (null != getUserProperty(name))
+ {
return;
}
setProperty(name, value);
}
- public Hashtable getProperties() {
+ /** Retrieve all ant properties.
+ *
+ * @return A <code>Hashtable</code> of all properties.
+ */
+ public Hashtable getProperties()
+ {
return this.context.asProperties();
}
- public Hashtable getUserProperties() {
+ /** Retrieve all ant user properties.
+ *
+ * @return A <code>Hashtable</code> of all user properties.
+ */
+ public Hashtable getUserProperties()
+ {
return this.context.asProperties();
}
}
1.11 +537 -468 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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Maven.java 22 Jun 2002 18:07:09 -0000 1.10
+++ Maven.java 24 Jun 2002 18:33:19 -0000 1.11
@@ -56,40 +56,41 @@
* ====================================================================
*/
-import org.apache.maven.MavenUtils;
-
-import org.apache.maven.ProjectProperties;
+import org.apache.maven.build.ProjectDescriptor;
import org.apache.maven.project.Project;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.Option;
+
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.ParseException;
-import org.apache.commons.cli.HelpFormatter;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.commons.grant.GrantProject;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.XMLOutput;
-import org.apache.commons.jelly.Script;
-import org.apache.commons.jelly.parser.XMLParser;
+import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.tags.jeez.JeezTagLibrary;
import org.apache.commons.jelly.tags.werkz.JellySession;
import org.apache.commons.jelly.tags.werkz.JellyBuildListener;
-import org.apache.commons.grant.GrantProject;
+
import org.apache.tools.ant.DemuxOutputStream;
+import org.xml.sax.SAXException;
+
import com.werken.werkz.Goal;
import com.werken.werkz.Session;
import com.werken.werkz.UnattainableGoalException;
+import java.beans.IntrospectionException;
import java.io.File;
import java.io.FileInputStream;
import java.io.Writer;
-import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.IOException;
import java.io.PrintStream;
-import java.net.URLClassLoader;
-import java.net.URL;
+
+import java.net.MalformedURLException;
+
import java.util.List;
import java.util.Properties;
import java.util.Collection;
@@ -107,37 +108,31 @@
// ------------------------------------------------------------
/** Filename of project-specific maven buildfile. */
- public static final String PROJECT_BUILD_FILE_NAME = "build.maven";
+ public static final String PROJECT_BUILD_FILE_NAME = "build.maven";
/** Filename of project descriptor. */
public static final String PROJECT_DESCRIPTOR_FILE_NAME = "project-ng.xml";
/** Filename of project maven script. */
- public static final String PROJECT_MAVEN_SCRIPT_NAME = "maven.xml";
-
- /** Jelly entrypoint script name. */
- public static final String MAVEN_DRIVER_FILE_NAME = "driver.jelly";
+ public static final String PROJECT_MAVEN_SCRIPT_NAME = "maven.xml";
/** Plug-in main script name. */
- public static final String PLUGIN_SCRIPT_NAME = "plugin.jelly";
+ public static final String PLUGIN_SCRIPT_NAME = "plugin.jelly";
/** Plug-in default properties name. */
- public static final String PLUGIN_PROPERTIES_NAME = "default.properties";
+ public static final String PLUGIN_PROPERTIES_NAME = "default.properties";
// ------------------------------------------------------------
// Class members
// ------------------------------------------------------------
/** Log. */
- private final static Log log = LogFactory.getLog( Maven.class );
+ private static final Log log = LogFactory.getLog(Maven.class);
// ------------------------------------------------------------
// Instance members
// ------------------------------------------------------------
- /** CLI options. */
- private Options options;
-
/** Parsed command-line. */
private CommandLine cli;
@@ -165,25 +160,35 @@
/** Aggregate properties. */
private Properties properties;
- /** Maven project. */
- private Project mavenProject;
+ /** Maven project descriptor. */
+ private ProjectDescriptor projectDescriptor;
/** Jelly conext. */
private MavenJellyContext jellyContext;
+ /** The Ant project. */
+ private GrantProject antProject;
+
/** Jelly's output. */
private XMLOutput output;
/** Jelly's underlying writer. */
private Writer writer;
+ /** Saved original console System.out. */
+ private PrintStream consoleOut;
+
+ /** Saved original console System.err. */
+ private PrintStream consoleErr;
+
// ------------------------------------------------------------
// Constructors
// ------------------------------------------------------------
/** Construct.
*/
- public Maven() {
+ public Maven()
+ {
this.properties = new Properties();
}
@@ -195,7 +200,8 @@
*
* @param projectFile The project descriptor file.
*/
- public void setProjectFile(File projectFile) {
+ public void setProjectFile(File projectFile)
+ {
this.projectFile = projectFile;
}
@@ -203,7 +209,8 @@
*
* @return The project descriptor file.
*/
- public File getProjectFile() {
+ public File getProjectFile()
+ {
return this.projectFile;
}
@@ -213,7 +220,8 @@
*
* @param projectBuildFile The project-specific build file.
*/
- public void setProjectBuildFile(File projectBuildFile) {
+ public void setProjectBuildFile(File projectBuildFile)
+ {
this.projectBuildFile = projectBuildFile;
}
@@ -222,7 +230,8 @@
* @return The project-specific build file if
* one exists, otherwise <code>null</code>.
*/
- public File getProjectBuildFile() {
+ public File getProjectBuildFile()
+ {
return this.projectBuildFile;
}
@@ -234,23 +243,35 @@
* @return <code>true</code> if a project-specific
* build file exists, otherwise <code>false</code>.
*/
- public boolean hasProjectBuildFile() {
+ public boolean hasProjectBuildFile()
+ {
return (this.projectBuildFile != null);
}
- /** Retrieve the Maven project.
+ /** Retrieve the maven <code>ProjectDescriptor</code>.
+ *
+ * @return The project descriptor.
+ */
+ ProjectDescriptor getProjectDescriptor()
+ {
+ return this.projectDescriptor;
+ }
+
+ /** Retrieve the Ant project.
*
- * @return The maven project.
+ * @return The ant project.
*/
- Project getMavenProject() {
- return this.mavenProject;
+ GrantProject getAntProject()
+ {
+ return this.antProject;
}
/** Set the project directory.
*
* @param dir The project directory.
*/
- public void setDir(File dir) {
+ public void setDir(File dir)
+ {
this.dir = dir;
}
@@ -258,9 +279,11 @@
*
* @return The project directory.
*/
- public File getDir() {
- if ( this.dir == null ) {
- this.dir = new File( System.getProperty( "user.dir" ) );
+ public File getDir()
+ {
+ if (this.dir == null)
+ {
+ this.dir = new File(System.getProperty("user.dir"));
}
return this.dir;
@@ -271,19 +294,23 @@
*
* @param mavenHome The ${maven.home} directory.
*/
- public void setMavenHome(File mavenHome) {
+ public void setMavenHome(File mavenHome)
+ {
this.mavenHome = mavenHome;
- this.mavenBin = new File( mavenHome,
- "bin" );
- this.pluginsDir = new File( this.mavenBin,
- "plugins" );
+
+ this.mavenBin = new File(mavenHome,
+ "bin");
+
+ this.pluginsDir = new File(this.mavenBin,
+ "plugins");
}
/** Retrieve the directory containing all plugins.
*
* @return The directory containing all plugins.
*/
- public File getPluginsDir() {
+ public File getPluginsDir()
+ {
return this.pluginsDir;
}
@@ -295,9 +322,10 @@
* @return The directory for the plugin, or
* <code>null</code> if no such plugin.
*/
- public File getPluginDir(String pluginName) {
- return new File( getPluginsDir(),
- pluginName );
+ public File getPluginDir(String pluginName)
+ {
+ return new File(getPluginsDir(),
+ pluginName);
}
/** Retrieve the plugin's entry-point jelly script.
@@ -307,9 +335,10 @@
* @return The entry-point script for the plugin, or
* <code>null</code> if no such plugin.
*/
- public File getPluginScript(String pluginName) {
- return new File( getPluginDir( pluginName ),
- PLUGIN_SCRIPT_NAME );
+ public File getPluginScript(String pluginName)
+ {
+ return new File(getPluginDir(pluginName),
+ PLUGIN_SCRIPT_NAME);
}
@@ -319,20 +348,25 @@
*
* @return The default properties file for the plugin, or
* <code>null</code> if no such plugin.
+ *
+ * @throws IOException If an IO error occurs while attempting
+ * to read the plugin's properties.
*/
- public Properties getPluginProperties(String pluginName) throws IOException {
- File propsFile = new File( getPluginDir( pluginName ),
- PLUGIN_PROPERTIES_NAME );
+ public Properties getPluginProperties(String pluginName) throws IOException
+ {
+ File propsFile = new File(getPluginDir(pluginName),
+ PLUGIN_PROPERTIES_NAME);
- if ( ! propsFile.exists() ) {
+ if (!propsFile.exists())
+ {
return null;
}
Properties props = new Properties();
- FileInputStream in = new FileInputStream( propsFile );
+ FileInputStream in = new FileInputStream(propsFile);
- props.load( in );
+ props.load(in);
in.close();
@@ -343,7 +377,8 @@
*
* @return The ${maven.home} directory.
*/
- public File getMavenHome() {
+ public File getMavenHome()
+ {
return this.mavenHome;
}
@@ -351,7 +386,8 @@
*
* @return The ${maven.home}/bin directory.
*/
- public File getMavenBin() {
+ public File getMavenBin()
+ {
return this.mavenBin;
}
@@ -359,16 +395,18 @@
*
* @return The project's script file.
*/
- public File getProjectScript() {
- return new File( getDir(),
- PROJECT_MAVEN_SCRIPT_NAME );
+ public File getProjectScript()
+ {
+ return new File(getDir(),
+ PROJECT_MAVEN_SCRIPT_NAME);
}
/** Retrieve the list of goal names.
*
* @return The list of goal names.
*/
- public List getGoalNames() {
+ public List getGoalNames()
+ {
return this.goalNames;
}
@@ -376,15 +414,44 @@
*
* @return Aggregated properties.
*/
- public Properties getProperties() {
+ public Properties getProperties()
+ {
return this.properties;
}
+ /** Retrieve the Jelly context.
+ *
+ * @return The Jelly context.
+ */
+ MavenJellyContext getJellyContext()
+ {
+ return this.jellyContext;
+ }
+
+ /** Retrieve the parsed command-line.
+ *
+ * @return The parsed command-line.
+ */
+ CommandLine getCli()
+ {
+ return this.cli;
+ }
+
+ /** Retrieve the XML execution output sink.
+ *
+ * @return The output sink.
+ */
+ XMLOutput getXMLOutput()
+ {
+ return this.output;
+ }
+
/** Produce a string representation, suitable for debugging.
*
* @return A debug string.
*/
- public String toString() {
+ public String toString()
+ {
return "[Maven: mavenHome=" + getMavenHome()
+ "; dir=" + getDir()
+ "; projectFile=" + getProjectFile()
@@ -393,182 +460,220 @@
+ "]";
}
- /** Initialize the driver given command-line arguments.
+ /** Perform initialization.
*
* @param args The command-line arguments.
+ *
+ * @throws ParseException If there is an error parsing the
+ * command-line.
+ * @throws IntrospectionException If there is an error while
+ * reading the project descriptor.
+ * @throws IOException If there is an error while
+ * reading the project descriptor.
+ * @throws SAXException If there is an error while
+ * reading the project descriptor.
*/
- public boolean initialize(String[] args) throws Exception {
+ public void initializeCore(String[] args)
+ throws ParseException, IntrospectionException, IOException, SAXException
+ {
- setMavenHome( new File( System.getProperty( "maven.home" ) ) );
-
- try {
- parseCommandLine( args );
- } catch (ParseException e) {
- System.err.println( e.getLocalizedMessage() );
- displayHelp();
- return false;
- }
-
- if ( ! processCommandLine() ) {
- return false;
- }
+ setMavenHome(new File(System.getProperty("maven.home")));
+
+ parseCommandLine(args);
+
+ initializeProjectDescriptor();
- // Now, read the project descriptor, initialize
- // jelly's context, which in tern causes initialization
- // of the ant side of the house.
-
- loadMavenProject();
initializeJelly();
+ initializeAnt();
+ initializeIO();
+ initializeTagLibs();
- return true;
+ System.setProperty("user.dir",
+ getDir().getPath());
}
- /** Retrieve the Jelly context.
+ /** Load the maven project descriptor.
*
- * @return The Jelly context.
+ * @throws IntrospectionException If there is an error while
+ * reading the project descriptor.
+ * @throws IOException If there is an error while
+ * reading the project descriptor.
+ * @throws SAXException If there is an error while
+ * reading the project descriptor.
*/
- MavenJellyContext getJellyContext() {
- return this.jellyContext;
+ void initializeProjectDescriptor()
+ throws IntrospectionException, IOException, SAXException
+ {
+ this.projectDescriptor = new ProjectDescriptor(getProjectFile());
}
+
/** Initialize Jelly.
*
- * @throws Exception If an error occurs.
+ * @throws MalformedURLException If the url specifying
+ * MAVEN_HOME/bin is malformed, which is highly
+ * unlikely, but technically possible.
*/
- void initializeJelly() throws Exception {
-
- this.jellyContext = new MavenJellyContext( getMavenBin().toURL(),
- this.properties );
+ void initializeJelly() throws MalformedURLException
+ {
+ this.jellyContext = new MavenJellyContext(getMavenBin().toURL(),
+ this.properties);
- PrintStream oldOut = System.out;
- PrintStream oldErr = System.err;
-
- this.writer = new OutputStreamWriter(oldOut);
- this.output = XMLOutput.createXMLOutput(writer);
-
- GrantProject antProject = initializeAntProject();
-
- antProject.addBuildListener( new JellyBuildListener( output ) );
- PrintStream demuxOut = new PrintStream(new DemuxOutputStream(antProject,
false));
- PrintStream demuxErr = new PrintStream(new DemuxOutputStream(antProject,
true));
- System.setOut( demuxOut );
- System.setErr( demuxErr );
-
- this.jellyContext.setVariable( "maven.home",
- getMavenHome() );
-
- this.jellyContext.setVariable( "maven.bin",
- getMavenBin() );
+ initializeJellyVariables();
+ }
- antProject.setBaseDir( getDir() );
- System.setProperty( "user.dir",
- getDir().getPath() );
+ /** Initialize common core <code>JellyContext</code> variables.
+ *
+ * <p>
+ * Adds the following variables to the <code>JellyContext</code>.
+ *
+ * <ul>
+ * <li>maven.home</li>
+ * <li>maven.bin</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.
+ */
+ void initializeJellyVariables() throws MalformedURLException
+ {
+ this.jellyContext.setVariable("maven.home",
+ getMavenHome());
- this.jellyContext.setVariable( "org.apache.commons.jelly.ant.Project",
- antProject );
+ this.jellyContext.setVariable("maven.bin",
+ getMavenBin());
- JeezTagLibrary jeezTagLib = new JeezTagLibrary( antProject );
+ if (hasProjectBuildFile())
+ {
+ this.jellyContext.setVariable("maven.project.buildFile.url",
+ getProjectBuildFile().toURL());
+ }
+ }
- this.jellyContext.registerTagLibrary( "jelly:jeez",
- jeezTagLib );
+ /** Initialize the core <code>jeez</code> Jelly tag library.
+ */
+ void initializeTagLibs()
+ {
+ JeezTagLibrary jeezTagLib = new JeezTagLibrary(getAntProject());
- this.jellyContext.registerTagLibrary( "",
- jeezTagLib );
+ this.jellyContext.registerTagLibrary("jelly:jeez",
+ jeezTagLib);
- if ( hasProjectBuildFile() ) {
- this.jellyContext.setVariable( "maven.project.buildFile.url",
- getProjectBuildFile().toURL() );
- }
+ this.jellyContext.registerTagLibrary("",
+ jeezTagLib);
}
/** Initialize Ant.
- *
- * @param context The Jelly context.
*/
- GrantProject initializeAntProject() throws Exception {
-
- // Use our special Project subclass that knows how to
- // call, if required, through to the JellyContext for
- // properties resolution.
+ void initializeAnt()
+ {
+ this.antProject = new GrantProject();
- GrantProject antProject = new GrantProject();
+ antProject.setPropsHandler(new GrantPropsHandler(getJellyContext()));
- antProject.setPropsHandler( new GrantPropsHandler( getJellyContext() ) );
- // antProject.setCoreLoader( Project.class.getClassLoader() );
+ getJellyContext().setAntProject(antProject);
- getJellyContext().setAntProject( antProject );
-
- antProject.setBaseDir( getDir() );
+ antProject.setBaseDir(getDir());
antProject.init();
+ }
- ProjectProperties projProps = new ProjectProperties();
+ /** Initialize the IO streams.
+ */
+ void initializeIO()
+ {
+ this.consoleOut = System.out;
+ this.consoleErr = System.err;
- projProps.setProject( antProject );
- projProps.setMavenProject( getMavenProject() );
- projProps.setProjectDescriptor( getProjectFile() );
+ this.writer = new OutputStreamWriter(this.consoleOut);
+ this.output = XMLOutput.createXMLOutput(writer);
- projProps.doExecute();
+ GrantProject project = getAntProject();
- return antProject;
- }
+ project.addBuildListener(new JellyBuildListener(output));
+
+ PrintStream demuxOut = new PrintStream(new DemuxOutputStream(project,
+ false));
+
+ PrintStream demuxErr = new PrintStream(new DemuxOutputStream(project,
+ true));
+ System.setOut(demuxOut);
+ System.setErr(demuxErr);
+ }
- /** Run the main jelly driver script.
+ /** Initialize all plugins.
+ *
+ * @throws Exception If an error occurs while initializing
+ * any plugin.
*/
- void runDriver() throws Exception {
- runScript( new File( getMavenBin(),
- MAVEN_DRIVER_FILE_NAME ) );
+ void initializePlugins() throws Exception
+ {
+ loadPlugins();
}
+
/** Load all plugins.
+ *
+ * @throws Exception If an error occurs while initializing
+ * any plugin.
*/
- void loadPlugins() throws Exception {
-
+ void loadPlugins() throws Exception
+ {
File pluginsDir = getPluginsDir();
File[] pluginDirs = pluginsDir.listFiles();
- boolean loaded = false;
-
- for ( int i = 0 ; i < pluginDirs.length ; ++i ) {
- if ( pluginDirs[i].isDirectory() ) {
- loaded = true;
- loadPlugin( pluginDirs[i].getName() );
+ for (int i = 0; i < pluginDirs.length; ++i)
+ {
+ if (pluginDirs[i].isDirectory())
+ {
+ loadPlugin(pluginDirs[i].getName());
}
}
-
- if ( loaded ) {
- output.write( "\n" );
- }
}
/** Load the specified plugin.
*
* @param name The name of the plugin to load.
+ *
+ * @throws Exception If an error occurs while initializing
+ * the plugin.
*/
- void loadPlugin(String name) throws Exception {
-
- File pluginScript = getPluginScript( name );
+ void loadPlugin(String name) throws Exception
+ {
+ File pluginScript = getPluginScript(name);
- if ( ! pluginScript.exists() ) {
- output.write( "Unable to load plugin script: " + pluginScript + "\n" );
+ if (!pluginScript.exists())
+ {
+ output.write("Unable to load plugin script: "
+ + pluginScript
+ + "\n");
return;
}
- loadPluginProperties( name );
+ loadPluginProperties(name);
- runScript( pluginScript,
- getPluginDir( name ).toURL() );
+ JellyUtils.runScript(pluginScript,
+ getPluginDir(name).toURL(),
+ getJellyContext(),
+ getXMLOutput());
}
/** Load the properties for the specified plugin.
*
* @param name The name of the plugin to load.
+ *
+ * @throws IOException If an error occurs while initializing
+ * the plugin's properties.
*/
- void loadPluginProperties(String name) throws IOException {
- Properties props = getPluginProperties( name );
+ void loadPluginProperties(String name) throws IOException
+ {
+ Properties props = getPluginProperties(name);
- if ( props == null ) {
+ if (props == null)
+ {
return;
}
@@ -578,11 +683,13 @@
String eachName = null;
- while ( propNames.hasMoreElements() ) {
+ while (propNames.hasMoreElements())
+ {
eachName = (String) propNames.nextElement();
- if ( context.getVariable( eachName ) == null ) {
- context.setVariable( eachName,
- props.getProperty( eachName ) );
+ if (context.getVariable(eachName) == null)
+ {
+ context.setVariable(eachName,
+ props.getProperty(eachName));
}
}
}
@@ -591,44 +698,30 @@
*
* @throws Exception If an error occurs.
*/
- void attainGoals() throws Exception {
-
- /*
- List goalNames = getGoalNames();
-
- if ( goalNames.isEmpty() ) {
- return;
- }
- */
-
+ void attainGoals() throws Exception
+ {
JellyContext context = getJellyContext();
- context.setVariable("goals", getGoalNames() );
-
- // Writer writer = new BufferedWriter(new
OutputStreamWriter(System.out));
- runDriver();
-
+ context.setVariable("goals",
+ getGoalNames());
+
loadPlugins();
loadProjectScript();
- runGoals( goalNames );
-
+ runGoals(goalNames);
}
- void displayGoals() throws Exception {
-
- JellyContext context = getJellyContext();
-
- runDriver();
-
- loadPlugins();
-
- loadProjectScript();
+ /** Display helpful information regarding
+ * all documented goals.
+ */
+ void displayGoals()
+ {
com.werken.werkz.Project werkzProject =
- (com.werken.werkz.Project) getJellyContext().getVariable(
"org.apache.commons.jelly.werkz.Project" );
+ (com.werken.werkz.Project) getJellyContext()
+ .getVariable("org.apache.commons.jelly.werkz.Project");
Collection goals = werkzProject.getGoals();
@@ -639,253 +732,193 @@
boolean hadDesc = false;
- while ( goalIter.hasNext() ) {
+ while (goalIter.hasNext())
+ {
eachGoal = (Goal) goalIter.next();
description = eachGoal.getDescription();
- if ( description == null ) {
+ if (description == null)
+ {
continue;
}
hadDesc = true;
- System.out.println( " " + format( eachGoal.getName() + " ",
- 30,
- '.' ) + " " +
eachGoal.getDescription() );
+ System.out.println(" "
+ + format(eachGoal.getName()
+ + " ",
+ 30,
+ '.')
+ + " " + eachGoal.getDescription());
}
- if ( !hadDesc ) {
- System.out.println( " No documented goals." );
+ if (!hadDesc)
+ {
+ System.out.println(" No documented goals.");
}
}
- private String format(String orig, int width, char pad) {
-
- if ( orig.length() > width ) {
+ /** Produce a formatted/padded string.
+ *
+ * @param orig The string to format.
+ * @param width The width of the resulting formatted string.
+ * @param pad The trailing pad character.
+ *
+ * @return The formatted string, or the original string
+ * if the length is already >= <code>width</code>.
+ */
+ private String format(String orig, int width, char pad)
+ {
+ if (orig.length() >= width)
+ {
return orig;
}
- StringBuffer buf = new StringBuffer().append( orig );
+ StringBuffer buf = new StringBuffer().append(orig);
int diff = width - orig.length();
- for ( int i = 0 ; i < diff ; ++i ) {
- buf.append( pad );
+ for (int i = 0; i < diff; ++i)
+ {
+ buf.append(pad);
}
return buf.toString();
-
}
/** Load the project's maven script.
+ *
+ * @throws Exception if there is an error loading
+ * the project's maven.xml script.
*/
- void loadProjectScript() throws Exception {
+ void loadProjectScript() throws Exception
+ {
File projectScript = getProjectScript();
- if ( ! projectScript.exists() ) {
+ if (!projectScript.exists())
+ {
return;
}
- runScript( projectScript );
+ JellyUtils.runScript(projectScript,
+ null,
+ getJellyContext(),
+ getXMLOutput());
}
/** Attain the goals.
*
* @param goalNames The list of goals to attain.
+ *
+ * @throws UnknownGoalException If one of the specified
+ * goals refers to an non-existent goal.
+ * @throws Exception If an exception occurs while
+ * running a goal.
*/
- void runGoals(List goalNames) throws Exception {
-
+ void runGoals(List goalNames) throws UnknownGoalException, Exception
+ {
com.werken.werkz.Project werkzProject =
- (com.werken.werkz.Project) getJellyContext().getVariable(
"org.apache.commons.jelly.werkz.Project" );
+ (com.werken.werkz.Project) getJellyContext()
+ . getVariable("org.apache.commons.jelly.werkz.Project");
- if ( goalNames.isEmpty() ) {
+ if (goalNames.isEmpty())
+ {
String defaultGoalName = werkzProject.getDefaultGoalName();
-
- if ( defaultGoalName != null ) {
- goalNames.add( defaultGoalName );
- } else {
+
+ if (defaultGoalName != null)
+ {
+ goalNames.add(defaultGoalName);
+ }
+ else
+ {
return;
}
}
Iterator goalNameIter = goalNames.iterator();
String eachGoalName = null;
- Goal eachGoal = null;
+ Goal eachGoal = null;
- while ( goalNameIter.hasNext() ) {
-
+ while (goalNameIter.hasNext())
+ {
eachGoalName = (String) goalNameIter.next();
- eachGoal = werkzProject.getGoal( eachGoalName );
+ eachGoal = werkzProject.getGoal(eachGoalName);
- if ( eachGoal == null ) {
- if ( ! eachGoalName.startsWith( "maven:" ) ) {
+ if (eachGoal == null)
+ {
+ if (!eachGoalName.startsWith("maven:"))
+ {
eachGoalName = "maven:" + eachGoalName;
- eachGoal = werkzProject.getGoal( eachGoalName );
+ eachGoal = werkzProject.getGoal(eachGoalName);
}
-
- if ( eachGoal == null ) {
- throw new UnknownGoalException( eachGoalName );
+
+ if (eachGoal == null)
+ {
+ throw new UnknownGoalException(eachGoalName);
}
}
}
goalNameIter = goalNames.iterator();
- Session session = new JellySession( output );
- // getJellyContext().setUseContextClassLoader( false );
- Thread.currentThread().setContextClassLoader( null );
+ Session session = new JellySession(output);
+
+ Thread.currentThread().setContextClassLoader(null);
- while ( goalNameIter.hasNext() ) {
+ while (goalNameIter.hasNext())
+ {
eachGoalName = (String) goalNameIter.next();
- eachGoal = werkzProject.getGoal( eachGoalName );
+ eachGoal = werkzProject.getGoal(eachGoalName);
- if ( eachGoal == null ) {
- if ( ! eachGoalName.startsWith( "maven:" ) ) {
+ if (eachGoal == null)
+ {
+ if (!eachGoalName.startsWith("maven:"))
+ {
eachGoalName = "maven:" + eachGoalName;
- eachGoal = werkzProject.getGoal( eachGoalName );
+ eachGoal = werkzProject.getGoal(eachGoalName);
}
}
- eachGoal.attain( session );
+ eachGoal.attain(session);
}
}
- /** Compile the first Jelly driver script.
- *
- * @return The compiled script.
- */
- Script compileScript(File scriptFile) throws Exception {
-
- XMLParser parser = new XMLParser();
- parser.setContext( getJellyContext() );
-
- Script script = parser.parse( scriptFile );
-
- script = script.compile();
-
- return script;
- }
-
-
- void runScript(File scriptFile) throws Exception {
- runScript(scriptFile,
- null);
- }
-
- void runScript(File scriptFile,
- URL rootUrl) throws Exception {
-
- Script script = compileScript( scriptFile );
-
- JellyContext context = getJellyContext();
-
- URL oldRoot = context.getRootURL();
- URL oldCurrent = context.getCurrentURL();
-
- if ( rootUrl != null ) {
- context.setRootURL( rootUrl );
- context.setCurrentURL( rootUrl );
- }
-
- script.run( getJellyContext(),
- this.output );
-
- context.setRootURL( oldRoot );
- context.setCurrentURL( oldCurrent );
- }
-
- /** Display help information on the console.
- */
- public void displayHelp() {
- HelpFormatter format = new HelpFormatter();
-
- format.printHelp( "maven [options] [goal [goal2 [goal3] ...]]",
"\nOptions:", this.options, "\n" );
- System.out.println("");
- }
-
/** Parse the command-line.
*
+ * <p>
+ * In addition to parsing the command-line, this will
+ * set the appropriate internal flags an options to
+ * allow for further execution.
+ * </p>
+ *
* @param args The command-line arguments.
*
* @throws ParseException If an error occurs during parsing.
*/
- void parseCommandLine(String[] args) throws ParseException {
-
- this.options = new Options();
-
- this.options.addOption( 'D', "define", true,
- "Define a system property.",
- false, false );
-
- this.options.addOption( 'd', "dir", true,
- "Set effective working directory",
- false, false );
-
- this.options.addOption( 'h', "help", false,
- "Display help information.",
- false, false );
-
- this.options.addOption( 'x', "verbose", false,
- "Produce verbose execution output.",
- false, false );
-
- this.options.addOption( 'X', "debug", false,
- "Produce debug execution output.",
- false, false );
-
- this.options.addOption( 'w', "wisdom", false,
- "Words of wisdom.",
- false, false );
-
- this.options.addOption( 'o', "offline", false,
- "Execute offline.",
- false, false );
-
- this.options.addOption( 'v', "version", false,
- "Display version information",
- false, false );
-
- this.options.addOption( 'g', "goals", false,
- "Display available goals.",
- false, false );
-
- 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.
- */
- boolean processCommandLine()
+ void parseCommandLine(String[] args) throws ParseException
{
- CommandLine cli = getCli();
-
- if ( cli.hasOption( 'h' ) ) {
- displayHelp();
- return false;
- }
+ this.cli = CLIManager.parse(args);
- if ( cli.hasOption( 'd' ) ) {
- setDir( new File( cli.getOptionValue( 'd' ) ) );
+ if (this.cli.hasOption('d'))
+ {
+ setDir(new File(cli.getOptionValue('d')));
}
+
+ setProjectFile(new File(getDir(),
+ PROJECT_DESCRIPTOR_FILE_NAME));
+
+ File projectBuildFile = new File(getDir(),
+ PROJECT_BUILD_FILE_NAME);
- setProjectFile( new File( getDir(), PROJECT_DESCRIPTOR_FILE_NAME ) );
-
- File projectBuildFile = new File( getDir(), PROJECT_BUILD_FILE_NAME );
-
- if ( projectBuildFile.exists() ) {
- setProjectBuildFile( projectBuildFile );
+ if (projectBuildFile.exists())
+ {
+ setProjectBuildFile(projectBuildFile);
}
+ /*
loadPropertiesChain();
if ( cli.hasOption( 'D' ) ) {
@@ -895,10 +928,9 @@
setCliProperty( defStrs[i] );
}
}
+ */
this.goalNames = cli.getArgList();
-
- return true;
}
/** Set a property based upon a commandline
@@ -906,33 +938,29 @@
*
* @param defStr The <code>name=value</code> string.
*/
- void setCliProperty(String defStr) {
-
+ void setCliProperty(String defStr)
+ {
String name = null;
String value = null;
- int equalLoc = defStr.indexOf( "=" );
+ int equalLoc = defStr.indexOf("=");
- if ( equalLoc <= 0 ) {
+ if (equalLoc <= 0)
+ {
name = defStr.trim();
value = "true";
- } else {
- name = defStr.substring( 0,
- equalLoc ).trim();
- value = defStr.substring( equalLoc+1 ).trim();
}
+ else
+ {
+ name = defStr.substring(0,
+ equalLoc).trim();
- this.properties.put( name,
- value );
- }
+ value = defStr.substring(equalLoc + 1).trim();
+ }
- /** Load the maven project descriptor.
- *
- * @throws Exception If an error occurs whilst loading.
- */
- void loadMavenProject() throws Exception {
- this.mavenProject = MavenUtils.getProject( getProjectFile() );
+ this.properties.put(name,
+ value);
}
-
+
/** Load the properties chain.
*
* <p>
@@ -944,37 +972,37 @@
* <li>--system properties--</li>
* </ol>
*/
- void loadPropertiesChain() {
-
+ void loadPropertiesChain()
+ {
Enumeration propNames = System.getProperties().propertyNames();
String eachName = null;
- while ( propNames.hasMoreElements() )
+ while (propNames.hasMoreElements())
{
eachName = (String) propNames.nextElement();
- this.properties.setProperty( eachName,
- System.getProperty( eachName ) );
+ this.properties.setProperty(eachName,
+ System.getProperty(eachName));
}
String propsFileName = null;
File propsFile = null;
- propsFile = new File( getDir(),
- "project.properties" );
+ propsFile = new File(getDir(),
+ "project.properties");
- loadProps( propsFile );
+ loadProps(propsFile);
- propsFile = new File( System.getProperty( "user.home" ),
- "build.properties" );
+ propsFile = new File(System.getProperty("user.home"),
+ "build.properties");
- loadProps( propsFile );
+ loadProps(propsFile);
- propsFile = new File( getDir(),
- "build.properties" );
+ propsFile = new File(getDir(),
+ "build.properties");
- loadProps( propsFile );
+ loadProps(propsFile);
}
@@ -983,27 +1011,39 @@
*
* @param propsFile The properties file to load.
*/
- void loadProps(File propsFile) {
-
- if ( ! propsFile.exists() ) {
- log.debug( "No properties file: " + propsFile );
- } else {
- log.debug( "Properties file: " + propsFile );
+ void loadProps(File propsFile)
+ {
+ if (!propsFile.exists())
+ {
+ log.debug("No properties file: " + propsFile);
+ }
+ else
+ {
+ log.debug("Properties file: " + propsFile);
}
FileInputStream in = null;
- try {
- in = new FileInputStream( propsFile );
- this.properties.load( in );
- } catch (IOException e) {
+ try
+ {
+ in = new FileInputStream(propsFile);
+ this.properties.load(in);
+ }
+ catch (IOException e)
+ {
// ignore
- } finally {
- try {
- if ( in != null ) {
+ }
+ finally
+ {
+ try
+ {
+ if (in != null)
+ {
in.close();
}
- } catch (IOException e) {
+ }
+ catch (IOException e)
+ {
// ignore
}
}
@@ -1013,64 +1053,92 @@
*
* @param args Command-line arguments.
*/
- public void doMain(String[] args) {
+ public void doMain(String[] args)
+ {
+ boolean done = false;
+
+ try
+ {
+ initializeCore(args);
+ }
+ catch (ParseException e)
+ {
+ System.err.println(e.getLocalizedMessage());
+ CLIManager.displayHelp();
+ done = true;
+ }
+ catch (IOException e)
+ {
+ System.err.println(e.getLocalizedMessage());
+ done = true;
+ }
+ catch (SAXException e)
+ {
+ System.err.println(e.getLocalizedMessage());
+ done = true;
+ }
+ catch (IntrospectionException e)
+ {
+ System.err.println(e.getLocalizedMessage());
+ done = true;
+ }
- try {
- if ( ! initialize( args ) ) {
- return;
- }
- } catch (Exception e) {
- System.err.println( "Error initializing: " + e.getLocalizedMessage() );
- // e.printStackTrace();
+ if (done)
+ {
+ System.out.println("");
return;
}
- Project mavenProject = getMavenProject();
-
- System.out.println( "" );
- System.out.println( " maven: intelligent projects" );
- System.out.println( "" );
+ if (getCli().hasOption('h'))
+ {
+ CLIManager.displayHelp();
+ System.out.println("");
+ return;
+ }
- System.out.println( "project-directory: "
- + getDir() );
- System.out.println( " project: "
- + mavenProject.getName()
- + " (" + mavenProject.getId() + ")" );
+ Project mavenProject = getProjectDescriptor().getProject();
- System.out.println( " current-version: "
- + mavenProject.getCurrentVersion() );
+ System.out.println("");
+ System.out.println(" maven: intelligent projects");
+ System.out.println("");
+ System.out.println("project-directory: "
+ + getDir());
+ System.out.println(" project: "
+ + mavenProject.getName()
+ + " (" + mavenProject.getId() + ")");
+ System.out.println(" current-version: "
+ + mavenProject.getCurrentVersion());
+ System.out.println("");
- try {
+ try
+ {
+ initializePlugins();
- if ( this.cli.hasOption( 'g' ) ) {
+ if (this.cli.hasOption('g'))
+ {
displayGoals();
- } else {
- attainGoals();
}
-
- System.out.println( "" );
-
- writer.flush();
- writer.close();
-
- } catch (UnknownGoalException e) {
- System.err.println( "BUILD FAILED" );
- System.err.println( "Goal \"" + e.getGoalName() + "\" does not exist in
this project." );
- System.out.println( "" );
-
- try
+ else
{
- writer.flush();
- writer.close();
- }catch (Exception i) {
- // ignore
+ attainGoals();
}
-
- return;
- } catch (Exception e) {
- // System.err.println( e.getLocalizedMessage() );
- System.out.println( "" );
}
+ catch (UnknownGoalException e)
+ {
+ System.err.println("BUILD FAILED");
+ System.err.println("Goal \"" + e.getGoalName()
+ + "\" does not exist in this project.");
+ }
+ catch (JellyException e)
+ {
+ System.err.println(e.getLocalizedMessage());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ System.out.println("");
}
@@ -1082,9 +1150,10 @@
*
* @param args The command-line arguments.
*/
- public static void main(String[] args) {
+ public static void main(String[] args)
+ {
Maven maven = new Maven();
- maven.doMain( args );
+ maven.doMain(args);
}
}
1.4 +79 -42
jakarta-turbine-maven/src/java/org/apache/maven/app/MavenJellyContext.java
Index: MavenJellyContext.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/app/MavenJellyContext.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MavenJellyContext.java 19 Jun 2002 17:21:53 -0000 1.3
+++ MavenJellyContext.java 24 Jun 2002 18:33:19 -0000 1.4
@@ -76,8 +76,8 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">bob mcwhirter</a>
*/
-public class MavenJellyContext extends JellyContext {
-
+public class MavenJellyContext extends JellyContext
+{
/** Backing properties. */
private Hashtable props;
@@ -90,10 +90,12 @@
/** Construct.
*
* @param rootContext The root context.
+ * @param props Backing-store of properties.
*/
public MavenJellyContext(URL rootContext,
- Hashtable props ) {
- super( rootContext );
+ Hashtable props)
+ {
+ super(rootContext);
this.props = props;
@@ -104,7 +106,8 @@
*
* @param antProject The ant Project.
*/
- public void setAntProject(Project antProject) {
+ public void setAntProject(Project antProject)
+ {
this.antProject = antProject;
}
@@ -112,7 +115,8 @@
*
* @return The ant project.
*/
- public Project getAntProject() {
+ public Project getAntProject()
+ {
return this.antProject;
}
@@ -129,11 +133,12 @@
* @param taglib The tag-lib to register.
*/
public void registerTagLibrary(String namespaceURI,
- TagLibrary taglib) {
-
- if ( ! isTagLibraryRegistered( namespaceURI ) ) {
- super.registerTagLibrary( namespaceURI,
- taglib );
+ TagLibrary taglib)
+ {
+ if (!isTagLibraryRegistered(namespaceURI))
+ {
+ super.registerTagLibrary(namespaceURI,
+ taglib);
}
}
@@ -150,50 +155,73 @@
* @param className The class name of the tag-lib to register.
*/
public void registerTagLibrary(String namespaceURI,
- String className) {
- if ( ! isTagLibraryRegistered( namespaceURI ) ) {
- super.registerTagLibrary( namespaceURI,
- className );
+ String className)
+ {
+ if (!isTagLibraryRegistered(namespaceURI))
+ {
+ super.registerTagLibrary(namespaceURI,
+ className);
}
}
- public void setVariable(String name, Object value) {
- super.setVariable(name, value);
- }
-
- public void setScopedVariable(String name, Object value) {
- super.setScopedVariable(name, value);
- }
-
- public Object getVariable(String name) {
- Object value = super.getVariable( name );
+ /** Retrieve a variable.
+ *
+ * @param name The name of the variable.
+ *
+ * @return The value of the variable, if set, otherwise
+ * <code>null</code>.
+ */
+ public Object getVariable(String name)
+ {
+ Object value = super.getVariable(name);
- if ( value == null ) {
- value = this.props.get( name );
+ if (value == null)
+ {
+ value = this.props.get(name);
}
- if ( value instanceof String ) {
- value = ProjectHelper.replaceProperties(getAntProject(), (String)
value, this.asProps);
+ if (value instanceof String)
+ {
+ value = ProjectHelper.replaceProperties(getAntProject(),
+ (String) value,
+ this.asProps);
}
return value;
}
- public Object getScopedVariable(String name) {
- Object value = super.getScopedVariable( name );
+ /** Retrieve a scoped variable.
+ *
+ * @param name The name of the variable.
+ *
+ * @return The value of the variable, if set, otherwise
+ * <code>null</code>.
+ */
+ public Object getScopedVariable(String name)
+ {
+ Object value = super.getScopedVariable(name);
- if ( value == null ) {
- value = this.props.get( name );
+ if (value == null)
+ {
+ value = this.props.get(name);
}
- if ( value instanceof String ) {
- value = ProjectHelper.replaceProperties(getAntProject(), (String)
value, this.asProps);
+ if (value instanceof String)
+ {
+ value = ProjectHelper.replaceProperties(getAntProject(),
+ (String) value,
+ this.asProps);
}
return value;
}
- public Hashtable asProperties() {
+ /** Retrieve this context as a <code>Hashtable</code>.
+ *
+ * @return This context as a <code>Hashtable</code>.
+ */
+ public Hashtable asProperties()
+ {
return this.asProps;
}
@@ -209,8 +237,9 @@
* @return <code>true</code> if an object is bound to the
* specific key, otherwise <code>false</code>.
*/
- public boolean containsKey(Object key) {
- return (getVariable( (String) key ) != null);
+ public boolean containsKey(Object key)
+ {
+ return (getVariable((String) key) != null);
}
/** Retrieve the object bound to a specific key.
@@ -221,12 +250,20 @@
* <code>null</code> if no object has been
* bound to the key.
*/
- public Object get(Object key) {
- return getVariable( (String) key );
+ public Object get(Object key)
+ {
+ return getVariable((String) key);
}
- public String toString() {
- return "[GrantPropsHandler.JellyProps: context=" +
MavenJellyContext.this + "]";
+ /** Produce output suitable for debugging.
+ *
+ * @return Output suitable for debugging.
+ */
+ public String toString()
+ {
+ return "[GrantPropsHandler.JellyProps: context="
+ + MavenJellyContext.this
+ + "]";
}
}
}
1.2 +7 -5
jakarta-turbine-maven/src/java/org/apache/maven/app/UnknownGoalException.java
Index: UnknownGoalException.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/app/UnknownGoalException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnknownGoalException.java 14 Jun 2002 04:34:01 -0000 1.1
+++ UnknownGoalException.java 24 Jun 2002 18:33:19 -0000 1.2
@@ -60,8 +60,8 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">bob mcwhirter</a>
*/
-public class UnknownGoalException extends Exception {
-
+public class UnknownGoalException extends Exception
+{
/** Name of unknown goal. */
private String goalName;
@@ -69,8 +69,9 @@
*
* @param goalName The name of the unknown goal.
*/
- public UnknownGoalException(String goalName) {
- super( "Unknown goal \"" + goalName + "\"" );
+ public UnknownGoalException(String goalName)
+ {
+ super("Unknown goal \"" + goalName + "\"");
this.goalName = goalName;
}
@@ -78,7 +79,8 @@
*
* @return The name of the unknown goal.
*/
- public String getGoalName() {
+ public String getGoalName()
+ {
return this.goalName;
}
}
1.1
jakarta-turbine-maven/src/java/org/apache/maven/app/CLIManager.java
Index: CLIManager.java
===================================================================
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.commons.cli.Options;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.ParseException;
/** Utility for managing and parsing Maven's command-line.
*
* <p>
* <b>implementation note:</b> This is the class to modify when
* adding, removing or modifying Maven's command-line options
* and flags.
* </p>
*
* <p>
* This class uses the
* <a href="http://jakarta.apache.org/commons/cli/">commons-cli</a>
* library for command-line parsing.
* </p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">bob mcwhirter</a>
*/
public class CLIManager
{
/** Maven't command-line option configuration. */
private static Options options = null;
/** Configure the option set. */
static
{
options = new Options();
options.addOption('D', "define", true,
"Define a system property.",
false, false);
options.addOption('d', "dir", true,
"Set effective working directory",
false, false);
options.addOption('h', "help", false,
"Display help information.",
false, false);
options.addOption('x', "verbose", false,
"Produce verbose execution output.",
false, false);
options.addOption('X', "debug", false,
"Produce debug execution output.",
false, false);
options.addOption('w', "wisdom", false,
"Words of wisdom.",
false, false);
options.addOption('o', "offline", false,
"Execute offline.",
false, false);
options.addOption('v', "version", false,
"Display version information",
false, false);
options.addOption('g', "goals", false,
"Display available goals.",
false, false);
}
/** Parse a string-array of command-line arguments.
*
* <p>
* This will parse the arguments against the configured
* maven command-line options, and return a <code>CommandLine</code>
* object which may be queried for the presence of flags
* and options and their arguments, if any.
* </p>
*
* @see http://jakarta.apache.org/commons/cli/
*
* @param args The command-line arguments to parse.
*
* @return The parsed <code>CommandLine</code> result.
*
* @throws ParseException If an error occurs while parsing
* the command-line options.
*/
public static CommandLine parse(String[] args) throws ParseException
{
return options.parse(args);
}
/** Display usage information based upon current
* command-line option configuration.
*/
public static void displayHelp()
{
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("maven [options] [goal [goal2 [goal3] ...]]",
"\nOptions:",
options,
"\n");
}
}
1.1
jakarta-turbine-maven/src/java/org/apache/maven/app/JellyUtils.java
Index: JellyUtils.java
===================================================================
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.commons.jelly.JellyContext;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.parser.XMLParser;
import java.io.File;
import java.net.URL;
/** Utilities for Jelly.
*
* @see <a href="http://jakarta.apache.org/commons/sandbox/jelly/">commons-jelly</a>
*
* @author <a href="mailto:[EMAIL PROTECTED]">bob mcwhirter</a>
*/
public class JellyUtils
{
/** Run a jelly script.
*
* @param scriptFile Location of the script to run.
* @param rootUrl Root explicit context of the script.
* @param context Jelly context.
* @param output Output sink.
*
* @throws Exception If an error occurs while locating,
* compiling or executing the script.
*/
public static void runScript(File scriptFile,
URL rootUrl,
JellyContext context,
XMLOutput output) throws Exception
{
URL oldRoot = context.getRootURL();
URL oldCurrent = context.getCurrentURL();
if (rootUrl != null)
{
context.setRootURL(rootUrl);
context.setCurrentURL(rootUrl);
}
Script script = compileScript(scriptFile,
context);
script.run(context,
output);
context.setRootURL(oldRoot);
context.setCurrentURL(oldCurrent);
}
/** Compile a jelly script.
*
* @param scriptFile Location of the script to run.
* @param context Jelly context.
*
* @throws Exception If an error occurs while locating
* or compiling the script.
*
* @return The compiled script.
*/
public static Script compileScript(File scriptFile,
JellyContext context) throws Exception
{
XMLParser parser = new XMLParser();
parser.setContext(context);
Script script = parser.parse(scriptFile);
script = script.compile();
return script;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>