aboutsummaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-01-25 20:46:17 +0100
committerJon Bratseth <bratseth@gmail.com>2022-01-25 20:46:17 +0100
commit67f133794502e7499f8f8e36821a04a46622fdb9 (patch)
tree2bcf9eb8d21049ea9376f60c8fe34544fc324e06 /config-model
parentda92eb2fb4a752efe47d1d89d846a40ebb2a4786 (diff)
Cleanup
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java46
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/derived/Deriver.java2
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/parser/SimpleCharStream.java6
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/SchemaImporterTestCase.java2
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java4
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/derived/InheritanceTestCase.java24
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/derived/MailTestCase.java2
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/derived/SimpleInheritTestCase.java4
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/derived/StructInheritanceTestCase.java4
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/derived/TwoStreamingStructsTestCase.java8
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/ImplicitSchemaFieldsTestCase.java2
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/documentmodel/DocumentModelBuilderTestCase.java10
12 files changed, 59 insertions, 55 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 033c0d819a1..d75d940d491 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java
@@ -131,20 +131,20 @@ public class ApplicationBuilder {
}
/**
- * Import search definition.
+ * Adds a schema to this application.
*
* @param fileName the name of the file to import
* @return the name of the imported object
* @throws IOException thrown if the file can not be read for some reason
* @throws ParseException thrown if the file does not contain a valid search definition
*/
- public Schema add(String fileName) throws IOException, ParseException {
+ public Schema addSchemaFile(String fileName) throws IOException, ParseException {
File file = new File(fileName);
return addSchema(IOUtils.readFile(file), file.getAbsoluteFile().getParent());
}
- private Schema add(Path file) throws IOException, ParseException {
- return add(file.toString());
+ private Schema addSchemaFile(Path file) throws IOException, ParseException {
+ return addSchemaFile(file.toString());
}
/**
@@ -177,7 +177,7 @@ public class ApplicationBuilder {
}
/**
- * Adds a schema to this.
+ * Adds a schema to this application.
*
* @param string the string to parse
* @return the schema
@@ -187,19 +187,8 @@ public class ApplicationBuilder {
return addSchema(string, null);
}
- private Schema addSchema(String str, String schemaDir) throws ParseException {
- SimpleCharStream stream = new SimpleCharStream(str);
- try {
- Schema schema = new SDParser(stream, applicationPackage, fileRegistry, deployLogger, properties,
- rankProfileRegistry, documentsOnly)
- .schema(documentTypeManager, schemaDir);
- add(schema);
- return schema;
- } catch (TokenMgrException e) {
- throw new ParseException("Unknown symbol: " + e.getMessage());
- } catch (ParseException pe) {
- throw new ParseException(stream.formatException(Exceptions.toMessageString(pe)));
- }
+ private Schema addSchema(String schemaString, String schemaDir) throws ParseException {
+ return add(createSchema(schemaString, schemaDir));
}
/**
@@ -210,10 +199,25 @@ public class ApplicationBuilder {
* @param schema the object to import
* @throws IllegalArgumentException if the given search object has already been processed
*/
- public void add(Schema schema) {
+ public Schema add(Schema schema) {
if (schema.getName() == null)
throw new IllegalArgumentException("Schema has no name");
schemas.add(schema);
+ return schema;
+ }
+
+ private Schema createSchema(String schemaString, String schemaDir) throws ParseException {
+ SimpleCharStream stream = new SimpleCharStream(schemaString);
+ try {
+ Schema schema = new SDParser(stream, applicationPackage, fileRegistry, deployLogger, properties,
+ rankProfileRegistry, documentsOnly)
+ .schema(documentTypeManager, schemaDir);
+ return schema;
+ } catch (TokenMgrException e) {
+ throw new ParseException("Unknown symbol: " + e.getMessage());
+ } catch (ParseException pe) {
+ throw new ParseException(stream.formatException(Exceptions.toMessageString(pe)));
+ }
}
/**
@@ -382,7 +386,7 @@ public class ApplicationBuilder {
rankProfileRegistry,
queryprofileRegistry);
for (String fileName : fileNames) {
- builder.add(fileName);
+ builder.addSchemaFile(fileName);
}
builder.build(true);
return builder;
@@ -423,7 +427,7 @@ public class ApplicationBuilder {
rankProfileRegistry,
queryProfileRegistry);
for (Iterator<Path> i = Files.list(new File(dir).toPath()).filter(p -> p.getFileName().toString().endsWith(".sd")).iterator(); i.hasNext(); ) {
- builder.add(i.next());
+ builder.addSchemaFile(i.next());
}
builder.build(true);
return builder;
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/Deriver.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/Deriver.java
index cf9d46ae985..475631f9241 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/Deriver.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/Deriver.java
@@ -21,7 +21,7 @@ public class Deriver {
ApplicationBuilder builder = new ApplicationBuilder();
try {
for (String schema : schemas)
- builder.add(schema);
+ builder.addSchemaFile(schema);
} catch (ParseException | IOException e) {
throw new IllegalArgumentException(e);
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/SimpleCharStream.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/SimpleCharStream.java
index cde172d00b9..0b275c6a722 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/parser/SimpleCharStream.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/SimpleCharStream.java
@@ -6,11 +6,11 @@ import com.yahoo.javacc.FastCharStream;
/**
* @author Simon Thoresen Hult
*/
-@SuppressWarnings("deprecation")
public class SimpleCharStream extends FastCharStream implements com.yahoo.searchdefinition.parser.CharStream,
- com.yahoo.vespa.indexinglanguage.parser.CharStream
-{
+ com.yahoo.vespa.indexinglanguage.parser.CharStream {
+
public SimpleCharStream(String input) {
super(input);
}
+
}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/SchemaImporterTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/SchemaImporterTestCase.java
index 31b47e4c719..1d01fd8cafa 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/SchemaImporterTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/SchemaImporterTestCase.java
@@ -37,7 +37,7 @@ public class SchemaImporterTestCase extends AbstractSchemaTestCase {
public void testSimpleImporting() throws IOException, ParseException {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
ApplicationBuilder sb = new ApplicationBuilder(rankProfileRegistry, new QueryProfileRegistry());
- sb.add("src/test/examples/simple.sd");
+ sb.addSchemaFile("src/test/examples/simple.sd");
sb.build();
Schema schema = sb.getSchema();
assertEquals("simple", schema.getName());
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java
index 1bb02ca36ec..48f0c862468 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java
@@ -145,8 +145,8 @@ public class ExportingTestCase extends AbstractExportingTestCase {
public void testTensor2() throws IOException, ParseException {
String dir = "src/test/derived/tensor2/";
ApplicationBuilder builder = new ApplicationBuilder();
- builder.add(dir + "first.sd");
- builder.add(dir + "second.sd");
+ builder.addSchemaFile(dir + "first.sd");
+ builder.addSchemaFile(dir + "second.sd");
builder.build();
derive("tensor2", builder, builder.getSchema("second"));
assertCorrectConfigFiles("tensor2");
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/InheritanceTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/InheritanceTestCase.java
index fcc2d116690..13de3f95fa5 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/InheritanceTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/InheritanceTestCase.java
@@ -42,8 +42,8 @@ public class InheritanceTestCase extends AbstractExportingTestCase {
public void requireThatIndexedStructFieldCanBeInherited() throws IOException, ParseException {
String dir = "src/test/derived/inheritstruct/";
ApplicationBuilder builder = new ApplicationBuilder();
- builder.add(dir + "parent.sd");
- builder.add(dir + "child.sd");
+ builder.addSchemaFile(dir + "parent.sd");
+ builder.addSchemaFile(dir + "child.sd");
builder.build();
derive("inheritstruct", builder, builder.getSchema("child"));
assertCorrectConfigFiles("inheritstruct");
@@ -67,7 +67,7 @@ public class InheritanceTestCase extends AbstractExportingTestCase {
ApplicationBuilder builder = new ApplicationBuilder();
for (int fileIdx = startIdx; fileIdx < startIdx + files.size(); ++fileIdx) {
String fileName = files.get(fileIdx % files.size());
- builder.add(dir + fileName);
+ builder.addSchemaFile(dir + fileName);
}
builder.build();
DocumentmanagerConfig.Builder b = new DocumentmanagerConfig.Builder();
@@ -112,8 +112,8 @@ public class InheritanceTestCase extends AbstractExportingTestCase {
public void requireThatStructTypesAreInheritedFromParent() throws IOException, ParseException {
String dir = "src/test/derived/inheritfromparent/";
ApplicationBuilder builder = new ApplicationBuilder();
- builder.add(dir + "parent.sd");
- builder.add(dir + "child.sd");
+ builder.addSchemaFile(dir + "parent.sd");
+ builder.addSchemaFile(dir + "child.sd");
builder.build();
derive("inheritfromparent", builder, builder.getSchema("child"));
assertCorrectConfigFiles("inheritfromparent");
@@ -123,9 +123,9 @@ public class InheritanceTestCase extends AbstractExportingTestCase {
public void requireThatStructTypesAreInheritedFromGrandParent() throws IOException, ParseException {
String dir = "src/test/derived/inheritfromgrandparent/";
ApplicationBuilder builder = new ApplicationBuilder();
- builder.add(dir + "grandparent.sd");
- builder.add(dir + "parent.sd");
- builder.add(dir + "child.sd");
+ builder.addSchemaFile(dir + "grandparent.sd");
+ builder.addSchemaFile(dir + "parent.sd");
+ builder.addSchemaFile(dir + "child.sd");
builder.build();
derive("inheritfromgrandparent", builder, builder.getSchema("child"));
assertCorrectConfigFiles("inheritfromgrandparent");
@@ -135,10 +135,10 @@ public class InheritanceTestCase extends AbstractExportingTestCase {
public void testInheritance() throws IOException, ParseException {
String dir = "src/test/derived/inheritance/";
ApplicationBuilder builder = new ApplicationBuilder();
- builder.add(dir + "grandparent.sd");
- builder.add(dir + "father.sd");
- builder.add(dir + "mother.sd");
- builder.add(dir + "child.sd");
+ builder.addSchemaFile(dir + "grandparent.sd");
+ builder.addSchemaFile(dir + "father.sd");
+ builder.addSchemaFile(dir + "mother.sd");
+ builder.addSchemaFile(dir + "child.sd");
builder.build();
derive("inheritance", builder, builder.getSchema("child"));
assertCorrectConfigFiles("inheritance");
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/MailTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/MailTestCase.java
index 6ae4f625bb3..53bf55fc73f 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/MailTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/MailTestCase.java
@@ -17,7 +17,7 @@ public class MailTestCase extends AbstractExportingTestCase {
public void testMail() throws IOException, ParseException {
String dir = "src/test/derived/mail/";
ApplicationBuilder sb = new ApplicationBuilder();
- sb.add(dir + "mail.sd");
+ sb.addSchemaFile(dir + "mail.sd");
assertCorrectDeriving(sb, dir, new TestableDeployLogger());
}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/SimpleInheritTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/SimpleInheritTestCase.java
index 8d5ee7e5405..8a4e403072b 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/SimpleInheritTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/SimpleInheritTestCase.java
@@ -20,8 +20,8 @@ public class SimpleInheritTestCase extends AbstractExportingTestCase {
final String expectedResultsDirName = "src/test/derived/" + name + "/";
ApplicationBuilder builder = new ApplicationBuilder();
- builder.add(expectedResultsDirName + "parent.sd");
- builder.add(expectedResultsDirName + "child.sd");
+ builder.addSchemaFile(expectedResultsDirName + "parent.sd");
+ builder.addSchemaFile(expectedResultsDirName + "child.sd");
builder.build();
Schema schema = builder.getSchema("child");
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/StructInheritanceTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/StructInheritanceTestCase.java
index 1141eec1820..c684ec17e42 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/StructInheritanceTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/StructInheritanceTestCase.java
@@ -32,7 +32,7 @@ public class StructInheritanceTestCase extends AbstractExportingTestCase {
public void requireThatStructCanInherit() throws IOException, ParseException {
String dir = "src/test/derived/structinheritance/";
ApplicationBuilder builder = new ApplicationBuilder();
- builder.add(dir + "simple.sd");
+ builder.addSchemaFile(dir + "simple.sd");
builder.build(false);
derive("structinheritance", builder, builder.getSchema("simple"));
assertCorrectConfigFiles("structinheritance");
@@ -44,7 +44,7 @@ public class StructInheritanceTestCase extends AbstractExportingTestCase {
exceptionRule.expectMessage("cannot inherit from base and redeclare field name");
String dir = "src/test/derived/structinheritance/";
ApplicationBuilder builder = new ApplicationBuilder();
- builder.add(dir + "bad.sd");
+ builder.addSchemaFile(dir + "bad.sd");
builder.build();
derive("structinheritance", builder, builder.getSchema("bad"));
}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/TwoStreamingStructsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/TwoStreamingStructsTestCase.java
index 7e0b3bddbc4..53948e2d5c8 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/TwoStreamingStructsTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/TwoStreamingStructsTestCase.java
@@ -18,14 +18,14 @@ public class TwoStreamingStructsTestCase extends AbstractExportingTestCase {
String root = "src/test/derived/twostreamingstructs";
ApplicationBuilder builder = new ApplicationBuilder();
- builder.add(root + "/streamingstruct.sd");
- builder.add(root + "/whatever.sd");
+ builder.addSchemaFile(root + "/streamingstruct.sd");
+ builder.addSchemaFile(root + "/whatever.sd");
builder.build();
assertCorrectDeriving(builder, builder.getSchema("streamingstruct"), root);
builder = new ApplicationBuilder();
- builder.add(root + "/streamingstruct.sd");
- builder.add(root + "/whatever.sd");
+ builder.addSchemaFile(root + "/streamingstruct.sd");
+ builder.addSchemaFile(root + "/whatever.sd");
builder.build();
assertCorrectDeriving(builder, builder.getSchema("streamingstruct"), root);
}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImplicitSchemaFieldsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImplicitSchemaFieldsTestCase.java
index 62f805f7b62..cfc1779ded0 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImplicitSchemaFieldsTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImplicitSchemaFieldsTestCase.java
@@ -83,7 +83,7 @@ public class ImplicitSchemaFieldsTestCase extends AbstractSchemaTestCase {
@Test
public void testRequireThatDerivedConfigurationWorks() throws IOException, ParseException {
ApplicationBuilder sb = new ApplicationBuilder();
- sb.add("src/test/examples/nextgen/simple.sd");
+ sb.addSchemaFile("src/test/examples/nextgen/simple.sd");
sb.build();
assertNotNull(sb.getSchema());
new DerivedConfiguration(sb.getSchema(), sb.getRankProfileRegistry());
diff --git a/config-model/src/test/java/com/yahoo/vespa/documentmodel/DocumentModelBuilderTestCase.java b/config-model/src/test/java/com/yahoo/vespa/documentmodel/DocumentModelBuilderTestCase.java
index 6fbe73011df..857a1499264 100644
--- a/config-model/src/test/java/com/yahoo/vespa/documentmodel/DocumentModelBuilderTestCase.java
+++ b/config-model/src/test/java/com/yahoo/vespa/documentmodel/DocumentModelBuilderTestCase.java
@@ -36,8 +36,8 @@ public class DocumentModelBuilderTestCase extends AbstractSchemaTestCase {
@Test
public void testDocumentTypesWithDocumentField() throws IOException, ParseException {
ApplicationBuilder search = new ApplicationBuilder();
- search.add("src/test/configmodel/types/other_doc.sd");
- search.add("src/test/configmodel/types/type_with_doc_field.sd");
+ search.addSchemaFile("src/test/configmodel/types/other_doc.sd");
+ search.addSchemaFile("src/test/configmodel/types/type_with_doc_field.sd");
search.build();
DocumentModel model = search.getModel();
@@ -49,9 +49,9 @@ public class DocumentModelBuilderTestCase extends AbstractSchemaTestCase {
@Test
public void testMultipleInheritanceArray() throws IOException, ParseException {
ApplicationBuilder search = new ApplicationBuilder();
- search.add("src/test/cfg/search/data/travel/schemas/TTData.sd");
- search.add("src/test/cfg/search/data/travel/schemas/TTEdge.sd");
- search.add("src/test/cfg/search/data/travel/schemas/TTPOI.sd");
+ search.addSchemaFile("src/test/cfg/search/data/travel/schemas/TTData.sd");
+ search.addSchemaFile("src/test/cfg/search/data/travel/schemas/TTEdge.sd");
+ search.addSchemaFile("src/test/cfg/search/data/travel/schemas/TTPOI.sd");
search.build();
}