This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModuleConfig.cfc
159 lines (139 loc) · 6.49 KB
/
ModuleConfig.cfc
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
component {
function configure() {
settings = {
enable = true,
version = 'LATEST',
apikey = "",
name = "",
tags = ""
};
}
function onServerStart(required struct interceptData) {
jobEnabled = wirebox.getBinder().mappingExists( 'interactiveJob' );
consoleLogger = wirebox.getInstance( dsl='logbox:logger:console' );
var serverInfo = arguments.interceptData.serverInfo;
var serverService = wirebox.getInstance( 'ServerService' );
var configService = wirebox.getInstance( 'ConfigService' );
var systemSettings = wirebox.getInstance( 'SystemSettings' );
// read server.json
var serverJSON = serverService.readServerJSON( serverInfo.serverConfigFile ?: '' );
// Get defaults
var defaults = configService.getSetting( 'server.defaults', {} );
systemSettings.expandDeepSystemSettings( serverJSON );
systemSettings.expandDeepSystemSettings( defaults );
var nvEnable = serverJSON.nerdvision.enable ?: defaults.nerdvision.enable ?: settings.enable;
var version = serverJSON.nerdvision.version ?: defaults.nerdvision.version ?: settings.version;
var apikey = serverJSON.nerdvision.apikey ?: defaults.nerdvision.apikey ?: settings.apikey;
var name = serverJSON.nerdvision.name ?: defaults.nerdvision.name ?: settings.name;
var tags = serverJSON.nerdvision.tags ?: defaults.nerdvision.tags ?: settings.tags;
if (isBoolean(nvEnable) && !nvEnable) {
logDebug('NerdVision is disabled');
return;
}
if ("#apikey#" == "") {
logError('NerdVision apikey not set.');
return;
}
logDebug( '******************************************' );
logDebug( '* CommandBox NerdVision Module Loaded *' );
logDebug( '******************************************' );
// Create a folder for the nerdvision.jar
var nvTargetDir = serverInfo.serverHomeDirectory & '/nv';
directoryCreate(nvTargetDir, true, true);
var download = true;
var versionsXML = "";
var latestAvail = "";
var jarExists = fileExists('#nvTargetDir#/nerdvision.jar');
var versionExists = fileExists("#nvTargetDir#/nv_version");
try {
versionsXML = xmlParse("https://repo1.maven.org/maven2/com/nerdvision/agent/maven-metadata.xml");
latestAvail = versionsXML.metadata.versioning.latest.XMLText;
if (versionExists) {
var nvVersion = fileRead("#nvTargetDir#/nv_version");
if ("#nvVersion#" == "#version#" and jarExists) {
download = false;
logDebug("Found existing nerdvision.jar (#nvVersion#) expecting (#version#) file in #nvTargetDir#");
} else {
if ("#version#" == "LATEST") {
download = "#latestAvail#" != "#nvVersion#";
if (download) {
logDebug("Found existing nerdvision.jar (#nvVersion#) updating to new version (#latestAvail#)");
} else {
logDebug("nerdvision.jar (#nvVersion#) already at latest version (#latestAvail#)");
}
} else {
logDebug("Found existing nerdvision.jar (#nvVersion#) updating to set version (#version#)");
}
}
}
} catch (any e) {
download = false;
if (jarExists and versionExists) {
var nvVersion = fileRead("#nvTargetDir#/nv_version");
logError("Could not download nerdvision version list. Using existing version (#nvVersion#)");
} else {
logError("Could not download nerdvision and no jar installed. Disabling plugin.");
return;
}
}
if (download) {
var nvUrl = 'https://repository.sonatype.org/service/local/artifact/maven/redirect';
logDebug('Downloading nerd.vision #version# from https://repository.sonatype.org to directory #nvTargetDir#...');
cfhttp(method = "GET", getasbinary = "true", url = nvUrl, path = nvTargetDir, file = "nerdvision.jar", timeout = "10") {
cfhttpparam(name = 'r', value = 'central-proxy');
cfhttpparam(name = 'g', value = 'com.nerdvision');
cfhttpparam(name = 'a', value = 'agent');
cfhttpparam(name = 'v', value = '#version#');
};
var versionInstalled = '';
if ("#version#" == "LATEST") {
versionInstalled = latestAvail;
} else {
versionInstalled = version;
}
fileWrite("#nvTargetDir#/nv_version", "#versionInstalled#");
}
// if we have an apikey set the agent args
if ("#apikey#" != "") {
var nvJVMArgs = ' "-javaagent:#replaceNoCase(serverInfo.serverHomeDirectory, '\', '\\', 'all')#/nv/nerdvision.jar=api.key=#trim(apikey)#';
if ("#name#" != "") {
nvJVMArgs &= ",name=#trim(reReplace(name, '\s', '', 'ALL'))#";
}
if ("#tags#" != "") {
nvJVMArgs &= ",tags=#trim(reReplace(tags, '\s', '', 'ALL'))#";
}
nvJVMArgs &= '"';
serverInfo.JVMArgs &= nvJVMArgs;
logDebug('Using nerd.vision JVM args #serverInfo.JVMArgs#');
} else {
logDebug("To use nerd.vision set an apikey by executing 'box set config modules.nerdvision.apikey=<your apikey>'");
}
}
private function logError( message ) {
if( jobEnabled ) {
if( message == '.' ) { return; }
var job = wirebox.getInstance( 'interactiveJob' );
job.addErrorLog( message );
} else {
consoleLogger.error( message );
}
}
private function logWarn( message ) {
if( jobEnabled ) {
if( message == '.' ) { return; }
var job = wirebox.getInstance( 'interactiveJob' );
job.addWarnLog( message );
} else {
consoleLogger.warn( message );
}
}
private function logDebug( message ) {
if( jobEnabled ) {
if( message == '.' ) { return; }
var job = wirebox.getInstance( 'interactiveJob' );
job.addLog( message );
} else {
consoleLogger.debug( message );
}
}
}