ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 7901] - [SUBMIT] SerialVer tasks
Date Fri, 12 Apr 2002 22:02:55 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7901>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7901

[SUBMIT] SerialVer tasks





------- Additional Comments From stchauvin@yahoo.com  2002-04-12 22:02 -------
Hi Magesh,

>If you want getProject to not return a null, your
>Filter Reader must implement ChainableReader.  Is it
>implementing it?  Which task are you using to test
>your filter reader, btw?  One of <copy>, <move>,
><loadfile>?
Yes, my filter implements ChainableReader and I am using
the <copy> task. It works fine if I add my filter in FilterChain:

  <javac srcdir="${src}" includes="**/SUIDTest1.java"/>
  <copy file="${src}" tofile="${dest}/SUIDTest2.java" overwrite="true">
    <filterchain>
      <suidfilterreader failonerror="false">
        <classpath>
          <pathelement path="${classpath}"/>
        </classpath>
      </suidfilterreader>
    </filterchain>
  </copy>

but not if I am using the filterreader element:

  <javac srcdir="${src}" includes="**/SUIDTest1.java"/>
  <copy file="${src}" tofile="${dest}/SUIDTest2.java" overwrite="true">
    <filterchain>
      <filterreader 
classname="org.apache.tools.ant.taskdefs.optional.serialver.SUIDFilterReader">
        <classpath>
          <pathelement path="${classpath}"/>
        </classpath>
        <param name="failonerror" value="true"/>
      </filterreader>
    </filterchain>
  </copy>
I enclosed the source of the filter, just for information, but the worse is not 
there...

>Why would you want to execute your SerialVer task
>from within a filterreader?  We do not encourage
>calling execute methods of tasks directly, anyway.

My goal is (and how works the serialver):
- I create a new serializable class (classA V0).
- I compile classA V0.
- I run the serialver program on the compiled classA 
(that's why I need the classpath). It returns its SUID (SUID V0).
- I add the "static final long serialVersionUID" declaration
in my source code (classA V0).
- I am done for the V0. If I compile again and run again
the serialver program on it, I will get the same SUID.
- I serialize an object with classA V0 (serA1 V0).
- Now I decide to add a method doNothing() in classA V0.
This modification is compatible and doesn't break the versioning.
I keep the serialVersionUID declaration. Let's name this new 
code classA V0-1.
- I compile classA V0-1.
- I do not need to run the serialver program. If I do it, it 
will return the SUID V0, which I put in hard coding.
- I serialize an object with classA V0-1 (serA2 V0-1).
- I am able to load serA2 V0-1 or serA1 V0 with classA V0.
I am also able to read them with classA V0-1. The JVM doesn't
return a java.io.InvalidClassException (Local class not compatible),
because all objects and classes have the same SUID V0.
- Now let's break the compatibility. I change the API in classA V0-1
to create classA V1.
- I need to change the SUID signature. I remove the serialVersionUID 
declaration in the source code.
- I compile classA V1.
- I run the serialver program on the compiled classA V1
It returns its new SUID (SUID V1).
- I add the "static final long serialVersionUID" declaration (SUID1)
in my source code (classA V1).
- I am done for the V1.
- The classA V1 is not able to read the serA2 V0 or serA2 V0-1.

What can ANT do for me? A great job!
- I can put a special token in the source code when I create a
new serializable class (classA V0) or when I would like to break 
the compatibility (classA V1).
- I compile (<javac>).
- I parse the source file to replace the special tokens with the
serialVersionUID declaration (<replaceSUID>).
- My code is ready for other compilation and compatible modifications.

To come back to the question, in the solution that I propose, I would like
to run the serialver program only when I read the special token in a source 
file.
If I am running it for all the fileset all the time, just before to parse the 
source file, this program returns:
- an error if the class is not serializable. So the user has to select the 
correct
files, and not only the source directory.
- the same SUID all the time, if the user keep the same serialVersionUID 
declaration.
It could be annoying to read this list in the ANT output, instead to have a 
list of the 
new SUID.

I am wondering if the filterreader is the good solution:
- calling a task from the read() method is not recommended.
- how can I get know the filename or better directly the classname of the 
current
file. I need it for the argument of the serialver program.
- if I am doing it in 2 steps: get all the SUID with the <serialver> task, and 
add them in
a property. Then, a <copy> task use a filterreader to do the replacement. 
	- it is 2 steps instead of once;
	- I have to call serialver on all files (see previous answer).
	- the token has to be unique for each file to replace it 
	with the good SUID (it could be the package name + token, but it is 
king of heavy 
	for the user).

Should we come back to the <replaceSUID> task?... I know that you will be 
disappointed.
An alternative solution could be to publish only the <serialver> task. I can 
use <replaceSUID> task for myself anyway ;-) May be, one day, a developer will 
find THE solution!

best regards,
Stephane.

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


Mime
View raw message