Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1109 from scm-manager/feature/os_specific_homes
OS Specific Homes
- Loading branch information
Showing
11 changed files
with
520 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Base Directory | ||
|
||
The SCM-Manager base directory aka. home directory, | ||
contains all data which is created by SCM-Manager such as repositories and configurations. | ||
The location of the base directory depends on your operating system and type of installation. | ||
|
||
| Type of Installation | Base directory | | ||
|----------------------|----------------| | ||
| Docker | /var/lib/scm | | ||
| RPM | /var/lib/scm | | ||
| DEB | /var/lib/scm | | ||
| Unix | ~/.scm | | ||
| Mac OS X | ~/Library/Application Support/SCM-Manager | | ||
| Windows | %APPDATA%\SCM-Manager | | ||
|
||
## Change base directory location | ||
|
||
The location of the base directory can be changed by using one of the following ways. | ||
The preferences are the following: Properties file over system property over environment variable. | ||
|
||
### Environment variable | ||
|
||
By setting the environment variable **SCM_HOME** e.g.: | ||
|
||
```bash | ||
export SCM_HOME=/home/scm | ||
/opt/scm-server/bin/scm-server | ||
``` | ||
|
||
For rpm and deb installations the variable can be changed via the file `/etc/default/scm-server`. | ||
|
||
## System property | ||
|
||
The path can be changed by setting the system property **scm.home** e.g.: | ||
|
||
```bash | ||
-Dscm.home=/home/scm | ||
``` | ||
## Properties file | ||
|
||
If SCM-Manager finds a file called `scm.properties` on the class path it reads the property `scm.home` e.g.: | ||
|
||
```properties | ||
scm.home=/home/scm | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Logging | ||
|
||
SCM-Manager logs information which can be useful, if the system does not behave as expected. | ||
The logging behavior depends on your operating system and installation. | ||
|
||
| Type of Installation | Logging | | ||
|----------------------|---------| | ||
| Docker | stdout | | ||
| RPM | /var/log/scm | | ||
| DEB | /var/log/scm | | ||
| Unix | $BASEDIR/logs | | ||
| Mac OS X | ~/Library/Logs/SCM-Manager | | ||
| Windows | $BASEDIR\logs | | ||
|
||
The location of the **$BASEDIR** can be found [here](basedirectory). | ||
|
||
## Configuration | ||
|
||
The logging behaviour of SCM-Manager can be configured via an xml file. | ||
The syntax and properties can be found [here](http://logback.qos.ch/manual/configuration.html). | ||
The location of the file depends also on the type of installation. | ||
|
||
| Type of Installation | Path | | ||
|----------------------|---------| | ||
| Docker | /opt/scm-server/conf/logging.xml | | ||
| RPM | /etc/scm/logging.xml | | ||
| DEB | /etc/scm/logging.xml | | ||
| Unix | $EXTRACT_PATH/scm-server/conf/logging.xml | | ||
| Mac OS X | $EXTRACT_PATH/scm-server/conf/logging.xml | | ||
| Windows | $EXTRACT_PATH/scm-server/conf/logging.xml | | ||
|
||
**$EXTRACT_PATH** is the path were you etract the content of the package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package sonia.scm; | ||
|
||
import com.google.common.base.Strings; | ||
import sonia.scm.util.SystemUtil; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Determines the base directory for SCM-Manager. | ||
* This class should not be used directory, use {@link SCMContextProvider#getBaseDirectory()} instead. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
final class BaseDirectory { | ||
|
||
/** Environment variable for the SCM-Manager base directory */ | ||
static final String ENVIRONMENT_VARIABLE = "SCM_HOME"; | ||
|
||
/** Java system property for the SCM-Manager base directory */ | ||
static final String SYSTEM_PROPERTY = "scm.home"; | ||
|
||
/** Classpath resource for the SCM-Manager base directory */ | ||
@SuppressWarnings("java:S1075") // it is already configurable | ||
static final String CLASSPATH_RESOURCE = "/scm.properties"; | ||
|
||
/** Property name in resource file */ | ||
static final String RESOURCE_PROPERTY = "scm.home"; | ||
|
||
private final Platform platform; | ||
private final String classPathResource; | ||
private final Map<String,String> environment; | ||
private final Properties systemProperties; | ||
|
||
BaseDirectory(Platform platform, String classPathResource, Map<String, String> environment, Properties systemProperties) { | ||
this.platform = platform; | ||
this.classPathResource = classPathResource; | ||
this.environment = environment; | ||
this.systemProperties = systemProperties; | ||
} | ||
|
||
/** | ||
* Returns the determined base directory. | ||
* | ||
* @return base directory | ||
*/ | ||
@SuppressWarnings("java:S5304") // it is safe to use environment in this case | ||
static Path get() { | ||
return new BaseDirectory( | ||
SystemUtil.getPlatform(), | ||
CLASSPATH_RESOURCE, | ||
System.getenv(), | ||
System.getProperties() | ||
).find(); | ||
} | ||
|
||
Path find() { | ||
String directory = getFromResource(); | ||
if (Strings.isNullOrEmpty(directory)) { | ||
directory = getFromSystemProperty(); | ||
} | ||
if (Strings.isNullOrEmpty(directory)) { | ||
directory = getFromEnvironmentVariable(); | ||
} | ||
if (Strings.isNullOrEmpty(directory)) { | ||
directory = getOsSpecificDefault(); | ||
} | ||
|
||
return Paths.get(directory); | ||
} | ||
|
||
private String getFromResource() { | ||
try (InputStream input = BasicContextProvider.class.getResourceAsStream(classPathResource)) | ||
{ | ||
if (input != null) | ||
{ | ||
Properties properties = new Properties(); | ||
properties.load(input); | ||
return properties.getProperty(RESOURCE_PROPERTY); | ||
} | ||
} | ||
catch (IOException ex) | ||
{ | ||
throw new ConfigurationException("could not load properties form resource " + CLASSPATH_RESOURCE, ex); | ||
} | ||
return null; | ||
} | ||
|
||
private String getFromEnvironmentVariable() { | ||
return environment.get(ENVIRONMENT_VARIABLE); | ||
} | ||
|
||
private String getFromSystemProperty() { | ||
return systemProperties.getProperty(SYSTEM_PROPERTY); | ||
} | ||
|
||
private String getOsSpecificDefault() { | ||
if (platform.isMac()) { | ||
return getOsxDefault(); | ||
} else if (platform.isWindows()) { | ||
return getWindowsDefault(); | ||
} | ||
return systemProperties.getProperty("user.home") + "/.scm"; | ||
} | ||
|
||
private String getOsxDefault() { | ||
return systemProperties.getProperty("user.home") + "/Library/Application Support/SCM-Manager"; | ||
} | ||
|
||
private String getWindowsDefault() { | ||
return environment.get("APPDATA") + "\\SCM-Manager"; | ||
} | ||
|
||
} |
Oops, something went wrong.