mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-06-19 00:51:57 +02:00
improve base directory handling
This commit is contained in:
@@ -78,15 +78,6 @@ public class ScmBackendModule extends ServletModule
|
||||
/** Field description */
|
||||
public static final String CACHE_CONFIG = "/config/ehcache.xml";
|
||||
|
||||
/** Field description */
|
||||
public static final String DIRECTORY_DEFAULT = ".scm-backend";
|
||||
|
||||
/** Field description */
|
||||
public static final String DIRECTORY_ENVIRONMENT = "SCMBACKEND_HOME";
|
||||
|
||||
/** Field description */
|
||||
public static final String DIRECTORY_PROPERTY = "scm-backend.home";
|
||||
|
||||
/** Field description */
|
||||
public static final String FILE_CONFIG = "config.xml";
|
||||
|
||||
@@ -100,8 +91,7 @@ public class ScmBackendModule extends ServletModule
|
||||
public static final String PATTERN_REST_API = "/*";
|
||||
|
||||
/** Field description */
|
||||
public static final String PATTERN_REST_EXCLUDE =
|
||||
"/(template/|news).*";
|
||||
public static final String PATTERN_REST_EXCLUDE = "/(template/|news).*";
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -112,14 +102,7 @@ public class ScmBackendModule extends ServletModule
|
||||
@Override
|
||||
protected void configureServlets()
|
||||
{
|
||||
File baseDirectory = findBaseDirectory();
|
||||
|
||||
if (baseDirectory == null)
|
||||
{
|
||||
throw new ConfigurationException("could not find base directory");
|
||||
}
|
||||
|
||||
File configurationFile = getConfigurationFile(baseDirectory);
|
||||
File configurationFile = BaseDirectory.getFile(FILE_CONFIG);
|
||||
|
||||
if (!configurationFile.exists())
|
||||
{
|
||||
@@ -130,8 +113,6 @@ public class ScmBackendModule extends ServletModule
|
||||
BackendConfiguration configuration = JAXB.unmarshal(configurationFile,
|
||||
BackendConfiguration.class);
|
||||
|
||||
bind(File.class).annotatedWith(Names.named(DIRECTORY_PROPERTY)).toInstance(
|
||||
baseDirectory);
|
||||
bind(BackendConfiguration.class).toInstance(configuration);
|
||||
bind(PluginBackend.class).to(DefaultPluginBackend.class);
|
||||
bind(PluginScannerFactory.class).to(DefaultPluginScannerFactory.class);
|
||||
@@ -168,50 +149,4 @@ public class ScmBackendModule extends ServletModule
|
||||
PATTERN_REST_EXCLUDE);
|
||||
filter(PATTERN_REST_API).through(GuiceContainer.class, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private File findBaseDirectory()
|
||||
{
|
||||
String path = System.getProperty(DIRECTORY_PROPERTY);
|
||||
|
||||
if (Util.isEmpty(path))
|
||||
{
|
||||
path = System.getenv(DIRECTORY_ENVIRONMENT);
|
||||
|
||||
if (Util.isEmpty(path))
|
||||
{
|
||||
path = System.getProperty("user.home").concat(File.separator).concat(
|
||||
DIRECTORY_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
File directory = new File(path);
|
||||
|
||||
if (!directory.exists() &&!directory.mkdirs())
|
||||
{
|
||||
throw new IllegalStateException("could not create directory");
|
||||
}
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param baseDirectory
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private File getConfigurationFile(File baseDirectory)
|
||||
{
|
||||
return new File(baseDirectory, FILE_CONFIG);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user