aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-documentgen-plugin
diff options
context:
space:
mode:
Diffstat (limited to 'vespa-documentgen-plugin')
-rw-r--r--vespa-documentgen-plugin/etc/complex/book.sd2
-rw-r--r--vespa-documentgen-plugin/etc/complex/common.sd2
-rw-r--r--vespa-documentgen-plugin/etc/complex/common2.sd2
-rw-r--r--vespa-documentgen-plugin/etc/complex/music2.sd2
-rw-r--r--vespa-documentgen-plugin/etc/complex/music3.sd2
-rw-r--r--vespa-documentgen-plugin/etc/complex/video.sd2
-rw-r--r--vespa-documentgen-plugin/etc/localapp/book.sd2
-rw-r--r--vespa-documentgen-plugin/etc/localapp/common.sd2
-rw-r--r--vespa-documentgen-plugin/etc/localapp/music.sd2
-rw-r--r--vespa-documentgen-plugin/etc/localapp/video.sd2
-rw-r--r--vespa-documentgen-plugin/etc/music/music.sd2
-rw-r--r--vespa-documentgen-plugin/pom.xml2
-rw-r--r--vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/Annotation.java2
-rw-r--r--vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java74
-rw-r--r--vespa-documentgen-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml2
-rw-r--r--vespa-documentgen-plugin/src/test/java/com/yahoo/vespa/DocumentGenTest.java20
16 files changed, 78 insertions, 44 deletions
diff --git a/vespa-documentgen-plugin/etc/complex/book.sd b/vespa-documentgen-plugin/etc/complex/book.sd
index 8f071ab63d1..953244ba93f 100644
--- a/vespa-documentgen-plugin/etc/complex/book.sd
+++ b/vespa-documentgen-plugin/etc/complex/book.sd
@@ -1,4 +1,4 @@
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
search book {
document book inherits common {
struct ss0 {
diff --git a/vespa-documentgen-plugin/etc/complex/common.sd b/vespa-documentgen-plugin/etc/complex/common.sd
index 3ab6e18c267..af9457dbaf9 100644
--- a/vespa-documentgen-plugin/etc/complex/common.sd
+++ b/vespa-documentgen-plugin/etc/complex/common.sd
@@ -1,4 +1,4 @@
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
search common {
document common {
field uri type string {
diff --git a/vespa-documentgen-plugin/etc/complex/common2.sd b/vespa-documentgen-plugin/etc/complex/common2.sd
index 65984ed8658..c2fa48c64b2 100644
--- a/vespa-documentgen-plugin/etc/complex/common2.sd
+++ b/vespa-documentgen-plugin/etc/complex/common2.sd
@@ -1,4 +1,4 @@
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
search common2 {
document {
field com2 type string {
diff --git a/vespa-documentgen-plugin/etc/complex/music2.sd b/vespa-documentgen-plugin/etc/complex/music2.sd
index 17736ab4e79..a1a3aefc639 100644
--- a/vespa-documentgen-plugin/etc/complex/music2.sd
+++ b/vespa-documentgen-plugin/etc/complex/music2.sd
@@ -1,4 +1,4 @@
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
search music2 {
document music2 inherits common {
field artist type string {
diff --git a/vespa-documentgen-plugin/etc/complex/music3.sd b/vespa-documentgen-plugin/etc/complex/music3.sd
index aae9fc9097e..1ba55a42545 100644
--- a/vespa-documentgen-plugin/etc/complex/music3.sd
+++ b/vespa-documentgen-plugin/etc/complex/music3.sd
@@ -1,4 +1,4 @@
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
search music3 {
document music3 inherits music2, common2 {
field mu3 type string {
diff --git a/vespa-documentgen-plugin/etc/complex/video.sd b/vespa-documentgen-plugin/etc/complex/video.sd
index 5d1f9c66d8d..71e51699cba 100644
--- a/vespa-documentgen-plugin/etc/complex/video.sd
+++ b/vespa-documentgen-plugin/etc/complex/video.sd
@@ -1,4 +1,4 @@
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
search video {
document video inherits common {
field director type string {
diff --git a/vespa-documentgen-plugin/etc/localapp/book.sd b/vespa-documentgen-plugin/etc/localapp/book.sd
index 8d7dd1e054e..95bf258bb54 100644
--- a/vespa-documentgen-plugin/etc/localapp/book.sd
+++ b/vespa-documentgen-plugin/etc/localapp/book.sd
@@ -1,4 +1,4 @@
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
search book {
document book inherits common {
struct ss0 {
diff --git a/vespa-documentgen-plugin/etc/localapp/common.sd b/vespa-documentgen-plugin/etc/localapp/common.sd
index a7828432c6b..c38518494e5 100644
--- a/vespa-documentgen-plugin/etc/localapp/common.sd
+++ b/vespa-documentgen-plugin/etc/localapp/common.sd
@@ -1,4 +1,4 @@
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
search common {
document common {
field uri type string {
diff --git a/vespa-documentgen-plugin/etc/localapp/music.sd b/vespa-documentgen-plugin/etc/localapp/music.sd
index 0ce004857c2..290b1c318ea 100644
--- a/vespa-documentgen-plugin/etc/localapp/music.sd
+++ b/vespa-documentgen-plugin/etc/localapp/music.sd
@@ -1,4 +1,4 @@
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
search music {
document music inherits common {
field artist type string {
diff --git a/vespa-documentgen-plugin/etc/localapp/video.sd b/vespa-documentgen-plugin/etc/localapp/video.sd
index 03c5c82ed64..a5d0b28cfdb 100644
--- a/vespa-documentgen-plugin/etc/localapp/video.sd
+++ b/vespa-documentgen-plugin/etc/localapp/video.sd
@@ -1,4 +1,4 @@
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
search video {
document video inherits common {
field director type string {
diff --git a/vespa-documentgen-plugin/etc/music/music.sd b/vespa-documentgen-plugin/etc/music/music.sd
index 8c2d324697c..37984beb305 100644
--- a/vespa-documentgen-plugin/etc/music/music.sd
+++ b/vespa-documentgen-plugin/etc/music/music.sd
@@ -1,4 +1,4 @@
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
# A basic search definition - called music, should be saved to music.sd
search music {
diff --git a/vespa-documentgen-plugin/pom.xml b/vespa-documentgen-plugin/pom.xml
index b73c1ab7595..83c392aedd1 100644
--- a/vespa-documentgen-plugin/pom.xml
+++ b/vespa-documentgen-plugin/pom.xml
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
-<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<!-- Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
diff --git a/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/Annotation.java b/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/Annotation.java
index b81459f0baf..797d1262466 100644
--- a/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/Annotation.java
+++ b/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/Annotation.java
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa;
/**
diff --git a/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java b/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java
index 7de2627209c..5cd1d3bf9b6 100644
--- a/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java
+++ b/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa;
import com.yahoo.collections.Pair;
@@ -53,7 +53,7 @@ public class DocumentGenMojo extends AbstractMojo {
private static final int STD_INDENT = 4;
- @Parameter( defaultValue = "${project}", readonly = true )
+ @Parameter(defaultValue = "${project}", readonly = true)
private MavenProject project;
/**
@@ -564,7 +564,7 @@ public class DocumentGenMojo extends AbstractMojo {
out.write(ind(ind)+"public "+className+"(com.yahoo.document.datatypes.StructuredFieldValue src) {\n"+
ind(ind+1)+"super("+className+".type);\n");
}
- out.write(ind() + "ConcreteDocumentFactory factory = new ConcreteDocumentFactory();\n");
+ out.write(ind(ind+1) + "ConcreteDocumentFactory factory = new ConcreteDocumentFactory();\n");
out.write(
ind(ind+1)+"for (java.util.Iterator<java.util.Map.Entry<com.yahoo.document.Field, com.yahoo.document.datatypes.FieldValue>>i=src.iterator() ; i.hasNext() ; ) {\n" +
ind(ind+2)+"java.util.Map.Entry<com.yahoo.document.Field, com.yahoo.document.datatypes.FieldValue> e = i.next();\n" +
@@ -851,8 +851,12 @@ public class DocumentGenMojo extends AbstractMojo {
for (Field field: fields) {
DataType dt = field.getDataType();
out.write(
- ind(ind)+"public "+toJavaType(dt)+" "+getter(field.getName())+"() { return "+field.getName()+"; }\n"+
- ind(ind)+"public "+className+" "+setter(field.getName())+"("+toJavaType(dt)+" "+field.getName()+") { this."+field.getName()+"="+field.getName()+"; return this; }\n");
+ ind(ind) + "public " + toJavaType(dt) + " " + getter(field.getName()) + "() { return " + field.getName() + "; }\n" +
+ ind(ind) + "public " + className + " " + setter(field.getName()) + "(" + toJavaType(dt) + " " + field.getName() + ") {\n" +
+ validateArgument(field.getDataType(), field.getName(), ind + 1) +
+ ind(ind+1) + "this." + field.getName() + "=" + field.getName() + ";\n" +
+ ind(ind+1) + "return this;\n" +
+ ind(ind) + "}\n");
if (spanTrees && dt.equals(DataType.STRING)) {
out.write(ind(ind)+"public java.util.Map<java.lang.String,com.yahoo.document.annotation.SpanTree> "+spanTreeGetter(field.getName())+"() { return "+field.getName()+"SpanTrees; }\n" +
ind(ind)+"public void "+spanTreeSetter(field.getName())+"(java.util.Map<java.lang.String,com.yahoo.document.annotation.SpanTree> spanTrees) { this."+field.getName()+"SpanTrees=spanTrees; }\n");
@@ -861,6 +865,38 @@ public class DocumentGenMojo extends AbstractMojo {
out.write("\n");
}
+ private static String validateArgument(DataType type, String variable, int ind) {
+ if (type instanceof MapDataType mdt) {
+ return validateWrapped(mdt.getKeyType(), variable, variable + ".keySet()", ind) +
+ validateWrapped(mdt.getValueType(), variable, variable + ".values()", ind);
+ }
+ else if (type instanceof CollectionDataType cdt) {
+ String elements = cdt instanceof WeightedSetDataType ? variable + ".keySet()" : variable;
+ return validateWrapped(cdt.getNestedType(), variable, elements, ind);
+ }
+ else if ( DataType.STRING.equals(type)
+ || DataType.URI.equals(type)
+ || type instanceof AnnotationReferenceDataType
+ || type instanceof NewDocumentReferenceDataType) {
+ return ind(ind) + "if (" + variable + " != null) {\n" +
+ ind(ind+1) + toJavaReference(type) + ".createFieldValue(" + variable + ");\n" +
+ ind(ind) + "}\n";
+ }
+ else {
+ return "";
+ }
+ }
+
+ private static String validateWrapped(DataType type, String variable, String elements, int ind) {
+ String wrappedValidation = validateArgument(type, variable + "$", ind + 2);
+ if (wrappedValidation.isBlank()) return "";
+ return ind(ind) + "if (" + variable + " != null) {\n" +
+ ind(ind+1) + "for (" + toJavaType(type) + " " + variable + "$ : " + elements + ") {\n" +
+ wrappedValidation +
+ ind(ind+1) + "}\n" +
+ ind(ind) + "}\n";
+ }
+
private static String spanTreeSetter(String field) {
return setter(field)+"SpanTrees";
}
@@ -914,10 +950,10 @@ public class DocumentGenMojo extends AbstractMojo {
if (DataType.BOOL.equals(dt)) return "java.lang.Boolean";
if (DataType.TAG.equals(dt)) return "java.lang.String";
if (dt instanceof StructDataType) return className(dt.getName());
- if (dt instanceof WeightedSetDataType) return "java.util.Map<"+toJavaType(((WeightedSetDataType)dt).getNestedType())+",java.lang.Integer>";
- if (dt instanceof ArrayDataType) return "java.util.List<"+toJavaType(((ArrayDataType)dt).getNestedType())+">";
- if (dt instanceof MapDataType) return "java.util.Map<"+toJavaType(((MapDataType)dt).getKeyType())+","+toJavaType(((MapDataType)dt).getValueType())+">";
- if (dt instanceof AnnotationReferenceDataType) return className(((AnnotationReferenceDataType) dt).getAnnotationType().getName());
+ if (dt instanceof WeightedSetDataType wdt) return "java.util.Map<"+toJavaType(wdt.getNestedType())+",java.lang.Integer>";
+ if (dt instanceof ArrayDataType adt) return "java.util.List<"+toJavaType(adt.getNestedType())+">";
+ if (dt instanceof MapDataType mdt) return "java.util.Map<"+toJavaType(mdt.getKeyType())+","+toJavaType((mdt).getValueType())+">";
+ if (dt instanceof AnnotationReferenceDataType ardt) return className(ardt.getAnnotationType().getName());
if (dt instanceof NewDocumentReferenceDataType) {
return "com.yahoo.document.DocumentId";
}
@@ -942,22 +978,22 @@ public class DocumentGenMojo extends AbstractMojo {
if (DataType.BOOL.equals(dt)) return "com.yahoo.document.DataType.BOOL";
if (DataType.TAG.equals(dt)) return "com.yahoo.document.DataType.TAG";
if (dt instanceof StructDataType) return className(dt.getName()) +".type";
- if (dt instanceof WeightedSetDataType) return "new com.yahoo.document.WeightedSetDataType("+toJavaReference(((WeightedSetDataType)dt).getNestedType())+", "+
- ((WeightedSetDataType)dt).createIfNonExistent()+", "+ ((WeightedSetDataType)dt).removeIfZero()+","+dt.getId()+")";
- if (dt instanceof ArrayDataType) return "new com.yahoo.document.ArrayDataType("+toJavaReference(((ArrayDataType)dt).getNestedType())+")";
- if (dt instanceof MapDataType) return "new com.yahoo.document.MapDataType("+toJavaReference(((MapDataType)dt).getKeyType())+", "+
- toJavaReference(((MapDataType)dt).getValueType())+", "+dt.getId()+")";
+ if (dt instanceof WeightedSetDataType wdt) return "new com.yahoo.document.WeightedSetDataType("+toJavaReference(wdt.getNestedType())+", "+
+ wdt.createIfNonExistent()+", "+ wdt.removeIfZero()+","+dt.getId()+")";
+ if (dt instanceof ArrayDataType adt) return "new com.yahoo.document.ArrayDataType("+toJavaReference(adt.getNestedType())+")";
+ if (dt instanceof MapDataType mdt) return "new com.yahoo.document.MapDataType("+toJavaReference(mdt.getKeyType())+", "+
+ toJavaReference(mdt.getValueType())+", "+dt.getId()+")";
// For annotation references and generated types, the references are to the actual objects of the correct types, so most likely this is never needed,
// but there might be scenarios where we want to look up the AnnotationType in the AnnotationTypeRegistry here instead.
- if (dt instanceof AnnotationReferenceDataType) return "new com.yahoo.document.annotation.AnnotationReferenceDataType(new com.yahoo.document.annotation.AnnotationType(\""+((AnnotationReferenceDataType)dt).getAnnotationType().getName()+"\"))";
- if (dt instanceof NewDocumentReferenceDataType) {
+ if (dt instanceof AnnotationReferenceDataType adt) return "new com.yahoo.document.annotation.AnnotationReferenceDataType(new com.yahoo.document.annotation.AnnotationType(\""+adt.getAnnotationType().getName()+"\"))";
+ if (dt instanceof NewDocumentReferenceDataType nrdt) {
// All concrete document types have a public `type` constant with their DocumentType.
return String.format("new com.yahoo.document.ReferenceDataType(%s.type, %d)",
- className(((NewDocumentReferenceDataType) dt).getTargetType().getName()), dt.getId());
+ className(nrdt.getTargetType().getName()), dt.getId());
}
- if (dt instanceof TensorDataType) {
+ if (dt instanceof TensorDataType tdt) {
return String.format("new com.yahoo.document.TensorDataType(com.yahoo.tensor.TensorType.fromSpec(\"%s\"))",
- ((TensorDataType)dt).getTensorType().toString());
+ tdt.getTensorType().toString());
}
return "com.yahoo.document.DataType.RAW";
}
diff --git a/vespa-documentgen-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml b/vespa-documentgen-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
index d674decb008..9406446d856 100644
--- a/vespa-documentgen-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
+++ b/vespa-documentgen-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
@@ -1,4 +1,4 @@
-<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<!-- Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
diff --git a/vespa-documentgen-plugin/src/test/java/com/yahoo/vespa/DocumentGenTest.java b/vespa-documentgen-plugin/src/test/java/com/yahoo/vespa/DocumentGenTest.java
index f55b226b11b..d0315f84272 100644
--- a/vespa-documentgen-plugin/src/test/java/com/yahoo/vespa/DocumentGenTest.java
+++ b/vespa-documentgen-plugin/src/test/java/com/yahoo/vespa/DocumentGenTest.java
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa;
import com.yahoo.document.DataType;
@@ -11,8 +11,9 @@ import java.io.File;
import java.util.Map;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
public class DocumentGenTest {
@@ -39,7 +40,7 @@ public class DocumentGenTest {
assertEquals(searches.get("music3").getDocument("music3").getField("pos").getDataType().getName(), "position");
assertTrue(searches.get("book").getDocument("book").getField("mystruct").getDataType() instanceof StructDataType);
assertTrue(searches.get("book").getDocument("book").getField("mywsinteger").getDataType() instanceof WeightedSetDataType);
- assertTrue(((WeightedSetDataType)(searches.get("book").getDocument("book").getField("mywsinteger").getDataType())).getNestedType() == DataType.INT);
+ assertSame(((WeightedSetDataType) (searches.get("book").getDocument("book").getField("mywsinteger").getDataType())).getNestedType(), DataType.INT);
}
@Test
@@ -50,18 +51,15 @@ public class DocumentGenTest {
assertEquals(searches.get("video").getDocument("video").getField("weight").getDataType(), DataType.FLOAT);
assertTrue(searches.get("book").getDocument("book").getField("mystruct").getDataType() instanceof StructDataType);
assertTrue(searches.get("book").getDocument("book").getField("mywsinteger").getDataType() instanceof WeightedSetDataType);
- assertTrue(((WeightedSetDataType)(searches.get("book").getDocument("book").getField("mywsinteger").getDataType())).getNestedType() == DataType.INT);
+ assertSame(((WeightedSetDataType) (searches.get("book").getDocument("book").getField("mywsinteger").getDataType())).getNestedType(), DataType.INT);
}
@Test
public void testEmptyPkgNameForbidden() {
- DocumentGenMojo mojo = new DocumentGenMojo();
- try {
- mojo.execute(new File("etc/localapp/"), new File("target/generated-test-sources/vespa-documentgen-plugin/"), "");
- fail("Didn't throw in empty pkg");
- } catch (IllegalArgumentException e) {
-
- }
+ assertThrows(IllegalArgumentException.class,
+ () -> new DocumentGenMojo().execute(new File("etc/localapp/"),
+ new File("target/generated-test-sources/vespa-documentgen-plugin/"),
+ ""));
}
}