From 814badf639d7f4a0f02b42de27d341eca73db541 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Thu, 12 Nov 2009 15:39:22 +0000
Subject: [PATCH] change BuildAndEnvironmentInfo class in order to avoid
 shadowing by using application specific BUILD.INFO files

SVN: 13363
---
 base/build/build.xml                          |  5 +-
 .../cisd/base/BuildAndEnvironmentInfo.java    | 46 +++++++++++++++++++
 ...a => AbstractBuildAndEnvironmentInfo.java} | 45 +++++++++---------
 .../cisd/base/convert/NativeDataTests.java    |  4 +-
 .../ch/systemsx/cisd/base/unix/UnixTests.java |  2 +-
 5 files changed, 75 insertions(+), 27 deletions(-)
 create mode 100644 base/source/java/ch/systemsx/cisd/base/BuildAndEnvironmentInfo.java
 rename base/source/java/ch/systemsx/cisd/base/utilities/{BuildAndEnvironmentInfo.java => AbstractBuildAndEnvironmentInfo.java} (86%)

diff --git a/base/build/build.xml b/base/build/build.xml
index d712a1c1b90..7a4071a64c5 100644
--- a/base/build/build.xml
+++ b/base/build/build.xml
@@ -1,4 +1,4 @@
-<project name="base" default="dist" basedir="..">
+<project name="cisd-base" default="dist" basedir="..">
 	<target name="clean">
 		<delete dir="${dist}" />
 	</target>
@@ -6,6 +6,7 @@
 	<import file="../../build_resources/ant/build-common.xml" />
 
 	<project-classpath name="ecp" classes="${classes}" />
+	<property name="application-name" value="cisd-base" />
 	<property name="distfolder" value="cisd-base" />
 	<property name="mainfolder" value="base" />
 	<property name="jar.file" value="${dist}/cisd-base.jar" />
@@ -55,7 +56,7 @@
 			</fileset>
 			<manifest>
 				<attribute name="Main-Class"
-				           value="ch.systemsx.cisd.base.utilities.BuildAndEnvironmentInfo" />
+				           value="ch.systemsx.cisd.base.BuildAndEnvironmentInfo" />
 				<attribute name="Version" value="${version.number}" />
 				<attribute name="Build-Number"
 				           value="${version.number} (r${revision.number},${clean.flag})" />
diff --git a/base/source/java/ch/systemsx/cisd/base/BuildAndEnvironmentInfo.java b/base/source/java/ch/systemsx/cisd/base/BuildAndEnvironmentInfo.java
new file mode 100644
index 00000000000..bf1c069c1f4
--- /dev/null
+++ b/base/source/java/ch/systemsx/cisd/base/BuildAndEnvironmentInfo.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2009 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.base;
+
+import ch.systemsx.cisd.base.utilities.AbstractBuildAndEnvironmentInfo;
+
+
+/**
+ * The build and environment information for cisd-base.
+ *
+ * @author Franz-Josef Elmer
+ */
+public class BuildAndEnvironmentInfo extends AbstractBuildAndEnvironmentInfo
+{
+    private final static String BASE = "cisd-base";
+    
+    public final static BuildAndEnvironmentInfo INSTANCE = new BuildAndEnvironmentInfo();
+    
+    private BuildAndEnvironmentInfo()
+    {
+        super(BASE);
+    }
+
+    /**
+     * Shows build and environment information on the console.
+     */
+    public static void main(String[] args)
+    {
+        System.out.println(INSTANCE);
+    }
+
+}
diff --git a/base/source/java/ch/systemsx/cisd/base/utilities/BuildAndEnvironmentInfo.java b/base/source/java/ch/systemsx/cisd/base/utilities/AbstractBuildAndEnvironmentInfo.java
similarity index 86%
rename from base/source/java/ch/systemsx/cisd/base/utilities/BuildAndEnvironmentInfo.java
rename to base/source/java/ch/systemsx/cisd/base/utilities/AbstractBuildAndEnvironmentInfo.java
index 04c90dc4428..1a9dae60537 100644
--- a/base/source/java/ch/systemsx/cisd/base/utilities/BuildAndEnvironmentInfo.java
+++ b/base/source/java/ch/systemsx/cisd/base/utilities/AbstractBuildAndEnvironmentInfo.java
@@ -25,34 +25,34 @@ import java.util.List;
 import java.util.StringTokenizer;
 
 /**
- * Bean with build and environment information.
+ * Abstract of all classes providing build and environment information.
  * <p>
  * Does <em>not</em> depend on any library jar files.
  * </p>
  * 
  * @author Franz-Josef Elmer
  */
-public final class BuildAndEnvironmentInfo
+public abstract class AbstractBuildAndEnvironmentInfo
 {
     private static final String UNKNOWN = "UNKNOWN";
 
-    /**
-     * The one-and-only instance.
-     */
-    public static final BuildAndEnvironmentInfo INSTANCE = new BuildAndEnvironmentInfo();
-
     private final String version;
 
     private final String revision;
 
     private final boolean cleanSources;
 
-    private BuildAndEnvironmentInfo()
+    private final String applicationName;
+
+    protected AbstractBuildAndEnvironmentInfo(String applicationName)
     {
+        this.applicationName = applicationName;
         String extractedVersion = UNKNOWN;
         String extractedRevision = UNKNOWN;
         boolean extractedCleanFlag = false;
-        final InputStream stream = BuildAndEnvironmentInfo.class.getResourceAsStream("/BUILD.INFO");
+        final InputStream stream =
+                AbstractBuildAndEnvironmentInfo.class.getResourceAsStream("/BUILD-" + applicationName
+                        + ".INFO");
         if (stream != null)
         {
             BufferedReader reader = null;
@@ -72,11 +72,14 @@ public final class BuildAndEnvironmentInfo
                 // ignored
             } finally
             {
-                try {
-                    if (reader != null) {
+                try
+                {
+                    if (reader != null)
+                    {
                         reader.close();
                     }
-                } catch (IOException ioe) {
+                } catch (IOException ioe)
+                {
                     // ignore
                 }
             }
@@ -141,8 +144,8 @@ public final class BuildAndEnvironmentInfo
     }
 
     /**
-     * @return <code>true</code> if the versioned entities of the working copy have been clean
-     *         when this build has been made, in other words, whether the revision given by
+     * @return <code>true</code> if the versioned entities of the working copy have been clean when
+     *         this build has been made, in other words, whether the revision given by
      *         {@link #getRevision()} does really identify the source that is build has been
      *         produced from.
      */
@@ -186,12 +189,18 @@ public final class BuildAndEnvironmentInfo
         return builder.toString();
     }
 
+    public String getApplicationName()
+    {
+        return applicationName;
+    }
+
     /**
      * Returns version, build number, Java VM, and OS as a {@link List} with four entries.
      */
     public final List<String> getEnvironmentInfo()
     {
         final List<String> environmentInfo = new ArrayList<String>();
+        environmentInfo.add("Application: " + getApplicationName());
         environmentInfo.add("Version: " + getFullVersion());
         environmentInfo.add("Java VM: " + getJavaVM());
         environmentInfo.add("CPU Architecture: " + getCPUArchitecture());
@@ -219,12 +228,4 @@ public final class BuildAndEnvironmentInfo
         return builder.toString();
     }
 
-    /**
-     * Shows build and environment information on the console.
-     */
-    public static void main(String[] args)
-    {
-        System.out.println(BuildAndEnvironmentInfo.INSTANCE);
-    }
-
 }
diff --git a/base/sourceTest/java/ch/systemsx/cisd/base/convert/NativeDataTests.java b/base/sourceTest/java/ch/systemsx/cisd/base/convert/NativeDataTests.java
index b8c296d232b..3bee4651bba 100644
--- a/base/sourceTest/java/ch/systemsx/cisd/base/convert/NativeDataTests.java
+++ b/base/sourceTest/java/ch/systemsx/cisd/base/convert/NativeDataTests.java
@@ -16,8 +16,8 @@
 
 package ch.systemsx.cisd.base.convert;
 
-import static org.testng.AssertJUnit.assertTrue;
 import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -26,8 +26,8 @@ import java.util.Arrays;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
+import ch.systemsx.cisd.base.BuildAndEnvironmentInfo;
 import ch.systemsx.cisd.base.convert.NativeData.ByteOrder;
-import ch.systemsx.cisd.base.utilities.BuildAndEnvironmentInfo;
 
 /**
  * Test cases for {@link NativeData}.
diff --git a/base/sourceTest/java/ch/systemsx/cisd/base/unix/UnixTests.java b/base/sourceTest/java/ch/systemsx/cisd/base/unix/UnixTests.java
index 1df26ca3e4d..8dc10b86263 100644
--- a/base/sourceTest/java/ch/systemsx/cisd/base/unix/UnixTests.java
+++ b/base/sourceTest/java/ch/systemsx/cisd/base/unix/UnixTests.java
@@ -25,11 +25,11 @@ import org.apache.commons.io.FileUtils;
 import org.testng.annotations.Test;
 
 import ch.rinn.restrictions.Friend;
+import ch.systemsx.cisd.base.BuildAndEnvironmentInfo;
 import ch.systemsx.cisd.base.tests.AbstractFileSystemTestCase;
 import ch.systemsx.cisd.base.unix.Unix.Group;
 import ch.systemsx.cisd.base.unix.Unix.Password;
 import ch.systemsx.cisd.base.unix.Unix.Stat;
-import ch.systemsx.cisd.base.utilities.BuildAndEnvironmentInfo;
 
 /**
  * Test cases for the {@link Unix} system calls.
-- 
GitLab