Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name-template: 'ESP Flasher v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'

categories:
- title: 'New Features'
labels: [ 'feat', 'feature', 'enhancement' ]
- title: 'Bug Fixes'
labels: [ 'fix', 'bug', 'bugfix' ]
- title: 'Performance'
labels: [ 'perf', 'performance' ]
- title: 'Maintenance'
labels: [ 'chore', 'deps', 'refactor', 'ci' ]
- title: 'Documentation'
labels: [ 'docs', 'documentation' ]

change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
change-title-escapes: '\<*_&'

version-resolver:
major:
labels: [ 'breaking', 'major' ]
minor:
labels: [ 'feat', 'feature', 'enhancement' ]
patch:
labels: [ 'fix', 'bug', 'bugfix', 'perf', 'chore', 'deps', 'docs', 'ci' ]
default: patch

template: |
## What's Changed

$CHANGES

**Full Changelog**: https://github.com/AjinkyaGokhale/esp-flasher-java/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI

on:
push:
branches: [ main, master, dev ]
pull_request:
branches: [ main, master, dev ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'zulu'
cache: 'maven'
- name: Build, test, and analyse
run: ./mvnw -B verify
19 changes: 19 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Release Drafter

on:
push:
branches: [ main, master ]
pull_request:
types: [ opened, reopened, synchronize ]

permissions:
contents: write
pull-requests: write

jobs:
update-release-draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@
<version>5.14.0</version>
</dependency>

<!-- SpotBugs annotations for @SuppressFBWarnings -->
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
<version>4.8.6</version>
<scope>compile</scope>
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down Expand Up @@ -197,6 +205,23 @@
</executions>
</plugin>

<!-- SpotBugs static analysis -->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.8.6.4</version>
<configuration>
<effort>Default</effort>
<threshold>Medium</threshold>
<failOnError>true</failOnError>
</configuration>
<executions>
<execution>
<goals><goal>check</goal></goals>
</execution>
</executions>
</plugin>

<!-- jpackage -->
<plugin>
<groupId>org.panteleyev</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -40,7 +41,7 @@ public void startFlashing(FlashConfig config, FlashListener listener) {

Pattern pattern = Pattern.compile("(\\d+(?:\\.\\d+)?)\\s*%");
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(currentProcess.getInputStream()))) {
new InputStreamReader(currentProcess.getInputStream(), StandardCharsets.UTF_8))) {
String line;
while ((line = reader.readLine()) != null) {
if (isCancelled) break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
import com.ajinkyagokhale.espflasher.model.AppSettings;
import com.ajinkyagokhale.espflasher.model.FlashResult;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

public class FlashLogger {

private static final String HEADER = "timestamp,port,mac_address,status,message";

private final AppSettings settings;

@SuppressFBWarnings("EI_EXPOSE_REP2")
public FlashLogger(AppSettings settings) {
this.settings = settings;
}
Expand All @@ -22,12 +26,15 @@ public void append(FlashResult result) {
if (!settings.isLogFileEnabled()) return;

File dir = new File(settings.getLogFilePath());
if (!dir.exists()) dir.mkdirs();
if (!dir.exists() && !dir.mkdirs()) {
System.err.println("Failed to create log directory: " + dir);
return;
}

File logFile = new File(dir, "flash-log.csv");
boolean writeHeader = !logFile.exists() || logFile.length() == 0;

try (PrintWriter pw = new PrintWriter(new FileWriter(logFile, true))) {
try (PrintWriter pw = new PrintWriter(new FileWriter(logFile, StandardCharsets.UTF_8, true))) {
if (writeHeader) pw.println(HEADER);
pw.printf("%s,%s,%s,%s,\"%s\"%n",
result.getTimeStamp(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.ajinkyagokhale.espflasher.service;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
Expand Down Expand Up @@ -164,7 +166,7 @@ public boolean installEsptool(Consumer<String> onLine) {
.redirectErrorStream(true)
.start();

try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8))) {
String line;
while ((line = reader.readLine()) != null) {
if (onLine != null) onLine.accept(line);
Expand All @@ -173,7 +175,8 @@ public boolean installEsptool(Consumer<String> onLine) {
p.waitFor();
checkAll();
return esptoolCmd != null;
} catch (Exception e) {
} catch (IOException | InterruptedException e) {
Thread.currentThread().interrupt();
return false;
}
}
Expand All @@ -182,10 +185,11 @@ private String runCommand(String... args) {
Process p = new ProcessBuilder(args)
.redirectErrorStream(true)
.start();
String output = new String(p.getInputStream().readAllBytes()).strip();
String output = new String(p.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
int exit = p.waitFor();
return (exit == 0 && !output.isEmpty()) ? output : null;
} catch (Exception e) {
} catch (IOException | InterruptedException e) {
Thread.currentThread().interrupt();
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ajinkyagokhale.espflasher.service;

import com.ajinkyagokhale.espflasher.model.AppSettings;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import tools.jackson.databind.ObjectMapper;

import java.io.File;
Expand All @@ -23,8 +24,9 @@ public void save() {
try {
// create directory if doesn't exist
File dir = new File(SETTINGS_DIR);
if (!dir.exists()) {
dir.mkdirs();
if (!dir.exists() && !dir.mkdirs()) {
System.err.println("Failed to create settings directory: " + dir);
return;
}

mapper.writerWithDefaultPrettyPrinter()
Expand All @@ -35,6 +37,7 @@ public void save() {
}
}

@SuppressFBWarnings("EI_EXPOSE_REP")
public AppSettings load() {
try {
File file = new File(SETTINGS_FILE);
Expand All @@ -48,6 +51,7 @@ public AppSettings load() {
return settings;
}

@SuppressFBWarnings("EI_EXPOSE_REP")
public AppSettings getSettings() {
return settings;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.ajinkyagokhale.espflasher.service;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.json.JSONArray;
import org.json.JSONObject;

import java.awt.Desktop;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
Expand Down Expand Up @@ -39,7 +41,7 @@ public String currentVersion() {
Properties props = new Properties();
props.load(in);
return props.getProperty("version", "0.0.0").trim();
} catch (Exception e) {
} catch (IOException e) {
return "0.0.0";
}
}
Expand Down Expand Up @@ -71,7 +73,8 @@ public Optional<Release> latestRelease() {
}
}
return Optional.empty();
} catch (Exception e) {
} catch (IOException | InterruptedException e) {
Thread.currentThread().interrupt();
return Optional.empty();
}
}
Expand All @@ -88,6 +91,7 @@ public boolean isNewer(String latest, String current) {
return false;
}

@SuppressFBWarnings("DM_EXIT")
public boolean downloadAndLaunch(Release release, ProgressListener listener, AtomicBoolean cancelled)
throws Exception {
String ext = assetExtension();
Expand Down Expand Up @@ -126,7 +130,7 @@ public boolean downloadAndLaunch(Release release, ProgressListener listener, Ato
return false;
}
Desktop.getDesktop().open(target.toFile());
System.exit(0);
System.exit(0); // intentional: installer takes over, JVM must exit
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.ajinkyagokhale.espflasher.model.FlashConfig;
import com.ajinkyagokhale.espflasher.model.FlashResult;
import com.ajinkyagokhale.espflasher.service.*;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import javafx.application.Application;
import javafx.application.Platform;
Expand All @@ -29,6 +30,7 @@

import java.awt.*;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -852,15 +854,15 @@ private boolean isDarkMode() {
Process p = Runtime.getRuntime().exec(
new String[]{"defaults", "read", "-g", "AppleInterfaceStyle"}
);
String result = new String(p.getInputStream().readAllBytes()).strip();
String result = new String(p.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
return result.equalsIgnoreCase("dark");
} else if (os.contains("windows")) {
Process p = Runtime.getRuntime().exec(new String[]{
"reg", "query",
"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
"/v", "AppsUseLightTheme"
});
String result = new String(p.getInputStream().readAllBytes());
String result = new String(p.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
return result.contains("0x0");
}
} catch (Exception e) {
Expand Down Expand Up @@ -1130,6 +1132,7 @@ void DwmSetWindowAttribute(com.sun.jna.platform.win32.WinDef.HWND hwnd, int attr
com.sun.jna.ptr.IntByReference value, int size);
}

@SuppressFBWarnings("DE_MIGHT_IGNORE")
private void applyDarkTitleBar(Stage stage) {
if (!System.getProperty("os.name", "").toLowerCase().contains("win")) return;
try {
Expand All @@ -1155,6 +1158,7 @@ private void checkForUpdates() {
worker.start();
}

@SuppressFBWarnings("DM_EXIT")
private void promptForcedUpdate(UpdateService updates, UpdateService.Release release, String current) {
ButtonType updateNow = new ButtonType("Update Now", ButtonBar.ButtonData.OK_DONE);
ButtonType quit = new ButtonType("Quit", ButtonBar.ButtonData.CANCEL_CLOSE);
Expand Down
Loading