* simplified logging interface to be independent of org.apache.log * made it so that you no longer need to build a classpath and hand it to ant!!! * added ant-call task git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268306 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -156,11 +156,13 @@ Legal: | |||
| optimize="${optimize}" | |||
| deprecation="${deprecation}" /> | |||
| <!-- | |||
| <copy todir="${build.classes}"> | |||
| <fileset dir="${build.src}"> | |||
| <exclude name="**/*.properties"/> | |||
| <include name="**/*.properties"/> | |||
| </fileset> | |||
| </copy> | |||
| --> | |||
| <mkdir dir="${build.classes}/TASK-LIB"/> | |||
| <copy file="${build.src}/org/apache/ant/tasks/core/taskdefs.properties" | |||
| @@ -175,8 +177,24 @@ Legal: | |||
| =================================================================== | |||
| --> | |||
| <target name="jar-ant" depends="compile"> | |||
| <jar jarfile="${build.lib}/ant.jar" basedir="${build.classes}"> | |||
| <jar jarfile="${build.lib}/ant.jar" | |||
| basedir="${build.classes}" | |||
| manifest="${manifest.dir}/ant-manifest.mf"> | |||
| <include name="org/apache/ant/launcher/*" /> | |||
| </jar> | |||
| </target> | |||
| <!-- | |||
| =================================================================== | |||
| Creates the myrmidon.jar file | |||
| =================================================================== | |||
| --> | |||
| <target name="jar-myrmidon" depends="compile"> | |||
| <jar jarfile="${build.lib}/myrmidon.jar" | |||
| basedir="${build.classes}" | |||
| manifest="${manifest.dir}/myrmidon-manifest.mf"> | |||
| <include name="org/apache/ant/**" /> | |||
| <exclude name="org/apache/ant/launcher/*" /> | |||
| <exclude name="org/apache/ant/tasks/**" /> | |||
| <exclude name="org/apache/ant/convert/core/**" /> | |||
| </jar> | |||
| @@ -200,7 +218,7 @@ Legal: | |||
| Creates the distribution | |||
| =================================================================== | |||
| --> | |||
| <target name="dist" depends="jar-ant,jar-core"> | |||
| <target name="dist" depends="jar-ant,jar-core,jar-myrmidon"> | |||
| <mkdir dir="${dist.dir}"/> | |||
| <mkdir dir="${dist.bin}"/> | |||
| <mkdir dir="${dist.lib}"/> | |||
| @@ -18,13 +18,15 @@ import java.net.URL; | |||
| import java.net.URLClassLoader; | |||
| import java.util.ArrayList; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Iterator; | |||
| import java.util.List; | |||
| import org.apache.ant.launcher.AntLoader; | |||
| import org.apache.ant.project.DefaultProjectEngine; | |||
| import org.apache.ant.project.Project; | |||
| import org.apache.ant.project.ProjectBuilder; | |||
| import org.apache.ant.project.ProjectEngine; | |||
| import org.apache.ant.project.ProjectListener; | |||
| import org.apache.ant.project.ProjectToListenerAdapter; | |||
| import org.apache.ant.tasklet.JavaVersion; | |||
| import org.apache.ant.tasklet.TaskletContext; | |||
| import org.apache.avalon.Disposable; | |||
| @@ -57,10 +59,14 @@ public class Main | |||
| public final static String VERSION = | |||
| "Ant " + BUILD_VERSION + " compiled on " + BUILD_DATE; | |||
| protected final static String DEFAULT_LOGLEVEL = "INFO"; | |||
| protected final static String DEFAULT_LIB_DIRECTORY = ".." + File.separator + "lib"; | |||
| protected final static String DEFAULT_LOGLEVEL = "WARN"; | |||
| protected final static String DEFAULT_LIB_DIRECTORY = "lib"; | |||
| protected final static String DEFAULT_TASKLIB_DIRECTORY = DEFAULT_LIB_DIRECTORY; | |||
| protected final static String DEFAULT_FILENAME = "build.xmk"; | |||
| protected final static String DEFAULT_ENGINE = | |||
| "org.apache.ant.project.DefaultProjectEngine"; | |||
| protected final static String DEFAULT_LISTENER = | |||
| "org.apache.ant.project.DefaultProjectListener"; | |||
| @@ -82,7 +88,7 @@ public class Main | |||
| private static final int HOME_DIR_OPT = 7; | |||
| //incompatable options for info options | |||
| private static final int INFO_OPT_INCOMPAT[] = new int[] | |||
| private static final int[] INFO_OPT_INCOMPAT = new int[] | |||
| { | |||
| HELP_OPT, QUIET_OPT, VERBOSE_OPT, FILE_OPT, | |||
| LOG_LEVEL_OPT, VERSION_OPT, LISTENER_OPT, | |||
| @@ -91,13 +97,14 @@ public class Main | |||
| }; | |||
| //incompatable options for other logging options | |||
| private static final int LOG_OPT_INCOMPAT[] = new int[] | |||
| private static final int[] LOG_OPT_INCOMPAT = new int[] | |||
| { | |||
| QUIET_OPT, VERBOSE_OPT, LOG_LEVEL_OPT | |||
| }; | |||
| protected Logger m_logger; | |||
| protected ProjectListener m_listener; | |||
| protected File m_binDir; | |||
| protected File m_homeDir; | |||
| protected File m_libDir; | |||
| @@ -105,7 +112,7 @@ public class Main | |||
| protected File m_buildFile; | |||
| protected File m_userDir; | |||
| public static void main( final String args[] ) | |||
| public static void main( final String[] args ) | |||
| { | |||
| final Main main = new Main(); | |||
| @@ -128,7 +135,7 @@ public class Main | |||
| protected CLOptionDescriptor[] createCLOptions() | |||
| { | |||
| //TODO: localise | |||
| final CLOptionDescriptor options[] = new CLOptionDescriptor[ 13 ]; | |||
| final CLOptionDescriptor[] options = new CLOptionDescriptor[ 13 ]; | |||
| options[0] = | |||
| new CLOptionDescriptor( "help", | |||
| @@ -291,9 +298,9 @@ public class Main | |||
| m_taskLibDir = getTaskLibDir( m_homeDir, taskLibDir ); | |||
| m_buildFile = getFile( filename ); | |||
| m_logger.info( "Ant Base Directory: " + m_homeDir ); | |||
| m_logger.warn( "Ant Build File: " + m_buildFile ); | |||
| m_logger.info( "Ant Home Directory: " + m_homeDir ); | |||
| m_logger.info( "Ant Bin Directory: " + m_binDir ); | |||
| m_logger.info( "Ant Build File: " + m_buildFile ); | |||
| m_logger.debug( "Ant Lib Directory: " + m_libDir ); | |||
| m_logger.debug( "Ant Task Lib Directory: " + m_taskLibDir ); | |||
| @@ -310,6 +317,8 @@ public class Main | |||
| ((Initializable)engine).init(); | |||
| } | |||
| engine.addProjectListener( m_listener ); | |||
| deployDefaultTaskLibs( engine, m_taskLibDir ); | |||
| BufferedReader reader = null; | |||
| @@ -343,10 +352,9 @@ public class Main | |||
| final File taskLibDirectory ) | |||
| { | |||
| final ExtensionFileFilter filter = | |||
| new ExtensionFileFilter( new String[] { ".tsk" } ); | |||
| final ExtensionFileFilter filter = new ExtensionFileFilter( ".tsk" ); | |||
| final File files[] = taskLibDirectory.listFiles( filter ); | |||
| final File[] files = taskLibDirectory.listFiles( filter ); | |||
| final Deployer deployer = engine.getDeployer(); | |||
| for( int i = 0; i < files.length; i++ ) | |||
| @@ -401,36 +409,35 @@ public class Main | |||
| protected void setupListener( final String listenerName ) | |||
| { | |||
| final ProjectListener listener = createListener( listenerName ); | |||
| m_logger.addLogTarget( listener ); | |||
| m_listener = createListener( listenerName ); | |||
| m_logger.addLogTarget( new ProjectToListenerAdapter( m_listener ) ); | |||
| } | |||
| protected void setupContextClassLoader( final File libDir ) | |||
| { | |||
| final ClassLoader classLoader = createClassLoader( libDir ); | |||
| Thread.currentThread().setContextClassLoader( classLoader ); | |||
| setupClassLoader( libDir ); | |||
| Thread.currentThread().setContextClassLoader( AntLoader.getLoader() ); | |||
| } | |||
| protected ClassLoader createClassLoader( final File libDir ) | |||
| protected void setupClassLoader( final File libDir ) | |||
| { | |||
| final ExtensionFileFilter filter = | |||
| new ExtensionFileFilter( new String[] { ".jar", ".zip" } ); | |||
| final ArrayList urlList = new ArrayList(); | |||
| toURLS( urlList, libDir.listFiles( filter ) ); | |||
| final URL urls[] = (URL[])urlList.toArray( new URL[0] ); | |||
| final File[] files = libDir.listFiles( filter ); | |||
| return new URLClassLoader( urls, ClassLoader.getSystemClassLoader() ); | |||
| } | |||
| final AntLoader classLoader = AntLoader.getLoader(); | |||
| protected void toURLS( final ArrayList urls, final File files[] ) | |||
| { | |||
| for( int i = 0; i < files.length; i++ ) | |||
| { | |||
| try { urls.add( files[ i ].toURL() ); } | |||
| catch( final MalformedURLException mue ) {} | |||
| } | |||
| if( !files[ i ].getName().equals( "ant.jar" ) && | |||
| !files[ i ].getName().equals( "myrmidon.jar" ) && | |||
| !files[ i ].getName().equals( "avalonapi.jar" ) ) | |||
| { | |||
| try { classLoader.addURL( files[ i ].toURL() ); } | |||
| catch( final MalformedURLException mue ) {} | |||
| } | |||
| } | |||
| } | |||
| protected Project getProject( final String builderName, final File file ) | |||
| @@ -497,7 +504,7 @@ public class Main | |||
| protected ProjectEngine createProjectEngine() | |||
| { | |||
| return new DefaultProjectEngine(); | |||
| return (ProjectEngine)createObject( DEFAULT_ENGINE, "project-engine" ); | |||
| } | |||
| protected File getHomeDir( final String homeDir ) | |||
| @@ -760,11 +767,11 @@ public class Main | |||
| { | |||
| try | |||
| { | |||
| final Class clazz = Class.forName( objectName ); | |||
| final Class clazz = Class.forName( objectName ); | |||
| return clazz.newInstance(); | |||
| } | |||
| catch( final IllegalAccessException iae ) | |||
| { | |||
| { | |||
| throw new AntException( "Non-public constructor for " + type + " " + objectName, | |||
| iae ); | |||
| } | |||
| @@ -22,13 +22,14 @@ public class DefaultConverterLoader | |||
| { | |||
| public DefaultConverterLoader() | |||
| { | |||
| super( new URLClassLoader( new URL[0], | |||
| super( new URLClassLoader( new URL[0], | |||
| Thread.currentThread().getContextClassLoader() ) ); | |||
| } | |||
| public DefaultConverterLoader( final URL location ) | |||
| { | |||
| super( new URLClassLoader( new URL[] { location } ) ); | |||
| super( new URLClassLoader( new URL[] { location }, | |||
| Thread.currentThread().getContextClassLoader() ) ); | |||
| } | |||
| public Converter loadConverter( final String converter ) | |||
| @@ -0,0 +1,64 @@ | |||
| /* | |||
| * 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.ant.launcher; | |||
| import java.lang.reflect.Method; | |||
| import java.net.URL; | |||
| import java.net.URLClassLoader; | |||
| /** | |||
| * AvalonLoader is the class that bootstraps and installs the security manager. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public final class AntLoader | |||
| extends URLClassLoader | |||
| { | |||
| protected static AntLoader c_classLoader; | |||
| public static AntLoader getLoader() | |||
| { | |||
| if( null == c_classLoader ) | |||
| { | |||
| c_classLoader = new AntLoader( new URL[ 0 ] ); | |||
| } | |||
| return c_classLoader; | |||
| } | |||
| public final static void main( final String args[] ) | |||
| throws Exception | |||
| { | |||
| final URL archive = new URL( "file:lib/myrmidon.jar" ); | |||
| c_classLoader = new AntLoader( new URL[] { archive } ); | |||
| try | |||
| { | |||
| //load class and retrieve appropriate main method. | |||
| final Class clazz = c_classLoader.loadClass( "org.apache.ant.Main" ); | |||
| final Method method = clazz.getMethod( "main", new Class[] { args.getClass() } ); | |||
| //kick the tires and light the fires.... | |||
| method.invoke( null, new Object[] { args } ); | |||
| } | |||
| catch( final Throwable throwable ) | |||
| { | |||
| throwable.printStackTrace(); | |||
| } | |||
| } | |||
| public AntLoader( final URL[] urls ) | |||
| { | |||
| super( urls ); | |||
| } | |||
| public void addURL( final URL url ) | |||
| { | |||
| super.addURL( url ); | |||
| } | |||
| } | |||
| @@ -32,39 +32,52 @@ import org.apache.log.Logger; | |||
| public class DefaultProjectEngine | |||
| implements ProjectEngine, Initializable, Disposable | |||
| { | |||
| protected Deployer m_deployer; | |||
| protected TaskletRegistry m_taskletRegistry; | |||
| protected ConverterRegistry m_converterRegistry; | |||
| protected TaskletEngine m_taskletEngine; | |||
| protected Logger m_logger; | |||
| protected Deployer m_deployer; | |||
| protected TaskletRegistry m_taskletRegistry; | |||
| protected ConverterRegistry m_converterRegistry; | |||
| protected TaskletEngine m_taskletEngine; | |||
| protected Logger m_logger; | |||
| protected ProjectListenerSupport m_listenerSupport; | |||
| protected DefaultComponentManager m_componentManager; | |||
| public void setLogger( final Logger logger ) | |||
| { | |||
| m_logger = logger; | |||
| } | |||
| public void addProjectListener( final ProjectListener listener ) | |||
| { | |||
| m_listenerSupport.addProjectListener( listener ); | |||
| } | |||
| public void removeProjectListener( final ProjectListener listener ) | |||
| { | |||
| m_listenerSupport.removeProjectListener( listener ); | |||
| } | |||
| public void init() | |||
| throws Exception | |||
| { | |||
| m_listenerSupport = new ProjectListenerSupport(); | |||
| m_taskletEngine = createTaskletEngine(); | |||
| m_taskletEngine.setLogger( m_logger ); | |||
| m_taskletRegistry = createTaskletRegistry(); | |||
| m_converterRegistry = createConverterRegistry(); | |||
| m_deployer = createDeployer(); | |||
| //final DefaultTaskletContext context = new DefaultTaskletContext(); | |||
| //m_taskletEngine.contextualize( context ); | |||
| final DefaultComponentManager componentManager = new DefaultComponentManager(); | |||
| componentManager.put( "org.apache.ant.tasklet.engine.TaskletRegistry", | |||
| m_taskletRegistry ); | |||
| m_componentManager = new DefaultComponentManager(); | |||
| m_componentManager.put( "org.apache.ant.project.ProjectEngine", this ); | |||
| m_componentManager.put( "org.apache.ant.tasklet.engine.TaskletRegistry", | |||
| m_taskletRegistry ); | |||
| componentManager.put( "org.apache.ant.convert.ConverterRegistry", | |||
| m_converterRegistry ); | |||
| m_componentManager.put( "org.apache.ant.convert.ConverterRegistry", | |||
| m_converterRegistry ); | |||
| componentManager.put( "org.apache.avalon.camelot.Deployer", m_deployer ); | |||
| m_componentManager.put( "org.apache.avalon.camelot.Deployer", m_deployer ); | |||
| m_taskletEngine.compose( componentManager ); | |||
| m_taskletEngine.compose( m_componentManager ); | |||
| if( m_taskletEngine instanceof Initializable ) | |||
| { | |||
| @@ -112,15 +125,36 @@ public class DefaultProjectEngine | |||
| public void execute( final Project project, final String target ) | |||
| throws AntException | |||
| { | |||
| m_taskletEngine.contextualize( project.getContext() ); | |||
| executeTarget( "<init>", project.getImplicitTarget() ); | |||
| m_componentManager.put( "org.apache.ant.project.Project", project ); | |||
| final TaskletContext context = project.getContext(); | |||
| final String projectName = (String)context.getProperty( Project.PROJECT ); | |||
| m_listenerSupport.projectStarted( projectName ); | |||
| executeTargetWork( "<init>", project.getImplicitTarget(), context ); | |||
| //context = new DefaultTaskletContext( context ); | |||
| //placing logger lower (at targetlevel or at task level) | |||
| //is possible if you want more fine grained control | |||
| context.setProperty( TaskletContext.LOGGER, m_logger ); | |||
| final ArrayList done = new ArrayList(); | |||
| execute( project, target, done ); | |||
| execute( project, target, context ); | |||
| m_listenerSupport.projectFinished(); | |||
| } | |||
| public void execute( Project project, String target, TaskletContext context ) | |||
| throws AntException | |||
| { | |||
| execute( project, target, context, new ArrayList() ); | |||
| } | |||
| protected void execute( final Project project, | |||
| final String targetName, | |||
| final TaskletContext context, | |||
| final ArrayList done ) | |||
| throws AntException | |||
| { | |||
| @@ -139,45 +173,67 @@ public class DefaultProjectEngine | |||
| final String dependency = (String)dependencies.next(); | |||
| if( !done.contains( dependency ) ) | |||
| { | |||
| execute( project, dependency, done ); | |||
| execute( project, dependency, context, done ); | |||
| } | |||
| } | |||
| final TaskletContext context = getContextFor( project, targetName ); | |||
| m_taskletEngine.contextualize( context ); | |||
| executeTarget( targetName, target ); | |||
| executeTarget( targetName, target, context ); | |||
| } | |||
| protected TaskletContext getContextFor( final Project project, final String targetName ) | |||
| protected void executeTarget( final String targetName, | |||
| final Target target, | |||
| final TaskletContext context ) | |||
| throws AntException | |||
| { | |||
| final DefaultTaskletContext context = | |||
| new DefaultTaskletContext( project.getContext() ); | |||
| m_componentManager.put( "org.apache.ant.project.Target", target ); | |||
| context.setProperty( Project.TARGET, targetName ); | |||
| context.put( TaskletContext.LOGGER, m_logger ); | |||
| final TaskletContext targetContext = new DefaultTaskletContext( context ); | |||
| targetContext.setProperty( Project.TARGET, targetName ); | |||
| m_listenerSupport.targetStarted( targetName ); | |||
| return context; | |||
| executeTargetWork( targetName, target, targetContext ); | |||
| m_listenerSupport.targetFinished(); | |||
| } | |||
| protected void executeTarget( final String targetName, final Target target ) | |||
| throws AntException | |||
| protected void executeTargetWork( final String name, | |||
| final Target target, | |||
| final TaskletContext context ) | |||
| { | |||
| m_logger.debug( "Executing target " + targetName ); | |||
| m_logger.debug( "Executing target " + name ); | |||
| final Iterator tasks = target.getTasks(); | |||
| while( tasks.hasNext() ) | |||
| { | |||
| final Configuration task = (Configuration)tasks.next(); | |||
| executeTask( task ); | |||
| executeTask( task, context ); | |||
| } | |||
| } | |||
| protected void executeTask( final Configuration configuration ) | |||
| protected void executeTask( final Configuration configuration, | |||
| final TaskletContext context ) | |||
| throws AntException | |||
| { | |||
| final String name = configuration.getName(); | |||
| m_logger.debug( "Executing task " + name ); | |||
| //Set up context for task... | |||
| final TaskletContext taskletContext = context; | |||
| //is Only necessary if we are multi-threaded | |||
| //final TaskletContext targetContext = new DefaultTaskletContext( context ); | |||
| taskletContext.setProperty( TaskletContext.NAME, name ); | |||
| m_taskletEngine.contextualize( taskletContext ); | |||
| //notify listeners | |||
| m_listenerSupport.taskletStarted( name ); | |||
| //run task | |||
| m_taskletEngine.execute( configuration ); | |||
| //notify listeners task has ended | |||
| m_listenerSupport.taskletFinished(); | |||
| } | |||
| } | |||
| @@ -7,25 +7,13 @@ | |||
| */ | |||
| package org.apache.ant.project; | |||
| import org.apache.log.format.PatternFormatter; | |||
| import org.apache.log.output.DefaultOutputLogTarget; | |||
| import org.apache.avalon.util.StringUtil; | |||
| public class DefaultProjectListener | |||
| extends DefaultOutputLogTarget | |||
| implements ProjectListener | |||
| { | |||
| protected String m_prefix; | |||
| /** | |||
| * Initialize the default pattern. | |||
| */ | |||
| protected void initPattern() | |||
| { | |||
| final PatternFormatter formatrer = new PatternFormatter(); | |||
| formatrer.setFormat( "%{message}\\n%{throwable}" ); | |||
| m_formatter = formatrer; | |||
| } | |||
| public void projectStarted( final String projectName ) | |||
| { | |||
| output( "Starting project " + projectName + "\n" ); | |||
| @@ -54,9 +42,19 @@ public class DefaultProjectListener | |||
| m_prefix = null; | |||
| } | |||
| public void log( String message ) | |||
| { | |||
| output( message ); | |||
| } | |||
| public void log( String message, Throwable throwable ) | |||
| { | |||
| output( message + "\n" + StringUtil.printStackTrace( throwable, 5, true ) ); | |||
| } | |||
| protected void output( final String data ) | |||
| { | |||
| if( null != m_prefix ) super.output( "[" + m_prefix + "] " + data ); | |||
| else super.output( data ); | |||
| if( null != m_prefix ) System.out.println( "\t[" + m_prefix + "] " + data ); | |||
| else System.out.println( data ); | |||
| } | |||
| } | |||
| @@ -10,8 +10,10 @@ package org.apache.ant.project; | |||
| import java.util.Iterator; | |||
| import org.apache.ant.AntException; | |||
| import org.apache.ant.tasklet.TaskletContext; | |||
| import org.apache.avalon.Component; | |||
| public interface Project | |||
| extends Component | |||
| { | |||
| // the name of currently executing project | |||
| String PROJECT = "ant.project.name"; | |||
| @@ -8,14 +8,21 @@ | |||
| package org.apache.ant.project; | |||
| import org.apache.ant.AntException; | |||
| import org.apache.ant.tasklet.TaskletContext; | |||
| import org.apache.avalon.Component; | |||
| import org.apache.avalon.camelot.Deployer; | |||
| import org.apache.avalon.camelot.Registry; | |||
| import org.apache.log.Logger; | |||
| public interface ProjectEngine | |||
| extends Component | |||
| { | |||
| Deployer getDeployer(); | |||
| void addProjectListener( ProjectListener listener ); | |||
| void removeProjectListener( ProjectListener listener ); | |||
| void setLogger( Logger logger ); | |||
| void execute( Project project, String target ) | |||
| throws AntException; | |||
| void execute( Project project, String target, TaskletContext context ) | |||
| throws AntException; | |||
| } | |||
| @@ -7,10 +7,7 @@ | |||
| */ | |||
| package org.apache.ant.project; | |||
| import org.apache.log.LogTarget; | |||
| public interface ProjectListener | |||
| extends LogTarget | |||
| { | |||
| void projectStarted( String projectName ); | |||
| void projectFinished(); | |||
| @@ -20,4 +17,7 @@ public interface ProjectListener | |||
| void taskletStarted( String taskletName ); | |||
| void taskletFinished(); | |||
| void log( String message ); | |||
| void log( String message, Throwable throwable ); | |||
| } | |||
| @@ -0,0 +1,110 @@ | |||
| /* | |||
| * 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.ant.project; | |||
| public class ProjectListenerSupport | |||
| implements ProjectListener | |||
| { | |||
| protected ProjectListener[] m_listeners = new ProjectListener[ 0 ]; | |||
| public void addProjectListener( final ProjectListener listener ) | |||
| { | |||
| final ProjectListener[] listeners = new ProjectListener[ m_listeners.length + 1 ]; | |||
| System.arraycopy( m_listeners, 0, listeners, 0, m_listeners.length ); | |||
| listeners[ m_listeners.length ] = listener; | |||
| m_listeners = listeners; | |||
| } | |||
| public void removeProjectListener( final ProjectListener listener ) | |||
| { | |||
| int found = -1; | |||
| for( int i = 0; i < m_listeners.length; i++ ) | |||
| { | |||
| if( listener == m_listeners[ i ] ) | |||
| { | |||
| found = i; | |||
| break; | |||
| } | |||
| } | |||
| if( -1 == found ) return; | |||
| final ProjectListener[] listeners = new ProjectListener[ m_listeners.length - 1 ]; | |||
| System.arraycopy( m_listeners, 0, listeners, 0, found ); | |||
| final int count = m_listeners.length - found - 1; | |||
| System.arraycopy( m_listeners, found, listeners, found + 1, count ); | |||
| m_listeners = listeners; | |||
| } | |||
| public void projectStarted( final String projectName ) | |||
| { | |||
| for( int i = 0; i < m_listeners.length; i++ ) | |||
| { | |||
| m_listeners[ i ].projectStarted( projectName ); | |||
| } | |||
| } | |||
| public void projectFinished() | |||
| { | |||
| for( int i = 0; i < m_listeners.length; i++ ) | |||
| { | |||
| m_listeners[ i ].projectFinished(); | |||
| } | |||
| } | |||
| public void targetStarted( String targetName ) | |||
| { | |||
| for( int i = 0; i < m_listeners.length; i++ ) | |||
| { | |||
| m_listeners[ i ].targetStarted( targetName ); | |||
| } | |||
| } | |||
| public void targetFinished() | |||
| { | |||
| for( int i = 0; i < m_listeners.length; i++ ) | |||
| { | |||
| m_listeners[ i ].targetFinished(); | |||
| } | |||
| } | |||
| public void taskletStarted( String taskletName ) | |||
| { | |||
| for( int i = 0; i < m_listeners.length; i++ ) | |||
| { | |||
| m_listeners[ i ].taskletStarted( taskletName ); | |||
| } | |||
| } | |||
| public void taskletFinished() | |||
| { | |||
| for( int i = 0; i < m_listeners.length; i++ ) | |||
| { | |||
| m_listeners[ i ].taskletFinished(); | |||
| } | |||
| } | |||
| public void log( String message ) | |||
| { | |||
| for( int i = 0; i < m_listeners.length; i++ ) | |||
| { | |||
| m_listeners[ i ].log( message ); | |||
| } | |||
| } | |||
| public void log( String message, Throwable throwable ) | |||
| { | |||
| for( int i = 0; i < m_listeners.length; i++ ) | |||
| { | |||
| m_listeners[ i ].log( message, throwable ); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,40 @@ | |||
| /* | |||
| * 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.ant.project; | |||
| import org.apache.log.LogEntry; | |||
| import org.apache.log.LogTarget; | |||
| public class ProjectToListenerAdapter | |||
| implements LogTarget | |||
| { | |||
| protected final ProjectListener m_listener; | |||
| public ProjectToListenerAdapter( final ProjectListener listener ) | |||
| { | |||
| m_listener = listener; | |||
| } | |||
| /** | |||
| * Process a log entry. | |||
| * | |||
| * @param entry the entry | |||
| */ | |||
| public void processEntry( final LogEntry entry ) | |||
| { | |||
| if( null == entry.getThrowable() ) | |||
| { | |||
| m_listener.log( entry.getMessage() ); | |||
| } | |||
| else | |||
| { | |||
| m_listener.log( entry.getMessage(), entry.getThrowable() ); | |||
| } | |||
| } | |||
| } | |||
| @@ -8,8 +8,10 @@ | |||
| package org.apache.ant.project; | |||
| import java.util.Iterator; | |||
| import org.apache.avalon.Component; | |||
| public interface Target | |||
| extends Component | |||
| { | |||
| Iterator getDependencies(); | |||
| Iterator getTasks(); | |||
| @@ -40,10 +40,14 @@ public class DefaultTaskletEngine | |||
| protected TaskletConfigurer m_configurer; | |||
| protected Logger m_logger; | |||
| public void setLogger( final Logger logger ) | |||
| { | |||
| m_logger = logger; | |||
| } | |||
| public void contextualize( final Context context ) | |||
| { | |||
| m_context = (TaskletContext)context; | |||
| m_logger = m_context.getLogger(); | |||
| } | |||
| public void compose( final ComponentManager componentManager ) | |||
| @@ -11,10 +11,12 @@ import org.apache.ant.AntException; | |||
| import org.apache.ant.configuration.Configuration; | |||
| import org.apache.avalon.Composer; | |||
| import org.apache.avalon.Contextualizable; | |||
| import org.apache.log.Logger; | |||
| public interface TaskletEngine | |||
| extends Contextualizable, Composer | |||
| { | |||
| void setLogger( Logger logger ); | |||
| void execute( final Configuration task ) | |||
| throws AntException; | |||
| } | |||
| @@ -138,6 +138,9 @@ public class TskDeployer | |||
| key + " due to " + re, | |||
| re ); | |||
| } | |||
| m_logger.debug( "Registered converter " + key + " that converts from " + | |||
| source + " to " + destination ); | |||
| } | |||
| } | |||
| @@ -158,6 +161,8 @@ public class TskDeployer | |||
| throw new DeploymentException( "Error registering " + key + " due to " + re, | |||
| re ); | |||
| } | |||
| m_logger.debug( "Registered tasklet " + key + " as " + value ); | |||
| } | |||
| } | |||
| @@ -0,0 +1,77 @@ | |||
| /* | |||
| * 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.ant.tasks.core; | |||
| import java.util.ArrayList; | |||
| import org.apache.ant.AntException; | |||
| import org.apache.ant.project.ProjectEngine; | |||
| import org.apache.ant.project.Project; | |||
| import org.apache.ant.tasklet.AbstractTasklet; | |||
| import org.apache.ant.tasklet.DefaultTaskletContext; | |||
| import org.apache.ant.tasklet.TaskletContext; | |||
| import org.apache.avalon.ComponentManager; | |||
| import org.apache.avalon.ComponentNotAccessibleException; | |||
| import org.apache.avalon.ComponentNotFoundException; | |||
| import org.apache.avalon.Composer; | |||
| /** | |||
| * This is abstract base class for tasklets. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public class AntCall | |||
| extends AbstractTasklet | |||
| implements Composer | |||
| { | |||
| protected ProjectEngine m_projectEngine; | |||
| protected Project m_project; | |||
| protected String m_target; | |||
| protected ArrayList m_properties = new ArrayList(); | |||
| public void compose( final ComponentManager componentManager ) | |||
| throws ComponentNotFoundException, ComponentNotAccessibleException | |||
| { | |||
| m_projectEngine = (ProjectEngine)componentManager. | |||
| lookup( "org.apache.ant.project.ProjectEngine" ); | |||
| m_project = (Project)componentManager.lookup( "org.apache.ant.project.Project" ); | |||
| } | |||
| public void setTarget( final String target ) | |||
| { | |||
| m_target = target; | |||
| } | |||
| public Property createParam() | |||
| { | |||
| final Property property = new Property(); | |||
| m_properties.add( property ); | |||
| return property; | |||
| } | |||
| public void run() | |||
| throws AntException | |||
| { | |||
| if( null == m_target ) | |||
| { | |||
| throw new AntException( "Target attribute must be specified" ); | |||
| } | |||
| final TaskletContext context = new DefaultTaskletContext( getContext() ); | |||
| final int size = m_properties.size(); | |||
| for( int i = 0; i < size; i++ ) | |||
| { | |||
| final Property property = (Property)m_properties.get( i ); | |||
| property.contextualize( context ); | |||
| property.run(); | |||
| } | |||
| getLogger().info( "Calling target " + m_target ); | |||
| m_projectEngine.execute( m_project, m_target, context ); | |||
| } | |||
| } | |||
| @@ -42,6 +42,6 @@ public class ConfigurationTest | |||
| public void run() | |||
| throws AntException | |||
| { | |||
| getLogger().info( m_message ); | |||
| getLogger().warn( m_message ); | |||
| } | |||
| } | |||
| @@ -20,7 +20,7 @@ public class ContentTest | |||
| { | |||
| public void addContent( final Integer value ) | |||
| { | |||
| getLogger().info( "Integer content: " + value ); | |||
| getLogger().warn( "Integer content: " + value ); | |||
| } | |||
| /* | |||
| @@ -28,6 +28,6 @@ public class Echo | |||
| public void run() | |||
| throws AntException | |||
| { | |||
| getLogger().info( m_message ); | |||
| getLogger().warn( m_message ); | |||
| } | |||
| } | |||
| @@ -20,67 +20,67 @@ public class PrimitiveTypesTest | |||
| { | |||
| public void setInteger( final Integer value ) | |||
| { | |||
| getLogger().info( "setInteger( " + value + " );" ); | |||
| getLogger().warn( "setInteger( " + value + " );" ); | |||
| } | |||
| public void setInteger2( final int value ) | |||
| { | |||
| getLogger().info( "setInteger2( " + value + " );" ); | |||
| getLogger().warn( "setInteger2( " + value + " );" ); | |||
| } | |||
| public void setShort( final Short value ) | |||
| { | |||
| getLogger().info( "setShort( " + value + " );" ); | |||
| getLogger().warn( "setShort( " + value + " );" ); | |||
| } | |||
| public void setShort2( final short value ) | |||
| { | |||
| getLogger().info( "setShort2( " + value + " );" ); | |||
| getLogger().warn( "setShort2( " + value + " );" ); | |||
| } | |||
| public void setByte( final Byte value ) | |||
| { | |||
| getLogger().info( "setByte( " + value + " );" ); | |||
| getLogger().warn( "setByte( " + value + " );" ); | |||
| } | |||
| public void setByte2( final byte value ) | |||
| { | |||
| getLogger().info( "setByte2( " + value + " );" ); | |||
| getLogger().warn( "setByte2( " + value + " );" ); | |||
| } | |||
| public void setLong( final Long value ) | |||
| { | |||
| getLogger().info( "setLong( " + value + " );" ); | |||
| getLogger().warn( "setLong( " + value + " );" ); | |||
| } | |||
| public void setLong2( final long value ) | |||
| { | |||
| getLogger().info( "setLong2( " + value + " );" ); | |||
| getLogger().warn( "setLong2( " + value + " );" ); | |||
| } | |||
| public void setFloat( final Float value ) | |||
| { | |||
| getLogger().info( "setFloat( " + value + " );" ); | |||
| getLogger().warn( "setFloat( " + value + " );" ); | |||
| } | |||
| public void setFloat2( final float value ) | |||
| { | |||
| getLogger().info( "setFloat2( " + value + " );" ); | |||
| getLogger().warn( "setFloat2( " + value + " );" ); | |||
| } | |||
| public void setDouble( final Double value ) | |||
| { | |||
| getLogger().info( "setDouble( " + value + " );" ); | |||
| getLogger().warn( "setDouble( " + value + " );" ); | |||
| } | |||
| public void setDouble2( final double value ) | |||
| { | |||
| getLogger().info( "setDouble2( " + value + " );" ); | |||
| getLogger().warn( "setDouble2( " + value + " );" ); | |||
| } | |||
| public void setString( final String value ) | |||
| { | |||
| getLogger().info( "setString( " + value + " );" ); | |||
| getLogger().warn( "setString( " + value + " );" ); | |||
| } | |||
| public void run() | |||
| @@ -0,0 +1,102 @@ | |||
| /* | |||
| * 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.ant.tasks.core; | |||
| import java.io.File; | |||
| import java.net.MalformedURLException; | |||
| import java.net.URL; | |||
| import org.apache.ant.AntException; | |||
| import org.apache.ant.tasklet.AbstractTasklet; | |||
| import org.apache.ant.tasklet.engine.DefaultTaskletInfo; | |||
| import org.apache.ant.tasklet.engine.TaskletRegistry; | |||
| import org.apache.avalon.ComponentManager; | |||
| import org.apache.avalon.ComponentNotAccessibleException; | |||
| import org.apache.avalon.ComponentNotFoundException; | |||
| import org.apache.avalon.Composer; | |||
| import org.apache.avalon.camelot.RegistryException; | |||
| /** | |||
| * Method to register a single tasklet. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public class RegisterTasklet | |||
| extends AbstractTasklet | |||
| implements Composer | |||
| { | |||
| protected TaskletRegistry m_taskletRegistry; | |||
| protected String m_tasklib; | |||
| protected String m_taskName; | |||
| protected String m_classname; | |||
| public void compose( final ComponentManager componentManager ) | |||
| throws ComponentNotFoundException, ComponentNotAccessibleException | |||
| { | |||
| m_taskletRegistry = (TaskletRegistry)componentManager. | |||
| lookup( "org.apache.ant.tasklet.engine.TaskletRegistry" ); | |||
| } | |||
| public void setTaskLib( final String tasklib ) | |||
| { | |||
| m_tasklib = tasklib; | |||
| } | |||
| public void setTaskName( final String taskName ) | |||
| { | |||
| m_taskName = taskName; | |||
| } | |||
| public void setClassname( final String classname ) | |||
| { | |||
| m_classname = classname; | |||
| } | |||
| public void run() | |||
| throws AntException | |||
| { | |||
| if( null == m_tasklib ) | |||
| { | |||
| throw new AntException( "Must specify tasklib parameter" ); | |||
| } | |||
| if( null == m_taskName ) | |||
| { | |||
| throw new AntException( "Must specify taskname parameter" ); | |||
| } | |||
| if( null == m_classname ) | |||
| { | |||
| m_classname = getDefaultClassName(); | |||
| } | |||
| try | |||
| { | |||
| final File tasklib = new File( getContext().resolveFilename( m_tasklib ) ); | |||
| final URL url = tasklib.toURL(); | |||
| final DefaultTaskletInfo info = new DefaultTaskletInfo( m_classname, url ); | |||
| m_taskletRegistry.register( m_taskName, info ); | |||
| } | |||
| catch( final MalformedURLException mue ) | |||
| { | |||
| throw new AntException( "Malformed task-lib parameter " + m_tasklib, mue ); | |||
| } | |||
| catch( final RegistryException re ) | |||
| { | |||
| throw new AntException( "Error registering " + m_taskName + " due to " + re, re ); | |||
| } | |||
| } | |||
| protected String getDefaultClassName() | |||
| throws AntException | |||
| { | |||
| //TODO: | |||
| throw new AntException( "Not yet capable of automagically finding classname" ); | |||
| } | |||
| } | |||
| @@ -4,4 +4,6 @@ prim-test=org.apache.ant.tasks.core.PrimitiveTypesTest | |||
| sub-elements-test=org.apache.ant.tasks.core.SubElementTest | |||
| conf-test=org.apache.ant.tasks.core.ConfigurationTest | |||
| content-test=org.apache.ant.tasks.core.ContentTest | |||
| property=org.apache.ant.tasks.core.Property | |||
| property=org.apache.ant.tasks.core.Property | |||
| register-tasklet=org.apache.ant.tasks.core.RegisterTasklet | |||
| ant-call=org.apache.ant.tasks.core.AntCall | |||
| @@ -58,7 +58,17 @@ Legal: | |||
| <property name="blah" value="fred" /> | |||
| <property name="${blah}" value="barney" /> | |||
| <register-tasklet task-lib="../../dist/lib/core.tsk" | |||
| task-name="echo2" | |||
| classname="org.apache.ant.tasks.core.Echo" /> | |||
| <echo message="Doing the funky Echo with ${blah} ${fred} Year=${year}!"/> | |||
| <echo2 message="Luke to Echo base. Can you hear me?"/> | |||
| <ant-call target="property-test2"> | |||
| <param name="blah" value="blah-value" /> | |||
| </ant-call> | |||
| </target> | |||
| <target name="property-test2"> | |||
| @@ -0,0 +1,3 @@ | |||
| Manifest-Version: 1.0 | |||
| Main-Class: org.apache.ant.launcher.AntLoader | |||
| Created-By: Apache Ant Project | |||
| @@ -0,0 +1,4 @@ | |||
| Manifest-Version: 1.0 | |||
| Main-Class: org.apache.ant.Main | |||
| Class-Path: avalonapi.jar | |||
| Created-By: Apache Ant Project | |||
| @@ -6,7 +6,6 @@ fi | |||
| # Cygwin support. | |||
| if [ "$OSTYPE" == "cygwin32" ] || [ "$OSTYPE" = "cygwin" ]; then | |||
| if [ ! "$JAVA_HOME" = "" ]; then | |||
| JAVA_HOME=`cygpath --path --unix $JAVA_HOME` | |||
| fi | |||
| @@ -28,31 +27,19 @@ done | |||
| ANT_HOME=`dirname "$PRG"`/.. | |||
| # Allow .antrc to specifiy flags to java cmd | |||
| if [ "$JAVACMD" = "" ] ; then | |||
| JAVACMD=java | |||
| fi | |||
| LOCALCLASSPATH=`echo $ANT_HOME/lib/*.jar | tr ' ' ':'` | |||
| if [ "$JAVA_HOME" == "" ] ; then | |||
| if [ "$CLASSPATH" != "" ] ; then | |||
| LOCALCLASSPATH=$CLASSPATH:$LOCALCLASSPATH | |||
| fi | |||
| if [ "$JAVA_HOME" != "" ] ; then | |||
| if test -f $JAVA_HOME/lib/tools.jar ; then | |||
| LOCALCLASSPATH=$LOCALCLASSPATH:$JAVA_HOME/lib/tools.jar | |||
| fi | |||
| else | |||
| echo "Warning: JAVA_HOME environment variable is not set." | |||
| echo " If build fails because sun.* classes could not be found" | |||
| echo " you will need to set the JAVA_HOME environment variable" | |||
| echo " to the installation directory of java." | |||
| if [ "$JAVACMD" = "" ] ; then | |||
| JAVACMD=java | |||
| fi | |||
| else | |||
| if [ "$JAVACMD" = "" ] ; then | |||
| JAVACMD=$JAVA_HOME/bin/java | |||
| fi | |||
| fi | |||
| # More Cygwin support | |||
| if [ "$OSTYPE" == "cygwin32" ] || [ "$OSTYPE" = "cygwin" ] ; then | |||
| LOCALCLASSPATH=`cygpath --path --windows "$LOCALCLASSPATH"` | |||
| fi | |||
| $JAVACMD -classpath $LOCALCLASSPATH $ANT_OPTS org.apache.ant.Main --ant-home=${ANT_HOME} $@ | |||
| $JAVACMD $ANT_OPTS -jar ant.jar --ant-home=${ANT_HOME} $@ | |||
| @@ -1,8 +1,8 @@ | |||
| @echo off | |||
| :checkJava | |||
| if "%JAVACMD%" == "" set JAVACMD=%JAVA_HOME%\bin\java | |||
| if not "%JAVA_HOME%" == "" goto setupClasspath | |||
| if exist "%HOME%\antrc_pre.bat" call "%HOME%\antrc_pre.bat" | |||
| if not "%JAVA_HOME%" == "" goto javaCmdSetup | |||
| echo. | |||
| echo Warning: JAVA_HOME environment variable is not set. | |||
| @@ -12,11 +12,17 @@ echo to the installation directory of java. | |||
| echo. | |||
| goto end | |||
| :setupClasspath | |||
| set LOCALCLASSPATH=lib\xerces.jar;lib\ant.jar;lib\avalonapi.jar;%JAVA_HOME%\lib\tools.jar | |||
| rem hope that there is java command in path | |||
| if "%JAVACMD%" == "" set JAVACMD=java | |||
| goto argSetup | |||
| set THIS_FILE=%0 | |||
| rem if JAVA_HOME is set then make sure we use that java exe | |||
| :javaCmdSetup | |||
| if "%JAVACMD%" == "" set JAVACMD=%JAVA_HOME%\bin\java | |||
| :argSetup | |||
| set THIS_FILE=%0 | |||
| set ANT_CMD_LINE_ARGS= | |||
| rem Slurp all args... | |||
| @@ -29,7 +35,9 @@ goto setupArgs | |||
| :doneArgs | |||
| rem Mmmmmm tasty - finished slurping args | |||
| %JAVACMD% -classpath "%LOCALCLASSPATH%" %ANT_OPTS% org.apache.ant.Main "--bin-dir=%THIS_FILE%" %ANT_CMD_LINE_ARGS% | |||
| %JAVACMD% %ANT_OPTS% -jar lib\ant.jar "--bin-dir=%THIS_FILE%" %ANT_CMD_LINE_ARGS% | |||
| :end | |||
| set LOCALCLASSPATH= | |||
| if exist "%HOME%\antrc_post.bat" call "%HOME%\antrc_post.bat" | |||
| set THIS_FILE= | |||
| set ANT_CMD_LINE_ARGS= | |||