mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-21 15:02:17 +01:00
read config from classpath
This commit is contained in:
@@ -29,6 +29,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.server;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -39,6 +41,7 @@ import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.cli.CliException;
|
||||
import sonia.scm.cli.CliParser;
|
||||
import sonia.scm.cli.DefaultCliHelpBuilder;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.ServiceUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
@@ -68,10 +71,51 @@ public class ServerApplication
|
||||
/** Field description */
|
||||
public static final int RETURNCODE_MISSING_SERVER_IMPLEMENTATION = 3;
|
||||
|
||||
/** Field description */
|
||||
public static final String SERVERCONFIG = "/config.xml";
|
||||
|
||||
/** Field description */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(ServerApplication.class.getName());
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static ServerConfig getServerConfig()
|
||||
{
|
||||
ServerConfig config = null;
|
||||
InputStream input =
|
||||
ServerApplication.class.getResourceAsStream(SERVERCONFIG);
|
||||
|
||||
if (input != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
config = JAXB.unmarshal(input, ServerConfig.class);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(input);
|
||||
}
|
||||
}
|
||||
|
||||
if (config == null)
|
||||
{
|
||||
config = new ServerConfig();
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -97,7 +141,7 @@ public class ServerApplication
|
||||
|
||||
ApplicationInformation appInfo = JAXB.unmarshal(input,
|
||||
ApplicationInformation.class);
|
||||
ServerConfig config = new ServerConfig();
|
||||
ServerConfig config = getServerConfig();
|
||||
CliParser parser = new CliParser();
|
||||
|
||||
parser.parse(config, args);
|
||||
|
||||
Reference in New Issue
Block a user