Skip to content

Commit

Permalink
move config files (datasource.properties, configuration.db, eReportin…
Browse files Browse the repository at this point in the history
…gHeader.db) and cache.tmp to WEBAPP_NAME/config folder
  • Loading branch information
Carsten Hollmann committed Mar 20, 2019
1 parent ccaf74e commit 5b451ca
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 deletions.
23 changes: 23 additions & 0 deletions core/api/src/main/java/org/n52/sos/service/SosContextListener.java
Expand Up @@ -28,6 +28,10 @@
*/
package org.n52.sos.service;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
Expand Down Expand Up @@ -61,6 +65,7 @@ public class SosContextListener implements ServletContextListener {

private static String path = null;
private static final List<Runnable> hooks = new LinkedList<>();
private static final String CONFIG = "config";

@Override
public void contextInitialized(ServletContextEvent sce) {
Expand Down Expand Up @@ -193,6 +198,24 @@ public static void setPath(String path) {
public static boolean hasPath() {
return SosContextListener.path != null;
}

public static String getConfigPath() {
Path configPath = Paths.get(SosContextListener.path, CONFIG);
if (Files.notExists(configPath)) {
try {
Files.createDirectories(configPath);
} catch (IOException ioe) {
String message = "Error creating 'config' folder!";
LOG.error(message, ioe);
throw new RuntimeException(message, ioe);
}
}
return configPath.toString();
}

public static boolean hasConfigPath() {
return hasPath() && Files.exists(getConfigPath());
}

public static void registerShutdownHook(Runnable runnable) {
if (runnable != null) {
Expand Down
4 changes: 4 additions & 0 deletions core/cache/pom.xml
Expand Up @@ -27,6 +27,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>test</artifactId>
Expand Down
Expand Up @@ -45,8 +45,8 @@

import org.n52.sos.cache.ContentCache;
import org.n52.sos.cache.WritableContentCache;
import org.n52.sos.service.Configurator;
import org.n52.sos.service.ServiceConfiguration;
import org.n52.sos.service.SosContextListener;

import com.google.common.base.Optional;

Expand Down Expand Up @@ -136,8 +136,9 @@ protected String getBasePath() {
if (cacheFileFolder != null && cacheFileFolder.exists()) {
return cacheFileFolder.getAbsolutePath();
}
return SosContextListener.getConfigPath();
// return Configurator.getInstance().getBasePath();
return System.getProperty("java.io.tmpdir");
// return System.getProperty("java.io.tmpdir");
}

@Override
Expand Down
Expand Up @@ -133,7 +133,7 @@ public class SQLiteSessionFactory extends AbstractSessionFactoryProvider {
protected String getFilename() {
String path = null;
try {
path = SosContextListener.getPath();
path = SosContextListener.getConfigPath();
} catch (Throwable t) {
}
if (path == null) {
Expand Down
Expand Up @@ -81,7 +81,7 @@ public class ReportingHeaderSQLiteSessionFactory extends AbstractSessionFactoryP
private String getFilename() {
String path = null;
try {
path = SosContextListener.getPath();
path = SosContextListener.getConfigPath();
} catch (Throwable t) {
}
if (path == null) {
Expand Down
4 changes: 2 additions & 2 deletions webapp/pom.xml
Expand Up @@ -14,7 +14,7 @@
<sqliteSettingDatabase>${project.parent.basedir}/misc/conf/default_settings.db</sqliteSettingDatabase>
<databaseConfigurationFile>${project.parent.basedir}/misc/conf/datasource.properties</databaseConfigurationFile>
<!-- do not overwrite this one! -->
<sqliteSettingDatabaseTargetFile>${project.build.directory}/${project.build.finalName}/configuration.db</sqliteSettingDatabaseTargetFile>
<sqliteSettingDatabaseTargetFile>${project.build.directory}/${project.build.finalName}/config/configuration.db</sqliteSettingDatabaseTargetFile>
<series.api.version>2.0.0-alpha.6</series.api.version>
<series.db.version>2.0.0-alpha.3</series.db.version>
<helgoland.version>1.0.0</helgoland.version>
Expand Down Expand Up @@ -1034,7 +1034,7 @@
</goals>
<configuration>
<tasks>
<copy file="${databaseConfigurationFile}" tofile="${project.build.directory}/${project.build.finalName}/WEB-INF/datasource.properties" />
<copy file="${databaseConfigurationFile}" tofile="${project.build.directory}/${project.build.finalName}/config/datasource.properties" />
</tasks>
</configuration>
</execution>
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/main/webapp/WEB-INF/web.xml
Expand Up @@ -22,7 +22,7 @@ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
<!-- location of the database configuration file -->
<context-param>
<param-name>datasourceConfigLocation</param-name>
<param-value>/WEB-INF/datasource.properties</param-value>
<param-value>/config/datasource.properties</param-value>
</context-param>
<!-- Memory leak preventer listener -->
<listener>
Expand Down

0 comments on commit 5b451ca

Please sign in to comment.