Hi,
The following is the JavaInputTask.java file

package com.channelpoint.build.ant.publiclib;

import org.apache.tools.ant.*;
import org.apache.tools.ant.taskdefs.*;

import java.io.*;

/**
 * This is an enhanced Java task. It can run java programs in another 
thread,
 * pause while they startup, and give them input.
 *
 * Arguments include:
 * <li>
 *   <ul>spawn (true or false to create a separate thread for this 
execution)
 *   <ul>sleep (milliseconds to pause before returning)
 *   <ul>input (nested ex. <input line="blah"/>)
 * </li>
 */
public class JavaInputTask extends Java {
    private Input _input = null;
    private boolean _spawn = false;
    private long _sleep = 0;

    public void setSpawn( boolean spawn ) {
        _spawn = spawn;
    }

    public void setSleep( long sleep ) {
        _sleep = sleep;
    }

    public Input createInput() {
        if( _input == null ) {
            _input = new Input();
        }
        return _input;
    }

    public void doit() throws BuildException {
        super.execute();
    }
    public void execute() throws BuildException {
        InputStream old = null;
        if( _input != null ) {
            old = System.in;
            System.setIn( new ByteArrayInputStream( _input.getBytes() ) );
        }

        if( _spawn ) {
            Spawn s = new Spawn( this );
            s.start();
            try {
                Thread.currentThread().sleep( _sleep );
            } catch ( InterruptedException e ) {
                throw new BuildException( e );
            }
        } else {
            doit();
        }

        if( old != null ) {
            System.setIn( old );
        }
    }

    public class Spawn extends Thread {
        private JavaInputTask _ji;

        public Spawn( JavaInputTask ji ) {
            _ji = ji;
        }

        public void run() {
            _ji.doit();
        }
    }

    public class Input {
        private StringBuffer _buf = new StringBuffer();

        public void setLine( String line ) {
            _buf.append( line + "\n" );
        }

        public byte[] getBytes() {
            return _buf.toString().getBytes();
        }
    }
}

the 
    public void setSpawn( boolean spawn ) {
        _spawn = spawn;
    }

does exist, but is there a need to use a taskdef task to define the 
new class that is to be used??

Regards,
Rosmon Sidhik


-----------------------------------------------------------------------------------------------------
It doesn't matter how many say it cannot be done or how many
people have tried it before; it's important to realize that whatever
you're doing, it's your first attempt at it.
-----------------------------------------------------------------------------------------------------




[EMAIL PROTECTED]
09/18/02 03:15 PM
Please respond to "Ant Users List"

 
        To:     Ant Users List <[EMAIL PROTECTED]>
        cc: 
        Subject:        Re: how to use a new task


you probably forgot to define a method named setSpawn(Object x) in your 
java class.


detlef
Quoting [EMAIL PROTECTED]:

> Hi all,
> I got this JavaInputTask.java file 
> adding the spawn attribute to the java task.
> I compiled it and placed it in the lib directory with the proper
> directory 
> structure
> and added the lib direrctory to the environment classpath and path.
> But when i use the attribute with the java task it says 
> 
> 
> file:D:/testbldgjag/jagbuild/cxbuild.xml:366: The <java> task doesn't 
> support the "spawn" attribute.
>         at 
>
org.apache.tools.ant.IntrospectionHelper.setAttribute(IntrospectionHelper.java:422)
>         at 
> org.apache.tools.ant.ProjectHelper.configure(ProjectHelper.java:306)
>         at 
>
org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:233)
>         at 
>
org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:202)
>         at org.apache.tools.ant.Task.maybeConfigure(Task.java:257)
>         at 
>
org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:251)
>         at 
>
org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:202)
>         at org.apache.tools.ant.Task.maybeConfigure(Task.java:257)
>         at org.apache.tools.ant.Task.perform(Task.java:316)
>         at org.apache.tools.ant.Target.execute(Target.java:309)
>         at org.apache.tools.ant.Target.performTasks(Target.java:334)
>         at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
>         at
> org.apache.tools.ant.Project.executeTargets(Project.java:1250)
>         at org.apache.tools.ant.Main.runBuild(Main.java:610)
>         at org.apache.tools.ant.Main.start(Main.java:196)
>         at org.apache.tools.ant.Main.main(Main.java:235)
> 
> 
> Any inputs on this would be very helpful.
> 
> Regards,
> Rosmon Sidhik
> 
> 
>
-----------------------------------------------------------------------------------------------------
> It doesn't matter how many say it cannot be done or how many
> people have tried it before; it's important to realize that whatever
> you're doing, it's your first attempt at it.
>
-----------------------------------------------------------------------------------------------------

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>



Reply via email to