|
|
@@ -5,68 +5,69 @@ |
|
|
|
* version 1.1, a copy of which has been included with this distribution in |
|
|
|
* the LICENSE file. |
|
|
|
*/ |
|
|
|
package org.apache.ant.runtime; |
|
|
|
package org.apache.myrmidon.components.embeddor; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.util.Properties; |
|
|
|
import org.apache.ant.AntException; |
|
|
|
import org.apache.myrmidon.components.configurer.Configurer; |
|
|
|
import org.apache.ant.convert.engine.ConverterEngine; |
|
|
|
import org.apache.ant.project.ProjectBuilder; |
|
|
|
import org.apache.ant.project.ProjectEngine; |
|
|
|
import org.apache.myrmidon.api.JavaVersion; |
|
|
|
import org.apache.ant.tasklet.engine.DataTypeEngine; |
|
|
|
import org.apache.ant.tasklet.engine.TaskletEngine; |
|
|
|
import org.apache.ant.tasklet.engine.TskDeployer; |
|
|
|
import org.apache.avalon.framework.logger.AbstractLoggable; |
|
|
|
import org.apache.avalon.framework.component.Component; |
|
|
|
import org.apache.avalon.framework.component.Composable; |
|
|
|
import org.apache.avalon.framework.component.DefaultComponentManager; |
|
|
|
import org.apache.avalon.excalibur.io.FileUtil; |
|
|
|
import org.apache.avalon.framework.activity.Initializable; |
|
|
|
import org.apache.avalon.framework.camelot.CamelotUtil; |
|
|
|
import org.apache.avalon.framework.camelot.DefaultFactory; |
|
|
|
import org.apache.avalon.framework.camelot.Deployer; |
|
|
|
import org.apache.avalon.framework.camelot.Factory; |
|
|
|
import org.apache.avalon.excalibur.io.FileUtil; |
|
|
|
import org.apache.avalon.framework.component.Component; |
|
|
|
import org.apache.avalon.framework.component.Composable; |
|
|
|
import org.apache.avalon.framework.component.DefaultComponentManager; |
|
|
|
import org.apache.avalon.framework.logger.AbstractLoggable; |
|
|
|
import org.apache.avalon.framework.parameters.Parameters; |
|
|
|
import org.apache.avalon.framework.parameters.Parameterizable; |
|
|
|
import org.apache.myrmidon.api.JavaVersion; |
|
|
|
import org.apache.myrmidon.components.configurer.Configurer; |
|
|
|
|
|
|
|
/** |
|
|
|
* Default implementation of Ant runtime. |
|
|
|
* |
|
|
|
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a> |
|
|
|
*/ |
|
|
|
public class DefaultAntEngine |
|
|
|
public class MyrmidonEmbeddor |
|
|
|
extends AbstractLoggable |
|
|
|
implements AntEngine, Initializable |
|
|
|
implements Embeddor |
|
|
|
{ |
|
|
|
protected ConverterEngine m_converterEngine; |
|
|
|
protected DataTypeEngine m_dataTypeEngine; |
|
|
|
protected TaskletEngine m_taskletEngine; |
|
|
|
protected ProjectEngine m_projectEngine; |
|
|
|
|
|
|
|
protected ProjectBuilder m_builder; |
|
|
|
protected TskDeployer m_deployer; |
|
|
|
protected Configurer m_configurer; |
|
|
|
|
|
|
|
protected Factory m_factory; |
|
|
|
|
|
|
|
protected DefaultComponentManager m_componentManager; |
|
|
|
protected Properties m_properties; |
|
|
|
protected Properties m_defaults; |
|
|
|
|
|
|
|
protected File m_homeDir; |
|
|
|
protected File m_binDir; |
|
|
|
protected File m_libDir; |
|
|
|
protected File m_taskLibDir; |
|
|
|
|
|
|
|
private ConverterEngine m_converterEngine; |
|
|
|
private DataTypeEngine m_dataTypeEngine; |
|
|
|
private TaskletEngine m_taskEngine; |
|
|
|
private ProjectEngine m_projectEngine; |
|
|
|
|
|
|
|
private ProjectBuilder m_builder; |
|
|
|
private TskDeployer m_deployer; |
|
|
|
private Configurer m_configurer; |
|
|
|
|
|
|
|
private Factory m_factory; |
|
|
|
|
|
|
|
private DefaultComponentManager m_componentManager; |
|
|
|
private Parameters m_parameters; |
|
|
|
private Parameters m_defaults; |
|
|
|
|
|
|
|
private File m_homeDir; |
|
|
|
private File m_binDir; |
|
|
|
private File m_libDir; |
|
|
|
private File m_taskLibDir; |
|
|
|
|
|
|
|
/** |
|
|
|
* Setup basic properties of engine. |
|
|
|
* Setup basic properties of engine. |
|
|
|
* Called before init() and can be used to specify alternate components in system. |
|
|
|
* |
|
|
|
* @param properties the properties |
|
|
|
*/ |
|
|
|
public void setProperties( final Properties properties ) |
|
|
|
public void parameterize( final Parameters parameters ) |
|
|
|
{ |
|
|
|
m_properties = properties; |
|
|
|
m_parameters = parameters; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -100,7 +101,7 @@ public class DefaultAntEngine |
|
|
|
throws Exception |
|
|
|
{ |
|
|
|
//setup default properties |
|
|
|
m_defaults = createDefaultProperties(); |
|
|
|
m_defaults = createDefaultParameters(); |
|
|
|
|
|
|
|
//create all the components |
|
|
|
m_factory = new DefaultFactory(); |
|
|
@@ -126,50 +127,50 @@ public class DefaultAntEngine |
|
|
|
{ |
|
|
|
m_converterEngine = null; |
|
|
|
m_dataTypeEngine = null; |
|
|
|
m_taskletEngine = null; |
|
|
|
m_taskEngine = null; |
|
|
|
m_projectEngine = null; |
|
|
|
m_builder = null; |
|
|
|
m_deployer = null; |
|
|
|
m_configurer = null; |
|
|
|
m_factory = null; |
|
|
|
m_componentManager = null; |
|
|
|
m_properties = null; |
|
|
|
m_parameters = null; |
|
|
|
m_defaults = null; |
|
|
|
m_homeDir = null; |
|
|
|
m_binDir = null; |
|
|
|
m_libDir = null; |
|
|
|
m_taskLibDir = null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Create default properties which includes default names of all components. |
|
|
|
* Overide this in sub-classes to change values. |
|
|
|
* |
|
|
|
* @return the Properties |
|
|
|
* @return the Parameters |
|
|
|
*/ |
|
|
|
protected Properties createDefaultProperties() |
|
|
|
private Parameters createDefaultParameters() |
|
|
|
{ |
|
|
|
final Properties defaults = new Properties(); |
|
|
|
final Parameters defaults = new Parameters(); |
|
|
|
|
|
|
|
//create all the default properties for files/directories |
|
|
|
defaults.setProperty( "ant.path.bin", "bin" ); |
|
|
|
defaults.setProperty( "ant.path.lib", "lib" ); |
|
|
|
defaults.setProperty( "ant.path.task-lib", "lib" ); |
|
|
|
defaults.setParameter( "ant.path.bin", "bin" ); |
|
|
|
defaults.setParameter( "ant.path.lib", "lib" ); |
|
|
|
defaults.setParameter( "ant.path.task-lib", "lib" ); |
|
|
|
|
|
|
|
//create all the default properties for components |
|
|
|
defaults.setProperty( "ant.comp.converter", |
|
|
|
defaults.setParameter( "ant.comp.converter", |
|
|
|
"org.apache.ant.convert.engine.DefaultConverterEngine" ); |
|
|
|
defaults.setProperty( "ant.comp.datatype", |
|
|
|
defaults.setParameter( "ant.comp.datatype", |
|
|
|
"org.apache.ant.tasklet.engine.DefaultDataTypeEngine" ); |
|
|
|
defaults.setProperty( "ant.comp.tasklet", |
|
|
|
defaults.setParameter( "ant.comp.task", |
|
|
|
"org.apache.ant.tasklet.engine.DefaultTaskletEngine" ); |
|
|
|
defaults.setProperty( "ant.comp.project", |
|
|
|
defaults.setParameter( "ant.comp.project", |
|
|
|
"org.apache.ant.project.DefaultProjectEngine" ); |
|
|
|
defaults.setProperty( "ant.comp.builder", |
|
|
|
defaults.setParameter( "ant.comp.builder", |
|
|
|
"org.apache.ant.project.DefaultProjectBuilder" ); |
|
|
|
defaults.setProperty( "ant.comp.deployer", |
|
|
|
defaults.setParameter( "ant.comp.deployer", |
|
|
|
"org.apache.ant.tasklet.engine.DefaultTskDeployer" ); |
|
|
|
defaults.setProperty( "ant.comp.configurer", |
|
|
|
defaults.setParameter( "ant.comp.configurer", |
|
|
|
"org.apache.myrmidon.components.configurer.DefaultConfigurer" ); |
|
|
|
|
|
|
|
return defaults; |
|
|
@@ -180,13 +181,13 @@ public class DefaultAntEngine |
|
|
|
* |
|
|
|
* @return the ComponentManager |
|
|
|
*/ |
|
|
|
protected DefaultComponentManager createComponentManager() |
|
|
|
private DefaultComponentManager createComponentManager() |
|
|
|
{ |
|
|
|
final DefaultComponentManager componentManager = new DefaultComponentManager(); |
|
|
|
|
|
|
|
componentManager.put( "org.apache.ant.tasklet.engine.TaskletEngine", m_taskletEngine ); |
|
|
|
componentManager.put( "org.apache.ant.tasklet.engine.TaskletEngine", m_taskEngine ); |
|
|
|
componentManager.put( "org.apache.ant.project.ProjectEngine", m_projectEngine ); |
|
|
|
componentManager.put( "org.apache.ant.convert.engine.ConverterEngine", |
|
|
|
componentManager.put( "org.apache.ant.convert.engine.ConverterEngine", |
|
|
|
m_converterEngine ); |
|
|
|
componentManager.put( "org.apache.ant.convert.Converter", m_converterEngine ); |
|
|
|
componentManager.put( "org.apache.ant.tasklet.engine.DataTypeEngine", m_dataTypeEngine ); |
|
|
@@ -203,30 +204,30 @@ public class DefaultAntEngine |
|
|
|
* |
|
|
|
* @exception Exception if an error occurs |
|
|
|
*/ |
|
|
|
protected void createComponents() |
|
|
|
private void createComponents() |
|
|
|
throws Exception |
|
|
|
{ |
|
|
|
String component = null; |
|
|
|
|
|
|
|
component = getProperty( "ant.comp.converter" ); |
|
|
|
component = getParameter( "ant.comp.converter" ); |
|
|
|
m_converterEngine = (ConverterEngine)createComponent( component, ConverterEngine.class ); |
|
|
|
|
|
|
|
component = getProperty( "ant.comp.datatype" ); |
|
|
|
component = getParameter( "ant.comp.datatype" ); |
|
|
|
m_dataTypeEngine = (DataTypeEngine)createComponent( component, DataTypeEngine.class ); |
|
|
|
|
|
|
|
component = getProperty( "ant.comp.tasklet" ); |
|
|
|
m_taskletEngine = (TaskletEngine)createComponent( component, TaskletEngine.class ); |
|
|
|
|
|
|
|
component = getProperty( "ant.comp.project" ); |
|
|
|
|
|
|
|
component = getParameter( "ant.comp.task" ); |
|
|
|
m_taskEngine = (TaskletEngine)createComponent( component, TaskletEngine.class ); |
|
|
|
|
|
|
|
component = getParameter( "ant.comp.project" ); |
|
|
|
m_projectEngine = (ProjectEngine)createComponent( component, ProjectEngine.class ); |
|
|
|
|
|
|
|
component = getProperty( "ant.comp.builder" ); |
|
|
|
component = getParameter( "ant.comp.builder" ); |
|
|
|
m_builder =(ProjectBuilder)createComponent( component, ProjectBuilder.class ); |
|
|
|
|
|
|
|
component = getProperty( "ant.comp.deployer" ); |
|
|
|
component = getParameter( "ant.comp.deployer" ); |
|
|
|
m_deployer = (TskDeployer)createComponent( component, TskDeployer.class ); |
|
|
|
|
|
|
|
component = getProperty( "ant.comp.configurer" ); |
|
|
|
component = getParameter( "ant.comp.configurer" ); |
|
|
|
m_configurer = (Configurer)createComponent( component, Configurer.class ); |
|
|
|
} |
|
|
|
|
|
|
@@ -235,13 +236,13 @@ public class DefaultAntEngine |
|
|
|
* |
|
|
|
* @exception Exception if an error occurs |
|
|
|
*/ |
|
|
|
protected void setupComponents() |
|
|
|
private void setupComponents() |
|
|
|
throws Exception |
|
|
|
{ |
|
|
|
setupComponent( m_factory ); |
|
|
|
setupComponent( m_converterEngine ); |
|
|
|
setupComponent( m_dataTypeEngine ); |
|
|
|
setupComponent( m_taskletEngine ); |
|
|
|
setupComponent( m_taskEngine ); |
|
|
|
setupComponent( m_projectEngine ); |
|
|
|
setupComponent( m_builder ); |
|
|
|
setupComponent( m_deployer ); |
|
|
@@ -254,7 +255,7 @@ public class DefaultAntEngine |
|
|
|
* @param component the component |
|
|
|
* @exception Exception if an error occurs |
|
|
|
*/ |
|
|
|
protected void setupComponent( final Component component ) |
|
|
|
private void setupComponent( final Component component ) |
|
|
|
throws Exception |
|
|
|
{ |
|
|
|
setupLogger( component ); |
|
|
@@ -273,38 +274,38 @@ public class DefaultAntEngine |
|
|
|
/** |
|
|
|
* Setup all the files attributes. |
|
|
|
*/ |
|
|
|
protected void setupFiles() |
|
|
|
private void setupFiles() |
|
|
|
{ |
|
|
|
String filepath = null; |
|
|
|
|
|
|
|
filepath = getProperty( "ant.home" ); |
|
|
|
filepath = getParameter( "ant.home" ); |
|
|
|
m_homeDir = (new File( filepath )).getAbsoluteFile(); |
|
|
|
checkDirectory( m_homeDir, "ant-home" ); |
|
|
|
|
|
|
|
filepath = getProperty( "ant.path.bin" ); |
|
|
|
filepath = getParameter( "ant.path.bin" ); |
|
|
|
m_binDir = resolveDirectory( filepath, "bin-dir" ); |
|
|
|
|
|
|
|
filepath = getProperty( "ant.path.lib" ); |
|
|
|
|
|
|
|
filepath = getParameter( "ant.path.lib" ); |
|
|
|
m_libDir = resolveDirectory( filepath, "lib-dir" ); |
|
|
|
|
|
|
|
filepath = getProperty( "ant.path.task-lib" ); |
|
|
|
filepath = getParameter( "ant.path.task-lib" ); |
|
|
|
m_taskLibDir = resolveDirectory( filepath, "task-lib-dir" ); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Retrieve value of named property. |
|
|
|
* Retrieve value of named property. |
|
|
|
* First access passed in properties and then the default properties. |
|
|
|
* |
|
|
|
* @param name the name of property |
|
|
|
* @return the value of property or null |
|
|
|
*/ |
|
|
|
protected String getProperty( final String name ) |
|
|
|
private String getParameter( final String name ) |
|
|
|
{ |
|
|
|
String value = m_properties.getProperty( name ); |
|
|
|
String value = m_parameters.getParameter( name, null ); |
|
|
|
|
|
|
|
if( null == value ) |
|
|
|
{ |
|
|
|
value = m_defaults.getProperty( name ); |
|
|
|
value = m_defaults.getParameter( name, null ); |
|
|
|
} |
|
|
|
|
|
|
|
return value; |
|
|
@@ -318,7 +319,7 @@ public class DefaultAntEngine |
|
|
|
* @return the created File |
|
|
|
* @exception AntException if an error occurs |
|
|
|
*/ |
|
|
|
protected File resolveDirectory( final String dir, final String name ) |
|
|
|
private File resolveDirectory( final String dir, final String name ) |
|
|
|
throws AntException |
|
|
|
{ |
|
|
|
final File file = FileUtil.resolveFile( m_homeDir, dir ); |
|
|
@@ -332,9 +333,9 @@ public class DefaultAntEngine |
|
|
|
* @param file the File |
|
|
|
* @param name the name of file type (used in error messages) |
|
|
|
*/ |
|
|
|
protected void checkDirectory( final File file, final String name ) |
|
|
|
private void checkDirectory( final File file, final String name ) |
|
|
|
throws AntException |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( !file.exists() ) |
|
|
|
{ |
|
|
|
throw new AntException( name + " (" + file + ") does not exist" ); |
|
|
@@ -351,10 +352,10 @@ public class DefaultAntEngine |
|
|
|
* |
|
|
|
* @return the current JVM version |
|
|
|
*/ |
|
|
|
protected JavaVersion getJavaVersion() |
|
|
|
private JavaVersion getJavaVersion() |
|
|
|
{ |
|
|
|
JavaVersion version = JavaVersion.JAVA1_0; |
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
Class.forName( "java.lang.Void" ); |
|
|
@@ -363,9 +364,9 @@ public class DefaultAntEngine |
|
|
|
version = JavaVersion.JAVA1_2; |
|
|
|
Class.forName( "java.lang.StrictMath" ); |
|
|
|
version = JavaVersion.JAVA1_3; |
|
|
|
} |
|
|
|
} |
|
|
|
catch( final ClassNotFoundException cnfe ) {} |
|
|
|
|
|
|
|
|
|
|
|
return version; |
|
|
|
} |
|
|
|
|
|
|
@@ -377,7 +378,7 @@ public class DefaultAntEngine |
|
|
|
* @return the created object |
|
|
|
* @exception AntException if an error occurs |
|
|
|
*/ |
|
|
|
protected Object createComponent( final String component, final Class clazz ) |
|
|
|
private Object createComponent( final String component, final Class clazz ) |
|
|
|
throws AntException |
|
|
|
{ |
|
|
|
try |
|
|
@@ -386,25 +387,25 @@ public class DefaultAntEngine |
|
|
|
|
|
|
|
if( !clazz.isInstance( object ) ) |
|
|
|
{ |
|
|
|
throw new AntException( "Object " + component + " is not an instance of " + |
|
|
|
throw new AntException( "Object " + component + " is not an instance of " + |
|
|
|
clazz ); |
|
|
|
} |
|
|
|
|
|
|
|
return object; |
|
|
|
} |
|
|
|
catch( final IllegalAccessException iae ) |
|
|
|
{ |
|
|
|
throw new AntException( "Non-public constructor for " + clazz + " " + component, |
|
|
|
{ |
|
|
|
throw new AntException( "Non-public constructor for " + clazz + " " + component, |
|
|
|
iae ); |
|
|
|
} |
|
|
|
catch( final InstantiationException ie ) |
|
|
|
{ |
|
|
|
throw new AntException( "Error instantiating class for " + clazz + " " + component, |
|
|
|
throw new AntException( "Error instantiating class for " + clazz + " " + component, |
|
|
|
ie ); |
|
|
|
} |
|
|
|
catch( final ClassNotFoundException cnfe ) |
|
|
|
{ |
|
|
|
throw new AntException( "Could not find the class for " + clazz + |
|
|
|
throw new AntException( "Could not find the class for " + clazz + |
|
|
|
" (" + component + ")", cnfe ); |
|
|
|
} |
|
|
|
} |