adammurdoch 2002/06/25 00:35:31
Modified: antlib/src/java/org/apache/antlib/runtime
TypeAvailableCondition.java
antlib/src/test/org/apache/antlib/runtime/test
TypeAvailableConditionTestCase.java
type-available.ant
Added: antlib/src/test/org/apache/antlib TestDataType.java
antlib/src/test/org/apache/antlib/project/test
AbstractAntTaskTestCase.java
Log:
<type-available> now uses java.lang.Object as the default role. Added test
case.
Revision Changes Path
1.5 +21 -16
jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/runtime/TypeAvailableCondition.java
Index: TypeAvailableCondition.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/runtime/TypeAvailableCondition.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TypeAvailableCondition.java 23 Jun 2002 10:45:54 -0000 1.4
+++ TypeAvailableCondition.java 25 Jun 2002 07:35:31 -0000 1.5
@@ -11,12 +11,11 @@
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.DataType;
import org.apache.myrmidon.framework.conditions.Condition;
+import org.apache.myrmidon.interfaces.role.RoleInfo;
+import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.type.TypeFactory;
import org.apache.myrmidon.interfaces.type.TypeManager;
-import org.apache.myrmidon.interfaces.role.RoleManager;
-import org.apache.myrmidon.interfaces.role.RoleInfo;
/**
* A condition that evaluates to true if a particular type is available.
@@ -32,7 +31,7 @@
private static final Resources REZ =
ResourceManager.getPackageResources( TypeAvailableCondition.class );
- private String m_roleName;
+ private String m_roleShortname;
private String m_typeName;
/**
@@ -40,7 +39,7 @@
*/
public void setRole( final String type )
{
- m_roleName = type;
+ m_roleShortname = type;
}
/**
@@ -68,23 +67,29 @@
try
{
- if( m_roleName == null )
+ // Determine which role to use
+ final RoleManager roleManager = (RoleManager)context.getService(
RoleManager.class );
+ final String role;
+ if( m_roleShortname == null )
{
- m_roleName = DataType.ROLE;
+ // Use generic role as default
+ role = Object.class.getName();
}
-
- // Lookup the role
- final RoleManager roleManager = (RoleManager)context.getService(
RoleManager.class );
- final RoleInfo role = roleManager.getRoleByShortName( m_roleName
);
- if( role == null )
+ else
{
- // No such role
- return false;
+ // Lookup the role by short-name
+ final RoleInfo roleInfo = roleManager.getRoleByShortName(
m_roleShortname );
+ if( roleInfo == null )
+ {
+ // No such role
+ return false;
+ }
+ role = roleInfo.getInterfaceName();
}
// Lookup the type
final TypeManager typeManager = (TypeManager)context.getService(
TypeManager.class );
- final TypeFactory typeFactory = typeManager.getFactory(
role.getInterfaceName() );
+ final TypeFactory typeFactory = typeManager.getFactory( role );
// Check if the type is available
return typeFactory.canCreate( m_typeName );
1.1
jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/TestDataType.java
Index: TestDataType.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.antlib;
/**
* A simple test data-type.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/06/25 07:35:31 $
*
* @ant.data-type name="antlib-test"
*/
public class TestDataType
{
private String m_prop;
public String getProp()
{
return m_prop;
}
public void setProp( final String prop )
{
m_prop = prop;
}
public String toString()
{
return "[" + m_prop + "]";
}
}
1.1
jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/project/test/AbstractAntTaskTestCase.java
Index: AbstractAntTaskTestCase.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.antlib.project.test;
import org.apache.antlib.AbstractProjectTestCase;
/**
* General test cases for the <ant>/<ant-call> tasks.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/06/25 07:35:31 $
*/
public class AbstractAntTaskTestCase
extends AbstractProjectTestCase
{
public AbstractAntTaskTestCase( final String name )
{
super( name );
}
public void testEvaluation() throws Exception
{
fail( "not implemented - test <param>" );
}
}
1.2 +2 -1
jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/runtime/test/TypeAvailableConditionTestCase.java
Index: TypeAvailableConditionTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/runtime/test/TypeAvailableConditionTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TypeAvailableConditionTestCase.java 23 Jun 2002 10:45:54 -0000
1.1
+++ TypeAvailableConditionTestCase.java 25 Jun 2002 07:35:31 -0000
1.2
@@ -28,6 +28,7 @@
{
final File projectFile = getTestResource( "type-available.ant" );
executeTarget( projectFile, "test-self" );
+ executeTarget( projectFile, "default-role" );
executeTarget( projectFile, "unknown-role" );
executeTarget( projectFile, "unknown-type" );
executeTarget( projectFile, "validate" );
1.2 +7 -0
jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/runtime/test/type-available.ant
Index: type-available.ant
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/runtime/test/type-available.ant,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- type-available.ant 23 Jun 2002 10:45:54 -0000 1.1
+++ type-available.ant 25 Jun 2002 07:35:31 -0000 1.2
@@ -5,6 +5,13 @@
</assert>
</target>
+ <target name="default-role">
+ <antlib-test id="some-prop"/>
+ <assert>
+ <type-available name="antlib-test"/>
+ </assert>
+ </target>
+
<target name="unknown-role">
<assert expected="false">
<type-available role="some-unknown-role" name="some-type"/>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>