Skip to content

Instantly share code, notes, and snippets.

@mavaddat
Last active October 16, 2019 02:59
Show Gist options
  • Save mavaddat/ef23fda9ddfe7bf12e460a8cf25340f2 to your computer and use it in GitHub Desktop.
Save mavaddat/ef23fda9ddfe7bf12e460a8cf25340f2 to your computer and use it in GitHub Desktop.
Preliminary version of a PowerShell script to get the .jar dependencies for a java build
function Get-Dependencies {
[CmdletBinding()]
param (
[Alias("CP", "ClassPath")]
[Parameter(Mandatory = $false)]
[string] ${Class-Path} = "F:\lwjgl-release-3.2.3-custom\",
[Alias("File", "JavaFile", "Target")]
[Parameter(Mandatory = $true)]
${Target-JavaFile}
)
begin {
$r = New-Object -TypeName System.Collections.ArrayList
}
process {
if ((Test-Path -Path ${Target-JavaFile}) -and (Test-Path -Path ${Class-Path})) {
$r.Add("$(Join-Path -Path $(Split-Path -Path ${Target-JavaFile}) -ChildPath '')*") > $null
$(Get-Content ${Target-JavaFile} | Where-Object -FilterScript { $_ -match "import" }) -creplace '^[\S\s]*?(\S+?)(?:\.[A-Z]\w+\.\*)?(?:\.\*)?;$', '$1' -replace '(?:^java.*$|org\.)', '' -replace '\.', '-' | Select-Object -Unique | ForEach-Object {
if ($_.Length -ne 0) {
$i = $(Get-ChildItem -Path ${Class-Path} -Name "$_.jar") -replace '^', "${Class-Path}" -join ';'
if ($i.Length -eq 0) {
$i = $(Get-ChildItem -Path ${Class-Path} -Filter "$_*.jar") -replace '^', "${Class-Path}" -join ';'
if ($i.Length -ne 0) {
$r.Add($i) > $null
}
}
else {
$r.Add($i) > $null
}
}
}
return $($r -join ';')
}
else {
return $false;
}
}
end {
Remove-Variable "r"
}
}
function Get-JavaParams {
[CmdletBinding()]
param (
[Alias("CP", "ClassPath")]
[Parameter(Mandatory = $false)]
[string] ${Class-Path} = "F:\lwjgl-release-3.2.3-custom\",
[Alias("File", "JavaFile", "Target")]
[Parameter(Mandatory = $true)]
${Target-JavaFile}
)
begin {
}
process {
}
end {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment