[share props] added ant taks to know host name
authorAsier Lostalé <asier.lostale@openbravo.com>
Wed, 21 Jan 2015 12:56:19 +0100
changeset 25752 fdd30bd81889
parent 25751 0522f7110df3
child 25753 b75d054ba4b4
[share props] added ant taks to know host name

to be executed by ant host.name
build.xml
src-core/src/org/openbravo/base/ConfigParameters.java
src/org/openbravo/base/session/HostNameTask.java
--- a/build.xml	Tue Jan 20 16:41:17 2015 +0100
+++ b/build.xml	Wed Jan 21 12:56:19 2015 +0100
@@ -12,7 +12,7 @@
 * under the License.
 * The Original Code is Openbravo ERP.
 * The Initial Developer of the Original Code is Openbravo SLU
-* All portions are Copyright (C) 2001-2014 Openbravo SLU
+* All portions are Copyright (C) 2001-2015 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************
@@ -1132,4 +1132,14 @@
                     propertiesFile="${base.config}/Openbravo.properties"/>
   </target>
   
+  <target name="host.name"
+          description="Prints this machine's name. This name can be used to overwrite common Openbravo.properties by machine.name.Openbravo properties file">
+    <javac srcdir="src/org/openbravo/base/session" includes="HostNameTask.java" destdir="build/classes" fork="true" deprecation="off" encoding="UTF-8" debug="true" debuglevel="lines,vars,source" includeantruntime="false">
+      <classpath refid="project.class.path"/>
+    </javac>
+    <taskdef name="hostName" classname="org.openbravo.base.session.HostNameTask">
+      <classpath refid="project.class.path"/>
+    </taskdef>
+    <hostName/>
+  </target>
 </project>
--- a/src-core/src/org/openbravo/base/ConfigParameters.java	Tue Jan 20 16:41:17 2015 +0100
+++ b/src-core/src/org/openbravo/base/ConfigParameters.java	Wed Jan 21 12:56:19 2015 +0100
@@ -331,6 +331,9 @@
    * <code>InetAddress.getLocalHost().getHostName()</code> if <code>machine.name</code> property is
    * not present.
    * </p>
+   * <p>
+   * Actual name for <code>hostName</code> can be determined by <code>ant host.name</code>
+   * </p>
    * 
    * @param obProperties
    * @param path
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/base/session/HostNameTask.java	Wed Jan 21 12:56:19 2015 +0100
@@ -0,0 +1,57 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2015 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.base.session;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <p>
+ * Prints local host name as it will be used when looking for machine specific Openbravo.properties
+ * files to override common properties. The name of the file should be
+ * <code>hostName.Openbravo.properties</code> where <code>hostName</code> is the output of the
+ * execution of this task.
+ * </p>
+ * <p>
+ * It can be executed by <code>ant host.name</code> command.
+ * </p>
+ * 
+ * @See ConfigParameters.overrideProperties
+ * 
+ * @author alostale
+ *
+ */
+public class HostNameTask extends Task {
+  private static final Logger log = LoggerFactory.getLogger(HostNameTask.class);
+
+  @Override
+  public void execute() throws BuildException {
+    try {
+      log.info("Machine name: {}", InetAddress.getLocalHost().getHostName());
+    } catch (UnknownHostException e) {
+      log.error("Could not determine machine name", e);
+    }
+  }
+}