aboutsummaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-01-24 16:07:49 +0100
committerJon Bratseth <bratseth@gmail.com>2022-01-24 16:07:49 +0100
commit4ee97e3a8b6a6be751f11e0f931029057a46664d (patch)
tree110569b31d13c1c0c5cde7c20fc6ff873d3fa482 /config-model
parent1f4b84f037b82b3ab9c416b5e01416ef13b2e8cb (diff)
Simplify
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java11
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/SchemaBuilder.java27
2 files changed, 20 insertions, 18 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java b/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java
index 7bc71556a22..fb7fa00ed88 100644
--- a/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java
+++ b/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java
@@ -481,12 +481,6 @@ public class DeployState implements ConfigDefinitionStore {
try {
String readerName = reader.getName();
String topLevelName = builder.importReader(reader, readerName);
- String sdName = stripSuffix(readerName, ApplicationPackage.SD_NAME_SUFFIX);
- if ( ! sdName.equals(topLevelName)) {
- throw new IllegalArgumentException("Schema file name ('" + sdName + "') and name of " +
- "top level element ('" + topLevelName +
- "') are not equal for file '" + readerName + "'");
- }
} catch (ParseException e) {
throw new IllegalArgumentException("Could not parse schema file '" + reader.getName() + "'", e);
} catch (IOException e) {
@@ -499,11 +493,6 @@ public class DeployState implements ConfigDefinitionStore {
return SearchDocumentModel.fromBuilder(builder);
}
- private static String stripSuffix(String nodeName, String postfix) {
- assert (nodeName.endsWith(postfix));
- return nodeName.substring(0, nodeName.length() - postfix.length());
- }
-
@SuppressWarnings("EmptyCatchBlock")
private static void closeIgnoreException(Reader reader) {
try {
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/SchemaBuilder.java b/config-model/src/main/java/com/yahoo/searchdefinition/SchemaBuilder.java
index 51466a5dbfa..3db9017fa8d 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/SchemaBuilder.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/SchemaBuilder.java
@@ -149,16 +149,29 @@ public class SchemaBuilder {
}
/**
- * Reads and parses the search definition string provided by the given reader. Once all search definitions have been
+ * Reads and parses the schema string provided by the given reader. Once all schemas have been
* imported, call {@link #build()}.
*
* @param reader the reader whose content to import
- * @param searchDefDir the path to use when resolving file references
- * @return the name of the imported object
+ * @param schemaDir the path to use when resolving file references
+ * @return the name of the imported schema
* @throws ParseException thrown if the file does not contain a valid search definition
*/
- public String importReader(NamedReader reader, String searchDefDir) throws IOException, ParseException {
- return importString(IOUtils.readAll(reader), searchDefDir);
+ public String importReader(NamedReader reader, String schemaDir) throws IOException, ParseException {
+ String schemaName = importString(IOUtils.readAll(reader), schemaDir);
+ String schemaFileName = stripSuffix(reader.getName(), ApplicationPackage.SD_NAME_SUFFIX);
+ if ( ! schemaFileName.equals(schemaName)) {
+ throw new IllegalArgumentException("Schema file name ('" + schemaFileName + "') and name of " +
+ "top level element ('" + schemaName +
+ "') are not equal for file '" + reader.getName() + "'");
+ }
+ return schemaName;
+ }
+
+ private static String stripSuffix(String readerName, String suffix) {
+ if ( ! readerName.endsWith(suffix))
+ throw new IllegalArgumentException("Schema '" + readerName + "' does not end with " + suffix);
+ return readerName.substring(0, readerName.length() - suffix.length());
}
/**
@@ -172,12 +185,12 @@ public class SchemaBuilder {
return importString(str, null);
}
- private String importString(String str, String searchDefDir) throws ParseException {
+ private String importString(String str, String schemaDir) throws ParseException {
SimpleCharStream stream = new SimpleCharStream(str);
try {
return importRawSchema(new SDParser(stream, fileRegistry, deployLogger, properties, application,
rankProfileRegistry, documentsOnly)
- .schema(docTypeMgr, searchDefDir));
+ .schema(docTypeMgr, schemaDir));
} catch (TokenMgrException e) {
throw new ParseException("Unknown symbol: " + e.getMessage());
} catch (ParseException pe) {