ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor Embeddor.java MyrmidonEmbeddor.java
Date Tue, 29 May 2001 07:13:14 GMT
donaldp     01/05/29 00:13:14

  Modified:    proposal/myrmidon/src/java/org/apache/ant Main.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor
                        Embeddor.java MyrmidonEmbeddor.java
  Added:       proposal/myrmidon/src/java/org/apache/myrmidon/components/builder
                        DefaultProjectBuilder.java ProjectBuilder.java
  Removed:     proposal/myrmidon/src/java/org/apache/ant/project
                        DefaultProjectBuilder.java ProjectBuilder.java
  Log:
  Migrate ProjectBuilderss to separate package
  
  Revision  Changes    Path
  1.19      +13 -14    jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/Main.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Main.java	2001/05/29 06:56:18	1.18
  +++ Main.java	2001/05/29 07:13:12	1.19
  @@ -20,21 +20,12 @@
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  -import org.apache.myrmidon.launcher.LauncherClassLoader;
   import org.apache.ant.project.LogTargetToListenerAdapter;
  -import org.apache.myrmidon.model.Project;
  -import org.apache.ant.project.ProjectBuilder;
   import org.apache.ant.project.ProjectEngine;
  -import org.apache.myrmidon.listeners.ProjectListener;
  -import org.apache.myrmidon.components.embeddor.Embeddor;
  -import org.apache.myrmidon.components.embeddor.MyrmidonEmbeddor;
  -import org.apache.myrmidon.api.JavaVersion;
  -import org.apache.myrmidon.api.TaskContext;
  -import org.apache.myrmidon.api.DefaultTaskContext;
   import org.apache.avalon.excalibur.cli.CLArgsParser;
   import org.apache.avalon.excalibur.cli.CLOption;
  -import org.apache.avalon.excalibur.cli.CLUtil;
   import org.apache.avalon.excalibur.cli.CLOptionDescriptor;
  +import org.apache.avalon.excalibur.cli.CLUtil;
   import org.apache.avalon.excalibur.io.ExtensionFileFilter;
   import org.apache.avalon.framework.ExceptionUtil;
   import org.apache.avalon.framework.activity.Disposable;
  @@ -45,9 +36,17 @@
   import org.apache.avalon.framework.logger.AbstractLoggable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.log.Hierarchy;
  -import org.apache.log.Logger;
   import org.apache.log.LogTarget;
  +import org.apache.log.Logger;
   import org.apache.log.Priority;
  +import org.apache.myrmidon.api.DefaultTaskContext;
  +import org.apache.myrmidon.api.TaskContext;
  +import org.apache.myrmidon.components.builder.ProjectBuilder;
  +import org.apache.myrmidon.components.embeddor.Embeddor;
  +import org.apache.myrmidon.components.embeddor.MyrmidonEmbeddor;
  +import org.apache.myrmidon.launcher.LauncherClassLoader;
  +import org.apache.myrmidon.listeners.ProjectListener;
  +import org.apache.myrmidon.model.Project;
   
   /**
    * The class to kick the tires and light the fires.
  @@ -227,7 +226,7 @@
               System.err.println( "Error: " + parser.getErrorString() );
               return;
           }
  -        
  +
           final List clOptions = parser.getArguments();
           final int size = clOptions.size();
           final ArrayList targets = new ArrayList();
  @@ -408,11 +407,11 @@
               throw new AntException( "Unknown log level - " + logLevel );
           }
   
  -        final Logger logger = 
  +        final Logger logger =
               Hierarchy.getDefaultHierarchy().getLoggerFor( "ant" );
   
           logger.setPriority( priority );
  -        
  +
           return logger;
       }
   
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java
  
  Index: DefaultProjectBuilder.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.myrmidon.components.builder;
  
  import java.io.File;
  import java.io.IOException;
  import org.apache.ant.AntException;
  import org.apache.ant.util.Condition;
  import org.apache.avalon.framework.ExceptionUtil;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.log.Logger;
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.model.DefaultProject;
  import org.apache.myrmidon.model.DefaultTarget;
  import org.apache.myrmidon.model.Project;
  import org.apache.myrmidon.model.Target;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  
  /**
   * Default implementation to construct project from a build file.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class DefaultProjectBuilder
      extends AbstractLoggable
      implements ProjectBuilder
  {
      protected DefaultConfigurationBuilder  m_builder;
  
      public DefaultProjectBuilder()
      {
          m_builder = new DefaultConfigurationBuilder();
      }
  
      /**
       * build a project from file.
       *
       * @param source the source
       * @return the constructed Project
       * @exception IOException if an error occurs
       * @exception AntException if an error occurs
       */
      public Project build( final File projectFile )
          throws IOException, AntException
      {
          try
          {
              final String location = projectFile.getCanonicalFile().toString();
              final Configuration configuration = buildConfiguration( location );
              return build( projectFile, configuration );
          }
          catch( final ConfigurationException ce )
          {
              throw new AntException( "ConfigurationException: " + ce.getMessage(), ce );
          }
      }
  
      /**
       * Utility method to build a Configuration tree from a source.
       * Overide this in sub-classes if you want to provide extra
       * functionality (ie xslt/css).
       *
       * @param location the location
       * @return the created Configuration
       * @exception AntException if an error occurs
       * @exception IOException if an error occurs
       */
      protected Configuration buildConfiguration( final String location )
          throws AntException, IOException, ConfigurationException
      {
          try
          {
              return (Configuration)m_builder.buildFromFile( location );
          }
          catch( final SAXException se )
          {
              throw new AntException( "SAXEception: " + se.getMessage(), se );
          }
      }
  
      /**
       * build project from configuration.
       *
       * @param file the file from which configuration was loaded
       * @param configuration the configuration loaded
       * @return the created Project
       * @exception IOException if an error occurs
       * @exception AntException if an error occurs
       * @exception ConfigurationException if an error occurs
       */
      protected Project build( final File file, final Configuration configuration )
          throws IOException, AntException, ConfigurationException
      {
          if( !configuration.getName().equals("project") )
          {
              throw new AntException( "Project file must be enclosed in project element" );
          }
  
          //get project-level attributes
          final String baseDirectoryName = configuration.getAttribute( "basedir" );
          final String defaultTarget = configuration.getAttribute( "default" );
          //final String name = configuration.getAttribute( "name" );
  
          //determine base directory for project
          final File baseDirectory =
              (new File( file.getParentFile(), baseDirectoryName )).getAbsoluteFile();
  
          getLogger().debug( "Project " + file + " base directory: " + baseDirectory );
  
          //create project and ...
          final DefaultProject project = new DefaultProject();
          project.setDefaultTargetName( defaultTarget );
          project.setBaseDirectory( baseDirectory );
          //project.setName( name );
  
          //build using all top-level attributes
          buildTopLevelProject( project, configuration );
  
          return project;
      }
  
      /**
       * Handle all top level elements in configuration.
       *
       * @param project the project
       * @param configuration the Configuration
       * @exception AntException if an error occurs
       */
      protected void buildTopLevelProject( final DefaultProject project,
                                           final Configuration configuration )
          throws AntException
      {
          final Configuration[] children = configuration.getChildren();
  
          for( int i = 0; i < children.length; i++ )
          {
              final Configuration element = children[ i ];
              final String name = element.getName();
  
              //handle individual elements
              if( name.equals( "target" ) ) buildTarget( project, element );
              else if( name.equals( "property" ) ) buildImplicitTask( project, element );
              else
              {
                  throw new AntException( "Unknown top-level element " + name +
                                          " at " + element.getLocation() );
              }
          }
      }
  
      /**
       * Build a target from configuration.
       *
       * @param project the project
       * @param task the Configuration
       */
      protected void buildTarget( final DefaultProject project, final Configuration target
)
      {
          final String name = target.getAttribute( "name", null );
          final String depends = target.getAttribute( "depends", null );
          final String ifCondition = target.getAttribute( "if", null );
          final String unlessCondition = target.getAttribute( "unless", null );
  
          if( null == name )
          {
              throw new AntException( "Discovered un-named target at " +
                                      target.getLocation() );
          }
  
          getLogger().debug( "Parsing target: " + name );
  
          if( null != ifCondition && null != unlessCondition )
          {
              throw new AntException( "Discovered invalid target that has both a if and "
+
                                      "unless condition at " + target.getLocation() );
          }
  
          Condition condition = null;
  
          if( null != ifCondition )
          {
              getLogger().debug( "Target if condition: " + ifCondition );
              condition = new Condition( true, ifCondition );
          }
          else if( null != unlessCondition )
          {
              getLogger().debug( "Target unless condition: " + unlessCondition );
              condition = new Condition( false, unlessCondition );
          }
  
          final DefaultTarget defaultTarget = new DefaultTarget( condition );
  
          //apply depends attribute
          if( null != depends )
          {
              final String[] elements = ExceptionUtil.splitString( depends, "," );
  
              for( int i = 0; i < elements.length; i++ )
              {
                  final String dependency = elements[ i ].trim();
  
                  if( 0 == dependency.length() )
                  {
                      throw new AntException( "Discovered empty dependency in target " +
                                              target.getName() + " at " + target.getLocation()
);
                  }
  
                  getLogger().debug( "Target dependency: " + dependency );
                  defaultTarget.addDependency( dependency );
              }
          }
  
          //add all the targets from element
          final Configuration[] tasks = target.getChildren();
          for( int i = 0; i < tasks.length; i++ )
          {
              getLogger().debug( "Parsed task: " + tasks[ i ].getName() );
              defaultTarget.addTask( tasks[ i ] );
          }
  
          //add target to project
          project.addTarget( name, defaultTarget );
      }
  
      /**
       * Create an implict task from configuration
       *
       * @param project the project
       * @param task the configuration
       */
      protected void buildImplicitTask( final DefaultProject project, final Configuration
task )
      {
          DefaultTarget target = (DefaultTarget)project.getImplicitTarget();
  
          if( null == target )
          {
              target = new DefaultTarget();
              project.setImplicitTarget( target );
          }
  
          getLogger().debug( "Parsed implicit task: " + task.getName() );
          target.addTask( task );
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/ProjectBuilder.java
  
  Index: ProjectBuilder.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.myrmidon.components.builder;
  
  import java.io.File;
  import java.io.IOException;
  import org.apache.ant.AntException;
  import org.apache.avalon.framework.component.Component;
  import org.apache.myrmidon.model.Project;
  
  /**
   * Interface implemented by components that build projects from sources.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface ProjectBuilder
      extends Component
  {
      /**
       * build a project from source.
       *
       * @param source the source
       * @return the constructed Project
       * @exception IOException if an error occurs
       * @exception AntException if an error occurs
       */
      Project build( File source )
          throws IOException, AntException;
  }
  
  
  
  1.2       +1 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/Embeddor.java
  
  Index: Embeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/Embeddor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Embeddor.java	2001/05/28 12:28:07	1.1
  +++ Embeddor.java	2001/05/29 07:13:14	1.2
  @@ -7,12 +7,12 @@
    */
   package org.apache.myrmidon.components.embeddor;
   
  -import org.apache.ant.project.ProjectBuilder;
   import org.apache.ant.project.ProjectEngine;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.parameters.Parameterizable;
  +import org.apache.myrmidon.components.builder.ProjectBuilder;
   
   /**
    * Interface through which you embed Myrmidon into applications.
  
  
  
  1.3       +9 -9      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/MyrmidonEmbeddor.java
  
  Index: MyrmidonEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/MyrmidonEmbeddor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MyrmidonEmbeddor.java	2001/05/29 06:00:49	1.2
  +++ MyrmidonEmbeddor.java	2001/05/29 07:13:14	1.3
  @@ -10,7 +10,6 @@
   import java.io.File;
   import org.apache.ant.AntException;
   import org.apache.ant.convert.engine.ConverterEngine;
  -import org.apache.ant.project.ProjectBuilder;
   import org.apache.ant.project.ProjectEngine;
   import org.apache.ant.tasklet.engine.DataTypeEngine;
   import org.apache.ant.tasklet.engine.TskDeployer;
  @@ -27,6 +26,7 @@
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.myrmidon.api.JavaVersion;
  +import org.apache.myrmidon.components.builder.ProjectBuilder;
   import org.apache.myrmidon.components.configurer.Configurer;
   import org.apache.myrmidon.components.executor.Executor;
   
  @@ -159,19 +159,19 @@
   
           //create all the default properties for components
           defaults.setParameter( "ant.comp.converter",
  -                              "org.apache.ant.convert.engine.DefaultConverterEngine" );
  +                               "org.apache.ant.convert.engine.DefaultConverterEngine" );
           defaults.setParameter( "ant.comp.datatype",
  -                              "org.apache.ant.tasklet.engine.DefaultDataTypeEngine" );
  +                               "org.apache.ant.tasklet.engine.DefaultDataTypeEngine" );
           defaults.setParameter( "ant.comp.task",
  -                              "org.apache.myrmidon.components.executor.DefaultExecutor"
);
  +                               "org.apache.myrmidon.components.executor.DefaultExecutor"
);
           defaults.setParameter( "ant.comp.project",
  -                              "org.apache.ant.project.DefaultProjectEngine" );
  +                               "org.apache.ant.project.DefaultProjectEngine" );
           defaults.setParameter( "ant.comp.builder",
  -                              "org.apache.ant.project.DefaultProjectBuilder" );
  +                               "org.apache.myrmidon.components.builder.DefaultProjectBuilder"
);
           defaults.setParameter( "ant.comp.deployer",
  -                              "org.apache.ant.tasklet.engine.DefaultTskDeployer" );
  +                               "org.apache.ant.tasklet.engine.DefaultTskDeployer" );
           defaults.setParameter( "ant.comp.configurer",
  -                              "org.apache.myrmidon.components.configurer.DefaultConfigurer"
);
  +                               "org.apache.myrmidon.components.configurer.DefaultConfigurer"
);
   
           return defaults;
       }
  @@ -190,7 +190,7 @@
                                 m_converterEngine );
           componentManager.put( "org.apache.ant.convert.Converter", m_converterEngine );
           componentManager.put( "org.apache.ant.tasklet.engine.DataTypeEngine", m_dataTypeEngine
);
  -        componentManager.put( "org.apache.ant.project.ProjectBuilder", m_builder );
  +        componentManager.put( "org.apache.myrmidon.components.builder.ProjectBuilder",
m_builder );
           componentManager.put( "org.apache.ant.tasklet.engine.TskDeployer", m_deployer );
           componentManager.put( "org.apache.avalon.framework.camelot.Factory", m_factory
);
   
  
  
  

Mime
View raw message