@@ -32,11 +32,6 @@ function Use-Icinga()
32
32
$global :Icinga.Add (' Minimal' , $TRUE );
33
33
}
34
34
35
- # If we load the minimal Framework files, we have to ensure our enums are loaded
36
- Import-Module ([string ]::Format(' {0}\lib\icinga\exception\Icinga_IcingaExceptionEnums.psm1' , $PSScriptRoot )) - Global;
37
- Import-Module ([string ]::Format(' {0}\lib\icinga\enums\Icinga_IcingaEnums.psm1' , $PSScriptRoot )) - Global;
38
- Import-Module ([string ]::Format(' {0}\lib\core\logging\Icinga_EventLog_Enums.psm1' , $PSScriptRoot )) - Global;
39
-
40
35
return ;
41
36
}
42
37
@@ -46,12 +41,6 @@ function Use-Icinga()
46
41
Use-IcingaPlugins ;
47
42
}
48
43
49
- # This function will allow us to load this entire module including possible
50
- # actions, making it available within our shell environment
51
- # First load our custom modules
52
- Import-IcingaLib ' \' - Init - Custom;
53
- Import-IcingaLib ' \' - Init;
54
-
55
44
if ($LibOnly -eq $FALSE ) {
56
45
$global :IcingaThreads = [hashtable ]::Synchronized(@ {});
57
46
$global :IcingaThreadContent = [hashtable ]::Synchronized(@ {});
@@ -107,150 +96,27 @@ function Get-IcingaFrameworkCodeCacheFile()
107
96
return (Join-Path - Path (Get-IcingaCacheDir ) - ChildPath ' framework_cache.psm1' );
108
97
}
109
98
110
- function Write-IcingaFrameworkCodeCache ()
111
- {
112
- Import-IcingaLib ' \' - Init - CompileCache;
113
- }
114
-
115
99
function Import-IcingaLib ()
116
100
{
117
- param (
118
- [String ]$Lib ,
119
- # The Force Reload will remove the module in case it's loaded and reload it to track
120
- # possible development changes without having to create new PowerShell environments
121
- [Switch ]$ForceReload ,
122
- [switch ]$Init ,
123
- [switch ]$Custom ,
124
- [switch ]$WriteManifests ,
125
- [switch ]$CompileCache
126
- );
127
-
128
- # This is just to only allow a global loading of the module. Import-IcingaLib is ignored on every other
129
- # location. It is just there to give a basic idea within commands, of which functions are used
130
- if ($Init -eq $FALSE ) {
131
- return ;
132
- }
133
-
134
- $CacheFile = Get-IcingaFrameworkCodeCacheFile ;
135
-
136
- if ($CompileCache -eq $FALSE ) {
137
- Import-Module ' icinga-powershell-framework' - Global - Force;
138
- return ;
139
- }
140
-
141
- [array ]$ImportModules = @ ();
142
- [array ]$RemoveModules = @ ();
143
-
144
- if ($Custom ) {
145
- [string ]$directory = Join-Path - Path $PSScriptRoot - ChildPath ' custom\' ;
146
- } else {
147
- [string ]$directory = Join-Path - Path $PSScriptRoot - ChildPath ' lib\' ;
148
- }
149
- [string ]$module = Join-Path - Path $directory - ChildPath $Lib ;
150
- [string ]$moduleName = ' ' ;
151
-
152
- $ListOfLoadedModules = Get-Module | Select-Object Name;
153
-
154
- # Load modules from directory
155
- if ((Test-Path $module - PathType Container)) {
156
-
157
- Get-ChildItem - Path $module - Recurse - Filter * .psm1 |
158
- ForEach-Object {
159
- [string ]$modulePath = $_.FullName ;
160
- $moduleName = $_.Name.Replace (' .psm1' , ' ' );
161
-
162
- if ($ListOfLoadedModules -like " *$moduleName *" ) {
163
- if ($ForceReload ) {
164
- $RemoveModules += $moduleName ;
165
- }
166
- $ImportModules += $modulePath ;
167
- } else {
168
- $ImportModules += $modulePath ;
169
- if ($WriteManifests ) {
170
- Publish-IcingaModuleManifest - Module $moduleName ;
171
- }
172
- }
173
- }
174
- } else {
175
- $module = $module.Replace (' .psm1' , ' ' ); # Cut possible .psm1 ending
176
- $moduleName = $module.Split (' \' )[-1 ]; # Get the last element
177
-
178
- if ($ForceReload ) {
179
- if ($ListOfLoadedModules -Like " *$moduleName *" ) {
180
- $RemoveModules += $moduleName ;
181
- }
182
- }
183
-
184
- $ImportModules += ([string ]::Format(' {0}.psm1' , $module ));
185
- if ($WriteManifests ) {
186
- Publish-IcingaModuleManifest - Module $moduleName ;
187
- }
188
- }
189
-
190
- if ($RemoveModules.Count -ne 0 ) {
191
- Remove-Module $RemoveModules ;
192
- }
193
-
194
- if ($ImportModules.Count -ne 0 ) {
195
-
196
- if ($CompileCache ) {
197
- $CacheContent = ' ' ;
198
- foreach ($module in $ImportModules ) {
199
- $Content = Get-Content $module - Raw;
200
- $CacheContent += $Content + " `r`n " ;
201
- }
202
-
203
- $CacheContent += $Content + " Export-ModuleMember -Function @( '*' )" ;
204
- Set-Content - Path $CacheFile - Value $CacheContent ;
205
- } else {
206
- Import-Module $ImportModules - Global;
207
- }
208
- }
101
+ # Do nothing, just leave it here as compatibility layer until we
102
+ # cleaned every other repository
209
103
}
210
104
211
- function Publish-IcingaModuleManifest ()
105
+ function Write-IcingaFrameworkCodeCache ()
212
106
{
213
- param (
214
- [string ]$Module
215
- );
216
-
217
- [string ]$ManifestDir = Join-Path - Path $PSScriptRoot - ChildPath ' manifests' ;
218
- [string ]$ModuleFile = [string ]::Format(' {0}.psd1' , $Module );
219
- [string ]$PSDFile = Join-Path - Path $ManifestDir - ChildPath $ModuleFile ;
107
+ [string ]$CacheFile = Get-IcingaFrameworkCodeCacheFile ;
108
+ [string ]$directory = Join-Path - Path $PSScriptRoot - ChildPath ' lib\' ;
109
+ [string ]$CacheContent = ' ' ;
220
110
221
- if (Test-Path $PSDFile ) {
222
- return ;
223
- }
224
-
225
- New-ModuleManifest - Path $PSDFile - ModuleVersion 1.0 - Author $env: USERNAME - CompanyName ' Icinga GmbH' - Copyright ' (c) 2019 Icinga GmbH. All rights reserved.' - PowerShellVersion 4.0 ;
226
- $Content = Get-Content $PSDFile ;
227
- $NewContent = @ ();
228
-
229
- foreach ($line in $Content ) {
230
- if ([string ]::IsNullOrEmpty($line )) {
231
- continue ;
232
- }
233
-
234
- if ($line [0 ] -eq ' #' ) {
235
- continue ;
236
- }
237
-
238
- if ($line.Contains (' #' )) {
239
- $line = $line.Substring (0 , $line.IndexOf (' #' ));
240
- }
241
-
242
- $tmpLine = $line ;
243
- while ($tmpLine.Contains (' ' )) {
244
- $tmpLine = $tmpLine.Replace (' ' , ' ' );
245
- }
246
- if ([string ]::IsNullOrEmpty($tmpLine )) {
247
- continue ;
111
+ # Load modules from directory
112
+ Get-ChildItem - Path $directory - Recurse - Filter ' *.psm1' |
113
+ ForEach-Object {
114
+ $CacheContent += (Get-Content - Path $_.FullName - Raw);
115
+ $CacheContent += " `r`n " ;
248
116
}
249
117
250
- $NewContent += $line ;
251
- }
252
-
253
- Set-Content - Path $PSDFile - Value $NewContent ;
118
+ $CacheContent += " Export-ModuleMember -Function @( '*' )" ;
119
+ Set-Content - Path $CacheFile - Value $CacheContent ;
254
120
}
255
121
256
122
function Publish-IcingaEventlogDocumentation ()
0 commit comments