-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlueJ.ps1
61 lines (50 loc) · 1.68 KB
/
BlueJ.ps1
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
61
# Maven to BlueJ helper script
# Author: Pawel Makles <https://insrt.uk>
# Repository: https://github.com/KCLOSS/maven-bluej
# Version: 0.2
param (
[switch]$Build = $false,
[switch]$Run = $false,
[switch]$NoClean = $false,
[string]$BlueJ = "C:/Program Files/BlueJ/BlueJ.exe",
[string]$TestDirectory = "test",
[string]$OutFile = "target/bluej_out.jar",
[string]$BuildCommand = "mvn clean compile assembly:single"
)
if ($Build) {
# Build Maven project.
Invoke-Expression $BuildCommand
# Copy the chad Maven build.
Get-ChildItem target/*-jar-with-dependencies.jar |
ForEach-Object { Copy-Item $_ "$OutFile" -Force }
# BlueJ expectes all package declarations to start from root.
# Inject source code into JAR file.
Push-Location src\main\java
jar -uf "../../../$OutFile" *
Pop-Location
# Mark this as a BlueJ project.
New-Item -ItemType file ThisIsABlueJProject
jar -uf $OutFile ThisIsABlueJProject
Remove-Item ThisIsABlueJProject
}
if ($Run) {
# Ensure project has been built.
if (-Not (Test-Path $OutFile -PathType Leaf)) {
Write-Error "Must build project first!"
Exit
}
# Remove existing BlueJ project.
if (Test-Path $TestDirectory -PathType Container) {
Remove-Item $TestDirectory -Recurse
}
# Copy exported jar
New-Item $TestDirectory -ItemType "directory"
Copy-Item $OutFile "$TestDirectory/out.jar"
# Open it with BlueJ
$Path = Resolve-Path "$TestDirectory/out.jar"
Start-Process -NoNewWindow -FilePath $BlueJ -ArgumentList $Path -Wait
if (-Not $NoClean) {
# Clean up afterwards
Remove-Item $TestDirectory -Recurse
}
}