Hi all,
I've created a patch for Ant that will set an internal property "hostname" to
the current hostname. See attached diff, generated against Project.java
revision 1.108.
Output when running ant -verbose:
ernst@zaphod$ ant -verbose init
Apache Ant version 1.6alpha compiled on May 29 2002
Buildfile: build.xml
Detected Java version: 1.3 in: /usr/local/jdk1.3.1/jre
Detected OS: FreeBSD
Detected hostname: zaphod.euronet.nl
parsing buildfile build.xml with URI =
file:/usr/home/ernst/jakarta-ant/build.xml
Project base dir set to: /usr/home/ernst/jakarta-ant
We need the hostname in our projects in order to distinguish between
host-specific configuration properties (in different property files).
Ernst
--
Ernst de Haan
EuroNet Internet B.V.
"Come to me all who are weary and burdened
and I will give you rest" -- Jesus Christ
? 0.diff
Index: Project.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.108
diff -d -u -r1.108 Project.java
--- Project.java 30 Apr 2002 14:20:16 -0000 1.108
+++ Project.java 29 May 2002 11:23:37 -0000
@@ -57,6 +57,8 @@
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.Hashtable;
import java.util.Vector;
import java.util.Properties;
@@ -242,6 +244,7 @@
*/
public void init() throws BuildException {
setJavaVersionProperty();
+ setHostnameProperty();
String defs = "/org/apache/tools/ant/taskdefs/defaults.properties";
@@ -772,6 +775,28 @@
+ System.getProperty("java.home"), MSG_VERBOSE);
log("Detected OS: " + System.getProperty("os.name"), MSG_VERBOSE);
+ }
+
+ /**
+ * Sets the <code>hostname</code> property. A verbose log message is
+ * generated to record the hostname and IP address. If the hostname cannot
+ * be determined, then the <code>hostname</code> property is not set.
+ */
+ public void setHostnameProperty() {
+ try {
+ InetAddress localhost = InetAddress.getLocalHost();
+ if (localhost == null) {
+ log("Unable to determine IP address of this host.", MSG_ERR);
+ return;
+ }
+ String hostname = localhost.getHostName();
+ setPropertyInternal("hostname", hostname);
+ log("Detected hostname: " + hostname, MSG_VERBOSE);
+ } catch (UnknownHostException unknownHostException) {
+ log("Unable to determine IP address of this host.", MSG_ERR);
+ } catch (SecurityException securityException) {
+ log("Not allowed to determine IP address of this host.", MSG_ERR);
+ }
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>