From ant-dev-return-34672-qmlist-jakarta-archive-ant-dev=jakarta.apache.org@jakarta.apache.org Wed Jun 26 02:12:47 2002 Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 25721 invoked from network); 26 Jun 2002 02:12:47 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 26 Jun 2002 02:12:47 -0000 Received: (qmail 23702 invoked by uid 97); 26 Jun 2002 02:12:57 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 23648 invoked by uid 97); 26 Jun 2002 02:12:56 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 23621 invoked by uid 97); 26 Jun 2002 02:12:55 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Date: 26 Jun 2002 02:12:36 -0000 Message-ID: <20020626021236.61186.qmail@icarus.apache.org> From: adammurdoch@apache.org To: jakarta-ant-myrmidon-cvs@apache.org Subject: cvs commit: jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test IncludeTaskTestCase.java LoadDOMTaskTestCase.java include-log.ant include-props.ant include.ant load-dom.ant test.xml X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N adammurdoch 2002/06/25 19:12:36 Modified: antlib/src/java/org/apache/antlib/core Resources.properties Added: antlib/src/java/org/apache/antlib/core IncludeTask.java LoadDOMTask.java antlib/src/test/org/apache/antlib/core/test IncludeTaskTestCase.java LoadDOMTaskTestCase.java include-log.ant include-props.ant include.ant load-dom.ant test.xml Log: - Added task, which loads and executes the contents of an XML file. Execution happens in the same scope as the task. - Added task, which loads the DOM of an XML file into a property, where it can be slurped over using XPath. - Added test cases. Revision Changes Path 1.7 +6 -2 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.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- Resources.properties 6 Jun 2002 10:57:03 -0000 1.6 +++ Resources.properties 26 Jun 2002 02:12:36 -0000 1.7 @@ -33,5 +33,9 @@ load-resource.loading.notice=Loading properties from resource "{0}". load-resource.missing-resource.notice=Unable to find resource "{0}". -for-each.no-propertry.error=No property name specified. -for-each.no-list.error=No values specified. \ No newline at end of file +load-dom.no-file.error=No source file specified. +load-dom.no-property.error=No property name specified. +load-dom.load-file.error=Could not load file "{0}". + +include.no-file.error=No source file specified. +include.load-file.error=Could not load file "{0}". \ No newline at end of file 1.1 jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core/IncludeTask.java Index: IncludeTask.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 org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.Resources; import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.api.metadata.ModelElement; import org.apache.myrmidon.framework.AbstractContainerTask; import org.apache.myrmidon.interfaces.builder.ModelBuilder; /** * A task that loads and executes an XML fragment. * * @author Adam Murdoch * @version $Revision: 1.1 $ $Date: 2002/06/26 02:12:36 $ * * @ant.task name="include" */ public class IncludeTask extends AbstractContainerTask { private static final Resources REZ = ResourceManager.getPackageResources( IncludeTask.class ); private File m_file; /** * The file to load the XML fragment from. * @param file */ public void setFile( final File file ) { m_file = file; } /** * Executes the task. */ public void execute() throws TaskException { if( m_file == null ) { final String message = REZ.getString( "include.no-file.error" ); throw new TaskException( message ); } // Load the model final ModelElement model; try { final ModelBuilder builder = (ModelBuilder)getService( ModelBuilder.class ); model = builder.build( m_file.getAbsolutePath() ); } catch( final Exception e ) { final String message = REZ.getString( "include.load-file.error", m_file ); throw new TaskException( message, e ); } // Execute the children executeTasks( model.getChildren() ); } } 1.1 jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core/LoadDOMTask.java Index: LoadDOMTask.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 javax.xml.parsers.DocumentBuilderFactory; import org.apache.myrmidon.api.AbstractTask; import org.apache.myrmidon.api.TaskException; import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.Resources; import org.w3c.dom.Document; /** * Loads an XML DOM from a file, and sets it as a property. * * @author Adam Murdoch * @version $Revision: 1.1 $ $Date: 2002/06/26 02:12:36 $ * * @ant.task name="load-dom" * * @todo - Convert this task into a data-type, instead. */ public class LoadDOMTask extends AbstractTask { private static final Resources REZ = ResourceManager.getPackageResources( LoadDOMTask.class ); private File m_file; private String m_property; /** * The file to load the XML DOM from. */ public void setFile( final File file ) { m_file = file; } /** * The name of the property to set. */ public void setProperty( final String property ) { m_property = property; } /** * Executes this task. */ public void execute() throws TaskException { if( m_file == null ) { final String message = REZ.getString( "load-dom.no-file.error" ); throw new TaskException( message ); } if( m_property == null ) { final String message = REZ.getString( "load-dom.no-property.error" ); throw new TaskException( message ); } try { final Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( m_file ); getContext().setProperty( m_property, dom.getDocumentElement() ); } catch( final Exception e ) { final String message = REZ.getString( "load-dom.load-file.error", m_file ); throw new TaskException( message, e ); } } } 1.1 jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/IncludeTaskTestCase.java Index: IncludeTaskTestCase.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 java.io.File; /** * Test cases for the task. * * @author Adam Murdoch * @version $Revision: 1.1 $ $Date: 2002/06/26 02:12:36 $ */ public class IncludeTaskTestCase extends AbstractProjectTestCase { public IncludeTaskTestCase( final String name ) { super( name ); } public void testExecution() throws Exception { final File projectFile = getTestResource( "include.ant" ); executeTarget( projectFile, "include-log" ); executeTarget( projectFile, "include-use-props" ); executeTarget( projectFile, "no-file" ); executeTarget( projectFile, "unknown-file" ); } } 1.1 jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/LoadDOMTaskTestCase.java Index: LoadDOMTaskTestCase.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 java.io.File; /** * Test cases for the task. * * @author Adam Murdoch * @version $Revision: 1.1 $ $Date: 2002/06/26 02:12:36 $ */ public class LoadDOMTaskTestCase extends AbstractProjectTestCase { public LoadDOMTaskTestCase( final String name ) { super( name ); } public void testExecute() throws Exception { final File projectFile = getTestResource( "load-dom.ant" ); executeTarget( projectFile, "load-file" ); executeTarget( projectFile, "no-propname" ); executeTarget( projectFile, "no-file" ); executeTarget( projectFile, "unknown-file" ); } } 1.1 jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/include-log.ant Index: include-log.ant =================================================================== Included task 1 Included task 2 1.1 jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/include-props.ant Index: include-props.ant =================================================================== new value 1.1 jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/include.ant Index: include.ant =================================================================== Included task 1 Included task 2 original value No source file specified. Could not load file "${myrmidon.project/baseDirectory}${file.separator}no-such-file". 1.1 jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/load-dom.ant Index: load-dom.ant =================================================================== No property name specified. No source file specified. Could not load file "${myrmidon.project/baseDirectory}${file.separator}no-such-file". 1.1 jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/test.xml Index: test.xml =================================================================== some text -- To unsubscribe, e-mail: For additional commands, e-mail: