diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-02-01 15:05:40 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-02-01 15:05:40 +0100 |
commit | 58a80a9ea9dafd36a8d9f204725bfced2e0dbcad (patch) | |
tree | 09e5395270a7ee89793dd071079a1bb27ad8f74d | |
parent | c2dc7f1e3f9371cc8b04246ca346b1c5f7f2fd3f (diff) |
Avoid schema dir
-rw-r--r-- | config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java | 36 | ||||
-rw-r--r-- | config-model/src/main/javacc/SDParser.jj | 11 |
2 files changed, 19 insertions, 28 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..134fc4dc5a2 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,18 @@ 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); + .schema(documentTypeManager); } catch (TokenMgrException e) { throw new ParseException("Unknown symbol: " + e.getMessage()); } catch (ParseException pe) { @@ -220,9 +214,9 @@ public class ApplicationBuilder { } } - private void addRankProfileFiles(Schema schema, String schemaPath) { - if (applicationPackage == null || schemaPath == null) return; - Path rankProfilePath = Path.fromString(schemaPath).append(schema.getName()); + private void addRankProfileFiles(Schema schema) { + if (applicationPackage == null) return; + Path rankProfilePath = ApplicationPackage.SCHEMAS_DIR.append(schema.getName()); for (NamedReader reader : applicationPackage.getFiles(rankProfilePath, ".profile")) { parseRankProfile(reader, schema); } diff --git a/config-model/src/main/javacc/SDParser.jj b/config-model/src/main/javacc/SDParser.jj index 5b7721c0fe9..b6a9ab789bf 100644 --- a/config-model/src/main/javacc/SDParser.jj +++ b/config-model/src/main/javacc/SDParser.jj @@ -395,16 +395,15 @@ SPECIAL_TOKEN : * The rule consumes any schema and returns the corresponding object. This is the only production that should * ever consume leading newlines. * - * @param dir the directory containing the file being parsed * @return the schema object */ -Schema schema(DocumentTypeManager docMan, String dir) : +Schema schema(DocumentTypeManager docMan) : { this.docMan = docMan; Schema schema; } { - (<NL>)* (schema = rootSchema(dir) | schema = rootDocument(dir)) + (<NL>)* (schema = rootSchema() | schema = rootDocument()) { return schema; } } @@ -412,10 +411,9 @@ Schema schema(DocumentTypeManager docMan, String dir) : * This rule consumes a proper schema block. This and rootDocument() are the only rules that should ever consume * trailing newline tokens. * - * @param dir the directory containing the file being parsed. * @return the schema definition object. */ -Schema rootSchema(String dir) : +Schema rootSchema() : { String name; String inherited = null; @@ -459,10 +457,9 @@ Object rootSchemaItem(Schema schema) : { } /** * Consumes a schema definition that contains only documents to be used for inheritance, etc. * - * @param dir the directory containing the file being parsed. * @return the schema definition object. */ -Schema rootDocument(String dir) : +Schema rootDocument() : { Schema schema = new DocumentOnlySchema(applicationPackage, fileRegistry, deployLogger, properties); } |