Skip to content

Commit

Permalink
fix #2822 Added configuration option to filter and pass system proper…
Browse files Browse the repository at this point in the history
…ties to jobs based on a regex pattern.
  • Loading branch information
marevol committed Jun 23, 2024
1 parent ec33a25 commit a26e133
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/java/org/codelibs/fess/job/CrawlJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ protected void executeCrawler() {

addFessConfigProperties(cmdList);
addFessSystemProperties(cmdList);
addFessCustomSystemProperties(cmdList, fessConfig.getJobSystemPropertyFilterPattern());
addSystemProperty(cmdList, Constants.FESS_CONF_PATH, null, null);
cmdList.add("-Dfess." + getExecuteType() + ".process=true");
cmdList.add("-Dfess.log.path=" + (logFilePath != null ? logFilePath : systemHelper.getLogFilePath()));
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/codelibs/fess/job/ExecJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.regex.Pattern;

import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -156,6 +157,14 @@ protected void addFessSystemProperties(final List<String> cmdList) {
.forEach(k -> addSystemProperty(cmdList, k.toString(), null, null));
}

protected void addFessCustomSystemProperties(final List<String> cmdList, final String regex) {
if (StringUtil.isNotBlank(regex)) {
final Pattern pattern = Pattern.compile(regex);
System.getProperties().keySet().stream().filter(k -> k != null && pattern.matcher(k.toString()).matches())
.forEach(k -> addSystemProperty(cmdList, k.toString(), null, null));
}
}

protected void deleteTempDir(final File ownTmpDir) {
if (ownTmpDir == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ protected void executeThumbnailGenerator() {

addFessConfigProperties(cmdList);
addFessSystemProperties(cmdList);
addFessCustomSystemProperties(cmdList, fessConfig.getJobSystemPropertyFilterPattern());
addSystemProperty(cmdList, Constants.FESS_CONF_PATH, null, null);
cmdList.add("-Dfess." + getExecuteType() + ".process=true");
if (logFilePath == null) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/codelibs/fess/job/SuggestJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ protected void executeSuggestCreator() {

addFessConfigProperties(cmdList);
addFessSystemProperties(cmdList);
addFessCustomSystemProperties(cmdList, fessConfig.getJobSystemPropertyFilterPattern());
addSystemProperty(cmdList, Constants.FESS_CONF_PATH, null, null);
cmdList.add("-Dfess." + getExecuteType() + ".process=true");
if (logFilePath == null) {
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. groovy */
String JOB_DEFAULT_SCRIPT = "job.default.script";

/** The key of the configuration. e.g. */
String JOB_SYSTEM_PROPERTY_FILTER_PATTERN = "job.system.property.filter.pattern";

/** The key of the configuration. e.g. 0 */
String PROCESSORS = "processors";

Expand Down Expand Up @@ -2161,6 +2164,21 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
*/
String getJobDefaultScript();

/**
* Get the value for the key 'job.system.property.filter.pattern'. <br>
* The value is, e.g. <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getJobSystemPropertyFilterPattern();

/**
* Get the value for the key 'job.system.property.filter.pattern' as {@link Integer}. <br>
* The value is, e.g. <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
* @throws NumberFormatException When the property is not integer.
*/
Integer getJobSystemPropertyFilterPatternAsInteger();

/**
* Get the value for the key 'processors'. <br>
* The value is, e.g. 0 <br>
Expand Down Expand Up @@ -7833,6 +7851,14 @@ public String getJobDefaultScript() {
return get(FessConfig.JOB_DEFAULT_SCRIPT);
}

public String getJobSystemPropertyFilterPattern() {
return get(FessConfig.JOB_SYSTEM_PROPERTY_FILTER_PATTERN);
}

public Integer getJobSystemPropertyFilterPatternAsInteger() {
return getAsInteger(FessConfig.JOB_SYSTEM_PROPERTY_FILTER_PATTERN);
}

public String getProcessors() {
return get(FessConfig.PROCESSORS);
}
Expand Down Expand Up @@ -10831,6 +10857,7 @@ protected java.util.Map<String, String> prepareGeneratedDefaultMap() {
"return container.getComponent(\"crawlJob\").logLevel(\"info\").webConfigIds([{0}] as String[]).fileConfigIds([{1}] as String[]).dataConfigIds([{2}] as String[]).jobExecutor(executor).execute();");
defaultMap.put(FessConfig.JOB_MAX_CRAWLER_PROCESSES, "0");
defaultMap.put(FessConfig.JOB_DEFAULT_SCRIPT, "groovy");
defaultMap.put(FessConfig.JOB_SYSTEM_PROPERTY_FILTER_PATTERN, "");
defaultMap.put(FessConfig.PROCESSORS, "0");
defaultMap.put(FessConfig.JAVA_COMMAND_PATH, "java");
defaultMap.put(FessConfig.PYTHON_COMMAND_PATH, "python");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ default void addCrawlerMetadataNameMapping(final String name, final String field
}

@SuppressWarnings("unchecked")
final Map<String, Tuple3<String, String, String>> params =
final Map<String, Tuple3<String, String, String>> params =
(Map<String, Tuple3<String, String, String>>) propMap.get(CRAWLER_METADATA_NAME_MAPPING);
params.put(name, new Tuple3<>(fieldName, mappingType, dateFormat));
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/fess_config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ job.template.title.data=Data Crawler - {0}
job.template.script=return container.getComponent("crawlJob").logLevel("info").webConfigIds([{0}] as String[]).fileConfigIds([{1}] as String[]).dataConfigIds([{2}] as String[]).jobExecutor(executor).execute();
job.max.crawler.processes=0
job.default.script=groovy
job.system.property.filter.pattern=

processors=0
java.command.path=java
Expand Down

0 comments on commit a26e133

Please sign in to comment.