Browse Source

fix #2822 Added configuration option to filter and pass system properties to jobs based on a regex pattern.

Shinsuke Sugaya 1 year ago
parent
commit
a26e133b55

+ 1 - 0
src/main/java/org/codelibs/fess/job/CrawlJob.java

@@ -274,6 +274,7 @@ public class CrawlJob extends ExecJob {
 
         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()));

+ 9 - 0
src/main/java/org/codelibs/fess/job/ExecJob.java

@@ -23,6 +23,7 @@ import java.util.ArrayList;
 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;
@@ -156,6 +157,14 @@ public abstract class ExecJob {
                 .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;

+ 1 - 0
src/main/java/org/codelibs/fess/job/GenerateThumbnailJob.java

@@ -164,6 +164,7 @@ public class GenerateThumbnailJob extends ExecJob {
 
         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) {

+ 1 - 0
src/main/java/org/codelibs/fess/job/SuggestJob.java

@@ -151,6 +151,7 @@ public class SuggestJob extends ExecJob {
 
         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) {

+ 27 - 0
src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java

@@ -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";
 
@@ -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>
@@ -7833,6 +7851,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
             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);
         }
@@ -10831,6 +10857,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
                     "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");

+ 1 - 1
src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java

@@ -982,7 +982,7 @@ public interface FessProp {
         }
 
         @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));
     }

+ 1 - 0
src/main/resources/fess_config.properties

@@ -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