Add getVersion() and getName() methods

Change-Id: I28a8ad1d5714228f0b34b9d5ee2be90cfd4d15bc
diff --git a/Changes b/Changes
index b11c8de..22f037d 100644
--- a/Changes
+++ b/Changes
@@ -1,8 +1,9 @@
-0.37 2020-12-02
+0.37 2021-03-04
     - [feature] Introduced query references in Poliqarp (diewald)
     - [bugfix] Ignore empty corpus queries (diewald)
     - [bugfix] Fix handling of apostrophes in multiword and regex
       values in virtual corpora (#85; diewald)
+    - [feature] Added getVersion() and getName() methods (diewald)
 
 0.36 2020-07-24
     - [security] Upgraded version of Google Guava
diff --git a/pom.xml b/pom.xml
index 9be6f1a..cd18728 100644
--- a/pom.xml
+++ b/pom.xml
@@ -357,5 +357,14 @@
 				</executions>
 			</plugin>
 		</plugins>
+    <resources>
+			<resource>
+				<directory>src/main/resources</directory>
+				<filtering>true</filtering>
+				<includes>
+					<include>koral.info</include>
+				</includes>
+			</resource>
+		</resources>
 	</build>
 </project>
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
index 44221a9..5ee9c77 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
@@ -5,7 +5,9 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Properties;
 import java.util.Map;
+import java.io.InputStream;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -16,6 +18,7 @@
 import de.ids_mannheim.korap.query.serialize.util.KoralObjectGenerator;
 import de.ids_mannheim.korap.query.serialize.util.StatusCodes;
 
+
 /**
  * Main class for Koral, serializes queries from concrete QLs to KoralQuery
  * 
@@ -27,6 +30,20 @@
  */
 public class QuerySerializer {
 
+    private String version = "Unknown";
+    private String name = "Unknown";
+    private static Properties info;
+
+        {
+          
+            loadInfo();
+            if (info != null) {
+                this.version = info.getProperty("koral.version");
+                this.name = info.getProperty("koral.name");
+            };
+        }
+
+    
     // fixme: not used in any way!
     @Deprecated
     static HashMap<String, Class<? extends AbstractQueryProcessor>> qlProcessorAssignment;
@@ -361,4 +378,47 @@
         }
         this.warnings.add(warning);
     }
+
+
+    /**
+     * Get the version number of Koral.
+     * 
+     * @return A string containing the version number of Koral.
+     */
+    public String getVersion () {
+        return this.version;
+    }
+
+
+    /**
+     * Get the name of Koral.
+     * 
+     * @return A string containing the name of Koral.
+     */
+    public String getName () {
+        return this.name;
+    }
+
+
+    // Load version info from file
+    public static Properties loadInfo () {
+        try {
+            info = new Properties();
+            InputStream iFile = QuerySerializer.class.getClassLoader()
+                    .getResourceAsStream("koral.info");
+
+            if (iFile == null) {
+                qllogger.error("Cannot find koral.info");
+                return null;
+            };
+
+            info.load(iFile);
+            iFile.close();
+        }
+        catch (IOException e) {
+            qllogger.error(e.getLocalizedMessage());
+            return null;
+        };
+        return info;
+    };
 }
diff --git a/src/main/resources/koral.info b/src/main/resources/koral.info
new file mode 100644
index 0000000..b2291f1
--- /dev/null
+++ b/src/main/resources/koral.info
@@ -0,0 +1,2 @@
+koral.version = ${project.version}
+koral.name = ${project.name}
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/EmptyResultsTest.java b/src/test/java/de/ids_mannheim/korap/query/test/EmptyResultsTest.java
index eb0c9ec..0ece243 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/EmptyResultsTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/EmptyResultsTest.java
@@ -69,4 +69,13 @@
         assertEquals("Beispiel 2", node.at("/warnings/1/1").asText());
         assertFalse(node.has("/warnings/1/2"));
     }    
+
+    @Test
+    public void testVersion () {
+        QuerySerializer s = new QuerySerializer();
+        assertTrue(s.getVersion().matches("^\\d+(\\.\\d+)+$"));
+        assertFalse(s.getVersion().equals("Unknown"));
+        assertTrue(s.getName().length() > 3);
+        assertFalse(s.getName().equals("Unknown"));
+    }
 }