Browse Source

Remove resolveValue() as it is not needed here but in AbstractContainerTask.

Cleaned up default implementation of TaskContext


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269294 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 24 years ago
parent
commit
8071268228
2 changed files with 22 additions and 77 deletions
  1. +22
    -67
      proposal/myrmidon/src/java/org/apache/myrmidon/api/DefaultTaskContext.java
  2. +0
    -10
      proposal/myrmidon/src/java/org/apache/myrmidon/api/TaskContext.java

+ 22
- 67
proposal/myrmidon/src/java/org/apache/myrmidon/api/DefaultTaskContext.java View File

@@ -23,7 +23,13 @@ public class DefaultTaskContext
extends DefaultContext extends DefaultContext
implements TaskContext implements TaskContext
{ {
private File m_baseDirectory;
/**
* Constructor for Context with no parent contexts.
*/
public DefaultTaskContext( final Map contextData )
{
this( contextData );
}


/** /**
* Constructor for Context with no parent contexts. * Constructor for Context with no parent contexts.
@@ -32,17 +38,13 @@ public class DefaultTaskContext
{ {
this( null ); this( null );
} }

/** /**
* Constructor. * Constructor.
*/ */
public DefaultTaskContext( final TaskContext parent ) public DefaultTaskContext( final TaskContext parent )
{ {
super( parent ); super( parent );

if( null != parent )
{
m_baseDirectory = (File)parent.getBaseDirectory();
}
} }


/** /**
@@ -52,10 +54,7 @@ public class DefaultTaskContext
*/ */
public JavaVersion getJavaVersion() public JavaVersion getJavaVersion()
{ {
try
{
return (JavaVersion)get( JAVA_VERSION );
}
try { return (JavaVersion)get( JAVA_VERSION ); }
catch( final ContextException ce ) catch( final ContextException ce )
{ {
throw new IllegalStateException( "No JavaVersion in Context" ); throw new IllegalStateException( "No JavaVersion in Context" );
@@ -70,10 +69,7 @@ public class DefaultTaskContext
*/ */
public String getName() public String getName()
{ {
try
{
return (String)get( NAME );
}
try { return (String)get( NAME ); }
catch( final ContextException ce ) catch( final ContextException ce )
{ {
throw new IllegalStateException( "No Name in Context" ); throw new IllegalStateException( "No Name in Context" );
@@ -87,7 +83,11 @@ public class DefaultTaskContext
*/ */
public File getBaseDirectory() public File getBaseDirectory()
{ {
return m_baseDirectory;
try { return (File)get( BASE_DIRECTORY ); }
catch( final ContextException ce )
{
throw new IllegalStateException( "No Base Directory in Context" );
}
} }


/** /**
@@ -102,27 +102,7 @@ public class DefaultTaskContext
*/ */
public File resolveFile( final String filename ) public File resolveFile( final String filename )
{ {
final File result = FileUtil.resolveFile( m_baseDirectory, filename );
if( null != result ) return result;
else return null;
}

/**
* Resolve property.
* This evaluates all property substitutions based on current context.
*
* @param property the property to resolve
* @return the resolved property
*/
public Object resolveValue( final String property )
throws TaskException
{
try { return PropertyUtil.resolveProperty( property, this, false ); }
catch( final PropertyException pe )
{
throw new TaskException( "Error resolving " + property + " due to " + pe.getMessage(),
pe );
}
return FileUtil.resolveFile( getBaseDirectory(), filename );
} }


/** /**
@@ -157,7 +137,7 @@ public class DefaultTaskContext
* *
* @param property the property * @param property the property
*/ */
public void setProperty( final String name, final Object value, final ScopeEnum scope )
public void setProperty( final String name, final Object value, final ScopeEnum scope )
throws TaskException throws TaskException
{ {
checkPropertyValid( name, value ); checkPropertyValid( name, value );
@@ -168,11 +148,11 @@ public class DefaultTaskContext
if( null == getParent() ) if( null == getParent() )
{ {
throw new TaskException( "Can't set a property with parent scope when context " + throw new TaskException( "Can't set a property with parent scope when context " +
" has no parent" );
" has no parent" );
} }
else else
{ {
((DefaultTaskContext)getParent()).put( name, value );
((TaskContext)getParent()).setProperty( name, value );
} }
} }
else if( TOP_LEVEL == scope ) else if( TOP_LEVEL == scope )
@@ -184,37 +164,12 @@ public class DefaultTaskContext
context = (DefaultTaskContext)context.getParent(); context = (DefaultTaskContext)context.getParent();
} }


context.putValue( name, value );
context.put( name, value );
} }
else else
{ {
throw new TaskException( "Can't set a property with an unknown " +
"property context! (" + scope + ")" );
}
}

/**
* put a value in context.
* This put method is overidden so new baseDirectory can be saved
* in member variable.
*
* @param key the key
* @param value the value
*/
public void putValue( final Object key, final Object value )
throws TaskException
{
if( key.equals( BASE_DIRECTORY ) )
{
try { m_baseDirectory = (File)value; }
catch( final ClassCastException cce )
{
throw new TaskException( "Can not set baseDirectory to a non-file value.",
cce );
}
throw new IllegalStateException( "Unknown property scope! (" + scope + ")" );
} }

put( key, value );
} }


/** /**
@@ -241,7 +196,7 @@ public class DefaultTaskContext
} }
else if( JAVA_VERSION.equals( name ) && !( value instanceof JavaVersion ) ) else if( JAVA_VERSION.equals( name ) && !( value instanceof JavaVersion ) )
{ {
throw new TaskException( "property " + JAVA_VERSION +
throw new TaskException( "Property " + JAVA_VERSION +
" must have a value of type " + " must have a value of type " +
JavaVersion.class.getName() ); JavaVersion.class.getName() );
} }


+ 0
- 10
proposal/myrmidon/src/java/org/apache/myrmidon/api/TaskContext.java View File

@@ -68,16 +68,6 @@ public interface TaskContext
File resolveFile( String filename ) File resolveFile( String filename )
throws TaskException; throws TaskException;


/**
* Resolve property.
* This evaluates all property substitutions based on current context.
*
* @param property the property to resolve
* @return the resolved property
*/
Object resolveValue( String property )
throws TaskException;

/** /**
* Retrieve property for name. * Retrieve property for name.
* *


Loading…
Cancel
Save