adammurdoch 02/05/15 03:11:55
Modified: antlib/src/java/org/apache/antlib/core Resources.properties
container/src/test/org/apache/myrmidon
LogMessageTracker.java
tools/xsl build.xsl
Added: antlib/src/java/org/apache/antlib/core
AbstractLoadPropertiesTask.java
LoadPropertyFileTask.java
LoadPropertyResourceTask.java
antlib/src/test/org/apache/antlib/core/test
AbstractLoadPropertiesTaskTestCase.java
LoadPropertyFileTaskTestCase.java
LoadPropertyResourceTaskTestCase.java
load-properties-resolve.properties
load-properties.ant load-properties.properties
load-resource.ant
Removed: antlib/src/java/org/apache/antlib/core LoadProperties.java
PropertyLoader.java
framework/src/todo/org/apache/tools/todo/taskdefs
Property.java
Log:
Ported the remainder of the old <property> task:
* Added <load-resource> task to load properties from a resource.
* Added common superclass for <load-properties> and <load-resource> tasks.
* Unit tests.
Revision Changes Path
1.4 +7 -4
jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core/Resources.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Resources.properties 3 May 2002 10:34:02 -0000 1.3
+++ Resources.properties 15 May 2002 10:11:54 -0000 1.4
@@ -4,9 +4,8 @@
property.no-value.error=Value must be specified.
loadprop.no-file.error=No file specified to load properties from.
-loadprop.file.notice=Loading proeprties from {0}.
-loadprop.missing-file.notice=Unable to find property file: {0}.
-loadprop.bad-resolve.error=Unable to resolve and set property named "{0}" to
value "{1}".
+loadprop.file.notice=Loading properties from "{0}".
+loadprop.missing-file.notice=Unable to find property file "{0}".
convert.bad-boolean.error=Error converting object ({0}) to Boolean.
convert.bad-byte.error=Error converting object ({0}) to Byte.
@@ -31,4 +30,8 @@
trycatch.missing-second.error=Missing <catch/> or <finally/> elements from
<try-catch/> task.
filetokenset.not-a-file.error=File {0} does not exist, or is not a file.
-filetokenset.read-tokens.error=Could not read tokens from {0}.
\ No newline at end of file
+filetokenset.read-tokens.error=Could not read tokens from {0}.
+
+load-resource.no-resource.error=No resource specified to load properties
from.
+load-resource.loading.notice=Loading properties from resource "{0}".
+load-resource.missing-resource.notice=Unable to find resource "{0}".
\ No newline at end of file
1.1
jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core/AbstractLoadPropertiesTask.java
Index: AbstractLoadPropertiesTask.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.core;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import org.apache.avalon.excalibur.io.IOUtil;
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskException;
/**
* An abstract task to load properties from an input stream.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/05/15 10:11:54 $
*/
public abstract class AbstractLoadPropertiesTask
extends AbstractTask
{
private String m_prefix;
/**
* Specify the prefix to be placed before all properties (if any).
*/
public void setPrefix( final String prefix )
{
m_prefix = prefix;
}
public void execute()
throws TaskException
{
//Make sure prefix ends with a '.' if specified
if( null == m_prefix )
{
m_prefix = "";
}
else if( !m_prefix.endsWith( "." ) )
{
m_prefix += ".";
}
// Load properties from the input stream
final Properties properties = new Properties();
try
{
final InputStream input = getInputStream();
if( input == null )
{
return;
}
try
{
properties.load( input );
}
finally
{
IOUtil.shutdownStream( input );
}
}
catch( final TaskException e )
{
throw e;
}
catch( final Exception e )
{
throw new TaskException( e.getMessage(), e );
}
// Resolve and set prop values
for( Iterator iterator = properties.entrySet().iterator();
iterator.hasNext(); )
{
Map.Entry entry = (Map.Entry)iterator.next();
addUnresolvedValue( (String)entry.getKey(),
(String)entry.getValue() );
}
}
/**
* Creates the input stream to load the properties from.
*/
protected abstract InputStream getInputStream()
throws Exception;
/**
* Utility method that will resolve and add specified proeprty.
*/
protected final void addUnresolvedValue( final String name, final String
value )
throws TaskException
{
final Object objectValue = getContext().resolveValue(
value.toString() );
getContext().setProperty( m_prefix + name, objectValue );
}
}
1.1
jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core/LoadPropertyFileTask.java
Index: LoadPropertyFileTask.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.core;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.api.TaskException;
/**
* This task loads properties from a property file and places them in the
context.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @ant.task name="load-properties"
*/
public class LoadPropertyFileTask
extends AbstractLoadPropertiesTask
{
private static final Resources REZ =
ResourceManager.getPackageResources( LoadPropertyFileTask.class );
private File m_file;
public void setFile( final File file )
{
m_file = file;
}
/**
* Creates the input stream to load the properties from.
*/
protected InputStream getInputStream()
throws Exception
{
if( null == m_file )
{
final String message = REZ.getString( "loadprop.no-file.error" );
throw new TaskException( message );
}
if( getContext().isDebugEnabled() )
{
final String message =
REZ.getString( "loadprop.file.notice",
m_file.getAbsolutePath() );
getContext().debug( message );
}
if( !m_file.exists() )
{
final String message =
REZ.getString( "loadprop.missing-file.notice",
m_file.getAbsolutePath() );
getContext().info( message );
return null;
}
return new FileInputStream( m_file );
}
}
1.1
jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core/LoadPropertyResourceTask.java
Index: LoadPropertyResourceTask.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.core;
import java.io.InputStream;
import org.apache.myrmidon.framework.file.Path;
import org.apache.myrmidon.framework.file.FileListUtil;
import org.apache.myrmidon.api.TaskException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
/**
* A task that loads properties from a resource.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/05/15 10:11:54 $
*
* @ant.task name="load-resource"
*/
public class LoadPropertyResourceTask
extends AbstractLoadPropertiesTask
{
private static final Resources REZ =
ResourceManager.getPackageResources( LoadPropertyResourceTask.class );
private String m_resource;
private Path m_classpath = new Path();
public void addClasspath( final Path classpath )
{
m_classpath.add( classpath );
}
public void setResource( final String resource )
{
m_resource = resource;
}
/**
* Creates the input stream to load the properties from.
*/
protected InputStream getInputStream()
throws Exception
{
if( m_resource == null )
{
final String message = REZ.getString(
"load-resource.no-resource.error" );
throw new TaskException( message );
}
if( getContext().isDebugEnabled() )
{
final String message = REZ.getString(
"load-resource.loading.notice", m_resource );
getContext().debug( message );
}
final ClassLoader classLoader = FileListUtil.createClassLoader(
m_classpath, getContext() );
final InputStream input = classLoader.getResourceAsStream( m_resource
);
if( input == null )
{
final String message = REZ.getString(
"load-resource.missing-resource.notice", m_resource );
getContext().info( message );
return null;
}
return input;
}
}
1.1
jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/AbstractLoadPropertiesTaskTestCase.java
Index: AbstractLoadPropertiesTaskTestCase.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.core.test;
import org.apache.antlib.AbstractProjectTestCase;
import org.apache.myrmidon.LogMessageTracker;
import java.io.File;
/**
* General purpose test case for property load tasks.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/05/15 10:11:54 $
*/
public abstract class AbstractLoadPropertiesTaskTestCase
extends AbstractProjectTestCase
{
public AbstractLoadPropertiesTaskTestCase( final String name )
{
super( name );
}
/**
* Returns the test file to use.
*/
protected abstract File getProjectFile();
/**
* Tests loading a file.
*/
public void testPropertyLoad() throws Exception
{
final File projectFile = getProjectFile();
final LogMessageTracker tracker = new LogMessageTracker();
tracker.addExpectedMessage(
"/load-properties/load-properties/property-dump", "load-properties-prop1=some
value" );
tracker.addExpectedMessage(
"/load-properties/load-properties/property-dump",
"load-properties-prop2=another value" );
executeTarget( projectFile, "load-properties", tracker );
}
/**
* Tests property resolution in loaded file.
*/
public void testPropertyResolve() throws Exception
{
final File projectFile = getProjectFile();
final LogMessageTracker tracker = new LogMessageTracker();
tracker.addExpectedMessage(
"/load-properties/resolve-properties/property-dump",
"load-properties-resolve-prop1=\"some value\"" );
executeTarget( projectFile, "resolve-properties", tracker );
}
/**
* Tests property prefixing.
*/
public void testPropertyPrefix() throws Exception
{
final File projectFile = getProjectFile();
final LogMessageTracker tracker = new LogMessageTracker();
tracker.addExpectedMessage(
"/load-properties/prefix-properties/property-dump",
"prefix.load-properties-prop1=some value" );
tracker.addExpectedMessage(
"/load-properties/prefix-properties/property-dump",
"prefix.load-properties-prop2=another value" );
executeTarget( projectFile, "prefix-properties", tracker );
}
}
1.1
jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/LoadPropertyFileTaskTestCase.java
Index: LoadPropertyFileTaskTestCase.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.core.test;
import java.io.File;
import org.apache.antlib.core.LoadPropertyFileTask;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.LogMessageTracker;
/**
* Test cases for the <load-properties> task.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/05/15 10:11:54 $
*/
public class LoadPropertyFileTaskTestCase
extends AbstractLoadPropertiesTaskTestCase
{
public LoadPropertyFileTaskTestCase( final String name )
{
super( name );
}
/**
* Returns the test file to use.
*/
protected File getProjectFile()
{
return getTestResource( "load-properties.ant" );
}
/**
* Tests validation.
*/
public void testValidation() throws Exception
{
final File projectFile = getProjectFile();
final Resources res = getResourcesForTested(
LoadPropertyFileTask.class );
// No file name
String message = res.getString( "loadprop.no-file.error" );
executeTargetExpectError( projectFile, "no-file-name", message );
// Unknown file
final LogMessageTracker tracker = new LogMessageTracker();
final File unknownFile = getTestResource( "no-such-file", false );
message = res.getString( "loadprop.missing-file.notice", unknownFile
);
tracker.addExpectedMessage(
"/load-properties/unknown-file/load-properties", message );
executeTarget( projectFile, "unknown-file", tracker );
}
}
1.1
jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/LoadPropertyResourceTaskTestCase.java
Index: LoadPropertyResourceTaskTestCase.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.core.test;
import java.io.File;
import org.apache.antlib.core.LoadPropertyResourceTask;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.LogMessageTracker;
/**
* Test cases for the <load-resource> task.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/05/15 10:11:54 $
*
* @todo Test loading resource using a classpath.
*/
public class LoadPropertyResourceTaskTestCase
extends AbstractLoadPropertiesTaskTestCase
{
public LoadPropertyResourceTaskTestCase( final String name )
{
super( name );
}
/**
* Returns the test file to use.
*/
protected File getProjectFile()
{
return getTestResource( "load-resource.ant" );
}
/**
* Tests validation.
*/
public void testValidation() throws Exception
{
final File projectFile = getProjectFile();
final Resources res = getResourcesForTested(
LoadPropertyResourceTask.class );
// No file name
String message = res.getString( "load-resource.no-resource.error" );
executeTargetExpectError( projectFile, "no-resource-name", message );
// Unknown file
final LogMessageTracker tracker = new LogMessageTracker();
message = res.getString( "load-resource.missing-resource.notice",
"no-such-resource" );
tracker.addExpectedMessage(
"/load-properties/unknown-resource/load-resource", message );
executeTarget( projectFile, "unknown-resource", tracker );
}
}
1.1
jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/load-properties-resolve.properties
Index: load-properties-resolve.properties
===================================================================
load-properties-resolve-prop1= "${prop1}"
1.1
jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/load-properties.ant
Index: load-properties.ant
===================================================================
<project version="2.0">
<target name="load-properties">
<load-properties file="load-properties.properties"/>
<property-dump prefix="load-properties"/>
</target>
<target name="resolve-properties">
<property name="prop1" value="some value"/>
<load-properties file="load-properties-resolve.properties"/>
<property-dump prefix="load-properties"/>
</target>
<target name="prefix-properties">
<load-properties prefix="prefix" file="load-properties.properties"/>
<property-dump prefix="prefix."/>
</target>
<target name="no-file-name">
<load-properties/>
</target>
<target name="unknown-file">
<load-properties file="no-such-file"/>
</target>
</project>
1.1
jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/load-properties.properties
Index: load-properties.properties
===================================================================
load-properties-prop1=some value
load-properties-prop2=another value
1.1
jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/load-resource.ant
Index: load-resource.ant
===================================================================
<project version="2.0" name="load-properties">
<target name="load-properties">
<load-resource
resource="org/apache/antlib/core/test/load-properties.properties"/>
<property-dump prefix="load-properties"/>
</target>
<target name="resolve-properties">
<property name="prop1" value="some value"/>
<load-resource
resource="org/apache/antlib/core/test/load-properties-resolve.properties"/>
<property-dump prefix="load-properties"/>
</target>
<target name="prefix-properties">
<load-resource prefix="prefix"
resource="org/apache/antlib/core/test/load-properties.properties"/>
<property-dump prefix="prefix."/>
</target>
<target name="no-resource-name">
<load-resource/>
</target>
<target name="unknown-resource">
<load-resource resource="no-such-resource"/>
</target>
</project>
1.4 +2 -2
jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/LogMessageTracker.java
Index: LogMessageTracker.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/LogMessageTracker.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LogMessageTracker.java 11 May 2002 12:44:00 -0000 1.3
+++ LogMessageTracker.java 15 May 2002 10:11:55 -0000 1.4
@@ -16,7 +16,7 @@
* correct order.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
- * @version $Revision: 1.3 $ $Date: 2002/05/11 12:44:00 $
+ * @version $Revision: 1.4 $ $Date: 2002/05/15 10:11:55 $
*/
public class LogMessageTracker
extends TrackingTaskListener
@@ -36,7 +36,7 @@
// Pop the next expected message off the list, and make sure it
// matches the message in the event
- assertTrue( "Unexpected log message", m_tasks.size() > 0 &&
m_messages.size() > 0 );
+ assertTrue( "Unexpected log message \"" + event.getMessage() + "\"",
m_tasks.size() > 0 && m_messages.size() > 0 );
assertEquals( "Incorrect task path", m_tasks.remove( 0 ),
event.getPath() );
assertEquals( "Incorrect log message", m_messages.remove( 0 ),
event.getMessage() );
}
1.17 +3 -11 jakarta-ant-myrmidon/tools/xsl/build.xsl
Index: build.xsl
===================================================================
RCS file: /home/cvs/jakarta-ant-myrmidon/tools/xsl/build.xsl,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- build.xsl 12 May 2002 11:17:05 -0000 1.16
+++ build.xsl 15 May 2002 10:11:55 -0000 1.17
@@ -84,6 +84,8 @@
</xsl:for-each>
</patternset>
+ <!-- General purpose targets -->
+
<target name="main" depends="jars" description="Builds the
project jars" />
<target name="rebuild" depends="clean, main"
description="Rebuilds the project jars" />
<target name="recompile" depends="clean-classes, main"
description="Recompiles the project jars" />
@@ -118,15 +120,6 @@
<available property="jdk1.3+"
classname="java.lang.StrictMath" />
<available property="jdk1.4+"
classname="java.lang.CharSequence" />
- <!-- Check for Ant version 1.5 -->
- <property resource="org/apache/tools/ant/version.txt"/>
- <condition property="ant1.5">
- <or>
- <equals arg1="${{VERSION}}" arg2="1.5alpha"/>
- <equals arg1="${{VERSION}}" arg2="1.5"/>
- </or>
- </condition>
-
<!-- taskdef the antlib descriptor task, necessary -->
<xsl:if test="build/jar[not(includeDescriptors =
'false')]|unitTest[not(includeDescriptors='false')]" >
<taskdef name="antlib-descriptor"
@@ -143,9 +136,8 @@
</target>
<target name="compile-src" depends="prepare">
- <mkdir dir="${{build.classes}}"/>
-
<xsl:if test="build/sourceDirectory">
+ <mkdir dir="${{build.classes}}"/>
<!-- Compile all classes -->
<javac
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>