1+ <#
2+ Licensed to the Apache Software Foundation (ASF) under one or more
3+ contributor license agreements. See the NOTICE file distributed with
4+ this work for additional information regarding copyright ownership.
5+ The ASF licenses this file to You under the Apache License, Version 2.0
6+ (the "License"); you may not use this file except in compliance with
7+ the License. You may obtain a copy of the License at
8+
9+ https://www.apache.org/licenses/LICENSE-2.0
10+
11+ Unless required by applicable law or agreed to in writing, software
12+ distributed under the License is distributed on an "AS IS" BASIS,
13+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ See the License for the specific language governing permissions and
15+ limitations under the License.
16+ #>
17+
18+ <#
19+ . SYNOPSIS
20+ Helper script to download and run the Apache Release Audit Tool (RAT).
21+
22+ . DESCRIPTION
23+ This script automates use of the Apache RAT tool during release preparation.
24+ It ensures that the RAT JAR is available locally (downloading it if needed)
25+ and then runs it against the source tree to check for missing license headers
26+ and other compliance issues.
27+
28+ By default, the tool is downloaded into a `.tools/rat` directory located next
29+ to this script. The script always runs RAT with the repository root (same
30+ directory as this script) as the target directory.
31+
32+ . PARAMETER Version
33+ The version of Apache RAT to use (default: 0.16).
34+
35+ . PARAMETER ExcludeFileName
36+ Name of an exclude file containing path patterns that RAT should ignore.
37+ This file should be located next to the script. Default: rat-exclude.txt
38+
39+ .REQUIREMENTS
40+ - Java 8+ must be installed and available on the PATH.
41+ - Internet connection (for first run, to download RAT).
42+
43+ . EXAMPLE
44+ pwsh ./rat.ps1
45+
46+ Runs Apache RAT (default version 0.16) with exclusions from `rat-exclude.txt`.
47+
48+ . EXAMPLE
49+ pwsh ./rat.ps1 -Version 0.16 -ExcludeFileName custom-exclude.txt
50+
51+ Runs Apache RAT version 0.16 using the specified exclude file.
52+
53+ . NOTES
54+ This script is intended for use by release managers when preparing official
55+ ASF releases. It is not normally required for day-to-day development.
56+ #>
57+ param (
58+ [string ]$Version = " 0.16" ,
59+ [string ]$ExcludeFileName = " .rat-excludes"
60+ )
61+
62+ # Script directory (works in PowerShell Core and Windows PowerShell)
63+ $scriptDir = $PSScriptRoot
64+
65+ # Tool paths (kept under the script dir)
66+ $ratDir = Join-Path $scriptDir " .tools\rat"
67+ $ratJar = Join-Path $ratDir " apache-rat-$Version .jar"
68+ $ratUrl = " https://repo1.maven.org/maven2/org/apache/rat/apache-rat/$Version /apache-rat-$Version .jar"
69+
70+ # Exclude file path (resolved relative to script dir)
71+ $ratExcludeFile = Join-Path $scriptDir $ExcludeFileName
72+
73+ # Ensure tool folder exists and jar is present (download if missing)
74+ if (-not (Test-Path $ratDir )) {
75+ New-Item - ItemType Directory - Path $ratDir | Out-Null
76+ }
77+
78+ if (-not (Test-Path $ratJar )) {
79+ Write-Host " Downloading Apache RAT $Version to $ratJar ..."
80+ Invoke-WebRequest - Uri $ratUrl - OutFile $ratJar
81+ }
82+
83+ # If exclude file is optional, optionally warn if missing:
84+ if (-not (Test-Path $ratExcludeFile )) {
85+ Write-Host " Warning: exclude file '$ratExcludeFile ' not found. Continuing without --exclude-file."
86+ $useExclude = $false
87+ } else {
88+ $useExclude = $true
89+ }
90+
91+ # Run from the script directory so '.' means the repository root next to this script
92+ Push-Location $scriptDir
93+ try {
94+ $argsList = @ (
95+ " -jar" , $ratJar ,
96+ " --dir" , " ." ,
97+ " --addLicense" ,
98+ " --force"
99+ )
100+
101+ if ($useExclude ) {
102+ $argsList += @ (" --exclude-file" , $ratExcludeFile )
103+ }
104+
105+ # Call java with argument list. Use & to invoke program.
106+ & java @argsList
107+
108+ if ($LASTEXITCODE -ne 0 ) {
109+ throw " RAT exited with code $LASTEXITCODE "
110+ }
111+ }
112+ finally {
113+ Pop-Location
114+ }
0 commit comments