|
@@ -20,14 +20,12 @@ import static org.codelibs.core.stream.StreamUtil.stream;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
-import java.io.FilenameFilter;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Properties;
|
|
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.apache.commons.lang3.SystemUtils;
|
|
|
import org.codelibs.core.lang.StringUtil;
|
|
@@ -43,44 +41,13 @@ import org.codelibs.fess.util.ResourceUtil;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
-public class GenerateThumbnailJob {
|
|
|
- private static final String REMOTE_DEBUG_OPTIONS = "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=localhost:8000";
|
|
|
-
|
|
|
- private static final Logger logger = LoggerFactory.getLogger(GenerateThumbnailJob.class);
|
|
|
-
|
|
|
- protected JobExecutor jobExecutor;
|
|
|
-
|
|
|
- protected String sessionId;
|
|
|
-
|
|
|
- protected boolean useLocaleElasticsearch = true;
|
|
|
-
|
|
|
- protected String logFilePath;
|
|
|
+public class GenerateThumbnailJob extends ExecJob {
|
|
|
+ static final Logger logger = LoggerFactory.getLogger(GenerateThumbnailJob.class);
|
|
|
|
|
|
protected int numOfThreads = 1;
|
|
|
|
|
|
protected boolean cleanup = false;
|
|
|
|
|
|
- protected String logLevel;
|
|
|
-
|
|
|
- protected String jvmOptions;
|
|
|
-
|
|
|
- protected String lastaEnv;
|
|
|
-
|
|
|
- public GenerateThumbnailJob jobExecutor(final JobExecutor jobExecutor) {
|
|
|
- this.jobExecutor = jobExecutor;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- public GenerateThumbnailJob sessionId(final String sessionId) {
|
|
|
- this.sessionId = sessionId;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- public GenerateThumbnailJob logFilePath(final String logFilePath) {
|
|
|
- this.logFilePath = logFilePath;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
public GenerateThumbnailJob numOfThreads(final int numOfThreads) {
|
|
|
this.numOfThreads = numOfThreads;
|
|
|
return this;
|
|
@@ -91,35 +58,13 @@ public class GenerateThumbnailJob {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public GenerateThumbnailJob logLevel(final String logLevel) {
|
|
|
- this.logLevel = logLevel;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- public GenerateThumbnailJob useLocaleElasticsearch(final boolean useLocaleElasticsearch) {
|
|
|
- this.useLocaleElasticsearch = useLocaleElasticsearch;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- public GenerateThumbnailJob remoteDebug() {
|
|
|
- return jvmOptions(REMOTE_DEBUG_OPTIONS);
|
|
|
- }
|
|
|
-
|
|
|
- public GenerateThumbnailJob jvmOptions(final String option) {
|
|
|
- this.jvmOptions = option;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- public GenerateThumbnailJob lastaEnv(final String env) {
|
|
|
- this.lastaEnv = env;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
+ @Deprecated
|
|
|
public String execute(final JobExecutor jobExecutor) {
|
|
|
jobExecutor(jobExecutor);
|
|
|
return execute();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public String execute() {
|
|
|
final StringBuilder resultBuf = new StringBuilder();
|
|
|
|
|
@@ -187,7 +132,7 @@ public class GenerateThumbnailJob {
|
|
|
// WEB-INF/lib
|
|
|
appendJarFile(cpSeparator, buf, new File(servletContext.getRealPath("/WEB-INF/lib")), "WEB-INF" + File.separator + "lib"
|
|
|
+ File.separator);
|
|
|
- // WEB-INF/crawler/lib
|
|
|
+ // WEB-INF/env/thumbnail/lib
|
|
|
appendJarFile(cpSeparator, buf, new File(servletContext.getRealPath("/WEB-INF/env/thumbnail/lib")), "WEB-INF" + File.separator
|
|
|
+ "env" + File.separator + "thumbnail" + File.separator + "lib" + File.separator);
|
|
|
final File targetLibDir = new File(targetDir, "fess" + File.separator + "WEB-INF" + File.separator + "lib");
|
|
@@ -196,7 +141,7 @@ public class GenerateThumbnailJob {
|
|
|
}
|
|
|
cmdList.add(buf.toString());
|
|
|
|
|
|
- if (useLocaleElasticsearch) {
|
|
|
+ if (useLocalElasticsearch) {
|
|
|
final String httpAddress = System.getProperty(Constants.FESS_ES_HTTP_ADDRESS);
|
|
|
if (StringUtil.isNotBlank(httpAddress)) {
|
|
|
cmdList.add("-D" + Constants.FESS_ES_HTTP_ADDRESS + "=" + httpAddress);
|
|
@@ -227,8 +172,8 @@ public class GenerateThumbnailJob {
|
|
|
if (logLevel != null) {
|
|
|
cmdList.add("-Dfess.log.level=" + logLevel);
|
|
|
}
|
|
|
- stream(fessConfig.getJvmSuggestOptionsAsArray()).of(
|
|
|
- stream -> stream.filter(StringUtil::isNotBlank).forEach(value -> cmdList.add(value)));
|
|
|
+ stream(fessConfig.getJvmThumbnailOptions())
|
|
|
+ .of(stream -> stream.filter(StringUtil::isNotBlank).forEach(value -> cmdList.add(value)));
|
|
|
|
|
|
File ownTmpDir = null;
|
|
|
final String tmpDir = System.getProperty("java.io.tmpdir");
|
|
@@ -310,38 +255,4 @@ public class GenerateThumbnailJob {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- private void addSystemProperty(final List<String> crawlerCmdList, final String name, final String defaultValue, final String appendValue) {
|
|
|
- final String value = System.getProperty(name);
|
|
|
- if (value != null) {
|
|
|
- final StringBuilder buf = new StringBuilder();
|
|
|
- buf.append("-D").append(name).append("=").append(value);
|
|
|
- if (appendValue != null) {
|
|
|
- buf.append(appendValue);
|
|
|
- }
|
|
|
- crawlerCmdList.add(buf.toString());
|
|
|
- } else if (defaultValue != null) {
|
|
|
- crawlerCmdList.add("-D" + name + "=" + defaultValue);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected void deleteTempDir(final File ownTmpDir) {
|
|
|
- if (ownTmpDir == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!FileUtils.deleteQuietly(ownTmpDir)) {
|
|
|
- logger.warn("Could not delete a temp dir: " + ownTmpDir.getAbsolutePath());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected void appendJarFile(final String cpSeparator, final StringBuilder buf, final File libDir, final String basePath) {
|
|
|
- final File[] jarFiles = libDir.listFiles((FilenameFilter) (dir, name) -> name.toLowerCase().endsWith(".jar"));
|
|
|
- if (jarFiles != null) {
|
|
|
- for (final File file : jarFiles) {
|
|
|
- buf.append(cpSeparator);
|
|
|
- buf.append(basePath);
|
|
|
- buf.append(file.getName());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|