You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Ja...@rzf.fin-nrw.de on 2008/11/07 11:53:12 UTC

JavaFront + running a task from command line

I tried to implement a starter so that you can start a task from the
command line like
	ant -lib JAVAFRONT -main org.apache.ant.javafront.TaskExec echo
message "Hallo Welt"
	ant -lib JAVAFRONT -main org.apache.ant.javafront.TaskExec
echoproperties prefix ant.

In Ant XML:
	<project><echo message="Hallo Welt"/></project>
	<project><echoproperties prefix="ant."/></project>

The starter is:
    public class TaskExec implements AntMain {

        public void startAnt(String[] args, Properties
additionalUserProperties, ClassLoader coreLoader) {
            Map<String, String> attributes = new Hashtable<String,
String>();

            // Analyzing the command line arguments
            String taskname = args[0];
            for(int i=1; i<args.length; ) {
                String attrName  = args[i++];
                String attrValue = args[i++];
                attributes.put(attrName, attrValue);
            }

            // Initializing
            Project    project = initProject();
            TagBuilder builder = TagBuilder.forProject(project);

            // Initializing the Task
            Tag tag = builder.tag(taskname);
            for (String key : attributes.keySet()) {
                tag.withAttribute(key, attributes.get(key));
            }

            // Run the task
            tag.execute();
        }

        private Project initProject() {
            DefaultLogger logger = new DefaultLogger();
            logger.setOutputPrintStream(System.out);
            logger.setErrorPrintStream(System.err);

            Project rv = new Project();
            rv.addBuildListener(logger);
            rv.init();

            return rv;
        }
    }


I cant find the mistake, but there is no output ...
Any ideas?


Jan

AW: JavaFront + running a task from command line

Posted by Ja...@rzf.fin-nrw.de.
>> I tried to implement a starter so that you can start a task from the
>> command line like
>> ant -lib JAVAFRONT -main org.apache.ant.javafront.TaskExec echo\
>>   message "Hallo Welt"
>
>interesting.  all you need from JavaFront is the TagBuilder, so it may
>better be split out.

Maybe next week. Splitting JavaFront in three parts
- tagbuilder library
- task executor
- java based buildfiles


>>         private Project initProject() {
>>             DefaultLogger logger = new DefaultLogger();
>>             logger.setOutputPrintStream(System.out);
>>             logger.setErrorPrintStream(System.err);
>>
>> I cant find the mistake, but there is no output ...
>> Any ideas?
>
>            logger.setMessageOutputLevel(Project.MSG_INFO);
>
>DefaultLogger's default level is MSG_ERR so your echo wasn't logging
>at a level severe enough to create output.


Thanks. I should had a look at THAT source too ...


Jan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: JavaFront + running a task from command line

Posted by Stefan Bodewig <bo...@apache.org>.
On Fri, 7 Nov 2008, Jan Materne <Ja...@rzf.fin-nrw.de> wrote:

> I tried to implement a starter so that you can start a task from the
> command line like
> ant -lib JAVAFRONT -main org.apache.ant.javafront.TaskExec echo\
>   message "Hallo Welt"

interesting.  all you need from JavaFront is the TagBuilder, so it may
better be split out.

>         private Project initProject() {
>             DefaultLogger logger = new DefaultLogger();
>             logger.setOutputPrintStream(System.out);
>             logger.setErrorPrintStream(System.err);
>
> I cant find the mistake, but there is no output ...
> Any ideas?

            logger.setMessageOutputLevel(Project.MSG_INFO);

DefaultLogger's default level is MSG_ERR so your echo wasn't logging
at a level severe enough to create output.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org