You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by David H Elrod <dh...@rivendell.com> on 2000/05/26 19:45:13 UTC

Re: How to tell what Javac did?

A new person's thoughts:

Maybe there could be an attribute 'exitStatusName="someName"'
for the task? When the task exits, then "someName" would be
set to the exit value. The user gets to pick the name and
set up the relationship between tasks (if any). The the
Project.getProperty("someName") call could return the
exist status of any arbitrary task.


Do you think tasks might be run in different threads?
If so, it seems like idea of "last task" is a tough one.
It seems like setting/checking a property might allow
tasks to better coordinate, but this opens the whole
critical_section/synchronization/etc. area.


David

-------------------------------------------------------------------
David Hunter Elrod                   Rivendell Technologies, Inc
dhelrod@rivendell.com                1111 W. El Camino #109, PMB348
http://www.rivendell.com             Sunnyvale, CA 94087-0126
Voice: 650/254-1790                  Fax: 650/254-1792



> This is a multi-part message in MIME format.
> 
> ------=_NextPart_000_001A_01BFC75D.12C29050
> Content-Type: text/plain;
> 	charset="iso-8859-1"
> Content-Transfer-Encoding: 7bit
> 
> > -----Original Message-----
> > From: Stefan Bodewig [mailto:bodewig@bost.de]
> >
> > >>>>> "AK" == Aaron Knauf <Aa...@geniesystems.com> writes:
> >
> >  AK> So, do we want to do exit status checking at the Task level or at
> >  AK> the Target level?
> >
> > Both seem to be usefull.
> >
> >  AK> If at the Task level, how does the next Task check/use the value?
> >  AK> (Target has a nice easy if="some.property.present".)
> >
> > Ask the Project? Let's assume Task.execute returns a TaskResult
> > object, this could be put into the project via something like
> > Project.setLastTaskResult(TaskResult) and retrieved by the next task
> > via say Project.getLastTaskResult().
> >
> > Stefan
> 
> I am in two minds over this whole thread.
> 
> When I built my weblogic tasks, I used a Java task internally to invoke a
> helper class with a defined classpath. This is a slightly unusual use of the
> Java task object. I wanted to know the return code from that Java task, but
> there was no way to get at it. If the weblogic tools failed, the build would
> continue. My solution to this was more narrowly focused than the proposals
> here. I added another entry point into the Java Task which would throw a
> build exception if the forked JVM returned an error. The patch for this is
> attached. In effect this makes the error code available for internal uses of
> the Java task and not to the build.xml level.
> 
> So, in one sense I see the use of getting at the return codes from tasks.
> And yet, I am wary of bringing visibility of that into build.xml file. It
> would seem to increase the complexity of ant either by adding lots of
> conditional stuff to build.xml or by building implicit coupling of tasks
> through task results.
> 
> In the example you give above, a task calling getLastResult() implies a
> relationship between two tasks which is not explicitly specified in the
> build.xml. As a user of ant I now need to know how one task sets that result
> and how another task will interpret it. If the tasks are closely coupled
> enough for this passing of result information to make sense, then perhaps
> they should be combined into a single ant task.
> 
> How will we decide the required structure of task results? The original
> request which prompted this thread was a desire to know if Javac did any
> work, not just whether it succeeded. So would a return result for Javac need
> to specify success/failure, did it do anything? How many files did it
> compile? Maybe even which files it compiled or even how long it took?
> 
> Even if we could come up with a sensible definition for results, how would
> another task use those results. Would it need to know it was using a Javac
> result? If we are going to expose the return result at the build.xml level,
> how would we do that? through a set of properties?
> 
> I like the current inter-task communication. If a task is executing it knows
> all previously executed tasks did not fail :-)
> 
> Thoughts?
> 
> Conor
> 
> ------=_NextPart_000_001A_01BFC75D.12C29050
> Content-Type: text/plain;
> 	name="patch.txt"
> Content-Transfer-Encoding: quoted-printable
> Content-Disposition: attachment;
> 	filename="patch.txt"
> 
> RCS file: =
> /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Java.j=
> ava,v
> retrieving revision 1.6
> diff -u -r1.6 Java.java
> --- src/main/org/apache/tools/ant/taskdefs/Java.java    2000/03/29 =
> 17:13:31     1.6
> +++ src/main/org/apache/tools/ant/taskdefs/Java.java    2000/05/26 =
> 11:25:00
> @@ -76,13 +76,31 @@
>       * Do the execution.
>       */
>      public void execute() throws BuildException {
> +        // invoke the Java class and ignore the return code.
> +        executeJava();
> +    }
> +
> +    /**
> +     * Execute the specified class and throw an exception if
> +     * the java class returns a non zero result.
> +     */
> +    public void executeWithThrow() throws BuildException {
> +        if (executeJava() !=3D 0) {
> +            throw new BuildException("Execution of " + classname + " =
> returned an error");
> +        }
> +    }
> 
> +    /**
> +     * Do the execution.
> +     */
> +    private int executeJava() throws BuildException {
>          project.log("Calling " + classname, "java", =
> project.MSG_VERBOSE);
> 
>          if (classname =3D=3D null) {
>              throw new BuildException("Classname must not be null.");
>          }
> 
> +        int returnCode =3D 0;
>          if (fork) {
>              StringBuffer b =3D new StringBuffer();
>              b.append("java ");
> @@ -101,13 +119,16 @@
>                  b.append(args);
>              }
> 
> -            run(b.toString());
> +            returnCode =3D run(b.toString());
>          } else {
>              Vector argList =3D tokenize(args);
>              if (jvmargs !=3D null) project.log("JVM args and classpath =
> ignored when same JVM is used.", "java", project.MSG_VERBOSE);
>              project.log("Java args: " + argList.toString(), "java", =
> project.MSG_VERBOSE);
>              run(classname, argList);
> +            returnCode =3D 0;
>          }
> +
> +        return returnCode;
>      }
> 
>      /**
> ------=_NextPart_000_001A_01BFC75D.12C29050--

RE: How to tell what Javac did?

Posted by Jason Sando <js...@think1up.com>.
> From: David H Elrod [mailto:dhelrod@rivendell.com]
>
> A new person's thoughts:
>
> Maybe there could be an attribute 'exitStatusName="someName"'
> for the task? When the task exits, then "someName" would be
> set to the exit value. The user gets to pick the name and
> set up the relationship between tasks (if any). The the
> Project.getProperty("someName") call could return the
> exist status of any arbitrary task.
>

As Conor MacNeill pointed out,

-> How will we decide the required structure of task results? The original
-> request which prompted this thread was a desire to know if Javac did any
-> work, not just whether it succeeded. So would a return result for Javac
need
-> to specify success/failure, did it do anything? How many files did it
-> compile? Maybe even which files it compiled or even how long it took?

I've already decided to approach it another way.  However, if I was able to
do anything within Ant, I would want not just an exit status.  Minimally I
would want to get at taskdefs.javac.compileList.size ().  Even better I
would want to get at the compileList attribute itself, so I could feed the
list of "out of date" files to another process.

So I don't think this is a general "exit status" type of opportunity.  The
desired feature is dependent on the Javac task, which is helpfully building
the list of out of date files.  Assuming a task following Javac's execution
could get at the just-built compileList, it would first detect whether
compileList.size() > 0.  If so, it would then have to translate that Vector
into a String[], and concatenate that array with the other arguments I need
to pass to my compiler, finally exec'ing the compiler.  (Then after the next
release of Ant renames the "compileList" attribute to "sourceOutOfDateList",
my builds break and I have to rewrite it again!)

Or, I can just make my compiler a little better ;)

-j