summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2022-02-01 23:04:53 +0100
committerGitHub <noreply@github.com>2022-02-01 23:04:53 +0100
commit58dbe08ac1cb5783787d4abb826b6ffe7d9f6714 (patch)
treeabf83f8aba13bb612a73e15e483910edea649f88 /config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java
parentb754deecd3cd7856f7c407dbab479e950316a9ab (diff)
parentd91569194fe13bed6c2fef28fc9b5633d6299a5f (diff)
Merge pull request #21011 from vespa-engine/bratseth/avoid-schema-dir
Bratseth/avoid schema dir
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java55
1 files changed, 26 insertions, 29 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java b/config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java
index 98c6897dbb7..533546b4d39 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java
@@ -139,7 +139,7 @@ public class ApplicationBuilder {
*/
public Schema addSchemaFile(String fileName) throws IOException, ParseException {
File file = new File(fileName);
- return addSchema(IOUtils.readFile(file), file.getAbsoluteFile().getParent());
+ return addSchema(IOUtils.readFile(file));
}
/**
@@ -148,9 +148,9 @@ public class ApplicationBuilder {
*
* @param reader the reader whose content to import
*/
- private void addSchema(NamedReader reader) {
+ public void addSchema(NamedReader reader) {
try {
- String schemaName = addSchema(IOUtils.readAll(reader), reader.getName()).getName();
+ String schemaName = addSchema(IOUtils.readAll(reader)).getName();
String schemaFileName = stripSuffix(reader.getName(), ApplicationPackage.SD_NAME_SUFFIX);
if ( ! schemaFileName.equals(schemaName)) {
throw new IllegalArgumentException("The file containing schema '" + schemaName + "' must be named '" +
@@ -172,18 +172,12 @@ public class ApplicationBuilder {
}
/**
- * Adds a schema to this application.
+ * Adds a schema to this
*
- * @param string the string to parse
- * @return the schema
- * @throws ParseException thrown if the file does not contain a valid search definition
+ * @param schemaString the content of the schema
*/
- public Schema addSchema(String string) throws ParseException {
- return addSchema(string, null);
- }
-
- private Schema addSchema(String schemaString, String schemaPath) throws ParseException {
- return add(createSchema(schemaString, schemaPath));
+ public Schema addSchema(String schemaString) throws ParseException {
+ return add(createSchema(schemaString));
}
/**
@@ -201,18 +195,16 @@ public class ApplicationBuilder {
return schema;
}
- private Schema createSchema(String schemaString, String schemaPath) throws ParseException {
- Schema schema = parseSchema(schemaString, schemaPath);
- addRankProfileFiles(schema, schemaPath);
+ private Schema createSchema(String schemaString) throws ParseException {
+ Schema schema = parseSchema(schemaString);
+ addRankProfileFiles(schema);
return schema;
}
- private Schema parseSchema(String schemaString, String schemaPath) throws ParseException {
+ private Schema parseSchema(String schemaString) throws ParseException {
SimpleCharStream stream = new SimpleCharStream(schemaString);
try {
- return new SDParser(stream, applicationPackage, fileRegistry, deployLogger, properties,
- rankProfileRegistry, documentsOnly)
- .schema(documentTypeManager, schemaPath);
+ return parserOf(stream).schema(documentTypeManager);
} catch (TokenMgrException e) {
throw new ParseException("Unknown symbol: " + e.getMessage());
} catch (ParseException pe) {
@@ -220,12 +212,16 @@ public class ApplicationBuilder {
}
}
- private void addRankProfileFiles(Schema schema, String schemaPath) {
- if (applicationPackage == null || schemaPath == null) return;
- Path rankProfilePath = Path.fromString(schemaPath).append(schema.getName());
- for (NamedReader reader : applicationPackage.getFiles(rankProfilePath, ".profile")) {
+ private void addRankProfileFiles(Schema schema) {
+ if (applicationPackage == null) return;
+
+ Path legacyRankProfilePath = ApplicationPackage.SEARCH_DEFINITIONS_DIR.append(schema.getName());
+ for (NamedReader reader : applicationPackage.getFiles(legacyRankProfilePath, ".profile"))
+ parseRankProfile(reader, schema);
+
+ Path rankProfilePath = ApplicationPackage.SCHEMAS_DIR.append(schema.getName());
+ for (NamedReader reader : applicationPackage.getFiles(rankProfilePath, ".profile"))
parseRankProfile(reader, schema);
- }
}
/** Parses the rank profile of the given reader and adds it to the rank profile registry for this schema. */
@@ -233,9 +229,7 @@ public class ApplicationBuilder {
try {
SimpleCharStream stream = new SimpleCharStream(IOUtils.readAll(reader.getReader()));
try {
- new SDParser(stream, applicationPackage, fileRegistry, deployLogger, properties,
- rankProfileRegistry, documentsOnly)
- .rankProfile(schema);
+ parserOf(stream).rankProfile(schema);
} catch (TokenMgrException e) {
throw new ParseException("Unknown symbol: " + e.getMessage());
} catch (ParseException pe) {
@@ -250,7 +244,10 @@ public class ApplicationBuilder {
}
}
-
+ private SDParser parserOf(SimpleCharStream stream) {
+ return new SDParser(stream, applicationPackage, fileRegistry, deployLogger, properties,
+ rankProfileRegistry, documentsOnly);
+ }
/**
* Processes and finalizes the schemas of this.