summaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorgjoranv <gjoranv@gmail.com>2017-08-22 09:23:34 +0200
committerGitHub <noreply@github.com>2017-08-22 09:23:34 +0200
commitdc0844dd2b56578757dc021179ea7380cda59f63 (patch)
treef3bebebeaba45850e9b117771f9b1a58ea66a9b3 /config
parent89cb75ca10c94d5587bbeee94c9afe0d28e87e3b (diff)
parentec42047f955009139b5491623f2290a1293612de (diff)
Merge pull request #3171 from vespa-engine/gjoranv/support-def-package-in-bundle-model
Gjoranv/support def package in bundle model
Diffstat (limited to 'config')
-rw-r--r--config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java32
1 files changed, 24 insertions, 8 deletions
diff --git a/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java b/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java
index ccb8993439e..0944569a413 100644
--- a/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java
+++ b/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java
@@ -208,14 +208,18 @@ public class ConfigUtils {
}
/**
- * Finds the def namespace from a reader for a def-file. Returns "" (empty string)
- * if no namespace was found.
+ * Finds the def package or namespace from a reader for a def-file. Returns "" (empty string)
+ * if no package or namespace was found. If both package and namespace are declared in the def
+ * file, the package is returned.
*
* @param in A reader to a def-file
* @return namespace of the def-file, or "" (empty string) if no namespace was found
*/
public static String getDefNamespace(Reader in) {
- return getDefKeyword(in, "namespace");
+ List<String> defLines = getDefLines(in);
+ String defPackage = getDefKeyword(defLines, "package");
+ if (! defPackage.isEmpty()) return defPackage;
+ return getDefKeyword(defLines, "namespace");
}
/**
@@ -226,9 +230,24 @@ public class ConfigUtils {
* @return value of keyword, or "" (empty string) if no line matching keyword was found
*/
public static String getDefKeyword(Reader in, String keyword) {
+ return getDefKeyword(getDefLines(in), keyword);
+ }
+
+ private static String getDefKeyword(List<String> defLines, String keyword) {
+ for (String line : defLines) {
+ if (line.startsWith(keyword)) {
+ String[] v = line.split("=");
+ return v[1].trim();
+ }
+ }
+ return "";
+ }
+
+ private static List<String> getDefLines(Reader in) {
if (null == in) {
throw new IllegalArgumentException("Null reader.");
}
+ List<String> defLines = new ArrayList<>();
LineNumberReader reader;
try {
if (in instanceof LineNumberReader) {
@@ -240,17 +259,14 @@ public class ConfigUtils {
while ((line = reader.readLine()) != null) {
line = line.trim();
if (!line.startsWith("#") && !line.equals("")) {
- if (line.startsWith(keyword)) {
- String[] v = line.split("=");
- return v[1].trim();
- }
+ defLines.add(line);
}
}
reader.close();
} catch (IOException e) {
throw new RuntimeException("IOException", e);
}
- return "";
+ return defLines;
}
/**