@@ -11,49 +11,75 @@ component {
11
11
this .webURL = " https://www.ortussolutions.com" ;
12
12
this .description = " A JavaLoader Module for ColdBox" ;
13
13
this .
version = " @build.version@[email protected] @" ;
14
- // If true, looks for views in the parent first, if not found, then in the module. Else vice-versa
15
- this .viewParentLookup = true ;
16
- // If true, looks for layouts in the parent first, if not found, then in module. Else vice-versa
17
- this .layoutParentLookup = true ;
18
- // CF Mapping
19
14
this .cfmapping = " cbjavaloader" ;
20
15
21
16
/**
22
17
* Configure module
23
18
*/
24
19
function configure (){
20
+
21
+ settings = {
22
+ // The array paths to load
23
+ loadPaths = [],
24
+ // Load ColdFusion classes with loader
25
+ loadColdFusionClassPath = false ,
26
+ // Attach a custom class loader as a parent
27
+ parentClassLoader = " " ,
28
+ // Directories that contain Java source code that are to be dynamically compiled
29
+ sourceDirectories = [],
30
+ // the directory to build the .jar file for dynamic compilation in, defaults to ./tmp
31
+ compileDirectory = variables .modulePath & " models/javaloader/tmp" ,
32
+ // Whether or not the source is trusted, i.e. it is going to change? Defaults to false, so changes will be recompiled and loaded
33
+ trustedSource = false
34
+ };
35
+
25
36
// Register Custom DSL, don't map it because it is too late, mapping DSLs are only good by the parent app
26
- controller . getWireBox ()
37
+ wireBox
27
38
.registerDSL ( namespace = " javaloader" , path = " #moduleMapping #.models.JavaLoaderDSL" );
28
39
}
29
40
30
41
/**
31
42
* Fired when the module is registered and activated.
32
43
*/
33
44
function onLoad (){
34
- var settings = controller .getConfigSettings ();
35
- // parse parent settings
36
- parseParentSettings ();
37
45
38
46
// Bind Core JavaLoader
39
47
binder .map ( " jl@cbjavaloader" )
40
- .to ( " #moduleMapping #.models.javaloader.JavaLoader" )
41
- .initArg ( name = " loadPaths" , value = settings .modules .cbjavaloader .settings .loadPaths )
42
- .initArg ( name = " loadColdFusionClassPath" , value = settings .modules .cbjavaloader .settings .loadColdFusionClassPath )
43
- .initArg ( name = " parentClassLoader" , value = settings .modules .cbjavaloader .settings .parentClassLoader )
44
- .initArg ( name = " sourceDirectories" , value = settings .modules .cbjavaloader .settings .sourceDirectories )
45
- .initArg ( name = " compileDirectory" , value = settings .modules .cbjavaloader .settings .compileDirectory )
46
- .initArg ( name = " trustedSource" , value = settings .modules .cbjavaloader .settings .trustedSource );
48
+ .to ( " #moduleMapping #.models.javaloader.JavaLoader" );
49
+
50
+ // Duplicating so our final change won't affect the main module settings
51
+ var finalSettings = duplicate ( settings );
47
52
48
- // Load JavaLoader and class loading
49
- wirebox .getInstance ( " loader@cbjavaloader" ).setup ();
50
- }
53
+ // Start with empty array
54
+ finalSettings .loadPaths = [];
51
55
52
- /**
53
- * Fired when the module is unregistered and unloaded
54
- */
55
- function onUnload (){
56
+ // Grab module settings
57
+ var moduleSettingsLoadPath = settings .loadPaths ;
58
+
59
+ // Force array
60
+ if ( isSimpleValue ( moduleSettingsLoadPath ) ) {
61
+ moduleSettingsLoadPath = moduleSettingsLoadPath .listToArray ();
62
+ }
63
+
64
+ // Loop over settings, adding files and expanding directories
65
+ for ( var this Location in moduleSettingsLoadPath ){
66
+ if ( directoryExists ( this Location ) ) {
67
+ finalSettings .loadPaths .addAll ( getJars ( this Location ) );
68
+ } else if ( fileExists ( this Location ) ) {
69
+ finalSettings .loadPaths .append ( this Location );
70
+ } else {
71
+ throw ( " Javalaoder cannot load #this Location # as it is not a valid path or file" );
72
+ }
73
+ }
56
74
75
+ // Dynamic Proxy
76
+ arrayPrepend (
77
+ finalSettings .loadPaths ,
78
+ variables .modulePath & " /models/javaloader/support/cfcdynamicproxy/lib/cfcdynamicproxy.jar"
79
+ );
80
+
81
+ // Load JavaLoader and class loading
82
+ wirebox .getInstance ( " loader@cbjavaloader" ).setup ( finalSettings );
57
83
}
58
84
59
85
/**
@@ -73,73 +99,4 @@ component {
73
99
);
74
100
}
75
101
76
- /**
77
- * parse parent settings
78
- */
79
- private function parseParentSettings (){
80
- var oConfig = controller .getSetting ( " ColdBoxConfig" );
81
- var configStruct = controller .getConfigSettings ();
82
- var javaLoaderDSL = oConfig .getPropertyMixin ( " javaloader" , " variables" , structnew () );
83
-
84
- // Default Configurations
85
- configStruct .modules .cbjavaloader .settings = {
86
- // The array paths to load
87
- loadPaths = variables .modulePath & " lib" ,
88
- // Load ColdFusion classes with loader
89
- loadColdFusionClassPath = false ,
90
- // Attach a custom class loader as a parent
91
- parentClassLoader = " " ,
92
- // Directories that contain Java source code that are to be dynamically compiled
93
- sourceDirectories = [],
94
- // the directory to build the .jar file for dynamic compilation in, defaults to ./tmp
95
- compileDirectory = variables .modulePath & " model/javaloader/tmp" ,
96
- // Whether or not the source is trusted, i.e. it is going to change? Defaults to false, so changes will be recompiled and loaded
97
- trustedSource = false
98
- };
99
-
100
- // Default load paths, empty array
101
- if ( ! structKeyExists ( javaLoaderDSL , " loadPaths" ) ){
102
- javaLoaderDSL .loadPaths = [];
103
- }
104
-
105
- // Array of locations
106
- if ( isArray ( javaLoaderDSL .loadPaths ) ){
107
- var aJarPaths = [];
108
- for ( var this Location in javaLoaderDSL .loadPaths ){
109
- if ( directoryExists ( this Location ) ) {
110
- aJarPaths .addAll ( getJars ( this Location ) );
111
- } else if ( ! fileExists ( this Location ) ) {
112
- throw ( " Cannot load #this Location # as it is not a valid path or file" );
113
- }
114
- }
115
- javaLoaderDSL .loadPaths = aJarPaths ;
116
- }
117
-
118
- // Single directory? Get all Jars in it
119
- if ( isSimpleValue ( javaLoaderDSL .loadPaths ) and directoryExists ( javaLoaderDSL .loadPaths ) ){
120
- javaLoaderDSL .loadPaths = getJars ( javaLoaderDSL .loadPaths );
121
- }
122
-
123
- // Single Jar?
124
- if ( isSimpleValue ( javaLoaderDSL .loadPaths ) and fileExists ( javaLoaderDSL .loadPaths ) ){
125
- javaLoaderDSL .loadPaths = [ javaLoaderDSL .loadPaths ];
126
- }
127
-
128
- // If simple value and no length
129
- if ( isSimpleValue ( javaLoaderDSL .loadPaths ) and ! len ( javaLoaderDSL .loadPaths ) ){
130
- javaLoaderDSL .loadPaths = [];
131
- }
132
-
133
- // Now that we have figured out the user's settings, let's incorporate ours
134
-
135
- // Dynamic Proxy
136
- arrayPrepend (
137
- javaLoaderDSL .loadPaths ,
138
- variables .modulePath & " /models/javaloader/support/cfcdynamicproxy/lib/cfcdynamicproxy.jar"
139
- );
140
-
141
- // incorporate settings
142
- structAppend ( configStruct .modules .cbjavaloader .settings , javaLoaderDSL , true );
143
- }
144
-
145
102
}
0 commit comments