@@ -32,11 +32,6 @@ function Use-Icinga()
3232 $global :Icinga.Add (' Minimal' , $TRUE );
3333 }
3434
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-
4035 return ;
4136 }
4237
@@ -46,12 +41,6 @@ function Use-Icinga()
4641 Use-IcingaPlugins ;
4742 }
4843
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-
5544 if ($LibOnly -eq $FALSE ) {
5645 $global :IcingaThreads = [hashtable ]::Synchronized(@ {});
5746 $global :IcingaThreadContent = [hashtable ]::Synchronized(@ {});
@@ -107,150 +96,27 @@ function Get-IcingaFrameworkCodeCacheFile()
10796 return (Join-Path - Path (Get-IcingaCacheDir ) - ChildPath ' framework_cache.psm1' );
10897}
10998
110- function Write-IcingaFrameworkCodeCache ()
111- {
112- Import-IcingaLib ' \' - Init - CompileCache;
113- }
114-
11599function Import-IcingaLib ()
116100{
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
209103}
210104
211- function Publish-IcingaModuleManifest ()
105+ function Write-IcingaFrameworkCodeCache ()
212106{
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 = ' ' ;
220110
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 " ;
248116 }
249117
250- $NewContent += $line ;
251- }
252-
253- Set-Content - Path $PSDFile - Value $NewContent ;
118+ $CacheContent += " Export-ModuleMember -Function @( '*' )" ;
119+ Set-Content - Path $CacheFile - Value $CacheContent ;
254120}
255121
256122function Publish-IcingaEventlogDocumentation ()
0 commit comments