The classcontents filterreader might very well be exactly what I want - if I
could understand how to use it!
I've just tried several experiments and nothing works for me; nothing at
all.
I must be misunderstanding some of the concepts. For instance, it _looks_ as
if I should be able to read a file, grab all the constants from it, and turn
them into properties. But I can't make out if I'm supposed to reading a
class file or a source file: it _looks_ as if I should be reading a class
file, which seems counterintuitive to me. Nevertheless, I've tried pointing
the task at both a real .class file and at a real Java source file in turn
but I inevitably get "Unable to load file: java.io.IOException" regardless
of which I use. Here is my task:
<loadproperties srcfile="ResumeConstants.java">
<filterchain>
<classconstants/>
</filterchain>
</loadproperties>
(Replacing the srcfile value with "ResumeConstants.class" made no difference
at all. Both the source and the class file are in the same directory as the
Ant script itself, just to keep things nice and simple.)
Here is the stackTrace:
BUILD FAILED
E:\eclipse\3.1.1\eclipse\workspace\Resume_JDK_1.5.0\xml\filter.xml:34:
Unable to load file: java.io.IOException
at
org.apache.tools.ant.taskdefs.LoadProperties.execute(LoadProperties.java:227)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at
org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at
org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
at
org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
Caused by: java.io.IOException
at org.apache.tools.ant.filters.ClassConstants.read(ClassConstants.java:136)
at
org.apache.tools.ant.filters.BaseFilterReader.read(BaseFilterReader.java:86)
at java.io.Reader.read(Unknown Source)
at org.apache.tools.ant.util.FileUtils.readFully(FileUtils.java:1107)
at
org.apache.tools.ant.filters.util.ChainReaderHelper.readFully(ChainReaderHelper.java:231)
at
org.apache.tools.ant.taskdefs.LoadProperties.execute(LoadProperties.java:204)
... 11 more
--- Nested Exception ---
java.io.IOException
at org.apache.tools.ant.filters.ClassConstants.read(ClassConstants.java:136)
at
org.apache.tools.ant.filters.BaseFilterReader.read(BaseFilterReader.java:86)
at java.io.Reader.read(Unknown Source)
at org.apache.tools.ant.util.FileUtils.readFully(FileUtils.java:1107)
at
org.apache.tools.ant.filters.util.ChainReaderHelper.readFully(ChainReaderHelper.java:231)
at
org.apache.tools.ant.taskdefs.LoadProperties.execute(LoadProperties.java:204)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at
org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at
org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
at
org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
What am I doing wrong? By the way, I've tried this task both ways, with the
convenience method and the "long way" but all approaches fail on
java.io.IOException.
Also, to accomplish what I want to do, am I correct in assuming that I will
need to put two or three filters in sequence in the task? From what I see in
the manual, I think I need to have everything within a LoadProperties task,
then use a ConstantChain to pull out all of the constants, then use a
LineContains to find the line containing my constant,
DESIRED_EMPLOYMENT_HISTORY_FORMAT, then store that constant and its value as
a property so that I end up with a property named
DESIRED_EMPLOYMENT_HISTORY_FORMAT with a value of PARAGRAPH_FORMAT or
LIST_FORMAT. Is that more-or-less correct?
If someone could please help me get started, I would really appreciate it. I
think I'm doing what the manual says but nothing seems to work. What's the
trick?
By the way, assuming this does what I want, thank you for pointing this
technique out to me. I'd seen the term FilterChain before but had never
looked at the article to see what they did.
--
Rhino
----- Original Message -----
From: "Matt Benson" <[EMAIL PROTECTED]>
To: "Ant Users List" <user@ant.apache.org>
Sent: Thursday, February 09, 2006 4:55 PM
Subject: Re: Displaying the value in a Java class?
Would the classconstants filterreader help? See
concepts and types, filterchains and filterreaders.
-Matt
--- Rhino <[EMAIL PROTECTED]> wrote:
I'm trying to figure out a simple, elegant way to do
something in Java and
Ant but I keep coming up with complicated ways of
doing it. I feel as if a
simple way is easily achievable but I'm blanking out
so I hope someone here
can tell me what I'm not seeing so that I can kick
myself for overlooking
the obvious :-)
At the start of my Ant build, I want to display the
value of a single
Constant that is sitting in one of my Java classes;
the value will be
displayed in an AntForm and the user will choose to
proceed with the build
or abort it, based on the value of that constant.
(Despite the fact that the
constant is defined to have a single value at any
one time, the user can
arbitrarily change it to a different value by simply
modifying the
initialization for the constant. This would be a
normal thing to do. The
constant in question is only able to have two
different values at the moment
but that could change to three or more somewhere
down the road.)
If Ant could "see" the values of my constants, I'd
just refer to the
constant as
ResumeConstants.DESIRED_EMPLOYMENT_HISTORY_FORMAT
and display
that value in the AntForm. But, unless I'm
misunderstanding something, Ant
_can't_ see the values of my constants so I am
struggling for a _SIMPLE_ way
to pass that single data value to my AntForm.
Yes, I could write a method in one of my programs to
get that value, then
write it somewhere more accessible to Ant, then have
Ant interrogate it,
store it in a property, and then display it but I
suspect there is a simpler
way to go; I just can't think of it.
Any suggestions?
--
Rhino
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.15.3/254 -
Release Date: 08/02/2006
---------------------------------------------------------------------
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.15.3/254 - Release Date: 08/02/2006
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.15.3/254 - Release Date: 08/02/2006
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]