From 9fdb0d52755217313ee142515cea299f23a5c2d9 Mon Sep 17 00:00:00 2001 From: "obed.vazquez" Date: Thu, 27 Nov 2025 17:32:00 -0600 Subject: [PATCH 1/3] feat(tts): prefer PowerShell TTS with VBS fallback Prefer PowerShell System.Speech for TTS and fall back to a temporary VBS executed with cscript when needed.\n\nAlso updated CI workflow to build the project and upload generated JARs to the GitHub Release for version tags.\n\nFiles changed: WinCommandExecutor.java, .github/workflows/release-on-version-change.yml --- .github/maven-settings.xml | 11 +++ .github/workflows/pull_request.yml | 19 ++++ .../workflows/release-on-version-change.yml | 91 +++++++++++++++++++ .gitignore | 4 + README.md | 2 +- pom.xml | 2 +- .../white_sdev/utils/WinCommandExecutor.java | 41 ++++++++- 7 files changed, 163 insertions(+), 7 deletions(-) create mode 100644 .github/maven-settings.xml create mode 100644 .github/workflows/pull_request.yml create mode 100644 .github/workflows/release-on-version-change.yml diff --git a/.github/maven-settings.xml b/.github/maven-settings.xml new file mode 100644 index 0000000..4daffea --- /dev/null +++ b/.github/maven-settings.xml @@ -0,0 +1,11 @@ + + + + nexus + ${env.NEXUS_USERNAME} + ${env.NEXUS_PASSWORD} + + + \ No newline at end of file diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..1113efd --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,19 @@ +name: Java CI + +on: + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v2 + with: + java-version: '19' + distribution: 'adopt' + + - name: Build and test + run: mvn -B verify diff --git a/.github/workflows/release-on-version-change.yml b/.github/workflows/release-on-version-change.yml new file mode 100644 index 0000000..3113f36 --- /dev/null +++ b/.github/workflows/release-on-version-change.yml @@ -0,0 +1,91 @@ +name: Detect version change and create tag + +on: + push: + branches: + - main + +jobs: + detect-version: + runs-on: ubuntu-latest + permissions: + contents: write + + outputs: + release: ${{ steps.decide.outputs.release }} + + + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 # needed so we can create tags + + + - name: Install libxml2-utils + run: sudo apt-get update && sudo apt-get install -y libxml2-utils + + - name: Extract version from pom.xml + id: version + run: | + VERSION=$(xmllint --xpath "string(/*[local-name()='project']/*[local-name()='version'])" pom.xml) + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Set up JDK 19 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '19' + + - name: Build package + run: | + mvn -B -DskipTests package + + - name: Get previous version from last tag (if any) + id: prev + run: | + LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") + echo "lasttag=$LAST_TAG" >> $GITHUB_OUTPUT + + - name: Determine whether to release + id: decide + run: | + CUR="${{ steps.version.outputs.version }}" + LAST="${{ steps.prev.outputs.lasttag }}" + LAST="${LAST#v}" # strip leading v if present + + if [ "$CUR" = "$LAST" ]; then + echo "release=false" >> $GITHUB_OUTPUT + else + echo "release=true" >> $GITHUB_OUTPUT + fi + + - name: Create tag and GitHub Release (only if version changed) + id: create_release + if: steps.decide.outputs.release == 'true' + uses: softprops/action-gh-release@v1 + with: + tag_name: v${{ steps.version.outputs.version }} + name: Release v${{ steps.version.outputs.version }} + generate_release_notes: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload fat JAR to Release + if: steps.decide.outputs.release == 'true' + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: target/win-command-executor/bin/win-command-executor.jar + asset_name: win-command-executor-${{ steps.version.outputs.version }}.jar + asset_content_type: application/java-archive + + - name: Upload root JAR to Release + if: steps.decide.outputs.release == 'true' + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: target/win-command-executor-${{ steps.version.outputs.version }}.jar + asset_name: win-command-executor-${{ steps.version.outputs.version }}-raw.jar + asset_content_type: application/java-archive diff --git a/.gitignore b/.gitignore index c06f585..3b8b671 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,10 @@ target\ .springBeans .sts4-cache + +### VS CODE ### +.vscode/ + ### IntelliJ IDEA ### .idea *.iws diff --git a/README.md b/README.md index ad515e4..393afb6 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This application will serve as a tool to help you execute sequential commmands i ## 1) What is this repository for? ### 1.1) Quick summary -Version: `0.1-SNAPSHOT` +Version: `1.0.1` #### 1.1.1) How to use You can call the jar and send arguments with the following format: diff --git a/pom.xml b/pom.xml index fb593f7..4b53265 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ org.white_sdev.utils win-command-executor - 1.0.0 + 1.0.1 ${project.groupId}:${project.artifactId} Command executor for windows diff --git a/src/main/java/org/white_sdev/utils/WinCommandExecutor.java b/src/main/java/org/white_sdev/utils/WinCommandExecutor.java index 8c1f331..02f4208 100644 --- a/src/main/java/org/white_sdev/utils/WinCommandExecutor.java +++ b/src/main/java/org/white_sdev/utils/WinCommandExecutor.java @@ -90,11 +90,42 @@ static boolean sendTextToSpeechMessage(String textToSpeechMessage) { String logID = "::sendTextToSpeechMessage([textToSpeechMessage]): "; logID = ""; log.trace("{}Start - textToSpeechMessage:{}", logID, textToSpeechMessage); - String textToSpeechCommand = String.format("mshta vbscript:Execute(" + - "\"CreateObject(\"\"SAPI.SpVoice\"\").Speak(\"\"%s\"\")(window.close)\")", textToSpeechMessage); - var result = executeCommandInConsole(textToSpeechCommand); - log.trace("{}Finish - result:{}", logID, result); - return result; + + if (textToSpeechMessage == null || textToSpeechMessage.isBlank()) { + log.warn("Empty TTS message"); + return false; + } + + // Prefer PowerShell System.Speech (more robust on many Windows setups) + try { + // Escape single quotes for PowerShell single-quoted string by doubling them + String safeForPs = textToSpeechMessage.replace("'", "''"); + String psCommand = String.format("powershell.exe -NoProfile -Command \"Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('%s')\"", safeForPs); + boolean psResult = executeCommandInConsole(psCommand); + log.trace("PowerShell TTS result: {}", psResult); + if (psResult) return true; + log.warn("PowerShell TTS returned false, attempting mshta fallback"); + } catch (Exception e) { + log.warn("PowerShell TTS attempt threw an exception", e); + } + + // Fallback: create a temporary .vbs file and run it with cscript (more robust than mshta) + try { + String safeForVbs = textToSpeechMessage.replace("\"", "\"\""); + String vbsContent = "CreateObject(\"SAPI.SpVoice\").Speak \"" + safeForVbs + "\""; + java.nio.file.Path temp = java.nio.file.Files.createTempFile("tts", ".vbs"); + java.nio.file.Files.writeString(temp, vbsContent); + String cscriptCmd = String.format("cscript //NoLogo %s", temp.toAbsolutePath().toString()); + boolean vbsResult = executeCommandInConsole(cscriptCmd); + try { + java.nio.file.Files.deleteIfExists(temp); + } catch (Exception ignore) {} + log.trace("vbs TTS result: {}", vbsResult); + return vbsResult; + } catch (Exception e) { + log.error("VBS TTS attempt failed", e); + return false; + } } @SuppressWarnings("all") From a575e6a94cbbae6d56201c02183519204964ccf9 Mon Sep 17 00:00:00 2001 From: "obed.vazquez" Date: Thu, 27 Nov 2025 17:41:44 -0600 Subject: [PATCH 2/3] action update --- .github/workflows/release-on-version-change.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/release-on-version-change.yml b/.github/workflows/release-on-version-change.yml index 3113f36..f42ca82 100644 --- a/.github/workflows/release-on-version-change.yml +++ b/.github/workflows/release-on-version-change.yml @@ -33,11 +33,16 @@ jobs: echo "version=$VERSION" >> $GITHUB_OUTPUT - name: Set up JDK 19 + id: setup-java uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '19' + - name: Export JAVA19_HOME for maven-antrun + run: | + echo "JAVA19_HOME=${{ steps.setup-java.outputs.java-home }}" >> $GITHUB_ENV + - name: Build package run: | mvn -B -DskipTests package From 3044c82cdd3ded3c61c75dd253ac34b966b18226 Mon Sep 17 00:00:00 2001 From: "obed.vazquez" Date: Thu, 27 Nov 2025 18:55:35 -0600 Subject: [PATCH 3/3] ci(pull_request): setup JDK 19 and export JAVA19_HOME for POM compatibility --- .github/workflows/pull_request.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 1113efd..4443ec6 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -10,10 +10,16 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-java@v2 + - name: Set up JDK 19 + id: setup-java + uses: actions/setup-java@v4 with: + distribution: 'temurin' java-version: '19' - distribution: 'adopt' + + - name: Export JAVA19_HOME for build + run: | + echo "JAVA19_HOME=${{ steps.setup-java.outputs.java-home }}" >> $GITHUB_ENV - name: Build and test run: mvn -B verify