-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathModuleConfig.cfc
More file actions
71 lines (62 loc) · 2.24 KB
/
Copy pathModuleConfig.cfc
File metadata and controls
71 lines (62 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
*/
component {
this.dependencies = [ "cfmigrations", "sqlFormatter" ];
/**
* Module lifecycle method. Registers the SqlHighlighter singleton, falling back
* to a no-op highlighter if the jLine SyntaxHighlighter can't be built.
*/
function configure() {
var sqlHighlighter = {
"highlight": ( str ) => ( {
"toAnsi": () => str
} )
};
try {
sqlHighlighter = createObject( "java", "org.jline.builtins.Nano$SyntaxHighlighter" ).build(
createObject( "java", "java.io.File" )
.init( expandPath( "/commandbox-migrations/lib/sql.nanorc" ) )
.toURI()
.toURL()
.toString()
);
} catch ( any e ) {
log.warn( "Could not create the jLine SyntaxHighlighter. Falling back to no highlighting", e );
}
binder
.map( "SqlHighlighter" )
.asSingleton()
.toValue( sqlHighlighter );
}
/**
* Fired when the module is registered and activated. When the active
* runtime is BoxLang, eagerly loads any JDBC driver modules already
* present in `<moduleRoot>/boxlang_modules/` so migrations can be
* executed without a second restart.
*
* Loading is a no-op when:
* - the runtime is not BoxLang
* - the `boxlang_modules` directory does not yet exist
* - the BoxRuntime singleton cannot be reached
*
* `loadModules(Path)` is idempotent — already-registered modules are
* skipped — so it is safe to call from both this hook and the
* `BaseMigrationCommand` install path.
*/
public void function onLoad() {
if ( !structKeyExists( server, "boxlang" ) ) {
return
}
var modulesDir = variables.modulePath & "/boxlang_modules";
if ( !directoryExists( modulesDir ) ) {
return
}
var paths = createObject( "java", "java.nio.file.Paths" );
getBoxRuntime()
.getModuleService()
.loadModules( paths.get( modulesDir ) )
}
}