mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-15 03:52:09 +01:00
Fix workdir configuration
This commit is contained in:
@@ -55,15 +55,16 @@ public class WorkdirProvider implements ServletContextListener {
|
||||
@ConfigValue(key = "workDir", defaultValue = "", description = "Working directory for internal repository operations") String workDir,
|
||||
RepositoryLocationResolver repositoryLocationResolver
|
||||
) {
|
||||
this(new File(!Strings.isNullOrEmpty(workDir) ? workDir : System.getProperty("java.io.tmpdir") , "scm-work"), repositoryLocationResolver, workDir == null);
|
||||
this(new File(Strings.isNullOrEmpty(workDir) ? System.getProperty("java.io.tmpdir") : workDir, "scm-work"), repositoryLocationResolver, workDir == null);
|
||||
}
|
||||
|
||||
public WorkdirProvider(File rootDirectory, RepositoryLocationResolver repositoryLocationResolver, boolean useRepositorySpecificDir) {
|
||||
this.rootDirectory = rootDirectory;
|
||||
this.rootDirectory = rootDirectory.isAbsolute() ? rootDirectory : new File(System.getProperty("basedir", "."), rootDirectory.getPath());
|
||||
LOG.info("using {} as work directory", this.rootDirectory);
|
||||
this.repositoryLocationResolver = repositoryLocationResolver;
|
||||
this.useRepositorySpecificDir = useRepositorySpecificDir;
|
||||
if (!rootDirectory.exists() && !rootDirectory.mkdirs()) {
|
||||
throw new IllegalStateException("could not create pool directory " + rootDirectory);
|
||||
throw new IllegalStateException("could not create pool directory " + this.rootDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public class ConfigurationResolver {
|
||||
rootNode = new ObjectMapper(new YAMLFactory()).readTree(resource).get("webapp");
|
||||
WebappConfigProvider.setConfigBindings(readConfigurationFile(rootNode));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new IllegalArgumentException("failed to read configuration from file " + configPath, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,9 @@ public class ConfigurationResolver {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
if (node.isNull()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(node.asText());
|
||||
}
|
||||
|
||||
@@ -112,6 +114,6 @@ public class ConfigurationResolver {
|
||||
}
|
||||
|
||||
private String createEnvKey(String key) {
|
||||
return PREFIX + key.toUpperCase(Locale.ENGLISH).replaceAll("\\.-/", "_");
|
||||
return PREFIX + key.toUpperCase(Locale.ENGLISH).replaceAll("[.\\-/]", "_");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sonia.scm.config.WebappConfigProvider;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -54,11 +54,13 @@ class ConfigurationResolverTest {
|
||||
|
||||
@Test
|
||||
void shouldResolveConfiguration_WithEnv() {
|
||||
ConfigurationResolver configurationResolver = new ConfigurationResolver(ImmutableMap.of("SCM_WEBAPP_CONTEXTPATH", "/scm"), "sonia/scm/plugin/config.yml");
|
||||
ConfigurationResolver configurationResolver = new ConfigurationResolver(Map.of("SCM_WEBAPP_CONTEXTPATH", "/scm", "SCM_WEBAPP_HTTPS_SSL", "true"), "sonia/scm/plugin/config.yml");
|
||||
|
||||
String port = configurationResolver.resolve("contextPath", "/");
|
||||
String ssl = configurationResolver.resolve("https.ssl", "false");
|
||||
|
||||
assertThat(port).isEqualTo("/scm");
|
||||
assertThat(ssl).isEqualTo("true");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,9 +82,12 @@ class ConfigurationResolverTest {
|
||||
|
||||
@Test
|
||||
void shouldReadNullValuesFromConfigYaml() {
|
||||
new ConfigurationResolver(Collections.emptyMap(), "sonia/scm/plugin/configWithNull.yml");
|
||||
ConfigurationResolver configurationResolver = new ConfigurationResolver(Collections.emptyMap(), "sonia/scm/plugin/configWithNull.yml");
|
||||
|
||||
assertThat(WebappConfigProvider.resolveAsBoolean("redirect")).contains(true);
|
||||
assertThat(WebappConfigProvider.resolveAsInteger("https.keyType")).isEmpty();
|
||||
assertThat(WebappConfigProvider.resolveAsString("https.keyType")).isEmpty();
|
||||
assertThat(WebappConfigProvider.resolveAsBoolean("https.keyType")).isEmpty();
|
||||
|
||||
assertThat(configurationResolver.resolve("https.keyType", "other")).isEqualTo("other");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user