Skip to content

Commit 7aaee97

Browse files
committed
Build logic updates
1 parent bc546b1 commit 7aaee97

File tree

5 files changed

+73
-57
lines changed

5 files changed

+73
-57
lines changed

build.gradle

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ plugins {
2727

2828
id 'idea'
2929
}
30-
idea.module.outputDir file("out/production/classes") // fix running via IntelliJ
30+
idea.module.outputDir file('out/production/classes') // fix running via IntelliJ
3131

3232
/*
3333
* REMEMBER: also update the version string in Main.java
3434
*/
35-
version = "3.5.1"
36-
description = "A cross-platform GUI and CLI app for saving SHSH blobs"
37-
String appIdentifier = "airsquared.blobsaver.app"
38-
String copyright = "Copyright (c) 2023 airsquared"
35+
version = '3.5.1'
36+
description = 'A cross-platform GUI and CLI app for saving SHSH blobs'
37+
String appIdentifier = 'airsquared.blobsaver.app'
38+
String copyright = 'Copyright (c) 2023 airsquared'
3939
def os = DefaultNativePlatform.currentOperatingSystem
4040

4141
startScripts.enabled = distZip.enabled = distTar.enabled = false
@@ -56,7 +56,7 @@ dependencies {
5656
implementation 'info.picocli:picocli:4.7.4'
5757

5858
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3'
59-
testImplementation group: 'org.testfx', name: 'openjfx-monocle', version: 'jdk-12.0.1+2'
59+
testImplementation 'org.testfx:openjfx-monocle:jdk-12.0.1+2'
6060
}
6161

6262
javafx {
@@ -71,26 +71,26 @@ compileJava {
7171
}
7272

7373
application {
74-
mainModule = "airsquared.blobsaver"
75-
mainClass = "airsquared.blobsaver.app.Main"
74+
mainModule = 'airsquared.blobsaver'
75+
mainClass = 'airsquared.blobsaver.app.Main'
7676
applicationDefaultJvmArgs.addAll addExports
7777
}
7878

7979
private String getJarDirectory() {
8080
String dir = ""
81-
if (DefaultNativePlatform.currentOperatingSystem.isMacOsX()) dir = "macos/Contents"
82-
else if (DefaultNativePlatform.currentOperatingSystem.isWindows()) dir = "windows/files"
83-
else if (DefaultNativePlatform.currentOperatingSystem.isLinux()) dir = "linux"
81+
if (DefaultNativePlatform.currentOperatingSystem.isMacOsX()) dir = 'macos/Contents'
82+
else if (DefaultNativePlatform.currentOperatingSystem.isWindows()) dir = 'windows/files'
83+
else if (DefaultNativePlatform.currentOperatingSystem.isLinux()) dir = 'linux'
8484
return "${projectDir}/dist/${dir}"
8585
}
8686

8787
run {
88-
systemProperty "jar.directory", getJarDirectory()
88+
systemProperty 'jar.directory', getJarDirectory()
8989
}
9090

9191
test {
9292
useJUnitPlatform()
93-
systemProperty "jar.directory", getJarDirectory()
93+
systemProperty 'jar.directory', getJarDirectory()
9494
jvmArgs addExports
9595
jvmArgs '--add-exports=javafx.graphics/com.sun.glass.ui=org.testfx.monocle'
9696
}
@@ -103,7 +103,7 @@ jlink {
103103
launcher {
104104
jvmArgs = [ '-Djar.directory={{BIN_DIR}}' ]
105105
jvmArgs.addAll addExports
106-
if (findProperty("noConsole") != 'false') {
106+
if (findProperty('noConsole') != 'false') {
107107
noConsole = true
108108
}
109109
}
@@ -114,9 +114,9 @@ jlink {
114114
installerOutputDir = file("${buildDir}/distributions/")
115115

116116
if (os.isMacOsX()) {
117-
installerType = "dmg"
118-
String arch = DefaultNativePlatform.currentArchitecture.amd64 ? "intel" : "arm"
119-
installerName = name + "-" + arch
117+
installerType = 'dmg'
118+
String arch = DefaultNativePlatform.currentArchitecture.amd64 ? 'intel' : 'arm'
119+
installerName = "${name}-${arch}"
120120
imageOptions.addAll '--mac-package-identifier', appIdentifier
121121
icon = "${projectDir}/dist/macos/Contents/Resources/blob.icns"
122122
} else if (os.isWindows()) {
@@ -143,13 +143,13 @@ jlink {
143143
into "${buildDir}/jpackage/blobsaver.app/Contents/Resources"
144144
}
145145
exec { // needed to prevent "application is damaged" error when opening quarantined app
146-
commandLine "codesign", "--force", "--deep", "--sign", "-", "${buildDir}/jpackage/blobsaver.app"
146+
commandLine 'codesign', '--force', '--deep', '--sign', '-', "${buildDir}/jpackage/blobsaver.app"
147147
}
148148
} else if (os.isWindows()) jpackageImage.doLast {
149149
copy {
150150
from "${projectDir}/dist/windows/files", "${buildDir}/jpackage/blobsaver/runtime/bin/zip.dll"
151-
rename "LICENSE_windows", "LICENSE"
152-
rename "libraries_used_windows.txt", "libraries_used.txt"
151+
rename 'LICENSE_windows', 'LICENSE'
152+
rename 'libraries_used_windows.txt', 'libraries_used.txt'
153153
into "${buildDir}/jpackage/blobsaver"
154154
}
155155
} else jpackageImage.doLast {
@@ -161,23 +161,22 @@ jlink {
161161

162162
}
163163

164-
if (!os.isWindows() && findProperty('installerType') != "tar.gz") {
165-
assemble.dependsOn jpackage
166-
}
167-
if (findProperty('installerType') == "tar.gz") {
168-
jpackage.enabled = false
169-
assemble.dependsOn createLinuxTargz
164+
task createZip(type: Zip, dependsOn: jpackageImage) {
165+
if (os.isMacOsX()) {
166+
String arch = DefaultNativePlatform.currentArchitecture.amd64 ? 'intel' : 'arm'
167+
archiveFileName = "${project.name}-${arch}-${project.version}.zip"
168+
} else {
169+
archiveFileName = "${project.name}-${project.version}.zip"
170+
}
171+
from "${buildDir}/jpackage"
172+
destinationDirectory = file("${buildDir}/distributions/")
170173
}
171174

172175
task createLinuxTargz(type: Tar, dependsOn: jpackageImage) {
173176
archiveFileName = "blobsaver-${project.version}.tar.gz"
174177
compression = Compression.GZIP
175-
destinationDirectory = file("${buildDir}/distributions/")
176178
from "${buildDir}/jpackage/blobsaver"
177-
178-
if (os.isLinux()) {
179-
jpackage.finalizedBy createLinuxTargz
180-
}
179+
destinationDirectory = file("${buildDir}/distributions/")
181180
}
182181

183182
task windowsInstaller(dependsOn: jpackageImage) { // requires inno setup to be installed
@@ -191,12 +190,36 @@ task windowsInstaller(dependsOn: jpackageImage) { // requires inno setup to be i
191190
OutputDir: "${buildDir}\\distributions".toString()])
192191
}
193192
exec {
194-
commandLine "iscc", "/Qp", "${buildDir}\\jpackage\\blobsaver.iss"
193+
commandLine 'iscc', '/Qp', "${buildDir}\\jpackage\\blobsaver.iss"
195194
}
196195
delete "${buildDir}/jpackage/blobsaver.iss"
197196
}
197+
}
198198

199-
if (os.isWindows() && findProperty('installerType') != "portable") {
200-
assemble.dependsOn windowsInstaller
201-
}
199+
task bumpCaskPR(type: Exec) {
200+
commandLine 'brew', 'bump-cask-pr', 'blobsaver', '--no-audit', '--no-style', '--version', version
201+
}
202+
203+
if (!os.isWindows()) { // never do jpackage on windows
204+
assemble.dependsOn jpackage // will be disabled on other OS if installerType is set to certain values
205+
}
206+
if (findProperty('installerType') == 'tar.gz') {
207+
jpackage.enabled = false
208+
assemble.dependsOn createLinuxTargz
209+
}
210+
if (findProperty('installerType') == 'zip') {
211+
jpackage.enabled = false
212+
assemble.dependsOn createZip
213+
}
214+
if (findProperty('installerType') == 'portable') {
215+
jpackage.enabled = false
216+
}
217+
if (os.isMacOsX() && findProperty('installerType') == null) {
218+
jpackage.finalizedBy createZip
219+
}
220+
if (os.isLinux() && findProperty('installerType') == null) {
221+
jpackage.finalizedBy createLinuxTargz
202222
}
223+
if (os.isWindows() && findProperty('installerType') == null) {
224+
assemble.dependsOn windowsInstaller
225+
}

dist/windows/blobsaver.iss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#define MyAppName "@AppName@"
55
#define MyAppVersion "@AppVersion@"
66
#define MyAppPublisher "airsquared"
7-
#define MyAppURL "https://www.github.com/airsquared/blobsaver"
8-
#define MyAppExeName "blobsaver.exe"
7+
#define MyAppURL "https://www.github.com/airsquared/@AppName@"
8+
#define MyAppExeName "@AppName@.exe"
99
#define MyAppCopyright "@AppCopyright@"
1010
#define OutputDir "@OutputDir@"
1111

@@ -28,7 +28,7 @@ Uninstallable=not IsTaskSelected('portableMode')
2828
DefaultDirName={pf}\{#MyAppName}
2929
DisableProgramGroupPage=yes
3030
OutputDir={#OutputDir}
31-
OutputBaseFilename=blobsaver-{#MyAppVersion}
31+
OutputBaseFilename={#MyAppName}-{#MyAppVersion}
3232
SetupIconFile=blob.ico
3333
Compression=lzma
3434
SolidCompression=yes
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

src/main/java/airsquared/blobsaver/app/Background.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020

2121
import com.sun.jna.Platform;
2222

23-
import java.io.BufferedReader;
2423
import java.io.IOException;
25-
import java.io.InputStreamReader;
2624
import java.io.UncheckedIOException;
2725
import java.nio.file.Files;
2826
import java.nio.file.Path;
@@ -73,7 +71,7 @@ private static void macosBackgroundFile() {
7371
"</dict>" +
7472
"</plist>";
7573
try {
76-
Files.createDirectories(Path.of(System.getProperty("user.home"), "Library/LaunchAgents"));
74+
Files.createDirectories(plistFilePath.getParent());
7775
Files.writeString(plistFilePath, plist);
7876
System.out.println("Wrote to: " + plistFilePath);
7977
} catch (IOException e) {
@@ -272,8 +270,7 @@ private static void execute(String program, String... args) {
272270
}
273271

274272
private static boolean outputMatches(Predicate<String> predicate, String... args) {
275-
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
276-
new ProcessBuilder(args).redirectErrorStream(true).start().getInputStream()))) {
273+
try (var reader = new ProcessBuilder(args).redirectErrorStream(true).start().inputReader()) {
277274
return reader.lines().anyMatch(predicate);
278275
} catch (IOException e) {
279276
throw new UncheckedIOException(e);

src/main/java/airsquared/blobsaver/app/Utils.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@
3737
import javafx.stage.Window;
3838
import org.apache.commons.compress.archivers.zip.ZipFile;
3939

40-
import java.io.BufferedReader;
4140
import java.io.File;
4241
import java.io.IOException;
43-
import java.io.InputStreamReader;
4442
import java.io.PrintWriter;
4543
import java.io.StringWriter;
4644
import java.io.UncheckedIOException;
@@ -57,6 +55,7 @@
5755
import java.util.concurrent.ExecutorService;
5856
import java.util.concurrent.Executors;
5957
import java.util.function.Consumer;
58+
import java.util.stream.Collectors;
6059
import java.util.stream.Stream;
6160
import java.util.stream.StreamSupport;
6261

@@ -224,21 +223,18 @@ static String executeProgram(List<String> command) throws IOException {
224223

225224
static String executeProgram(List<String> command, boolean print) throws IOException {
226225
Process process = new ProcessBuilder(command).redirectErrorStream(true).start();
227-
StringBuilder logBuilder = new StringBuilder();
228-
229-
try (var reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
230-
String line;
231-
while ((line = reader.readLine()) != null) {
232-
if (print) {
233-
System.out.println(line);
234-
}
235-
logBuilder.append(line).append("\n");
226+
String log;
227+
try (var reader = process.inputReader()) {
228+
if (print) {
229+
log = reader.lines().peek(System.out::println).collect(Collectors.joining("\n"));
230+
} else {
231+
log = reader.lines().collect(Collectors.joining("\n"));
236232
}
237233
process.waitFor();
234+
return log;
238235
} catch (InterruptedException e) {
239-
e.printStackTrace();
236+
throw new RuntimeException(e);
240237
}
241-
return logBuilder.toString();
242238
}
243239

244240
static void reportError(Alert alert) {

0 commit comments

Comments
 (0)