You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2004/09/08 06:38:34 UTC
cvs commit: jakarta-commons/jelly/jelly-tags/ant/src/java/org/apache/commons/jelly/task JellyTask.java
dion 2004/09/07 21:38:34
Modified: jelly/jelly-tags/ant/src/test/org/apache/commons/jelly/ant/task
DummyTask.java
jelly/jelly-tags/ant/src/test/org/apache/commons/jelly/ant/tag
DummyTag.java
jelly/jelly-tags/ant/src/java/org/apache/commons/jelly/tags/ant
AntTag.java
jelly/jelly-tags/ant/src/java/org/apache/commons/jelly/task
JellyTask.java
Log:
detab
Revision Changes Path
1.8 +35 -35 jakarta-commons/jelly/jelly-tags/ant/src/test/org/apache/commons/jelly/ant/task/DummyTask.java
Index: DummyTask.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/ant/src/test/org/apache/commons/jelly/ant/task/DummyTask.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DummyTask.java 1 Sep 2004 17:19:19 -0000 1.7
+++ DummyTask.java 8 Sep 2004 04:38:34 -0000 1.8
@@ -1,12 +1,12 @@
/*
* Copyright 2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -65,15 +65,15 @@
*/
-/**
+/**
* A sample Task to test out the Ant introspection logic
*
* @author Aslak Helles�y (aslak.hellesoy@bekk.no)
* @version $Revision$
*/
public class DummyTask extends Task {
- private int i = 0;
- private String[] messages = { "a", "b", "c", "d", "e", "f", "g", "h", "i" };
+ private int i = 0;
+ private String[] messages = { "a", "b", "c", "d", "e", "f", "g", "h", "i" };
private boolean force;
public void execute() throws BuildException {
@@ -81,32 +81,32 @@
throw new BuildException("Should have set force to be true!");
}
}
-
- public Thingy createDing() {
- System.out.println("createDing: " + messages[i++]);
- return new Thingy();
- }
-
- public void addDang(Thingy thingy) {
- System.out.println("addDang: " + messages[i++]);
- }
-
- public void addConfiguredDong(Thingy thingy) {
- System.out.println("addConfiguredDong: " + messages[i++]);
- }
-
- public Thingy createHipHop() {
- System.out.println("createHipHop: " + messages[i++]);
- return new Thingy();
- }
-
- public void addWontStop(Thingy thingy) {
- System.out.println("addWontStop: " + messages[i++]);
- }
-
- public void addConfiguredTillYouDrop(Thingy thingy) {
- System.out.println("addConfiguredTillYouDrop: " + messages[i++]);
- }
+
+ public Thingy createDing() {
+ System.out.println("createDing: " + messages[i++]);
+ return new Thingy();
+ }
+
+ public void addDang(Thingy thingy) {
+ System.out.println("addDang: " + messages[i++]);
+ }
+
+ public void addConfiguredDong(Thingy thingy) {
+ System.out.println("addConfiguredDong: " + messages[i++]);
+ }
+
+ public Thingy createHipHop() {
+ System.out.println("createHipHop: " + messages[i++]);
+ return new Thingy();
+ }
+
+ public void addWontStop(Thingy thingy) {
+ System.out.println("addWontStop: " + messages[i++]);
+ }
+
+ public void addConfiguredTillYouDrop(Thingy thingy) {
+ System.out.println("addConfiguredTillYouDrop: " + messages[i++]);
+ }
public boolean isForce() {
return force;
@@ -115,7 +115,7 @@
public void setForce(boolean force) {
this.force = force;
}
-
- public static class Thingy {
- }
+
+ public static class Thingy {
+ }
}
1.7 +36 -36 jakarta-commons/jelly/jelly-tags/ant/src/test/org/apache/commons/jelly/ant/tag/DummyTag.java
Index: DummyTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/ant/src/test/org/apache/commons/jelly/ant/tag/DummyTag.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DummyTag.java 1 Sep 2004 15:51:40 -0000 1.6
+++ DummyTag.java 8 Sep 2004 04:38:34 -0000 1.7
@@ -1,12 +1,12 @@
/*
* Copyright 2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,7 +26,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.tools.ant.types.Path;
-/**
+/**
* A mock tag which is used for testing the Ant nested properties behaviour
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
@@ -37,77 +37,77 @@
/** The Log to which logging calls will be made. */
private static Log log = LogFactory.getLog(DummyTag.class);
- private String var;
-
- private boolean calledCreatepath;
- private boolean calledSetClasspath;
+ private String var;
+
+ private boolean calledCreatepath;
+ private boolean calledSetClasspath;
private boolean calledSetFlag;
-
+
private Path classpath;
private boolean flag;
-
+
public DummyTag() {
}
// BeanSource interface
//-------------------------------------------------------------------------
public Object getBean() {
- return this;
- }
+ return this;
+ }
// Tag interface
- //-------------------------------------------------------------------------
+ //-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws JellyTagException {
if (! calledSetFlag) {
throw new AssertionFailedError("call to setFlag() was not made");
}
-
- calledCreatepath = false;
- calledSetClasspath = false;
+
+ calledCreatepath = false;
+ calledSetClasspath = false;
invokeBody(output);
-
+
if (! calledCreatepath) {
- throw new AssertionFailedError("call to createClasspath() was not made");
+ throw new AssertionFailedError("call to createClasspath() was not made");
}
-
+
if (! calledSetClasspath) {
- throw new AssertionFailedError("call to setClasspath() was not made");
+ throw new AssertionFailedError("call to setClasspath() was not made");
}
log.info( "Called with classpath: " + classpath );
-
+
if (var != null) {
- context.setVariable(var, classpath);
+ context.setVariable(var, classpath);
}
}
-
+
// Ant Task-like nested property methods
//-------------------------------------------------------------------------
public Path createClasspath() {
- log.info("called createClasspath()");
- calledCreatepath = true;
- return new Path( AntTagLibrary.getProject(context) );
+ log.info("called createClasspath()");
+ calledCreatepath = true;
+ return new Path( AntTagLibrary.getProject(context) );
}
-
+
public void setClasspath(Path classpath) {
- log.info("called setClasspath()");
- calledSetClasspath = true;
- this.classpath = classpath;
+ log.info("called setClasspath()");
+ calledSetClasspath = true;
+ this.classpath = classpath;
}
-
+
public void setFlag(boolean flag)
{
log.info("called setFlag()");
- calledSetFlag = true;
+ calledSetFlag = true;
this.flag = flag;
-
+
}
-
+
// Tag properties
//-------------------------------------------------------------------------
-
+
public void setVar(String var) {
- this.var = var;
+ this.var = var;
}
}
1.34 +64 -64 jakarta-commons/jelly/jelly-tags/ant/src/java/org/apache/commons/jelly/tags/ant/AntTag.java
Index: AntTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/ant/src/java/org/apache/commons/jelly/tags/ant/AntTag.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- AntTag.java 2 Sep 2004 05:57:06 -0000 1.33
+++ AntTag.java 8 Sep 2004 04:38:34 -0000 1.34
@@ -1,12 +1,12 @@
/*
* Copyright 2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -66,7 +66,7 @@
/** Task, if this tag represents a task. */
protected Task task;
-
+
/** Construct with a project and tag name.
*
@@ -82,7 +82,7 @@
// TaskSource interface
//-------------------------------------------------------------------------
-
+
/** Retrieve the general object underlying this tag.
*
* @return The object underlying this tag.
@@ -108,10 +108,10 @@
Project project = getAntProject();
String tagName = getTagName();
Object parentObject = findBeanAncestor();
- Object parentTask = findParentTaskObject();
-
+ Object parentTask = findParentTaskObject();
+
// lets assume that Task instances are not nested inside other Task instances
- // for example <manifest> inside a <jar> should be a nested object, where as
+ // for example <manifest> inside a <jar> should be a nested object, where as
// if the parent is not a Task the <manifest> should create a ManifestTask
//
// also its possible to have a root Ant tag which isn't a task, such as when
@@ -121,20 +121,20 @@
if (parentObject != null && !( parentTask instanceof TaskContainer) ) {
nested = createNestedObject( parentObject, tagName );
}
-
+
if (nested == null) {
task = createTask( tagName );
-
+
if (task != null) {
if ( log.isDebugEnabled() ) {
- log.debug( "Creating an ant Task for name: " + tagName );
+ log.debug( "Creating an ant Task for name: " + tagName );
}
-
+
// the following algorithm follows the lifetime of a tag
// http://jakarta.apache.org/ant/manual/develop.html#writingowntask
// kindly recommended by Stefan Bodewig
-
+
// create and set its project reference
if ( task instanceof TaskAdapter ) {
setObject( ((TaskAdapter)task).getProxy() );
@@ -142,24 +142,24 @@
else {
setObject( task );
}
-
+
// set the task ID if one is given
Object id = getAttributes().remove( "id" );
if ( id != null ) {
project.addReference( (String) id, task );
}
-
+
// ### we might want to spoof a Target setting here
-
+
// now lets initialize
task.init();
-
+
// now lets invoke the body to call all the createXXX() or addXXX() methods
String body = getBodyText();
-
+
// now lets set any attributes of this tag...
setBeanProperties();
-
+
// now lets set the addText() of the body content, if its applicaable
Method method = MethodUtils.getAccessibleMethod( task.getClass(),
"addText",
@@ -168,30 +168,30 @@
Object[] args = { body };
try {
method.invoke(this.task, args);
- }
+ }
catch (IllegalAccessException e) {
throw new JellyTagException(e);
- }
+ }
catch (InvocationTargetException e) {
throw new JellyTagException(e);
}
}
-
+
// now lets set all the attributes of the child elements
// XXXX: to do!
-
+
// now we're ready to invoke the task
// XXX: should we call execute() or perform()?
task.perform();
}
}
-
+
if (task == null) {
-
+
if (nested == null) {
-
- if ( log.isDebugEnabled() ) {
- log.debug( "Trying to create a data type for tag: " + tagName );
+
+ if ( log.isDebugEnabled() ) {
+ log.debug( "Trying to create a data type for tag: " + tagName );
}
nested = createDataType( tagName );
}
@@ -221,59 +221,59 @@
// now lets invoke the body
String body = getBodyText();
-
+
// now lets set any attributes of this tag...
setBeanProperties();
-
+
// now lets add it to its parent
if ( parentObject != null ) {
IntrospectionHelper ih = IntrospectionHelper.getHelper( parentObject.getClass() );
try {
- if (log.isDebugEnabled()) {
- log.debug("About to set the: " + tagName
- + " property on: " + parentObject + " to value: "
- + nested + " with type: " + nested.getClass()
- );
- }
-
+ if (log.isDebugEnabled()) {
+ log.debug("About to set the: " + tagName
+ + " property on: " + parentObject + " to value: "
+ + nested + " with type: " + nested.getClass()
+ );
+ }
+
ih.storeElement( project, parentObject, nested, tagName.toLowerCase() );
}
catch (Exception e) {
log.warn( "Caught exception setting nested: " + tagName, e );
}
-
+
// now try to set the property for good measure
// as the storeElement() method does not
// seem to call any setter methods of non-String types
try {
- BeanUtils.setProperty( parentObject, tagName, nested );
+ BeanUtils.setProperty( parentObject, tagName, nested );
}
catch (Exception e) {
- log.debug("Caught exception trying to set property: " + tagName + " on: " + parentObject);
+ log.debug("Caught exception trying to set property: " + tagName + " on: " + parentObject);
}
}
}
else {
log.warn("Could not convert tag: " + tagName + " into an Ant task, data type or property");
-
- // lets treat this tag as static XML...
+
+ // lets treat this tag as static XML...
StaticTag tag = new StaticTag("", tagName, tagName);
tag.setParent( getParent() );
tag.setBody( getBody() );
-
+
tag.setContext(context);
-
+
for (Iterator iter = getAttributes().entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
String name = (String) entry.getKey();
Object value = entry.getValue();
-
+
tag.setAttribute(name, value);
}
-
+
tag.doTag(output);
}
- }
+ }
}
@@ -330,9 +330,9 @@
}
else
{
- super.setAttribute( name, value.toString() );
- }
- }
+ super.setAttribute( name, value.toString() );
+ }
+ }
}
public void setBeanProperty(Object object, String name, Object value) throws JellyTagException {
@@ -361,7 +361,7 @@
try {
// let any exceptions bubble up from here
BeanUtils.setProperty( object, name, value );
- }
+ }
catch (IllegalAccessException ex) {
throw new JellyTagException(ex);
}
@@ -425,7 +425,7 @@
ctor = type.getConstructor(new Class[] { Project.class });
noArg = false;
} catch (NoSuchMethodException nsme) {
- log.info("datatype '" + name
+ log.info("datatype '" + name
+ "' didn't have a constructor with an Ant Project", nsme);
}
}
@@ -438,7 +438,7 @@
}
if (dataType != null) {
((DataType)dataType).setProject( getAntProject() );
- }
+ }
}
return dataType;
@@ -477,7 +477,7 @@
public Task createTask(String taskName,
Class taskType) throws JellyTagException {
-
+
if (taskType == null) {
return null;
}
@@ -491,7 +491,7 @@
catch (IllegalAccessException e) {
throw new JellyTagException(e);
}
-
+
Task task = null;
if ( o instanceof Task ) {
task = (Task) o;
@@ -507,11 +507,11 @@
return task;
}
-
+
/**
- * Attempts to look up in the parent hierarchy for a tag that implements the
+ * Attempts to look up in the parent hierarchy for a tag that implements the
* TaskSource interface, which returns an Ant Task object or that implements
- * BeanSource interface which creates a bean,
+ * BeanSource interface which creates a bean,
* or will return the parent tag, which is also a bean.
*/
protected Object findBeanAncestor() throws JellyTagException {
@@ -522,14 +522,14 @@
return beanSource.getBean();
}
if (tag instanceof TaskSource) {
- TaskSource taskSource = (TaskSource) tag;
- return taskSource.getTaskObject();
+ TaskSource taskSource = (TaskSource) tag;
+ return taskSource.getTaskObject();
}
tag = tag.getParent();
}
return getParent();
}
-
+
/**
* Walks the hierarchy until it finds a parent TaskSource and returns its source or returns null
*/
@@ -537,12 +537,12 @@
Tag tag = getParent();
while (tag != null) {
if (tag instanceof TaskSource) {
- TaskSource source = (TaskSource) tag;
- return source.getTaskObject();
+ TaskSource source = (TaskSource) tag;
+ return source.getTaskObject();
}
tag = tag.getParent();
}
return null;
}
-
+
}
1.14 +37 -37 jakarta-commons/jelly/jelly-tags/ant/src/java/org/apache/commons/jelly/task/JellyTask.java
Index: JellyTask.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/ant/src/java/org/apache/commons/jelly/task/JellyTask.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- JellyTask.java 25 Feb 2004 01:24:48 -0000 1.13
+++ JellyTask.java 8 Sep 2004 04:38:34 -0000 1.14
@@ -1,12 +1,12 @@
/*
* Copyright 2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -36,8 +36,8 @@
import org.xml.sax.SAXException;
-/**
- * <p><code>JellyTask</code> is an Ant task which will
+/**
+ * <p><code>JellyTask</code> is an Ant task which will
* run a given Jelly script.
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
@@ -57,16 +57,16 @@
/** The URL of the root context for other scripts */
private URL rootContext;
-
+
/** The XML output */
private XMLOutput xmlOutput;
/** The file where output is going */
- private File output;
+ private File output;
// Task interface
//-------------------------------------------------------------------------
-
+
/**
* Excutes the Jelly script
*/
@@ -76,7 +76,7 @@
if ( output != null ) {
log( "Sending output to: " + output );
}
-
+
Script script = compileScript();
JellyContext context = getJellyContext();
context.setVariable( "project", getProject() );
@@ -87,35 +87,35 @@
throw new BuildException(e, getLocation() );
}
}
-
+
// Properties
- //-------------------------------------------------------------------------
-
- /**
+ //-------------------------------------------------------------------------
+
+ /**
* Sets the script URL to use as an absolute URL or a relative filename
*/
public void setScript(String script) throws MalformedURLException {
setUrl(resolveURL(script));
}
-
+
public URL getUrl() {
return url;
}
-
- /**
- * Sets the script URL to use
+
+ /**
+ * Sets the script URL to use
*/
public void setUrl(URL url) {
this.url = url;
}
-
+
/**
* Sets the script file to use
*/
public void setFile(File file) throws MalformedURLException {
setUrl( file.toURL() );
}
-
+
/**
* Sets the output to generate
*/
@@ -123,22 +123,22 @@
this.output = output;
xmlOutput = XMLOutput.createXMLOutput( new FileWriter( output ) );
}
-
+
public XMLOutput getXMLOutput() throws IOException {
if (xmlOutput == null) {
xmlOutput = XMLOutput.createXMLOutput( System.out );
}
return xmlOutput;
}
-
+
/**
* Sets the XMLOutput used
*/
public void setXMLOutput(XMLOutput xmlOutput) {
this.xmlOutput = xmlOutput;
}
-
- /**
+
+ /**
* Gets the root context
*/
public URL getRootContext() throws MalformedURLException {
@@ -147,14 +147,14 @@
}
return rootContext;
}
-
- /**
+
+ /**
* Sets the root context
*/
public void setRootContext(URL rootContext) {
this.rootContext = rootContext;
}
-
+
/**
* The context to use
*/
@@ -166,27 +166,27 @@
text = text.substring(0, idx + 1);
JellyContext parentContext = new JellyContext(getRootContext(), new URL(text));
context = new AntJellyContext(getProject() , parentContext);
-
+
// register the Ant tag library
context.registerTagLibrary( "jelly:ant", new AntTagLibrary() );
}
return context;
}
-
+
// Implementation methods
- //-------------------------------------------------------------------------
-
+ //-------------------------------------------------------------------------
+
/**
* Compiles the script
*/
protected Script compileScript() throws JellyException {
XMLParser parser = new XMLParser();
-
+
Script script = null;
try {
parser.setContext(getJellyContext());
script = parser.parse(getUrl().toString());
- }
+ }
catch (IOException e) {
throw new JellyException(e);
}
@@ -194,19 +194,19 @@
throw new JellyException(e);
}
script = script.compile();
-
+
if (log.isDebugEnabled()) {
log.debug("Compiled script: " + getUrl());
}
return script;
}
-
-
+
+
/**
- * @return the URL for the relative file name or absolute URL
+ * @return the URL for the relative file name or absolute URL
*/
protected URL resolveURL(String name) throws MalformedURLException {
- File file = getProject().resolveFile(name);
+ File file = getProject().resolveFile(name);
if (file.exists()) {
return file.toURL();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org