fix 1560 add version info
This commit is contained in:
parent
56080ba528
commit
0ea9b16f3d
11 changed files with 73 additions and 18 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -30,3 +30,4 @@ dbflute_fess/output/doc/lastadoc-fess.html
|
|||
dbflute_fess/schema/project-lastadoc-fess.json
|
||||
src/main/resources/fess_indices/.fess_config/access_token.bulk
|
||||
src/main/resources/ga_client_secrets.p12
|
||||
src/main/webapp/WEB-INF/project.properties
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -327,6 +327,8 @@
|
|||
<property name="with.fess" value="true" />
|
||||
</ant>
|
||||
<ant antfile="deps.xml" target="install.jars" />
|
||||
<echo message="fess.version=${project.version}"
|
||||
file="${basedir}/src/main/webapp/WEB-INF/project.properties"/>
|
||||
</tasks>
|
||||
</configuration>
|
||||
<goals>
|
||||
|
|
|
@ -22,18 +22,11 @@ import org.codelibs.core.CoreLibConstants;
|
|||
import org.codelibs.core.lang.StringUtil;
|
||||
|
||||
public class Constants extends CoreLibConstants {
|
||||
public static final int MAJOR_VERSION = 12;
|
||||
|
||||
public static final int MINOR_VERSION = 1;
|
||||
|
||||
public static final String FESS_VERSION = String.valueOf(MAJOR_VERSION) + "." + String.valueOf(MINOR_VERSION);
|
||||
|
||||
public static final String LINE_SEPARATOR = System.getProperty("line.separator");
|
||||
|
||||
public static final int DEFAULT_ADMIN_PAGE_NUMBER = 1;
|
||||
|
||||
public static final String WEB_API_VERSION = FESS_VERSION;
|
||||
|
||||
public static final String TRUE = "true";
|
||||
|
||||
public static final String FALSE = "false";
|
||||
|
@ -95,6 +88,8 @@ public class Constants extends CoreLibConstants {
|
|||
|
||||
public static final String CRAWLING_THREAD_COUNT_PROPERTY = "crawling.thread.count";
|
||||
|
||||
public static final String CRAWLING_USER_AGENT_PROPERTY = "crawling.user.agent";
|
||||
|
||||
public static final String DAY_FOR_CLEANUP_PROPERTY = "day.for.cleanup";
|
||||
|
||||
public static final String WEB_API_JSON_PROPERTY = "web.api.json";
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.codelibs.core.CoreLibConstants;
|
|||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.exception.InvalidAccessTokenException;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.lastaflute.web.util.LaRequestUtil;
|
||||
import org.lastaflute.web.util.LaResponseUtil;
|
||||
|
||||
|
@ -89,7 +90,7 @@ public abstract class BaseJsonApiManager extends BaseApiManager {
|
|||
}
|
||||
buf.append("{\"response\":");
|
||||
buf.append("{\"version\":");
|
||||
buf.append(Constants.WEB_API_VERSION);
|
||||
buf.append(ComponentUtil.getSystemHelper().getProductVersion());
|
||||
buf.append(',');
|
||||
buf.append("\"status\":");
|
||||
buf.append(status);
|
||||
|
|
|
@ -124,7 +124,7 @@ public class CreateForm {
|
|||
crudMode = CrudMode.CREATE;
|
||||
boost = 1.0f;
|
||||
if (StringUtil.isBlank(userAgent)) {
|
||||
userAgent = ComponentUtil.getUserAgentName();
|
||||
userAgent = ComponentUtil.getFessConfig().getUserAgentName();
|
||||
}
|
||||
numOfThread = Constants.DEFAULT_NUM_OF_THREAD_FOR_WEB;
|
||||
intervalTime = Constants.DEFAULT_INTERVAL_TIME_FOR_WEB;
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.entity.SearchRenderData;
|
||||
import org.codelibs.fess.mylasta.action.FessMessages;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
|
@ -51,7 +50,7 @@ public class ApiResult {
|
|||
}
|
||||
|
||||
public static class ApiResponse {
|
||||
protected String version = Constants.WEB_API_VERSION;
|
||||
protected String version = ComponentUtil.getSystemHelper().getProductVersion();
|
||||
protected int status;
|
||||
|
||||
public ApiResponse status(final Status status) {
|
||||
|
|
|
@ -19,11 +19,13 @@ import static org.codelibs.core.stream.StreamUtil.stream;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
@ -32,6 +34,7 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -48,10 +51,12 @@ import org.codelibs.core.lang.StringUtil;
|
|||
import org.codelibs.core.misc.Pair;
|
||||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.crawler.util.CharUtil;
|
||||
import org.codelibs.fess.exception.FessSystemException;
|
||||
import org.codelibs.fess.mylasta.action.FessMessages;
|
||||
import org.codelibs.fess.mylasta.action.FessUserBean;
|
||||
import org.codelibs.fess.mylasta.direction.FessConfig;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.util.ResourceUtil;
|
||||
import org.codelibs.fess.validation.FessActionValidator;
|
||||
import org.lastaflute.core.message.supplier.UserMessagesCreator;
|
||||
import org.lastaflute.web.TypicalAction;
|
||||
|
@ -85,6 +90,14 @@ public class SystemHelper {
|
|||
|
||||
protected AtomicInteger previousClusterState = new AtomicInteger(0);
|
||||
|
||||
protected String version;
|
||||
|
||||
protected int majorVersion;
|
||||
|
||||
protected int minorVersion;
|
||||
|
||||
protected String productVersion;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
final FessConfig fessConfig = ComponentUtil.getFessConfig();
|
||||
|
@ -117,6 +130,25 @@ public class SystemHelper {
|
|||
});
|
||||
|
||||
ComponentUtil.doInitProcesses(p -> p.run());
|
||||
|
||||
parseProjectProperties();
|
||||
}
|
||||
|
||||
protected void parseProjectProperties() {
|
||||
final Path propPath = ResourceUtil.getProjectPropertiesFile();
|
||||
try (final InputStream in = Files.newInputStream(propPath)) {
|
||||
Properties prop = new Properties();
|
||||
prop.load(in);
|
||||
version = prop.getProperty("fess.version", "0.0.0");
|
||||
final String[] values = version.split("\\.");
|
||||
majorVersion = Integer.parseInt(values[0]);
|
||||
minorVersion = Integer.parseInt(values[1]);
|
||||
productVersion = majorVersion + "." + minorVersion;
|
||||
System.setProperty("fess.version", version);
|
||||
System.setProperty("fess.product.version", productVersion);
|
||||
} catch (Exception e) {
|
||||
throw new FessSystemException("Failed to parse project.properties.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
|
@ -191,15 +223,14 @@ public class SystemHelper {
|
|||
if (locale != null) {
|
||||
final String lang = locale.getLanguage();
|
||||
if (ComponentUtil.getFessConfig().isOnlineHelpSupportedLang(lang)) {
|
||||
return url.replaceFirst("\\{lang\\}", lang).replaceFirst("\\{version\\}",
|
||||
Constants.MAJOR_VERSION + "." + Constants.MINOR_VERSION);
|
||||
return url.replaceFirst("\\{lang\\}", lang).replaceFirst("\\{version\\}", majorVersion + "." + minorVersion);
|
||||
}
|
||||
}
|
||||
return getDefaultHelpLink(url);
|
||||
}
|
||||
|
||||
protected String getDefaultHelpLink(final String url) {
|
||||
return url.replaceFirst("/\\{lang\\}/", "/").replaceFirst("\\{version\\}", Constants.MAJOR_VERSION + "." + Constants.MINOR_VERSION);
|
||||
return url.replaceFirst("/\\{lang\\}/", "/").replaceFirst("\\{version\\}", majorVersion + "." + minorVersion);
|
||||
}
|
||||
|
||||
public void addDesignJspFileName(final String key, final String value) {
|
||||
|
@ -387,4 +418,20 @@ public class SystemHelper {
|
|||
return response;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public int getMajorVersion() {
|
||||
return majorVersion;
|
||||
}
|
||||
|
||||
public int getMinorVersion() {
|
||||
return minorVersion;
|
||||
}
|
||||
|
||||
public String getProductVersion() {
|
||||
return productVersion;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -624,6 +624,11 @@ public interface FessProp {
|
|||
return getSystemProperty(Constants.NOTIFICATION_SEARCH_TOP, StringUtil.EMPTY);
|
||||
}
|
||||
|
||||
public default String getUserAgentName() {
|
||||
return getSystemProperty(Constants.CRAWLING_USER_AGENT_PROPERTY, "Mozilla/5.0 (compatible; Fess/"
|
||||
+ ComponentUtil.getSystemHelper().getProductVersion() + "; +http://fess.codelibs.org/bot.html)");
|
||||
}
|
||||
|
||||
//
|
||||
// fess_*.properties
|
||||
//
|
||||
|
|
|
@ -80,6 +80,10 @@ public class ResourceUtil {
|
|||
return getPath("site", names);
|
||||
}
|
||||
|
||||
public static Path getProjectPropertiesFile() {
|
||||
return getPath("", "project.properties");
|
||||
}
|
||||
|
||||
protected static Path getPath(final String base, final String... names) {
|
||||
|
||||
try {
|
||||
|
|
|
@ -383,8 +383,5 @@
|
|||
</component>
|
||||
<component name="queryResponseList" class="org.codelibs.fess.util.QueryResponseList" instance="prototype">
|
||||
</component>
|
||||
<component name="userAgentName" class="java.lang.String">
|
||||
<arg>"Mozilla/5.0 (compatible; Fess/" + org.codelibs.fess.Constants.FESS_VERSION + "; +http://fess.codelibs.org/bot.html)"</arg>
|
||||
</component>
|
||||
|
||||
</components>
|
||||
|
|
|
@ -24,7 +24,11 @@ public class SystemHelperTest extends UnitFessTestCase {
|
|||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
systemHelper = new SystemHelper();
|
||||
systemHelper = new SystemHelper() {
|
||||
@Override
|
||||
protected void parseProjectProperties() {
|
||||
}
|
||||
};
|
||||
systemHelper.init();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue