werken      2002/06/13 14:37:33

  Modified:    .        jars.list project.xml
               src/bin  core-plugin.jelly driver.jelly maven plugins.jelly
               xdocs    quotes.txt
  Added:       src/java/org/apache/maven/app Maven.java
                        MavenAntProject.java MavenJellyContext.java
  Log:
  More work towards app-ifying and jelly-izing maven.
  
    - We now have a trul main() for maven
    - Integrated with Jelly, Werkz and Ant
  
  Still needs more polishing before porting maven to it.
  
  Revision  Changes    Path
  1.21      +3 -3      jakarta-turbine-maven/jars.list
  
  Index: jars.list
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/jars.list,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- jars.list 13 Jun 2002 06:13:41 -0000      1.20
  +++ jars.list 13 Jun 2002 21:37:33 -0000      1.21
  @@ -33,7 +33,6 @@
   commons-digester-1.2.jar
   commons-graph-0.8.jar
   commons-io-0.1.jar
  -commons-jelly-1.0-dev.20020613.055722.jar
   commons-jexl-1.0-dev.jar
   commons-lang-1.0-dev.jar
   commons-logging-1.0.jar
  @@ -41,11 +40,12 @@
   dom4j-1.4-dev.jar
   jdepend-2.2.jar
   junit-3.7.jar
  -log4j-1.1.3.jar
  +logkit-1.0.1.jar
   oro-2.0.6.jar
   regexp-1.2.jar
   velocity-1.4-dev.jar
   velocity-dvsl-0.43.jar
   xercesImpl-2.0.0.jar
   xmlParserAPIs-2.0.0.jar
  -# werkz-1.0-build-2.jar
  +werkz-1.0-dev.20020613.091536.jar
  +commons-jelly-1.0-dev.20020613.091851.jar
  
  
  
  1.109     +9 -3      jakarta-turbine-maven/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/project.xml,v
  retrieving revision 1.108
  retrieving revision 1.109
  diff -u -r1.108 -r1.109
  --- project.xml       13 Jun 2002 10:46:23 -0000      1.108
  +++ project.xml       13 Jun 2002 21:37:33 -0000      1.109
  @@ -312,7 +312,7 @@
   
       <dependency>
         <id>commons-jelly</id>
  -      <version>1.0-dev.20020613.055722</version>
  +      <version>1.0-dev.20020613.091851</version>
         <url>http://jakarta.apache.org/commons/sandbox/jelly/</url>
       </dependency>
   
  @@ -352,12 +352,18 @@
       </dependency>
   
       <!-- Runtime dependencies -->
  -
  +<!--
       <dependency>
         <id>log4j</id>
         <version>1.1.3</version>
         <url>http://jakarta.apache.org/log4j/</url>
       </dependency>
  +-->
  +
  +    <dependency>
  +      <id>logkit</id>
  +      <version>1.0.1</version>
  +    </dependency>
   
       <dependency>
         <id>commons-lang</id>
  @@ -494,7 +500,7 @@
   
       <jarResources>
           <jarResource>include = *.dtd</jarResource>
  -        <jarResource>include = log4j.properties</jarResource>
  +<!--        <jarResource>include = log4j.properties</jarResource> -->
           <jarResource>include = maven-taskdefs.properties</jarResource>
       </jarResources>
   
  
  
  
  1.2       +12 -1     jakarta-turbine-maven/src/bin/core-plugin.jelly
  
  Index: core-plugin.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/bin/core-plugin.jelly,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- core-plugin.jelly 13 Jun 2002 05:25:17 -0000      1.1
  +++ core-plugin.jelly 13 Jun 2002 21:37:33 -0000      1.2
  @@ -6,6 +6,18 @@
       xmlns="jelly:core">
   
       <werkz:project>
  +        <werkz:goal
  +          name="maven:env">
  +
  +        <ant:echo>
  +          <whitespace>
  +           maven.home = <expr value="${maven.home}"/>
  +            maven.bin = <expr value="${maven.bin}"/>
  +              basedir = <expr value="${basedir}"/>
  +          </whitespace>
  +        </ant:echo>
  +
  +        </werkz:goal>
   
           <werkz:goal 
             name="maven:prepare-source">
  @@ -32,7 +44,6 @@
           <werkz:goal 
             name="maven:jar" 
             prereqs="maven:compile, maven:test">
  -
           </werkz:goal>
   
       </werkz:project>
  
  
  
  1.3       +4 -5      jakarta-turbine-maven/src/bin/driver.jelly
  
  Index: driver.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/bin/driver.jelly,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- driver.jelly      13 Jun 2002 05:54:54 -0000      1.2
  +++ driver.jelly      13 Jun 2002 21:37:33 -0000      1.3
  @@ -7,13 +7,12 @@
   
       <werkz:project>
   
  -      <import uri="banner.jelly"/>
  -      <import uri="init.jelly"/>
  -      <import uri="plugins.jelly"/>
  +      <include uri="init.jelly"/>
  +      <include uri="plugins.jelly"/>
   
         <werkz:attain>
  -          <forEach var="arg" items="${args}" begin="1">
  -              <werkz:attainGoal name="${arg}"/>
  +          <forEach var="goal" items="${goals}">
  +              <werkz:attainGoal name="${goal}"/>
             </forEach>
         </werkz:attain>
   
  
  
  
  1.4       +3 -1      jakarta-turbine-maven/src/bin/maven
  
  Index: maven
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/bin/maven,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- maven     13 Jun 2002 05:25:17 -0000      1.3
  +++ maven     13 Jun 2002 21:37:33 -0000      1.4
  @@ -146,5 +146,7 @@
   
   ## echo $LOCALCLASSPATH
   
  +MAIN_CLASS=org.apache.maven.app.Maven
  +
   $JAVACMD -classpath "$LOCALCLASSPATH" -Dmaven.home="${MAVEN_HOME}" $MAVEN_OPTS \
  -    org.apache.commons.jelly.Jelly file://${MAVEN_HOME}/bin/driver.jelly 
$MAVEN_ARGS "$@"
  +    $MAIN_CLASS $MAVEN_ARGS "$@"
  
  
  
  1.2       +1 -1      jakarta-turbine-maven/src/bin/plugins.jelly
  
  Index: plugins.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/bin/plugins.jelly,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- plugins.jelly     13 Jun 2002 05:25:17 -0000      1.1
  +++ plugins.jelly     13 Jun 2002 21:37:33 -0000      1.2
  @@ -3,7 +3,7 @@
       trim="true"
       xmlns="jelly:core">
   
  -    <import uri="core-plugin.jelly"/>
  +    <include uri="core-plugin.jelly"/>
   
   </jelly>
   
  
  
  
  1.1                  jakarta-turbine-maven/src/java/org/apache/maven/app/Maven.java
  
  Index: Maven.java
  ===================================================================
  
  package org.apache.maven.app;
  
  import org.apache.maven.MavenUtils;
  
  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.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.tags.ant.AntTagLibrary;
  
  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.util.List;
  import java.util.Properties;
  import java.util.Enumeration;
  
  public class Maven 
  {
      private final static Log log = LogFactory.getLog( Maven.class );
  
      public static final String PROJECT_BUILD_FILE_NAME      = "build.maven";
      public static final String PROJECT_DESCRIPTOR_FILE_NAME = "project.xml";
  
      public static final String MAVEN_DRIVER_FILE_NAME       = "driver.jelly";
  
      private Options options;
      private CommandLine cli;
  
      private File mavenHome;
      private File mavenBin;
  
      private File dir;
      private File projectFile;
      private File projectBuildFile;
  
      private List goalNames;
  
      private Properties properties;
  
      private org.apache.maven.project.Project mavenProject;
  
      private JellyContext jellyContext;
  
      public Maven() {
          this.properties = new Properties();
      }
  
      public void setProjectFile(File projectFile) {
          this.projectFile = projectFile;
      }
  
      public File getProjectFile() {
          return this.projectFile;
      }
  
      public void setProjectBuildFile(File projectBuildFile) {
          this.projectBuildFile = projectBuildFile;
      }
  
      public File getProjectBuildFile() {
          return this.projectBuildFile;
      }
  
      public boolean hasProjectBuildFile() {
          return (this.projectBuildFile != null);
      }
  
      public org.apache.maven.project.Project getMavenProject() {
          return this.mavenProject;
      }
  
      public void setDir(File dir) {
          this.dir = dir;
      }
  
      public void setMavenHome(File mavenHome) {
          this.mavenHome = mavenHome;
          this.mavenBin = new File( mavenHome,
                                    "bin" );
      }
  
      public File getMavenHome() {
          return this.mavenHome;
      }
  
      public File getMavenBin() {
          return this.mavenBin;
      }
  
      public File getDir() {
          if ( this.dir == null ) {
              this.dir = new File( System.getProperty( "user.dir" ) );
          }
  
          return this.dir;
      }
  
      public List getGoalNames() {
          return this.goalNames;
      }
  
      public Properties getProperties() {
          return this.properties;
      }
  
      public String toString() {
          return "[Maven: mavenHome=" + getMavenHome()
              + "; dir=" + getDir()
              + "; projectFile=" + getProjectFile()
              + "; goalNames=" + getGoalNames()
              + "; props=" + getProperties()
              + "]";
      }
  
      public void initialize(String[] args) throws Exception {
  
          setMavenHome( new File( System.getProperty( "maven.home" ) ) );
  
          try {
              parseCommandLine( args );
          } catch (ParseException e) {
              System.err.println( e.getLocalizedMessage() );
              displayHelp();
              return;
          }
          
          processCommandLine();
  
          log.debug( this.toString() );
  
          loadMavenProject();
          initializeJelly();
          // run();
      }
  
      JellyContext getJellyContext() {
          return this.jellyContext;
      }
  
      void initializeJelly() throws Exception {
  
          this.jellyContext = new MavenJellyContext( getMavenBin().toURL() );
          
          Enumeration propNames = this.properties.propertyNames();
          String      eachName  = null;
  
          while ( propNames.hasMoreElements() )
          {
              eachName = (String) propNames.nextElement();
  
              this.jellyContext.setVariable( eachName,
                                             this.properties.getProperty( eachName ) );
          }
  
          this.jellyContext.setVariable( "maven.home",
                                         getMavenHome() );
  
          this.jellyContext.setVariable( "maven.bin",
                                         getMavenBin() );
  
          this.jellyContext.setVariable( "basedir",
                                         getDir() );
  
          MavenAntProject antProject = initializeAntProject( this.jellyContext );
          AntTagLibrary antTagLib = new AntTagLibrary( antProject );
  
          this.jellyContext.registerTagLibrary( "jelly:ant",
                                                antTagLib );
  
          if ( hasProjectBuildFile() ) {
              this.jellyContext.setVariable( "maven.project.buildFile.url",
                                             getProjectBuildFile().toURL() );
          }
      }
  
      MavenAntProject initializeAntProject(JellyContext context) {
          MavenAntProject antProject = new MavenAntProject( context );
  
          antProject.init();
  
          return antProject;
      }
  
      void run() throws Exception {
  
          Writer writer = new BufferedWriter(new OutputStreamWriter(System.out));
          Script script = compileScript();
          XMLOutput output = XMLOutput.createXMLOutput(writer);
          
          JellyContext context = getJellyContext();
  
          context.setVariable("goals", getGoalNames() );
          script.run(context, output);
  
          writer.close();
      }
  
      public Script compileScript() throws Exception {
  
          XMLParser parser = new XMLParser();
          parser.setContext( getJellyContext() );
  
          File driverFile = new File( getMavenBin(),
                                      MAVEN_DRIVER_FILE_NAME );
  
          Script script = parser.parse( driverFile );
  
          script = script.compile();
  
          return script;
      }
      public void displayHelp() {
          HelpFormatter format = new HelpFormatter();
          
          format.printHelp( "maven [options] [gaol [goal2 [goal3] ...]]", "Options:", 
this.options, "\n" );
      }
  
      void parseCommandLine(String[] args) throws ParseException {
  
          this.options = new Options();
          
          this.options.addOption( 'D', "define", true,
                                  "Define a system property.",
                                  false, true );
          
          this.options.addOption( 'd', "dir", true,
                                  "Set effective working directory",
                                  false, false );
  
          this.options.addOption( 'h', "help", false,
                                  "Display help information.",
                                  false, false );
          
          this.cli = this.options.parse( args );
      }
  
      CommandLine getCli() {
          return this.cli;
      }
  
      void processCommandLine()
      {
          CommandLine cli = getCli();
  
          if ( cli.hasOption( 'h' ) ) {
              displayHelp();
              return;
          }
  
          if ( 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 );
  
          if ( projectBuildFile.exists() ) {
              setProjectBuildFile( projectBuildFile );
          }
  
          loadPropertiesChain();
  
          if ( cli.hasOption( 'D' ) ) {
              // cache command-line specified properties.
          }
  
          this.goalNames = cli.getArgList();
      }
  
      void loadMavenProject() throws Exception {
          this.mavenProject = MavenUtils.getProject( getProjectFile() );
      }
      
      void loadPropertiesChain() {
  
          Enumeration propNames = System.getProperties().propertyNames();
          String      eachName  = null;
  
          while ( propNames.hasMoreElements() )
          {
              eachName = (String) propNames.nextElement();
  
              this.properties.setProperty( eachName,
                                           System.getProperty( eachName ) );
          }
  
          String propsFileName = null;
  
          File propsFile = null;
  
          propsFile = new File( getDir(),
                                "project.properties" );
          
          loadProps( propsFile );
          
          propsFile = new File( System.getProperty( "user.home" ),
                                "build.properties" );
          
          loadProps( propsFile );
          
          propsFile = new File( getDir(),
                                "build.properties" );
  
          loadProps( 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) {
              // ignore
          } finally {
              try {
                  if ( in != null ) {
                      in.close();
                  }
              } catch (IOException e) {
                  // ignore
              }
          }
      }
  
      
      public static void main(String[] args) {
          // log.info( "maven: intelligent projects" );
  
          System.out.println( "            maven: intelligent projects" );
          System.out.println( "" );
  
          Maven maven = new Maven();
  
          try {
              maven.initialize( args );
          } catch (Exception e) {
              System.err.println( "Error initializing: " + e.getLocalizedMessage() );
              e.printStackTrace();
              return;
          }
  
          org.apache.maven.project.Project mavenProject = maven.getMavenProject();
  
          System.out.println( "project-directory: "
                              + maven.getDir() );
          System.out.println( "          project: "
                              + mavenProject.getName()
                              + " (" + mavenProject.getId() + ")" );
  
          System.out.println( "  current-version: "
                              + mavenProject.getCurrentVersion() );
  
          System.out.println( "" );
  
          try
          {
              maven.run();
          }
          catch (Exception e)
          {
              e.printStackTrace();
          }
      }
  }
  
  
  
  1.1                  
jakarta-turbine-maven/src/java/org/apache/maven/app/MavenAntProject.java
  
  Index: MavenAntProject.java
  ===================================================================
  
  package org.apache.maven.app;
  
  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 java.util.Hashtable;
  
  public class MavenAntProject extends Project
  {
      private Hashtable props;
      JellyContext context;
  
      public MavenAntProject(JellyContext context) {
          this.context = context;
          props = new JellyProps();
      }
  
      public String replaceProperties(String value) throws BuildException {
          return ProjectHelper.replaceProperties(this, value, this.props);
      }
  
      public void setProperty(String name, String value) {
          context.setScopedVariable( name, 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 );
      }
  
      public Hashtable getProperties() {
          return this.props;
      }
  
      class JellyProps extends Hashtable
      {
          public boolean containsKey(Object key) {
              return (context.getScopedVariable( (String) key ) != null);
          }
          
          public Object get(Object key) {
              return context.getScopedVariable( (String) key );
          }
      }
  }
  
  
  
  1.1                  
jakarta-turbine-maven/src/java/org/apache/maven/app/MavenJellyContext.java
  
  Index: MavenJellyContext.java
  ===================================================================
  
  package org.apache.maven.app;
  
  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.TagLibrary;
  
  import java.net.URL;
  
  public class MavenJellyContext extends JellyContext {
  
      public MavenJellyContext(URL rootContext) {
          super( rootContext );
      }
  
      public void registerTagLibrary(String namespaceURI,
                                     TagLibrary taglib) {
  
          if ( ! isTagLibraryRegistered( namespaceURI ) ) {
              super.registerTagLibrary( namespaceURI,
                                        taglib );
          }
      }
  
      public void registerTagLibrary(String namespaceURI,
                                     String className) {
          if ( ! isTagLibraryRegistered( namespaceURI ) ) {
              super.registerTagLibrary( namespaceURI,
                                        className );
          }
      }
  
      public TagLibrary getTagLibrary(String namespaceURI) {
          return super.getTagLibrary( namespaceURI );
      }
  }
  
  
  
  1.2       +1 -0      jakarta-turbine-maven/xdocs/quotes.txt
  
  Index: quotes.txt
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/xdocs/quotes.txt,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- quotes.txt        13 Jun 2002 14:35:44 -0000      1.1
  +++ quotes.txt        13 Jun 2002 21:37:33 -0000      1.2
  @@ -1,2 +1,3 @@
   ant is our bitch slave.
   Jelly: fascinating but evil.
  +dom4j is hurting me again. --James Taylor
  
  
  

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

Reply via email to