William Uther wrote:
>
> Hi all,
> As I'm sure most of you know, Macs carry meta-info around with their
> files. Currently ANT's copyFile methods don't copy that. I've modified
> the Project.copyFile() method to copy that data. My modifications use this
> open source java library: <http://www.amug.org/~glguerin/sw/#macbinary>.
>
> At the same time I noticed that the copyFile method will leave the file
> open if an IOException is thrown. I've added try/finally blocks to close
> the files.
>
> Both modifications should have no effect on Non-Mac platforms. You'll
> need to download the library though.
>
> later,
>
> \x/ill :-}
>
> Here is the replacement copyFile method. Sorry, I don't have a 'diff'
> utility on my Mac, so this is the entire method:
>
> public void copyFile(File sourceFile, File destFile, boolean filtering)
> throws IOException
> {
>
> if (destFile.lastModified() < sourceFile.lastModified()) {
> log("Copy: " + sourceFile.getAbsolutePath() + " > "
> + destFile.getAbsolutePath(), MSG_VERBOSE);
>
> // ensure that parent dir of dest file exists!
> // not using getParentFile method to stay 1.1 compat
> File parent = new File(destFile.getParent());
> if (!parent.exists()) {
> parent.mkdirs();
> }
>
> if (filtering) {
> BufferedReader in = null;
> BufferedWriter out = null;
>
> try {
> int length;
> String line;
> String newline = null;
>
> in = new BufferedReader(new FileReader(sourceFile));
> out = new BufferedWriter(new FileWriter(destFile));
> line = in.readLine();
> while (line != null) {
> if (line.length() == 0) {
> out.newLine();
> } else {
> newline = replace(line, filters);
> out.write(newline);
> out.newLine();
> }
> line = in.readLine();
> }
> } finally {
> if (out != null)
> out.close();
> if (in != null)
> in.close();
> }
> } else {
> FileInputStream in = null;
> FileOutputStream out = null;
>
> try {
> in = new FileInputStream(sourceFile);
> out = new FileOutputStream(destFile);
>
> byte[] buffer = new byte[8 * 1024];
> int count = 0;
> do {
> out.write(buffer, 0, count);
> count = in.read(buffer, 0, buffer.length);
> } while (count != -1);
> } finally {
> if (in != null)
> in.close();
> if (out != null)
> out.close();
> }
> }
>
> // now copy the mac resource fork and other Meta-Info.
> // Should never filter the Meta-Info!
> if (glguerin.util.MacPlatform.getJDirectVersion() == 2) {
>
> glguerin.mac.io.MacFileForker.SetFactoryName("glguerin.mac.io.imp.macos.JD
> 2.JD2Forker");
> glguerin.mac.io.MacFileForker sourceFF =
> glguerin.mac.io.MacFileForker.MakeOne(
> new glguerin.mac.io.MacFilePathname(sourceFile));
> glguerin.mac.io.MacFileForker destFF =
> glguerin.mac.io.MacFileForker.MakeOne(
> new glguerin.mac.io.MacFilePathname(destFile));
-1
I don't want to have dependencies on stuff like that.
Can't you use reflection to instance the classes?
Anyway, isn't this a mac JDK bug?
--
Stefano Mazzocchi One must still have chaos in oneself to be
able to give birth to a dancing star.
<stefano@apache.org> Friedrich Nietzsche
--------------------------------------------------------------------
Come to the first official Apache Software Foundation Conference!
------------------------- http://ApacheCon.Com ---------------------
|