Skip to content

Commit

Permalink
Ensure top-level boxlang.json modules get scoped in to the runtime co…
Browse files Browse the repository at this point in the history
…nfig
  • Loading branch information
jclausen committed May 2, 2024
1 parent 9cd9e90 commit bbce62a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import ortus.boxlang.runtime.config.segments.CompilerConfig;
import ortus.boxlang.runtime.config.segments.RuntimeConfig;
import ortus.boxlang.runtime.dynamic.casters.StructCaster;
import ortus.boxlang.runtime.scopes.Key;
import ortus.boxlang.runtime.types.IStruct;
import ortus.boxlang.runtime.types.Struct;
Expand Down Expand Up @@ -85,7 +86,12 @@ public Configuration process( IStruct config ) {
// Runtime
if ( config.containsKey( "runtime" ) ) {
if ( config.get( "runtime" ) instanceof Map<?, ?> castedMap ) {
this.runtime.process( new Struct( castedMap ) );
IStruct configStruct = StructCaster.cast( castedMap );
// move our top-level module settings in to the runtime config
if ( config.containsKey( "modules" ) ) {
configStruct.put( Key.modules, StructCaster.cast( config.get( Key.modules ) ) );
}
this.runtime.process( configStruct );
} else {
logger.warn( "The [runtime] configuration is not a JSON Object, ignoring it." );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package ortus.boxlang.runtime.config.segments;

import ortus.boxlang.runtime.dynamic.casters.StructCaster;
import ortus.boxlang.runtime.scopes.Key;
import ortus.boxlang.runtime.types.IStruct;
import ortus.boxlang.runtime.types.Struct;
Expand Down Expand Up @@ -65,7 +66,7 @@ public ModuleConfig process( IStruct config ) {
}

// Store the settings
this.settings = ( IStruct ) config.getOrDefault( Key.settings, new Struct() );
this.settings = StructCaster.cast( config.getOrDefault( Key.settings, new Struct() ) );

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import ortus.boxlang.runtime.BoxRuntime;
import ortus.boxlang.runtime.config.util.PlaceholderHelper;
import ortus.boxlang.runtime.dynamic.casters.KeyCaster;
import ortus.boxlang.runtime.scopes.Key;
import ortus.boxlang.runtime.types.Array;
import ortus.boxlang.runtime.types.IStruct;
Expand Down Expand Up @@ -269,8 +270,8 @@ public RuntimeConfig process( IStruct config ) {
}

// Process mappings
if ( config.containsKey( "mappings" ) ) {
if ( config.get( "mappings" ) instanceof Map<?, ?> castedMap ) {
if ( config.containsKey( Key.mappings ) ) {
if ( config.get( Key.mappings ) instanceof Map<?, ?> castedMap ) {
castedMap.forEach( ( key, value ) -> this.mappings.put(
Key.of( key ),
PlaceholderHelper.resolve( value )
Expand All @@ -281,8 +282,8 @@ public RuntimeConfig process( IStruct config ) {
}

// Process Modules directories
if ( config.containsKey( "modulesDirectory" ) ) {
if ( config.get( "modulesDirectory" ) instanceof List<?> castedList ) {
if ( config.containsKey( Key.modulesDirectory ) ) {
if ( config.get( Key.modulesDirectory ) instanceof List<?> castedList ) {
// iterate and add to the original list if it doesn't exist
castedList.forEach( item -> {
if ( !this.modulesDirectory.contains( item ) ) {
Expand All @@ -295,8 +296,8 @@ public RuntimeConfig process( IStruct config ) {
}

// Process customTags directories
if ( config.containsKey( "customTagsDirectory" ) ) {
if ( config.get( "customTagsDirectory" ) instanceof List<?> castedList ) {
if ( config.containsKey( Key.customTagsDirectory ) ) {
if ( config.get( Key.customTagsDirectory ) instanceof List<?> castedList ) {
// iterate and add to the original list if it doesn't exist
castedList.forEach( item -> {
if ( !this.customTagsDirectory.contains( item ) ) {
Expand All @@ -309,17 +310,17 @@ public RuntimeConfig process( IStruct config ) {
}

// Process default cache configuration
if ( config.containsKey( "defaultCache" ) ) {
if ( config.get( "defaultCache" ) instanceof Map<?, ?> castedMap ) {
if ( config.containsKey( Key.defaultCache ) ) {
if ( config.get( Key.defaultCache ) instanceof Map<?, ?> castedMap ) {
this.defaultCache = new CacheConfig().processProperties( new Struct( castedMap ) );
} else {
logger.warn( "The [runtime.defaultCache] configuration is not a JSON Object, ignoring it." );
}
}

// Process declared cache configurations
if ( config.containsKey( "caches" ) ) {
if ( config.get( "caches" ) instanceof Map<?, ?> castedCaches ) {
if ( config.containsKey( Key.caches ) ) {
if ( config.get( Key.caches ) instanceof Map<?, ?> castedCaches ) {
// Process each cache configuration
castedCaches
.entrySet()
Expand All @@ -337,13 +338,13 @@ public RuntimeConfig process( IStruct config ) {
}

// Process default datasource configuration
if ( config.containsKey( "defaultDatasource" ) ) {
this.defaultDatasource = PlaceholderHelper.resolve( config.get( "defaultDatasource" ) );
if ( config.containsKey( Key.defaultDatasource ) ) {
this.defaultDatasource = PlaceholderHelper.resolve( config.get( Key.defaultDatasource ) );
}

// Process Datasource Configurations
if ( config.containsKey( "datasources" ) ) {
if ( config.get( "datasources" ) instanceof Map<?, ?> castedDataSources ) {
if ( config.containsKey( Key.datasources ) ) {
if ( config.get( Key.datasources ) instanceof Map<?, ?> castedDataSources ) {
// Process each datasource configuration
castedDataSources
.entrySet()
Expand All @@ -361,14 +362,14 @@ public RuntimeConfig process( IStruct config ) {
}

// Process modules
if ( config.containsKey( "modules" ) ) {
if ( config.get( "modules" ) instanceof Map<?, ?> castedModules ) {
if ( config.containsKey( Key.modules ) ) {
if ( config.get( Key.modules ) instanceof Map<?, ?> castedModules ) {
// Process each module configuration
castedModules
.entrySet()
.forEach( entry -> {
if ( entry.getValue() instanceof Map<?, ?> castedMap ) {
ModuleConfig moduleConfig = new ModuleConfig( ( String ) entry.getKey() ).process( new Struct( castedMap ) );
ModuleConfig moduleConfig = new ModuleConfig( KeyCaster.cast( entry.getKey() ).getName() ).process( new Struct( castedMap ) );
this.modules.put( moduleConfig.name, moduleConfig );
} else {
logger.warn( "The [runtime.modules.{}] configuration is not a JSON Object, ignoring it.", entry.getKey() );
Expand Down

0 comments on commit bbce62a

Please sign in to comment.