-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
must build default json config with default values (#540)
- Loading branch information
Showing
4 changed files
with
55 additions
and
38 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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/mageddo/dnsproxyserver/config/dataprovider/ConfigPathBuilder.java
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,40 @@ | ||
package com.mageddo.dnsproxyserver.config.dataprovider; | ||
|
||
import com.mageddo.utils.Files; | ||
import com.mageddo.utils.Runtime; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
@Slf4j | ||
public class ConfigPathBuilder { | ||
private static Path build0(Path workDir, String configPath) { | ||
if (ConfigDAOJson.runningInTestsAndNoCustomConfigPath()) { | ||
final var file = Files.createTempFileDeleteOnExit("dns-proxy-server-junit", ".json"); | ||
log.trace("status=runningInTests, usingEmptyFile={}", file); | ||
return file; | ||
} | ||
if (workDir != null) { | ||
return workDir | ||
.resolve(configPath) | ||
.toAbsolutePath() | ||
; | ||
} | ||
final var confRelativeToCurrDir = Paths | ||
.get(configPath) | ||
.toAbsolutePath(); | ||
if (Files.exists(confRelativeToCurrDir)) { | ||
return confRelativeToCurrDir; | ||
} | ||
return Runtime.getRunningDir() | ||
.resolve(configPath) | ||
.toAbsolutePath(); | ||
} | ||
|
||
public static Path build(Path workDir, String relativeConfigFilePath) { | ||
final var path = build0(workDir, relativeConfigFilePath); | ||
log.debug("status=configPathBuilt, path={}", path); | ||
return path; | ||
} | ||
} |
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