adammurdoch 02/05/17 00:48:10
Modified: framework/src/test/org/apache/myrmidon
AbstractTaskTestCase.java
framework/src/test/org/apache/myrmidon/framework/conditions/test
isset.ant istrue.ant
Added: framework/src/test/org/apache/myrmidon/framework
PropertyTask.java
Log:
Added a temporary implementation of AbstractTaskTestCase.executeTarget(), to
get the framework tests happening.
Revision Changes Path
1.2 +92 -4
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/AbstractTaskTestCase.java
Index: AbstractTaskTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/AbstractTaskTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractTaskTestCase.java 11 May 2002 12:44:01 -0000 1.1
+++ AbstractTaskTestCase.java 17 May 2002 07:48:10 -0000 1.2
@@ -8,15 +8,24 @@
package org.apache.myrmidon;
import java.io.File;
-import org.apache.myrmidon.components.AbstractComponentTest;
-import org.apache.myrmidon.listeners.ProjectListener;
import org.apache.myrmidon.api.event.TaskListener;
+import org.apache.myrmidon.api.metadata.ModelElement;
+import org.apache.myrmidon.components.AbstractComponentTest;
+import org.apache.myrmidon.components.builder.ModelElementUtil;
+import org.apache.myrmidon.interfaces.event.TaskEventManager;
+import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
+import org.apache.myrmidon.interfaces.executor.Executor;
+import org.apache.myrmidon.interfaces.library.Library;
+import org.apache.myrmidon.interfaces.library.LibraryManager;
+import org.apache.myrmidon.interfaces.deployer.Deployer;
+import org.apache.myrmidon.interfaces.deployer.TypeLibraryDeployer;
+import org.apache.avalon.framework.ExceptionUtil;
/**
* A base class for test cases which need to execute tasks.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
- * @version $Revision: 1.1 $ $Date: 2002/05/11 12:44:01 $
+ * @version $Revision: 1.2 $ $Date: 2002/05/17 07:48:10 $
*
* @todo - Move the guts of AbstractProjectTestCase back to this class,
* and add a specialised project builder.
@@ -76,6 +85,85 @@
final TaskListener listener )
throws Exception
{
- assertTrue( "not implemented", false );
+ // TODO - implement this as a ProjectBuilder, and use EmbeddedAnt
+ // (or an Embeddor at least) instead.
+
+ // Load model
+ final String systemId = projectFile.toURL().toString();
+ final ModelElement model = ModelElementUtil.loadModel( systemId );
+
+ // Locate and execute the target
+ final ModelElement[] targets = model.getChildren( "target" );
+ for( int i = 0; i < targets.length; i++ )
+ {
+ final ModelElement target = targets[ i ];
+ if( targetName.equals( target.getAttribute( "name" ) ) )
+ {
+ try
+ {
+ executeTarget( target, listener );
+ return;
+ }
+ catch( Exception e )
+ {
+ System.out.println( ExceptionUtil.printStackTrace( e,
999, true, true ) );
+ throw e;
+ }
+ }
+ }
+
+ // Target not found
+ throw new Exception( "Target \"" + targetName + "\" not found in
project " + projectFile + "." );
+ }
+
+ /**
+ * Executes a target.
+ */
+ private void executeTarget( final ModelElement target,
+ final TaskListener listener )
+ throws Exception
+ {
+ // Register all the types visible in the classloader
+ final LibraryManager libraryManager =
(LibraryManager)getServiceManager().lookup( LibraryManager.ROLE );
+ final Library lib = libraryManager.createLibrary(
getClass().getClassLoader() );
+ final Deployer deployer = (Deployer)getServiceManager().lookup(
Deployer.ROLE );
+ final TypeLibraryDeployer typeLibraryDeployer =
deployer.createDeployer( lib, "test" );
+ typeLibraryDeployer.deployAll();
+
+ final TaskEventManager eventManager =
(TaskEventManager)getServiceManager().lookup( TaskEventManager.ROLE );
+ final Executor executor = (Executor)getServiceManager().lookup(
Executor.ROLE );
+ final ExecutionFrame frame = createExecutionFrame();
+
+ // Install listener
+ if( listener != null )
+ {
+ eventManager.addTaskListener( listener );
+ }
+
+ try
+ {
+ // Execute each of the tasks
+ final ModelElement[] tasks = target.getChildren();
+ for( int i = 0; i < tasks.length; i++ )
+ {
+ final ModelElement task = tasks[ i ];
+ final ExecutionFrame taskFrame = frame.createChildFrame(
task.getName(), null, null, false );
+ executor.execute( task, taskFrame );
+ }
+ }
+ finally
+ {
+ if( listener != null )
+ {
+ // Uninstall listener
+ eventManager.removeTaskListener( listener );
+ }
+ }
+
+ if( listener instanceof TrackingTaskListener )
+ {
+ TrackingTaskListener taskListener =
(TrackingTaskListener)listener;
+ taskListener.assertComplete();
+ }
}
}
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/PropertyTask.java
Index: PropertyTask.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.txt file.
*/
package org.apache.myrmidon.framework;
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskException;
/**
* A simplified version of the <property> task, for use in the framework
* unit tests. Handles string properties only.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/05/17 07:48:10 $
*
* @ant.task name="string-prop"
*/
public class PropertyTask
extends AbstractTask
{
private String m_name;
private String m_value;
public void setName( final String name )
{
m_name = name;
}
public void setValue( final String value )
{
m_value = value;
}
/**
* Execute task.
*/
public void execute()
throws TaskException
{
getContext().setProperty( m_name, m_value );
}
}
1.2 +3 -5
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/isset.ant
Index: isset.ant
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/isset.ant,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- isset.ant 14 Apr 2002 09:33:13 -0000 1.1
+++ isset.ant 17 May 2002 07:48:10 -0000 1.2
@@ -3,9 +3,7 @@
<!-- Set to some arbirary value -->
<target name="set">
- <property name="test-prop">
- <path location="some-location"/>
- </property>
+ <path id="test-prop" location="some-location"/>
<assert>
<is-set property="test-prop"/>
</assert>
@@ -13,7 +11,7 @@
<!-- Set to true -->
<target name="set2true">
- <property name="test-prop" value="true"/>
+ <string-prop name="test-prop" value="true"/>
<assert>
<is-set property="test-prop"/>
</assert>
@@ -21,7 +19,7 @@
<!-- Set to false -->
<target name="set2false">
- <property name="test-prop" value="false"/>
+ <string-prop name="test-prop" value="false"/>
<assert>
<is-set property="test-prop"/>
</assert>
1.2 +3 -5
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/istrue.ant
Index: istrue.ant
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/istrue.ant,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- istrue.ant 14 Apr 2002 09:33:13 -0000 1.1
+++ istrue.ant 17 May 2002 07:48:10 -0000 1.2
@@ -3,9 +3,7 @@
<!-- Set to some arbirary value -->
<target name="set">
- <property name="test-prop">
- <path location="some-location"/>
- </property>
+ <path id="test-prop" location="some-location"/>
<assert>
<is-true property="test-prop"/>
</assert>
@@ -13,7 +11,7 @@
<!-- Set to true -->
<target name="set2true">
- <property name="test-prop" value="true"/>
+ <string-prop name="test-prop" value="true"/>
<assert>
<is-true property="test-prop"/>
</assert>
@@ -21,7 +19,7 @@
<!-- Set to false -->
<target name="set2false">
- <property name="test-prop" value="false"/>
+ <string-prop name="test-prop" value="false"/>
<assert expected="false">
<is-true property="test-prop"/>
</assert>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>