-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
277 additions
and
67 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
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
55 changes: 41 additions & 14 deletions
55
runtime/src/main/java/ortus/boxlang/runtime/config/segments/RuntimeConfig.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 |
---|---|---|
@@ -1,41 +1,68 @@ | ||
/** | ||
* [BoxLang] | ||
* | ||
* Copyright [2023] [Ortus Solutions, Corp] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ortus.boxlang.runtime.config.segments; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import ortus.boxlang.runtime.config.util.PlaceholderHelper; | ||
import ortus.boxlang.runtime.types.Struct; | ||
|
||
/** | ||
* The runtime configuration for the BoxLang runtime | ||
*/ | ||
public class RuntimeConfig { | ||
|
||
/** | ||
* A struct of mappings for the runtime | ||
*/ | ||
@JsonProperty( "mappings" ) | ||
public Struct mappings = new Struct(); | ||
|
||
/** | ||
* The directory where the modules are located by default: | ||
* {@code /{user-home}/modules} | ||
*/ | ||
@JsonProperty( "modulesDirectory" ) | ||
private String modulesDirectory; | ||
public String modulesDirectory = System.getProperty( "user.home" ) + "/modules"; | ||
|
||
/** | ||
* The cache configurations for the runtime | ||
*/ | ||
@JsonProperty( "caches" ) | ||
private List<CacheConfig> caches = new ArrayList<>(); | ||
public Struct caches = new Struct(); | ||
|
||
public RuntimeConfig() { | ||
} | ||
/** | ||
* -------------------------------------------------------------------------- | ||
* Methods | ||
* -------------------------------------------------------------------------- | ||
*/ | ||
|
||
public String getModulesDirectory() { | ||
return modulesDirectory; | ||
public RuntimeConfig() { | ||
} | ||
|
||
/** | ||
* @param modulesDirectory the modulesDirectory to set | ||
*/ | ||
public void setModulesDirectory( String modulesDirectory ) { | ||
this.modulesDirectory = modulesDirectory; | ||
this.modulesDirectory = PlaceholderHelper.resolve( modulesDirectory ); | ||
} | ||
|
||
public List<CacheConfig> getCaches() { | ||
return caches; | ||
} | ||
|
||
public void setCaches( List<CacheConfig> caches ) { | ||
this.caches = caches; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
runtime/src/main/java/ortus/boxlang/runtime/config/util/PlaceholderHelper.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,56 @@ | ||
/** | ||
* [BoxLang] | ||
* | ||
* Copyright [2023] [Ortus Solutions, Corp] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ortus.boxlang.runtime.config.util; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* A helper class for resolving placeholders in configuration files | ||
*/ | ||
public class PlaceholderHelper { | ||
|
||
private static final Map<String, String> PLACEHOLDER_MAP = new HashMap<>(); | ||
|
||
static { | ||
// Add default replacements | ||
PLACEHOLDER_MAP.put( "{user-home}", System.getProperty( "user.home" ) ); | ||
PLACEHOLDER_MAP.put( "{java-temp}", System.getProperty( "java.io.tmpdir" ) ); | ||
// Add additional replacements here | ||
// placeholderMap.put("{your-placeholder}", "replacement-value"); | ||
} | ||
|
||
/** | ||
* Resolve the input string and replace all placeholders with their values | ||
* | ||
* @param input The input string to Resolve | ||
* | ||
* @return The Resolved string | ||
*/ | ||
public static String resolve( String input ) { | ||
// Create a pattern to match placeholder patterns like "{...}" | ||
Pattern pattern = Pattern.compile( "\\{([^}]+)\\}" ); | ||
|
||
// Use Matcher and the stream API to replace placeholders | ||
Matcher matcher = pattern.matcher( input ); | ||
return matcher.replaceAll( match -> PLACEHOLDER_MAP.getOrDefault( match.group( 1 ), match.group() ) ); | ||
} | ||
|
||
} |
Oops, something went wrong.