-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWrite-PackagesToOpen.ps1
More file actions
60 lines (56 loc) · 3.1 KB
/
Write-PackagesToOpen.ps1
File metadata and controls
60 lines (56 loc) · 3.1 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
# Configure the extensions of the resources that other modules must have access to here. Add additional extensions for other types of resources when needed (for example for images and fonts).
$WildcardsForResourcesForWhichToOpenPackage = 'css', 'html', 'js', 'properties', 'properties.xml' |
ForEach-Object { "*.$_" }
# Halt the script at the first error.
$ErrorActionPreference = 'Stop'
# Make sure the build results in `target\classes` are up-to-date.
.\mvnw clean compile
$NodeModulesFullName = Join-Path ( Get-Location ) node_modules\
$PackagesFullName = Join-Path ( Get-Location ) packages\
# Find all `pom.xml` files. Ignore errors as those files are very unlikely to contain a POM (that needs processing).
Get-ChildItem pom.xml -Recurse -File -ErrorAction SilentlyContinue |
# Remove `pom.xml` files in front-end modules.
Where-Object {
-not $_.FullName.StartsWith( $NodeModulesFullName ) -and -not $_.FullName.StartsWith( $PackagesFullName )
} |
# Pass the directory of the module and the `target\classes` directory of the `pom.xml` file down the pipeline.
ForEach-Object {
@{
'ClassesPath' = ( Join-Path $_.Directory target\classes\ );
'MainJavaSourcesPath' = ( Join-Path $_.Directory src\main\java\ )
}
} |
# Only process modules that have a `target\classes` directory.
Where-Object {
Test-Path $_.ClassesPath
} |
# Determine the `opens` statements to use for each module.
ForEach-Object {
Push-Location $_.ClassesPath
try {
$PackagesToOpenForModule = @(
# Get all Wicket and front-end resources.
#
# There are many with a path that is too long, and the errors for these are ignored. This may result in missing a package that has to be opened.
Get-ChildItem $WildcardsForResourcesForWhichToOpenPackage -File -Recurse -ErrorAction SilentlyContinue |
# Relative path to `target\classes` so it will be the package name with backslashes.
Resolve-Path -Relative |
# Remove the `.\` at the front.
ForEach-Object { $_.Substring( 2 ) } |
# Remove the filename.
Split-Path -Parent |
# Packages are only needed once instead of for each file.
Sort-Object -Unique |
# Ignore directories that are not packages (as they are not encapsulated by default, and cant be declared in `module-info.java`).
Where-Object { $_ -match '^[a-z][a-z0-9_]+(\\[a-z][a-z0-9_]+)+$' } |
# Convert it into an `opens` statement.
ForEach-Object { "opens $( $_.Replace('\', '.') );" }
) -join "`n"
# Write a file containing the `opens` statements that `module-info.java` should contain.
if ( $PackagesToOpenForModule.Trim() -ne '' ) {
Set-Content ( Join-Path $_.MainJavaSourcesPath opens-list.txt ) $PackagesToOpenForModule
}
} finally {
Pop-Location
}
}