Added info file to make properties file optional
Change-Id: I50cdc07d41c96e6fd26bfea24da701df6581d737
diff --git a/src/main/java/de/ids_mannheim/korap/KrillIndex.java b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
index 9fb32a4..b5930a6 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
@@ -145,9 +145,10 @@
// Some initializations ...
{
- Properties prop = loadProperties();
- this.version = prop.getProperty("krill.version");
- this.name = prop.getProperty("krill.name");
+ Properties prop = loadProperties();
+ Properties version = loadInfo();
+ this.version = version.getProperty("krill.version");
+ this.name = version.getProperty("krill.name");
// Check for auto commit value
String stringProp = prop.getProperty("krill.index.commit.auto");
diff --git a/src/main/java/de/ids_mannheim/korap/index/Indexer.java b/src/main/java/de/ids_mannheim/korap/index/Indexer.java
index 9c528a7..4eed08a 100644
--- a/src/main/java/de/ids_mannheim/korap/index/Indexer.java
+++ b/src/main/java/de/ids_mannheim/korap/index/Indexer.java
@@ -23,7 +23,7 @@
int count;
int commitCount;
- private static String propFile = "krill.properties";
+ // private static String propFile = "krill.properties";
private static String path = null;
// Init logger
@@ -116,15 +116,37 @@
*/
public static void main (String[] argv) throws IOException {
+ if (argv.length == 0) {
+ /*
+ String jar = new File(Indexer.class.getProtectionDomain()
+ .getCodeSource().getLocation().getPath()).getName();
+ System.out.println("Usage: java -jar " + jar
+ + "--config [propfile] [directories]*");
+ return;
+ */
+
+ System.err.println("Call with parameters:");
+ System.err.println("--config|-c Configuration file (defaults to " +
+ de.ids_mannheim.korap.util.KrillProperties.file +
+ ")");
+ System.err.println("--indexDir|-d Index directory "+
+ "(defaults to krill.indexDir in configuration)");
+ System.err.println();
+ return;
+ };
+
int i = 0;
boolean last = false;
+ String propFile = null;
+
for (i = 0; i < argv.length; i += 2) {
switch (argv[i]) {
case "--config":
case "-cfg":
+ case "-c":
propFile = argv[i + 1];
break;
- case "--dir":
+ case "--indexDir":
case "-d":
path = argv[i + 1];
break;
@@ -137,14 +159,6 @@
break;
};
- /*
- String jar = new File(Indexer.class.getProtectionDomain()
- .getCodeSource().getLocation().getPath()).getName();
- System.out.println("Usage: java -jar " + jar
- + "--config [propfile] [directories]*");
- return;
- */
-
// Load properties
/*
InputStream fr = new FileInputStream(argv[0]);
diff --git a/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java b/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java
index 551fc0c..6d1aec8 100644
--- a/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java
+++ b/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java
@@ -9,39 +9,49 @@
// Todo: Properties may be loaded twice - althogh Java may cache automatically
public class KrillProperties {
+ public static String file = "krill.properties";
+ private static String info = "krill.info";
+ private static Properties prop;
+
// Logger
private final static Logger log = LoggerFactory.getLogger(Krill.class);
// Load properties from file
public static Properties loadProperties () {
- return loadProperties("krill.properties");
+ if (prop != null)
+ return prop;
+
+ prop = loadProperties(file);
+ return prop;
};
// Load properties from file
public static Properties loadProperties (String propFile) {
- InputStream file;
- Properties prop;
+ if (propFile == null)
+ return loadProperties();
+
+ InputStream iFile;
try {
- file = new FileInputStream(propFile);
+ iFile = new FileInputStream(propFile);
prop = new Properties();
- prop.load(file);
+ prop.load(iFile);
}
catch (IOException t) {
try {
- file = KrillProperties.class.getClassLoader()
- .getResourceAsStream(propFile);
+ iFile = KrillProperties.class.getClassLoader()
+ .getResourceAsStream(propFile);
- if (file == null) {
+ if (iFile == null) {
log.error(
- "Cannot find {}. Please create it using \"{}.info\" as template.",
- propFile, propFile);
+ "Cannot find {}. Please create it using \"{}.info\" as template.",
+ propFile, propFile);
return null;
};
prop = new Properties();
- prop.load(file);
+ prop.load(iFile);
}
catch (IOException e) {
log.error(e.getLocalizedMessage());
@@ -50,4 +60,20 @@
};
return prop;
};
+
+
+ // Load version info from file
+ public static Properties loadInfo () {
+ try {
+ InputStream iFile = KrillProperties.class.getClassLoader()
+ .getResourceAsStream(info);
+ Properties prop = new Properties();
+ prop.load(iFile);
+ }
+ catch (IOException e) {
+ log.error(e.getLocalizedMessage());
+ return null;
+ };
+ return prop;
+ };
};
diff --git a/src/main/resources/krill.info b/src/main/resources/krill.info
new file mode 100644
index 0000000..f9cbc50
--- /dev/null
+++ b/src/main/resources/krill.info
@@ -0,0 +1,2 @@
+krill.version = ${project.version}
+krill.name = ${project.name}
diff --git a/src/main/resources/krill.properties.info b/src/main/resources/krill.properties.info
index b9fcc72..2f4871f 100644
--- a/src/main/resources/krill.properties.info
+++ b/src/main/resources/krill.properties.info
@@ -1,6 +1,3 @@
-krill.version = ${project.version}
-krill.name = ${project.name}
-
# Krill Backend properties
krill.properties = true
krill.indexDir = [PATH TO INDEX DIRECTORY]