ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steffen Schluff" <schl...@oio.de>
Subject AW: echoing filesize
Date Wed, 30 Jul 2003 11:39:26 GMT
Hello David,

Sun once had such a task shipped with one of its MIDP examples. I pasted it
below including the respective ant settings. Once you got the jar file size
just use a token to put it in the jad file.

------------------------------------------------------

/*
 * Copyright 2001 by Sun Microsystems, Inc.,
 * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
 * All rights reserved.
 */
package ant;

import java.io.*;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

/**
 * Simple task set a property to the size of a file.
 * It has two attributes, the file name and
 * the property name. The property set to the empty string
 * if the file does not exist.
 */

public class FileSizeTask extends Task {
    File file;
    String property;

    // The method executing the task
    public void execute() throws BuildException {
	if (property != null && property.length() > 0) {
	    if (file.exists()) {
		int size = (int)file.length();
		project.setProperty(property, Integer.toString(size));
	    } else {
		project.setProperty(property, "");
	    }
	}
    }

    // The setter for the "message" attribute
    public void setFile(File file) {
	this.file = file;
    }

    // The setter for the "property" attribute
    public void setProperty(String prop) {
	property = prop;
    }

}

------------------------------------------------------


Best wishes,

Steffen Schluff
Orientation in Objects GmbH
http://www.oio.de


-----Ursprungliche Nachricht-----
Von: dc [mailto:dc@wm.namco.co.jp]
Gesendet: Mittwoch, 30. Juli 2003 12:57
An: 'Ant Users List'
Betreff: echoing filesize


Is there a built in ant task that can echo a filesize?
can task output be directed to a variable?

I am trying to create a portable build env that doesn't require external
tools/taskdefs.

vis:

<property name="filesize" value="... somehow read a file's size" />

<echo file="${MIDlet-Name}.jad" append="false">
	MIDlet-Name: ${MIDlet-Name}
	MIDlet-Jar-Size:${filesize}"
</echo>

tx,

/dc
+-----+-----------------------------------------+
david [dc] collier

NAMCO Ltd.
Web & Mobile Contents Business Group

  e   |   dc@wm.namco.co.jp
  v   |  +81(0)90 7414 6107


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


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


Mime
View raw message