mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
display app version
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.commafeed.backend;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.ejb.TransactionManagement;
|
||||
@@ -19,13 +18,15 @@ import liquibase.resource.ClassLoaderResourceAccessor;
|
||||
import liquibase.resource.ResourceAccessor;
|
||||
import liquibase.structure.DatabaseObject;
|
||||
|
||||
import com.commafeed.backend.services.ApplicationPropertiesService;
|
||||
|
||||
@Stateless
|
||||
@TransactionManagement(TransactionManagementType.BEAN)
|
||||
public class DatabaseUpdater {
|
||||
|
||||
public void update() {
|
||||
String datasourceName = ResourceBundle.getBundle("application")
|
||||
.getString("datasource");
|
||||
ApplicationPropertiesService properties = ApplicationPropertiesService.get();
|
||||
String datasourceName = properties.getDatasource();
|
||||
try {
|
||||
Context context = null;
|
||||
Connection connection = null;
|
||||
|
||||
@@ -72,7 +72,6 @@ public class FeedRefreshUpdater {
|
||||
public void init() {
|
||||
ApplicationSettings settings = applicationSettingsService.get();
|
||||
int threads = Math.max(settings.getDatabaseUpdateThreads(), 1);
|
||||
log.info("Creating database pool with {} threads", threads);
|
||||
pool = new FeedRefreshExecutor("feed-refresh-updater", threads, 500 * threads);
|
||||
locks = Striped.lazyWeakLock(threads * 100000);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ public class FeedRefreshWorker {
|
||||
private void init() {
|
||||
ApplicationSettings settings = applicationSettingsService.get();
|
||||
int threads = settings.getBackgroundThreads();
|
||||
log.info("Creating refresh worker pool with {} threads", threads);
|
||||
pool = new FeedRefreshExecutor("feed-refresh-worker", threads,
|
||||
20 * threads);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.commafeed.backend.services;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class ApplicationPropertiesService {
|
||||
|
||||
private ResourceBundle bundle;
|
||||
|
||||
private static ApplicationPropertiesService INSTANCE = new ApplicationPropertiesService();
|
||||
|
||||
public static ApplicationPropertiesService get() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private ApplicationPropertiesService() {
|
||||
bundle = ResourceBundle.getBundle("application");
|
||||
}
|
||||
|
||||
public String getDatasource() {
|
||||
return bundle.getString("datasource");
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return bundle.getString("version");
|
||||
}
|
||||
|
||||
public String getGitCommit() {
|
||||
return bundle.getString("git.commit");
|
||||
}
|
||||
|
||||
public boolean isProduction() {
|
||||
return Boolean.valueOf(bundle.getString("production"));
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@ import com.wordnik.swagger.annotations.ApiClass;
|
||||
public class ServerInfo implements Serializable {
|
||||
|
||||
private String announcement;
|
||||
private String version;
|
||||
private String gitCommit;
|
||||
private Map<String, String> supportedLanguages = Maps.newHashMap();
|
||||
|
||||
public String getAnnouncement() {
|
||||
@@ -35,4 +37,20 @@ public class ServerInfo implements Serializable {
|
||||
this.supportedLanguages = supportedLanguages;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getGitCommit() {
|
||||
return gitCommit;
|
||||
}
|
||||
|
||||
public void setGitCommit(String gitCommit) {
|
||||
this.gitCommit = gitCommit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
package com.commafeed.frontend.resources;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import ro.isdc.wro.config.jmx.WroConfiguration;
|
||||
import ro.isdc.wro.http.WroServletContextListener;
|
||||
|
||||
import com.commafeed.backend.services.ApplicationPropertiesService;
|
||||
|
||||
public class WroListener extends WroServletContextListener {
|
||||
|
||||
@Override
|
||||
protected WroConfiguration newConfiguration() {
|
||||
WroConfiguration conf = super.newConfiguration();
|
||||
|
||||
boolean prod = Boolean.valueOf(ResourceBundle.getBundle("application")
|
||||
.getString("production"));
|
||||
ApplicationPropertiesService properties = ApplicationPropertiesService.get();
|
||||
boolean prod = properties.isProduction();
|
||||
|
||||
conf.setResourceWatcherUpdatePeriod(prod ? 0 : 1);
|
||||
conf.setDisableCache(!prod);
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.commafeed.backend.HttpGetter;
|
||||
import com.commafeed.backend.HttpGetter.HttpResult;
|
||||
import com.commafeed.backend.StartupBean;
|
||||
import com.commafeed.backend.feeds.FeedUtils;
|
||||
import com.commafeed.backend.services.ApplicationPropertiesService;
|
||||
import com.commafeed.frontend.model.ServerInfo;
|
||||
import com.wordnik.swagger.annotations.Api;
|
||||
import com.wordnik.swagger.annotations.ApiOperation;
|
||||
@@ -30,11 +31,15 @@ public class ServerREST extends AbstractResourceREST {
|
||||
@GET
|
||||
@ApiOperation(value = "Get server infos", notes = "Get server infos", responseClass = "com.commafeed.frontend.model.ServerInfo")
|
||||
public Response get() {
|
||||
ApplicationPropertiesService properties = ApplicationPropertiesService.get();
|
||||
|
||||
ServerInfo infos = new ServerInfo();
|
||||
infos.setAnnouncement(applicationSettingsService.get()
|
||||
.getAnnouncement());
|
||||
infos.getSupportedLanguages().putAll(
|
||||
startupBean.getSupportedLanguages());
|
||||
infos.setVersion(properties.getVersion());
|
||||
infos.setGitCommit(properties.getGitCommit());
|
||||
return Response.ok(infos).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Properties;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -26,6 +25,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.commafeed.backend.dao.UserSettingsDAO;
|
||||
import com.commafeed.backend.model.UserSettings;
|
||||
import com.commafeed.backend.services.ApplicationPropertiesService;
|
||||
import com.commafeed.frontend.CommaFeedSession;
|
||||
|
||||
/**
|
||||
@@ -43,6 +43,17 @@ public class InternationalizationDevelopmentFilter implements Filter {
|
||||
|
||||
private boolean production = true;
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
ApplicationPropertiesService properties = ApplicationPropertiesService.get();
|
||||
production = properties.isProduction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
@@ -108,18 +119,6 @@ public class InternationalizationDevelopmentFilter implements Filter {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
String prod = ResourceBundle.getBundle("application").getString(
|
||||
"production");
|
||||
production = Boolean.valueOf(prod);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
private static class ServletOutputStreamWrapper extends ServletOutputStream {
|
||||
|
||||
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
Reference in New Issue
Block a user