diff options
author | Harald Musum <musum@verizonmedia.com> | 2021-06-03 10:58:32 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2021-06-03 10:58:32 +0200 |
commit | 2a85cadde1ed663f1ba04cfede6ce84986b79007 (patch) | |
tree | fa57c7ee9605545b16e24131e23b07f5e1324252 /vespa-documentgen-plugin | |
parent | 5bf38bbdda250c5fdac68a1f8d989fb303702715 (diff) |
Add schemasDirectory parameter and use it if set
Diffstat (limited to 'vespa-documentgen-plugin')
3 files changed, 30 insertions, 18 deletions
diff --git a/vespa-documentgen-plugin/README b/vespa-documentgen-plugin/README index 5afe4630355..3b016dccc9c 100644 --- a/vespa-documentgen-plugin/README +++ b/vespa-documentgen-plugin/README @@ -1 +1 @@ -Maven plugin which generates Vespa document classes from SD files. +Maven plugin which generates Vespa document classes from schema files. 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 31046206392..465abae9504 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,13 +1,14 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa; /** * Represents one configured provided annotation type * - * @author vegardh + * @author Vegard Balgaard Havdal */ public class Annotation { String type; String clazz; + } 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 3faf47ccfa9..35dba79644e 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 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. 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; @@ -30,13 +30,11 @@ import org.apache.maven.project.MavenProject; import java.io.File; import java.io.FileWriter; -import java.io.FilenameFilter; import java.io.IOException; import java.io.Writer; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -44,10 +42,10 @@ import java.util.List; import java.util.Map; import java.util.Set; - /** - * Goal which generates Vespa document classes from SD files. - * @author vegardh + * Generates Vespa document classes from schema files. + * + * @author Vegard Balgaard Havdal */ @Mojo(name = "document-gen", defaultPhase = LifecyclePhase.GENERATE_SOURCES) public class DocumentGenMojo extends AbstractMojo { @@ -60,12 +58,22 @@ public class DocumentGenMojo extends AbstractMojo { private MavenProject project; /** - * Directory containing the SD files + * Directory containing the searchdefinition files + * @deprecated use {@link #schemasDirectory} instead */ - @Parameter(defaultValue = ".", required = true) + // TODO: Remove in Vespa 8 + @Deprecated + @Parameter(defaultValue = ".", required = false) private File sdDirectory; /** + * Directory containing the schema files + */ + // TODO: Make this required when sdDirectory is removed in Vespa 8 + @Parameter(defaultValue = ".", required = false) + private File schemasDirectory; + + /** * Java package for generated classes */ @Parameter(defaultValue = "com.yahoo.vespa.document", required = true) @@ -98,7 +106,7 @@ public class DocumentGenMojo extends AbstractMojo { private Map<String, String> structTypes; private Map<String, String> annotationTypes; - void execute(File sdDir, File outputDir, String packageName) { + void execute(File schemasDir, File outputDir, String packageName) { if ("".equals(packageName)) throw new IllegalArgumentException("You may not use empty package for generated types."); searches = new HashMap<>(); docTypes = new HashMap<>(); @@ -106,7 +114,7 @@ public class DocumentGenMojo extends AbstractMojo { annotationTypes = new HashMap<>(); outputDir.mkdirs(); - SearchBuilder builder = buildSearches(sdDir); + SearchBuilder builder = buildSearches(schemasDir); boolean annotationsExported=false; for (NewDocumentType docType : builder.getModel().getDocumentManager().getTypes()) { @@ -127,10 +135,7 @@ public class DocumentGenMojo extends AbstractMojo { } private SearchBuilder buildSearches(File sdDir) { - File[] sdFiles = sdDir.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.endsWith(".sd"); - }}); + File[] sdFiles = sdDir.listFiles((dir, name) -> name.endsWith(".sd")); SearchBuilder builder = new SearchBuilder(true); for (File f : sdFiles) { try { @@ -980,7 +985,12 @@ public class DocumentGenMojo extends AbstractMojo { @Override public void execute() { - execute(this.sdDirectory, this.outputDirectory, this.packageName); + File dir = sdDirectory; + // Prefer schemasDirectory if set + if ( ! schemasDirectory.getName().equals(".")) + dir = schemasDirectory; + + execute(dir, outputDirectory, packageName); } Map<String, Search> getSearches() { @@ -990,4 +1000,5 @@ public class DocumentGenMojo extends AbstractMojo { private static String upperCaseFirstChar(String s) { return s.substring(0, 1).toUpperCase()+s.substring(1); } + } |