diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..2f05af9 --- /dev/null +++ b/.envrc @@ -0,0 +1,9 @@ +#!/bin/bash + +# Automatically sets up your devbox environment whenever you cd into this +# directory via our direnv integration: + +eval "$(devbox generate direnv --print-envrc)" + +# check out https://www.jetpack.io/devbox/docs/ide_configuration/direnv/ +# for more details diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..4ca67ad --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: gomod + directory: / + schedule: + interval: daily \ No newline at end of file diff --git a/.github/release-please/config.json b/.github/release-please/config.json new file mode 100644 index 0000000..a035c39 --- /dev/null +++ b/.github/release-please/config.json @@ -0,0 +1,65 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "changelog-sections": [ + { + "section": "🎉 Features", + "type": "feat" + }, + { + "section": "🐛 Bug Fixes", + "type": "fix" + }, + { + "section": "⚡ Performance Improvements", + "type": "perf" + }, + { + "section": "🔗 Dependencies", + "type": "deps" + }, + { + "section": "📝 Documentation", + "type": "docs" + }, + { + "section": "🏗️ Build System", + "type": "build" + }, + { + "section": "🤖 Continuous Integration", + "type": "ci" + }, + { + "section": "🔧 Miscellaneous Chores", + "type": "chore" + }, + { + "section": "⏪ Reverts", + "type": "revert" + }, + { + "section": "✅ Tests", + "type": "test" + }, + { + "section": "💄 Style", + "type": "style" + }, + { + "section": "♻️ Code Refactoring", + "type": "refactor" + } + ], + "include-component-in-tag": false, + "packages": { + ".": { + "release-type": "simple", + "include-v-in-tag": true, + "package-name": "jbinary", + "extra-files": [ + "readme.md" + ] + } + }, + "release-type": "simple" +} \ No newline at end of file diff --git a/.github/release-please/manifest.json b/.github/release-please/manifest.json new file mode 100644 index 0000000..e58f3d1 --- /dev/null +++ b/.github/release-please/manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.0.6" +} \ No newline at end of file diff --git a/.github/workflows/dependabot-automerge.yml b/.github/workflows/dependabot-automerge.yml new file mode 100644 index 0000000..c5274d2 --- /dev/null +++ b/.github/workflows/dependabot-automerge.yml @@ -0,0 +1,23 @@ +name: Dependabot auto-merge +on: pull_request + +permissions: + contents: write + pull-requests: write + +jobs: + dependabot: + runs-on: ubuntu-latest + if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'segator/jbinary' + steps: + - name: Dependabot metadata + id: metadata + uses: dependabot/fetch-metadata@d7267f607e9d3fb96fc2fbe83e0af444713e90b7 + with: + github-token: "${{ secrets.RELEASE_PLEASE_TOKEN }}" + - name: Enable auto-merge for Dependabot PRs + #if: steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor' + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GH_TOKEN: ${{secrets.RELEASE_PLEASE_TOKEN}} \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..9766516 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,61 @@ +name: Build And Push + +on: + pull_request: + branches: + - master + push: + branches: + - master + +permissions: + contents: write + pull-requests: write + packages: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23.10' + - name: Release + id: release + uses: googleapis/release-please-action@v4.2.0 + with: + token: ${{ secrets.RELEASE_PLEASE_TOKEN }} + config-file: .github/release-please/config.json + manifest-file: .github/release-please/manifest.json + - + name: GoReleaser snapshot + uses: goreleaser/goreleaser-action@v6 + if: ${{ ! steps.release.outputs.release_created }} + with: + distribution: goreleaser + # 'latest', 'nightly', or a semver + version: '~> v2' + args: release --snapshot --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - + name: GoReleaser + uses: goreleaser/goreleaser-action@v6 + if: ${{ steps.release.outputs.release_created }} + with: + distribution: goreleaser + # 'latest', 'nightly', or a semver + version: '~> v2' + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Upload Github release assets + if: ${{ steps.release.outputs.release_created }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh release upload ${{ steps.release.outputs.tag_name }} ./dist/jbinary_* --clobber \ No newline at end of file diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000..77d449e --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,14 @@ +name: "Close stale issues and PRs" +on: + schedule: + - cron: "30 1 * * *" + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v9 + with: + stale-issue-message: "This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 30 days." + days-before-stale: 120 + days-before-close: 30 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4ddf2a3..d522ef4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea/ jbinary.exe +# Added by goreleaser init: +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..f61d991 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,23 @@ +version: 2 +project_name: jbinary +builds: + - + goos: + - linux + - windows + goarch: + - amd64 + - arm64 + no_unique_dist_dir: true + binary: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' + +checksum: + # This is the crucial addition. It tells GoReleaser to generate + # a checksum file for each artifact individually. + split: true + + # Now that `split` is true, this template will be run for each binary, + # and {{ .ArtifactName }} will be correctly populated. + name_template: '{{ .ArtifactName }}.sha256' + + algorithm: sha256 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1171bc9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -language: go -go: - - 1.10.x -env: - - "PATH=/home/travis/gopath/bin:$PATH" - - -before_install: - - go get github.com/mitchellh/gox - - go get github.com/tcnksm/ghr - - go get github.com/pkg/errors -script: -- go build -install: -- gox -osarch="linux/amd64" -osarch="windows/amd64" -output "dist/{{.OS}}_{{.Arch}}_{{.Dir}}_$TRAVIS_BRANCH" -deploy: - provider: releases - file_glob: true - api_key: $GITHUB_TOKEN - file: dist/* - skip_cleanup: true - on: - tags: true \ No newline at end of file diff --git a/Readme.md b/Readme.md index 2c6af1e..81c6856 100644 --- a/Readme.md +++ b/Readme.md @@ -61,14 +61,14 @@ A single windows linux binary is shiped out of the box. ## Install ### Linux ``` -wget https://github.com/segator/jbinary/releases/download/0.0.5/linux_amd64_jbinary_0.0.5-ALPHA5 -O /usr/bin/JBinary && chmod 777 /usr/bin/JBinary +wget https://github.com/segator/jbinary/releases/download/0.0.6/linux_amd64_jbinary_0.0.6-ALPHA5 -O /usr/bin/JBinary && chmod 777 /usr/bin/JBinary # x-release-please-version ``` ### Windows Execute as admin ``` [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -Invoke-WebRequest -Uri "https://github.com/segator/jbinary/releases/download/0.0.5/windows_amd64_jbinary_0.0.5-ALPHA5.exe" -OutFile "C:\Windows\System32\JBinary.exe" +Invoke-WebRequest -Uri "https://github.com/segator/jbinary/releases/download/0.0.6/windows_amd64_jbinary_0.0.6-ALPHA5.exe" -OutFile "C:\Windows\System32\JBinary.exe" # x-release-please-version ``` ## Example ```bash diff --git a/devbox.json b/devbox.json new file mode 100644 index 0000000..76d9c1b --- /dev/null +++ b/devbox.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.14.0/.schema/devbox.schema.json", + "packages": [ + "go@latest", + "goreleaser@latest" + ], + "shell": { + "init_hook": [ + "echo 'Welcome to devbox!' > /dev/null" + ], + "scripts": { + "test": [ + "echo \"Error: no test specified\" && exit 1" + ] + } + } +} diff --git a/devbox.lock b/devbox.lock new file mode 100644 index 0000000..21af4c4 --- /dev/null +++ b/devbox.lock @@ -0,0 +1,104 @@ +{ + "lockfile_version": "1", + "packages": { + "github:NixOS/nixpkgs/nixpkgs-unstable": { + "resolved": "github:NixOS/nixpkgs/cdc68935eba9f86d155585fdf6f17af6824f38ac?lastModified=1749523198&narHash=sha256-How2kQw0psKmCdXgojc95Sf3K5maHB3qfINxTZFCAPM%3D" + }, + "go@latest": { + "last_modified": "2025-05-16T20:19:48Z", + "resolved": "github:NixOS/nixpkgs/12a55407652e04dcf2309436eb06fef0d3713ef3#go", + "source": "devbox-search", + "version": "1.24.3", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/ps3admpzmc1ryvn9q7sw5xfd94dkrb3f-go-1.24.3", + "default": true + } + ], + "store_path": "/nix/store/ps3admpzmc1ryvn9q7sw5xfd94dkrb3f-go-1.24.3" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/45bnqhyyq40p91k3cjw0farx3hn1swx6-go-1.24.3", + "default": true + } + ], + "store_path": "/nix/store/45bnqhyyq40p91k3cjw0farx3hn1swx6-go-1.24.3" + }, + "x86_64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/9z2kb6hxij7pqi0fgcn9ijhpb7ajpazs-go-1.24.3", + "default": true + } + ], + "store_path": "/nix/store/9z2kb6hxij7pqi0fgcn9ijhpb7ajpazs-go-1.24.3" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/5xvi25nqmbrg58aixp4zgczilfnp7pwg-go-1.24.3", + "default": true + } + ], + "store_path": "/nix/store/5xvi25nqmbrg58aixp4zgczilfnp7pwg-go-1.24.3" + } + } + }, + "goreleaser@latest": { + "last_modified": "2025-05-16T20:19:48Z", + "resolved": "github:NixOS/nixpkgs/12a55407652e04dcf2309436eb06fef0d3713ef3#goreleaser", + "source": "devbox-search", + "version": "2.9.0", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/lqihz0f2h9zjqlhk74cayb9l74zgkxj2-goreleaser-2.9.0", + "default": true + } + ], + "store_path": "/nix/store/lqihz0f2h9zjqlhk74cayb9l74zgkxj2-goreleaser-2.9.0" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/wg1ndxx3hq7lcxg0nkzgs3myrflr5jm0-goreleaser-2.9.0", + "default": true + } + ], + "store_path": "/nix/store/wg1ndxx3hq7lcxg0nkzgs3myrflr5jm0-goreleaser-2.9.0" + }, + "x86_64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/v17lq7ap19pajdhp04n4b7p4y5f2mxrr-goreleaser-2.9.0", + "default": true + } + ], + "store_path": "/nix/store/v17lq7ap19pajdhp04n4b7p4y5f2mxrr-goreleaser-2.9.0" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/rvjwgy6zz5qwipcm709jvf3j38r552nw-goreleaser-2.9.0", + "default": true + } + ], + "store_path": "/nix/store/rvjwgy6zz5qwipcm709jvf3j38r552nw-goreleaser-2.9.0" + } + } + } + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ae75bea --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/segator/jbinary + +go 1.23.10 + +require github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7c401c3 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/jbinary.go b/main.go similarity index 60% rename from jbinary.go rename to main.go index 7663f58..0e3e0f2 100644 --- a/jbinary.go +++ b/main.go @@ -8,7 +8,6 @@ import ( "compress/gzip" "flag" "fmt" - "github.com/pkg/errors" "io" "io/ioutil" "log" @@ -21,49 +20,49 @@ import ( "syscall" "text/template" "time" + + "github.com/pkg/errors" ) const ( - nameSourceFile = "data.go" + nameSourceFile = "data.go" nameVersionInfoFile = "versioninfo.json" - nameManifestFile = "manifest.xml" + nameManifestFile = "manifest.xml" ) var namePackage string var ( flagJavaAppPath = flag.String("jar", path.Join(".", "application.jar"), "Path of the java application") - flagDest = flag.String("build", ".", "The destination path of the generated package.") - flagPlatform = flag.String("platform", "windows", "Operating system(linux|windows)") - flagArchitecture = flag.String("architecture", "amd64", "Building Architecture (amd64|386)") - flagJreVersio = flag.String("jre-version", "1.8.0_131", "The destination path of the generated package.") - flagJavaType = flag.String("java-type", "jre", "Java type jre|jdk") - flagNoMtime = flag.Bool("ignore-modtime", false, "Ignore modification times on files.") - flagNoCompress = flag.Bool("no-compress", false, "Do not use compression to shrink the files.") - flagJVMArguments = flag.String("jvm-arguments", "", "JVM Arguments") - flagAppArguments = flag.String("app-arguments", "", "App Arguments") - flagPkg = flag.String("output-name", "application", "Name of the generated package") - flagDebugPort = flag.Int64("jre-debug-port", 21500, "Debug port to listen if the generated binary is executed with cli -debug") - flagServerURL = flag.String("java-server-url","https://artifacts.alfresco.com/nexus/content/repositories/public","Server base URL to look for java download") - flagDefaultDownloadURL="{serverURL}/com/oracle/java/{javaType}/{javaVersion}/{javaType}-{javaVersion}-{platform}{architecture}.tgz" - jreDownloadURL = flag.String("java-download-link",flagDefaultDownloadURL,"Link where to download java distribution format:"+flagDefaultDownloadURL) + flagDest = flag.String("build", ".", "The destination path of the generated package.") + flagPlatform = flag.String("platform", "windows", "Operating system(linux|windows)") + flagArchitecture = flag.String("architecture", "amd64", "Building Architecture (amd64|386)") + flagJreVersio = flag.String("jre-version", "1.8.0_131", "The destination path of the generated package.") + flagJavaType = flag.String("java-type", "jre", "Java type jre|jdk") + flagNoMtime = flag.Bool("ignore-modtime", false, "Ignore modification times on files.") + flagNoCompress = flag.Bool("no-compress", false, "Do not use compression to shrink the files.") + flagJVMArguments = flag.String("jvm-arguments", "", "JVM Arguments") + flagAppArguments = flag.String("app-arguments", "", "App Arguments") + flagPkg = flag.String("output-name", "application", "Name of the generated package") + flagDebugPort = flag.Int64("jre-debug-port", 21500, "Debug port to listen if the generated binary is executed with cli -debug") + flagServerURL = flag.String("java-server-url", "https://artifacts.alfresco.com/nexus/content/repositories/public", "Server base URL to look for java download") + flagDefaultDownloadURL = "{serverURL}/com/oracle/java/{javaType}/{javaVersion}/{javaType}-{javaVersion}-{platform}{architecture}.tgz" + jreDownloadURL = flag.String("java-download-link", flagDefaultDownloadURL, "Link where to download java distribution format:"+flagDefaultDownloadURL) //https://artifacts.alfresco.com/nexus/content/repositories/public/com/oracle/java/jre/1.8.0_131/jre-1.8.0_131-win64.tgz - flagWinDescription = flag.String("win-description", "no description", "Windows Application description") - flagWinCopyright = flag.String("win-copyright", "no copyright", "Windows Application copyright") - flagWinCompany = flag.String("win-company", "no company", "Windows Application company name") - flagWinIconPath = flag.String("win-icon-path", "", "icon path") - flagWinProductName = flag.String("win-product-name", "product name", "Windows Application product name") - flagWinProductVersion = flag.String("win-product-version", "1.0.0.0", "Windows Application product version") - flagWinMajorVersion = flag.String("win-version-major", "1", "Windows Application Major version") - flagWinMinorVersion = flag.String("win-version-minor", "0", "Windows Application Minor version") - flagWinPatchVersion = flag.String("win-version-patch", "0", "Windows Application Patch version") - flagWinBuildVersion = flag.String("win-version-build", "0", "Windows Application Build version") - flagWinExecutionLevel = flag.String("win-invoker", "asInvoker", "Windows Invoker type asInvoker|requireAdministrator default(asInvoker)") - flagWinExecutionBehaviour = flag.String("win-execution-behaviour", "console", "Default behaviour to run app, in gui mode no console is shown but you can't execute by console or capture stdout, (console|gui) default(console)") + flagWinDescription = flag.String("win-description", "no description", "Windows Application description") + flagWinCopyright = flag.String("win-copyright", "no copyright", "Windows Application copyright") + flagWinCompany = flag.String("win-company", "no company", "Windows Application company name") + flagWinIconPath = flag.String("win-icon-path", "", "icon path") + flagWinProductName = flag.String("win-product-name", "product name", "Windows Application product name") + flagWinProductVersion = flag.String("win-product-version", "1.0.0.0", "Windows Application product version") + flagWinMajorVersion = flag.String("win-version-major", "1", "Windows Application Major version") + flagWinMinorVersion = flag.String("win-version-minor", "0", "Windows Application Minor version") + flagWinPatchVersion = flag.String("win-version-patch", "0", "Windows Application Patch version") + flagWinBuildVersion = flag.String("win-version-build", "0", "Windows Application Build version") + flagWinExecutionLevel = flag.String("win-invoker", "asInvoker", "Windows Invoker type asInvoker|requireAdministrator default(asInvoker)") + flagWinExecutionBehaviour = flag.String("win-execution-behaviour", "console", "Default behaviour to run app, in gui mode no console is shown but you can't execute by console or capture stdout, (console|gui) default(console)") flagWinExecutionBehaviourConsoleArgs = flag.String("win-execution-enable-console-behaviour-args", "-console;-terminal", "Arguments that will force console mode in case of default behaviour gui, default (-console;-terminal)") - - ) // mtimeDate holds the arbitrary mtime that we assign to files when @@ -72,67 +71,67 @@ var mtimeDate = time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC) func main() { flag.Parse() - javaAppPathAbs,_:=filepath.Abs(*flagJavaAppPath) + javaAppPathAbs, _ := filepath.Abs(*flagJavaAppPath) namePackage = *flagPkg //Create work dir - tempWorkFolder, _ :=ioutil.TempDir("", "jbinary") - fmt.Printf("Created Working folder %s\n",tempWorkFolder) + tempWorkFolder, _ := ioutil.TempDir("", "jbinary") + fmt.Printf("Created Working folder %s\n", tempWorkFolder) os.MkdirAll(tempWorkFolder, 0755) downloadJRE(tempWorkFolder) - fmt.Printf("Java application:%s\n",javaAppPathAbs) - Copy(javaAppPathAbs,filepath.Join(tempWorkFolder,"application.jar")) + fmt.Printf("Java application:%s\n", javaAppPathAbs) + Copy(javaAppPathAbs, filepath.Join(tempWorkFolder, "application.jar")) fmt.Println("Generating golang source class") - file, err := generateSource(*flagJVMArguments,*flagAppArguments,tempWorkFolder) + file, err := generateSource(*flagJVMArguments, *flagAppArguments, tempWorkFolder) if err != nil { - exitWithError(err,1) + exitWithError(err, 1) } destDir := *flagDest err = os.MkdirAll(destDir, 0755) if err != nil { - exitWithError(err,2) + exitWithError(err, 2) } - sourceFile :=path.Join(destDir, nameSourceFile) - err = rename(file.Name(),sourceFile) + sourceFile := path.Join(destDir, nameSourceFile) + err = rename(file.Name(), sourceFile) if err != nil { - exitWithError(err,3) + exitWithError(err, 3) } - sourceVersionInfoFilePath :=path.Join(destDir, nameVersionInfoFile) - manifestInfoFilePath :=path.Join(destDir, nameManifestFile) + sourceVersionInfoFilePath := path.Join(destDir, nameVersionInfoFile) + manifestInfoFilePath := path.Join(destDir, nameManifestFile) goGetDependencies([]string{"github.com/segator/jbinary"}) extension := "bin" - if strings.Compare(*flagPlatform,"windows")==0 { + if strings.Compare(*flagPlatform, "windows") == 0 { fmt.Println("Go Generate version info") - _,err =generateVersionInfoFile(sourceVersionInfoFilePath) + _, err = generateVersionInfoFile(sourceVersionInfoFilePath) if err != nil { - exitWithError(err,5) + exitWithError(err, 5) } fmt.Println("Go Generate windows manifest file") - _,err =generateManifestFile(manifestInfoFilePath) + _, err = generateManifestFile(manifestInfoFilePath) if err != nil { - exitWithError(err,5) + exitWithError(err, 5) } goGetDependencies([]string{"github.com/josephspurrier/goversioninfo/cmd/goversioninfo@v1.4.0"}) - goversionInfo:=exec.Command("goversioninfo","-manifest",manifestInfoFilePath,"-description",*flagWinDescription,"-copyright",*flagWinCopyright,"-company",*flagWinCompany,"-icon",*flagWinIconPath, - "-product-name",*flagWinProductName,"-product-version",*flagWinProductVersion,"-ver-major",*flagWinMajorVersion,"-ver-minor",*flagWinMinorVersion,"-ver-patch",*flagWinPatchVersion, - "-trademark",*flagWinCompany) - goversionInfo.Env=os.Environ() - goversionInfo.Dir=destDir + goversionInfo := exec.Command("goversioninfo", "-manifest", manifestInfoFilePath, "-description", *flagWinDescription, "-copyright", *flagWinCopyright, "-company", *flagWinCompany, "-icon", *flagWinIconPath, + "-product-name", *flagWinProductName, "-product-version", *flagWinProductVersion, "-ver-major", *flagWinMajorVersion, "-ver-minor", *flagWinMinorVersion, "-ver-patch", *flagWinPatchVersion, + "-trademark", *flagWinCompany) + goversionInfo.Env = os.Environ() + goversionInfo.Dir = destDir goversionInfo.Stdout = os.Stdout goversionInfo.Stderr = os.Stderr goversionInfo.Start() if err := goversionInfo.Wait(); err != nil { - exitWithError(err,6) + exitWithError(err, 6) } - extension="exe" + extension = "exe" } - fmt.Printf("Building Jre embeded application OS:%s ARCH:%s FILENAME:%s\n",*flagPlatform,*flagArchitecture,filepath.Join(destDir,namePackage+"."+extension)) + fmt.Printf("Building Jre embeded application OS:%s ARCH:%s FILENAME:%s\n", *flagPlatform, *flagArchitecture, filepath.Join(destDir, namePackage+"."+extension)) //"-ldflags","-H=windowsgui", - cmd := exec.Command("go","build","-o",namePackage+"."+extension) - cmd.Env=append(os.Environ(),"GOOS="+*flagPlatform,"GOARCH="+*flagArchitecture) - cmd.Dir=destDir + cmd := exec.Command("go", "build", "-o", namePackage+"."+extension) + cmd.Env = append(os.Environ(), "GOOS="+*flagPlatform, "GOARCH="+*flagArchitecture) + cmd.Dir = destDir cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.Start() @@ -142,7 +141,7 @@ func main() { ws := exitError.Sys().(syscall.WaitStatus) exitCode = ws.ExitStatus() } - fmt.Printf("deleting Working Folder:%s\n",tempWorkFolder) + fmt.Printf("deleting Working Folder:%s\n", tempWorkFolder) os.Remove(sourceFile) os.Remove(path.Join(destDir, "resource.syso")) os.Remove(sourceVersionInfoFilePath) @@ -171,22 +170,23 @@ func generateManifestFile(srcPath string) (file *os.File, err error) { -`,*flagWinProductName,*flagWinMajorVersion,*flagWinMinorVersion,*flagWinPatchVersion,*flagWinBuildVersion,*flagWinExecutionLevel) - return f,err +`, *flagWinProductName, *flagWinMajorVersion, *flagWinMinorVersion, *flagWinPatchVersion, *flagWinBuildVersion, *flagWinExecutionLevel) + return f, err } func goGetDependencies(dependencies []string) { for _, dependency := range dependencies { - goget:=exec.Command("go","get", "-u",dependency) - goget.Env=os.Environ() + goget := exec.Command("go", "get", "-u", dependency) + goget.Env = os.Environ() goget.Stdout = os.Stdout goget.Stderr = os.Stderr goget.Start() if err := goget.Wait(); err != nil { - exitWithError(err,7) + exitWithError(err, 7) } } } + /* func test(zip string) { jvmArguments:=[]string{} @@ -271,11 +271,10 @@ func generateVersionInfoFile(srcPath string) (file *os.File, err error) { } } }`) - return f,err + return f, err } - -func generateSource(jvmArguments string,appArguments string,srcPath string) (file *os.File, err error) { +func generateSource(jvmArguments string, appArguments string, srcPath string) (file *os.File, err error) { var ( buffer bytes.Buffer zipWriter io.Writer @@ -339,11 +338,11 @@ func generateSource(jvmArguments string,appArguments string,srcPath string) (fil jvmArgumentsString := generateCodeStringArray(jvmArguments) javaArgumentsString := generateCodeStringArray(appArguments) forceConsoleBehaviourArgsString := generateCodeStringArray(*flagWinExecutionBehaviourConsoleArgs) - windowsFunction :="" - windowsImports:="" - if(*flagPlatform == "windows") { - windowsImports=`"syscall"` - windowsFunction =` + windowsFunction := "" + windowsImports := "" + if *flagPlatform == "windows" { + windowsImports = `"syscall"` + windowsFunction = ` var getWin = syscall.NewLazyDLL("kernel32.dll").NewProc("GetConsoleWindow") var showWin = syscall.NewLazyDLL("user32.dll").NewProc("ShowWindow") hwnd, _, _ := getWin.Call() @@ -382,7 +381,7 @@ func main() { var function=func(show bool) { %s } - data := "`,windowsImports,jvmArgumentsString,javaArgumentsString,*flagWinExecutionBehaviour,forceConsoleBehaviourArgsString,*flagDebugPort,windowsFunction) + data := "`, windowsImports, jvmArgumentsString, javaArgumentsString, *flagWinExecutionBehaviour, forceConsoleBehaviourArgsString, *flagDebugPort, windowsFunction) FprintZipData(&qb, buffer.Bytes()) fmt.Fprint(&qb, `" loader.ExecuteJavaApplication(defaultExecutionBehaviour,forceConsoleBehaviourArgs,jvmArguments,javaAppArguments,debugPort,&data,function) @@ -394,17 +393,16 @@ func main() { return f, nil } - func generateCodeStringArray(parameters string) string { parameters = strings.TrimSpace(parameters) if parameters != "" { - parametersSlice := strings.Split(parameters,";") + parametersSlice := strings.Split(parameters, ";") var templStr = `{{range $i, $e := $}}{{if $i}},{{end}}"{{$e}}"{{end}}` var tpl bytes.Buffer t := template.Must(template.New("splitParameters").Parse(templStr)) t.Execute(&tpl, parametersSlice) return tpl.String() - }else { + } else { return "" } @@ -434,39 +432,38 @@ func FprintZipData(dest *bytes.Buffer, zipData []byte) { } // Prints out the error message and exists with a non-success signal. -func exitWithError(err error,exitCode int) { +func exitWithError(err error, exitCode int) { fmt.Println(err) os.Exit(exitCode) } -func downloadJRE(workDir string){ - var jreTarPath = filepath.Join(workDir,"jre.tar.gz") - var ossystem="linux" - var arch="32" +func downloadJRE(workDir string) { + var jreTarPath = filepath.Join(workDir, "jre.tar.gz") + var ossystem = "linux" + var arch = "32" if *flagArchitecture == "amd64" { - arch="64" + arch = "64" } if *flagPlatform == "windows" { - ossystem="win" - }else{ - arch="" - } - var jreURL =strings.Replace(*jreDownloadURL,"{javaType}",*flagJavaType,-1) - jreURL=strings.Replace(jreURL,"{javaVersion}",*flagJreVersio,-1) - jreURL=strings.Replace(jreURL,"{serverURL}",*flagServerURL,-1) - jreURL=strings.Replace(jreURL,"{platform}",ossystem,-1) - jreURL=strings.Replace(jreURL,"{architecture}",arch,-1) - DownloadFile(jreTarPath,jreURL) - fmt.Printf("Extracting JRE version:%s architecture:%s\n",ossystem,arch) - ExtractTarGz(jreTarPath,workDir) + ossystem = "win" + } else { + arch = "" + } + var jreURL = strings.Replace(*jreDownloadURL, "{javaType}", *flagJavaType, -1) + jreURL = strings.Replace(jreURL, "{javaVersion}", *flagJreVersio, -1) + jreURL = strings.Replace(jreURL, "{serverURL}", *flagServerURL, -1) + jreURL = strings.Replace(jreURL, "{platform}", ossystem, -1) + jreURL = strings.Replace(jreURL, "{architecture}", arch, -1) + DownloadFile(jreTarPath, jreURL) + fmt.Printf("Extracting JRE version:%s architecture:%s\n", ossystem, arch) + ExtractTarGz(jreTarPath, workDir) os.Remove(jreTarPath) - } func DownloadFile(filepath string, url string) error { - fmt.Printf("Downloading %s\n",url) + fmt.Printf("Downloading %s\n", url) // Create the file out, err := os.Create(filepath) if err != nil { @@ -477,7 +474,7 @@ func DownloadFile(filepath string, url string) error { // Get the data resp, err := http.Get(url) if resp.StatusCode == 404 || resp.StatusCode == 409 { - exitWithError(errors.New(strings.Replace("URL Repository JRE not found: {url}","{url}",url,-1)),4) + exitWithError(errors.New(strings.Replace("URL Repository JRE not found: {url}", "{url}", url, -1)), 4) } if err != nil { return err @@ -492,9 +489,9 @@ func DownloadFile(filepath string, url string) error { return nil } -func ExtractTarGz(srcTarGzPath string,destination string) { +func ExtractTarGz(srcTarGzPath string, destination string) { file, err := os.Open(srcTarGzPath) - gzipStream :=bufio.NewReader(file) + gzipStream := bufio.NewReader(file) uncompressedStream, err := gzip.NewReader(gzipStream) if err != nil { log.Fatal("ExtractTarGz: NewReader failed") @@ -515,11 +512,11 @@ func ExtractTarGz(srcTarGzPath string,destination string) { switch header.Typeflag { case tar.TypeDir: - if err := os.Mkdir(filepath.Join(destination,header.Name), 0755); err != nil { + if err := os.Mkdir(filepath.Join(destination, header.Name), 0755); err != nil { log.Fatalf("ExtractTarGz: Mkdir() failed: %s", err.Error()) } case tar.TypeReg: - outFile, err := os.Create(filepath.Join(destination,header.Name)) + outFile, err := os.Create(filepath.Join(destination, header.Name)) if err != nil { log.Fatalf("ExtractTarGz: Create() failed: %s", err.Error()) } @@ -527,8 +524,8 @@ func ExtractTarGz(srcTarGzPath string,destination string) { if _, err := io.Copy(outFile, tarReader); err != nil { log.Fatalf("ExtractTarGz: Copy() failed: %s", err.Error()) } - case tar.TypeLink,tar.TypeSymlink,tar.TypeChar,tar.TypeBlock,tar.TypeFifo: - log.Printf("Ignoring tar object:%s file:%s",string(header.Typeflag),header.Name) + case tar.TypeLink, tar.TypeSymlink, tar.TypeChar, tar.TypeBlock, tar.TypeFifo: + log.Printf("Ignoring tar object:%s file:%s", string(header.Typeflag), header.Name) default: log.Fatalf( "ExtractTarGz: uknown type: %s in %s",