Skip to content

Commit

Permalink
GH-448 add compiler config in the CompiledSail builder (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 authored Feb 8, 2024
1 parent 42f4d62 commit 4a65dbe
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,24 @@ private CompiledSail(CompiledSailCompiler config) throws IOException, SailCompil
files = Objects.requireNonNullElseGet(config.endpointFiles,
() -> new EndpointFiles(Path.of("native-store"), Path.of("hdt-store"), "index_dev.hdt"));
}

SailCompiler sailCompiler = new SailCompiler();

// load the validator
if (config.validator != null) {
sailCompiler.setValidator(config.validator);
}

// register custom strings
sailCompiler.registerDirObject(files);
config.stringObject.forEach(sailCompiler::registerDirObject);
config.stringConfig.forEach(sailCompiler::registerDirString);

// register custom configs
if (config.sailCompilerConfig != null) {
config.sailCompilerConfig.config(sailCompiler);
}

LuceneSailCompiler luceneCompiler = (LuceneSailCompiler) sailCompiler
.getCompiler(SailCompilerSchema.LUCENE_TYPE);

Expand Down Expand Up @@ -354,6 +365,7 @@ public static class CompiledSailCompiler {
private final List<Object> stringObject = new ArrayList<>();
private CompiledSailOptions options;
private SailCompilerValidator validator;
private SailCompilerConfig sailCompilerConfig;

private CompiledSailCompiler() {
}
Expand Down Expand Up @@ -481,6 +493,18 @@ public CompiledSailCompiler withValidator(SailCompilerValidator validator) {
return this;
}

/**
* set the config for the sail compiler
*
* @param config the config
* @return this
* @throws java.lang.NullPointerException a parameter is null
*/
public CompiledSailCompiler withCompilerConfig(SailCompilerConfig config) {
this.sailCompilerConfig = Objects.requireNonNull(config, "config can't be null!");
return this;
}

/**
* set a source sail to wrap with this compiled sail
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.the_qa_company.qendpoint.compiler;

import java.io.IOException;

/**
* Config option for the {@link SailCompiler}.
*
* @author Antoine Willerval
*/
public interface SailCompilerConfig {
/**
* Config the sail compiler
*
* @param compiler compiler
* @throws IOException io exception
*/
void config(SailCompiler compiler) throws IOException;
}

0 comments on commit 4a65dbe

Please sign in to comment.