From 1dadec5c9abb433abbc9a2ea821cee16e464a19c Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Tue, 31 Oct 2023 11:16:54 +0200 Subject: [PATCH 01/17] feat: update to go ver 1.21, update depreciated ioutil calls, removed unused underscore variables, added gitignore, create executables in a dist folder, moved flags handling in the recomended main.go file, cleared main.go file, moved processing files to jdowser package --- .gitignore | 1 + Makefile | 38 ++----------- src/ansible-jdowser => ansible-jdowser | 0 go.mod | 4 +- go.sum | 4 +- {src => jdowser}/classfile.go | 5 +- {src => jdowser}/classfilereader.go | 2 +- src/main.go => jdowser/commands.go | 61 +++++--------------- {src => jdowser}/config.go | 79 ++++++++++++-------------- {src => jdowser}/jvminstallation.go | 38 ++++++------- {src => jdowser}/scanlock.go | 2 +- {src => jdowser}/status.go | 13 ++--- {src => jdowser}/utils.go | 5 +- main.go | 69 ++++++++++++++++++++++ src/LICENSE | 29 ---------- src/version.sh => version.sh | 0 16 files changed, 160 insertions(+), 190 deletions(-) create mode 100644 .gitignore rename src/ansible-jdowser => ansible-jdowser (100%) rename {src => jdowser}/classfile.go (99%) rename {src => jdowser}/classfilereader.go (98%) rename src/main.go => jdowser/commands.go (81%) rename {src => jdowser}/config.go (54%) rename {src => jdowser}/jvminstallation.go (91%) rename {src => jdowser}/scanlock.go (98%) rename {src => jdowser}/status.go (94%) rename {src => jdowser}/utils.go (97%) create mode 100644 main.go delete mode 100644 src/LICENSE rename src/version.sh => version.sh (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53c37a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dist \ No newline at end of file diff --git a/Makefile b/Makefile index 9e56ffd..9e4f950 100644 --- a/Makefile +++ b/Makefile @@ -1,38 +1,10 @@ # Copyright 2020-2021 Azul Systems, Inc. All rights reserved. # Use of this source code is governed by the 3-Clause BSD # license that can be found in the LICENSE file. -MYDIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) -APP := jdowser -SCRIPT := ansible-jdowser +build-dist: + rm -rf dist + GOOS=linux GOARCH=amd64 go build -o dist/jdowser_linux main.go + GOOS=darwin GOARCH=amd64 go build -o dist/jdowser_mac main.go + GOOS=windows GOARCH=amd64 go build -o dist/jdowser_windows.exe main.go -GOOS ?= $(shell go env GOOS) -GOARCH ?= $(shell go env GOARCH) - -FILES := \ - classfile.go \ - classfilereader.go \ - config.go \ - jvminstallation.go \ - main.go \ - scanlock.go \ - status.go \ - utils.go \ - -all: $(APP) $(SCRIPT) - -$(APP): $(FILES:%=$(MYDIR)/src/%) $(VERSION) - V=$$($(MYDIR)/src/version.sh) && \ - CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags="-s -w -X \"main.VERSION=$${V}\"" -o $@ $^ - -$(SCRIPT): $(MYDIR)/src/$(SCRIPT) - V=$$($(MYDIR)/src/version.sh) && \ - sed "s#%VERSION%#$${V}#" $^ > $@ && chmod +x $@ - -resolve: - go get -u golang.org/x/sys/unix - -clean: - rm -f $(APP) $(SCRIPT) - -.PHONY: clean resolve all diff --git a/src/ansible-jdowser b/ansible-jdowser similarity index 100% rename from src/ansible-jdowser rename to ansible-jdowser diff --git a/go.mod b/go.mod index 311f120..d7ba60a 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module jdowser -go 1.13 +go 1.21.3 -require golang.org/x/sys v0.0.0-20210923061019-b8560ed6a9b7 // indirect +require golang.org/x/sys v0.13.0 diff --git a/go.sum b/go.sum index d570d24..d4673ec 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -golang.org/x/sys v0.0.0-20210923061019-b8560ed6a9b7 h1:c20P3CcPbopVp2f7099WLOqSNKURf30Z0uq66HpijZY= -golang.org/x/sys v0.0.0-20210923061019-b8560ed6a9b7/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/src/classfile.go b/jdowser/classfile.go similarity index 99% rename from src/classfile.go rename to jdowser/classfile.go index e1d04f3..db35527 100644 --- a/src/classfile.go +++ b/jdowser/classfile.go @@ -2,11 +2,12 @@ // Use of this source code is governed by the 3-Clause BSD // license that can be found in the LICENSE file. -package main +package jdowser import ( "fmt" "log" + ) type ConstantPool []ConstantPoolEntry @@ -337,7 +338,7 @@ func (e *ConstantUtf8Entry) Read(r *ClassFileReader) int { } func (e *ConstantUtf8Entry) String() string { - return fmt.Sprintf("%s", e.bytes) + return string(e.bytes) } func (e *ConstantMethodHandleEntry) Read(r *ClassFileReader) int { diff --git a/src/classfilereader.go b/jdowser/classfilereader.go similarity index 98% rename from src/classfilereader.go rename to jdowser/classfilereader.go index e8ab8fd..b4662bf 100644 --- a/src/classfilereader.go +++ b/jdowser/classfilereader.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the 3-Clause BSD // license that can be found in the LICENSE file. -package main +package jdowser import "encoding/binary" diff --git a/src/main.go b/jdowser/commands.go similarity index 81% rename from src/main.go rename to jdowser/commands.go index f967fad..38a4b25 100644 --- a/src/main.go +++ b/jdowser/commands.go @@ -1,14 +1,9 @@ -// Copyright 2020 Azul Systems, Inc. All rights reserved. -// Use of this source code is governed by the 3-Clause BSD -// license that can be found in the LICENSE file. - -package main +package jdowser import ( "bufio" "encoding/json" "fmt" - "io/ioutil" "math" "os" "os/signal" @@ -18,38 +13,14 @@ import ( "syscall" ) -var VERSION = "private build" - -func main() { - if config := InitConfig(); config != nil { - switch config.command { - case CMD_START: - cmdStart(config) - break - case CMD_STOP: - cmdStop(config) - break - case CMD_STATUS: - cmdStatus(config) - break - case CMD_REPORT: - cmdReport(config) - break - default: - fmt.Println("Unknown command:", config.command) - os.Exit(1) - } - } -} - -func cmdReport(config *Config) { +func CmdReport(config *Config) { if config.wait { lock, e := ScanLock(config) if e != nil { fmt.Println(e.Error()) return } - e = lock.Lock() + lock.Lock() defer lock.Unlock() } @@ -110,8 +81,8 @@ func unmarshalInfo(bytes []byte, inUseLibJVM map[string]int) (*JVMInstallation, return nil, e } for running := range inUseLibJVM { - stat1, e1 := os.Stat(running); - stat2, e2 := os.Stat(info.LibJVM); + stat1, e1 := os.Stat(running) + stat2, e2 := os.Stat(info.LibJVM) if e1 == nil && e2 == nil && os.SameFile(stat1, stat2) { info.RunningInstances += inUseLibJVM[running] } @@ -119,7 +90,7 @@ func unmarshalInfo(bytes []byte, inUseLibJVM map[string]int) (*JVMInstallation, return &info, nil } -func cmdStart(config *Config) { +func CmdStart(config *Config) { cookie := os.Getenv("SCANJVM_COOKIE") _ = os.Setenv("LC_ALL", "C") @@ -131,7 +102,7 @@ func cmdStart(config *Config) { signal.Notify(signals, syscall.SIGUSR1) go func() { - _ = <-signals + <-signals if status := ReadStatus(config); status != nil { status.Report() } @@ -200,7 +171,7 @@ func cmdStart(config *Config) { status := NewStatus(config) go func() { - _ = <-signals + <-signals status.SetState(Terminated) lock.Unlock() os.Exit(1) @@ -215,14 +186,13 @@ func cmdStart(config *Config) { e = findFiles(config, func(libjvm string) { if info := InitJVMInstallation(libjvm, config); info != nil { if txt, _ := json.Marshal(info); txt != nil { - _, _ = fmt.Fprintln(outFile, string(txt)) + fmt.Fprintln(outFile, string(txt)) } - } else { } }) if e != nil { - _, _ = fmt.Fprintln(errFile, e.Error()) + fmt.Fprintln(errFile, e.Error()) status.SetState(Error) } else { status.SetState(Finished) @@ -233,7 +203,7 @@ func cmdStart(config *Config) { } } -func cmdStatus(config *Config) { +func CmdStatus(config *Config) { lock, e := ScanLock(config) if e != nil { fmt.Println(e.Error()) @@ -266,8 +236,8 @@ func cmdStatus(config *Config) { status.Report() } -func cmdStop(config *Config) { - procDir, e := ioutil.ReadDir("/proc") +func CmdStop(config *Config) { + procDir, e := os.ReadDir("/proc") if e != nil { fmt.Println(e.Error()) return @@ -281,9 +251,9 @@ func cmdStop(config *Config) { continue } envFile := path.Join("/proc", pidStr, "environ") - _ = processStringsFromFile(envFile, 0, math.MaxInt64, func(str string) bool { + processStringsFromFile(envFile, 0, math.MaxInt64, func(str string) bool { if strings.HasPrefix(str, config.cookie) { - _ = syscall.Kill(pid, syscall.SIGTERM) + syscall.Kill(pid, syscall.SIGTERM) return false } return true @@ -295,4 +265,3 @@ func cmdStop(config *Config) { status.Report() } } - diff --git a/src/config.go b/jdowser/config.go similarity index 54% rename from src/config.go rename to jdowser/config.go index 459f486..b83e221 100644 --- a/src/config.go +++ b/jdowser/config.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the 3-Clause BSD // license that can be found in the LICENSE file. -package main +package jdowser import ( "encoding/csv" @@ -18,13 +18,16 @@ import ( "strings" ) +var VERSION = "private build" + type CommandType string const ( - CMD_START CommandType = "start" - CMD_STOP CommandType = "stop" - CMD_STATUS CommandType = "status" - CMD_REPORT CommandType = "report" + CMD_START CommandType = "start" + CMD_STOP CommandType = "stop" + CMD_STATUS CommandType = "status" + CMD_REPORT CommandType = "report" + CMD_UNDEFINED CommandType = "undefined" ) type Config struct { @@ -34,7 +37,7 @@ type Config struct { csv bool skipfs []string root string - command CommandType + Command CommandType cookie string wait bool logdir string @@ -52,41 +55,30 @@ func (c *Config) StatusFilePath() string { return path.Join(c.logdir, "jdowser.status") } -func InitConfig() *Config { - config := Config{} - config.libjvmFileName = getLibJVMFileName() +type GivenFlags struct { + OutJson bool + OutCsv bool + Root string + SkipFs string + NoJVMRun bool + Wait bool + Version bool +} - outjson := flag.Bool("json", false, "dump output in JSON format") - outcsv := flag.Bool("csv", false, "dump output in CSV format") - root := flag.String("root", "/", "root scan directory") - skipfs := flag.String("skipfs", "nfs,tmp,proc", "list of filesystem types to skip.") - nojvmrun := flag.Bool("nojvmrun", false, "do not run java -version to detect version") - wait := flag.Bool("wait", false, "wait completion of scan process") - version := flag.Bool("version", false, "show version and exit") - - flag.Usage = func() { - name := filepath.Base(os.Args[0]) - fmt.Println(name, "- Utility to find JVMs/JDKs and report their versions") - fmt.Println("Version:", VERSION) - fmt.Println() - fmt.Printf("Usage: %s [-json|-csv] [-skipfs=fstype[,fstype..]] [-nojvmrun] [-wait] [-root=] %s\n", name, CMD_START) - fmt.Printf(" %s [-json|-csv] [-wait] %s\n", name, CMD_STATUS) - fmt.Printf(" %s [-json|-csv] [-wait] %s\n", name, CMD_REPORT) - fmt.Printf(" %s [-json|-csv] %s\n", name, CMD_STOP) - fmt.Printf(" %s [-json|-csv] -version\n", name) - flag.PrintDefaults() +func InitConfig(givenFlags GivenFlags) *Config { + config := Config{ + Command: CMD_UNDEFINED, } + config.libjvmFileName = getLibJVMFileName() - flag.Parse() - - if *version { - if *outjson { + if givenFlags.Version { + if givenFlags.OutJson { type Version struct { Version string `json:"version"` } txt, _ := json.Marshal(Version{VERSION}) fmt.Println(string(txt)) - } else if *outcsv { + } else if givenFlags.OutCsv { w := csv.NewWriter(os.Stdout) w.Write([]string{"version", VERSION}) w.Flush() @@ -101,25 +93,27 @@ func InitConfig() *Config { return nil } - config.command = CommandType(flag.Arg(0)) + if flag.Arg(0) != "" { + config.Command = CommandType(flag.Arg(0)) + } allowedChars := regexp.MustCompile(`^[a-z,]+$`).MatchString - if *skipfs != "" && !allowedChars(*skipfs) { - fmt.Println("Error: bad -skipfs parameter:", *skipfs) + if givenFlags.SkipFs != "" && !allowedChars(givenFlags.SkipFs) { + fmt.Println("Error: bad -skipfs parameter:", givenFlags.SkipFs) os.Exit(1) } - for _, fs := range strings.Split(*skipfs, ",") { + for _, fs := range strings.Split(givenFlags.SkipFs, ",") { if fs != "" { config.skipfs = append(config.skipfs, fs) } } - config.nojvmrun = *nojvmrun - config.json = *outjson - config.csv = *outcsv - config.root = *root - config.wait = *wait + config.nojvmrun = givenFlags.NoJVMRun + config.json = givenFlags.OutJson + config.csv = givenFlags.OutCsv + config.root = givenFlags.Root + config.wait = givenFlags.Wait u, err := user.Current() checkError(err) @@ -156,4 +150,3 @@ func getLibJVMFileName() string { return "libjvm.so" } } - diff --git a/src/jvminstallation.go b/jdowser/jvminstallation.go similarity index 91% rename from src/jvminstallation.go rename to jdowser/jvminstallation.go index 7ef6147..3d9595f 100644 --- a/src/jvminstallation.go +++ b/jdowser/jvminstallation.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the 3-Clause BSD // license that can be found in the LICENSE file. -package main +package jdowser import ( "archive/zip" @@ -15,7 +15,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "math" "os" @@ -63,7 +62,9 @@ func InitJVMInstallation(libjvm string, config *Config) *JVMInstallation { if _, err := os.Stat(path.Join(inst.JavaHome, "bin/javac")); err == nil || os.IsExist(err) { inst.IsJDK = true } + var found bool + wf := func(p string, info os.FileInfo, err error) error { if found { return filepath.SkipDir @@ -84,7 +85,7 @@ func InitJVMInstallation(libjvm string, config *Config) *JVMInstallation { return nil } - _ = filepath.Walk(inst.JavaHome, wf) + filepath.Walk(inst.JavaHome, wf) } for { @@ -122,20 +123,20 @@ func md5sum(path string) (string, error) { } func (inst *JVMInstallation) Dump(out *os.File) { - _, _ = fmt.Fprintln(out, "host:", inst.Host) - _, _ = fmt.Fprintln(out, "libjvm:", inst.LibJVM) - _, _ = fmt.Fprintln(out, "libjvm_hash:", inst.LibJVMHash) - _, _ = fmt.Fprintln(out, "java_home:", inst.JavaHome) - _, _ = fmt.Fprintln(out, "is_jdk:", inst.IsJDK) - _, _ = fmt.Fprintln(out, "java_version:", inst.VersionInfo.Version) - _, _ = fmt.Fprintln(out, "java_runtime_name:", inst.VersionInfo.RuntimeName) - _, _ = fmt.Fprintln(out, "java_runtime_version:", inst.VersionInfo.RuntimeVersion) - _, _ = fmt.Fprintln(out, "java_runtime_vendor:", inst.VersionInfo.RuntimeVendor) - _, _ = fmt.Fprintln(out, "java_vm_name:", inst.VersionInfo.VMName) - _, _ = fmt.Fprintln(out, "java_vm_version:", inst.VersionInfo.VMVersion) - _, _ = fmt.Fprintln(out, "java_vm_vendor:", inst.VersionInfo.VMVendor) - _, _ = fmt.Fprintln(out, "running_instances:", inst.RunningInstances) - _, _ = fmt.Fprintln(out) + fmt.Fprintln(out, "host:", inst.Host) + fmt.Fprintln(out, "libjvm:", inst.LibJVM) + fmt.Fprintln(out, "libjvm_hash:", inst.LibJVMHash) + fmt.Fprintln(out, "java_home:", inst.JavaHome) + fmt.Fprintln(out, "is_jdk:", inst.IsJDK) + fmt.Fprintln(out, "java_version:", inst.VersionInfo.Version) + fmt.Fprintln(out, "java_runtime_name:", inst.VersionInfo.RuntimeName) + fmt.Fprintln(out, "java_runtime_version:", inst.VersionInfo.RuntimeVersion) + fmt.Fprintln(out, "java_runtime_vendor:", inst.VersionInfo.RuntimeVendor) + fmt.Fprintln(out, "java_vm_name:", inst.VersionInfo.VMName) + fmt.Fprintln(out, "java_vm_version:", inst.VersionInfo.VMVersion) + fmt.Fprintln(out, "java_vm_vendor:", inst.VersionInfo.VMVendor) + fmt.Fprintln(out, "running_instances:", inst.RunningInstances) + fmt.Fprintln(out) } func (inst *JVMInstallation) DumpCSV(out *os.File) { @@ -390,7 +391,7 @@ func extractVersionClass(filename string) ([]byte, error) { if err != nil { log.Fatal("Error reading archive entry") } - data, err = ioutil.ReadAll(fc) + data, err = io.ReadAll(fc) _ = fc.Close() if err != nil { return nil, err @@ -402,4 +403,3 @@ func extractVersionClass(filename string) ([]byte, error) { return nil, errors.New("entry sun/misc/Version.class not found") } - diff --git a/src/scanlock.go b/jdowser/scanlock.go similarity index 98% rename from src/scanlock.go rename to jdowser/scanlock.go index 3674fa9..c3fd356 100644 --- a/src/scanlock.go +++ b/jdowser/scanlock.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the 3-Clause BSD // license that can be found in the LICENSE file. -package main +package jdowser import ( "golang.org/x/sys/unix" diff --git a/src/status.go b/jdowser/status.go similarity index 94% rename from src/status.go rename to jdowser/status.go index f2e3bab..c879900 100644 --- a/src/status.go +++ b/jdowser/status.go @@ -2,14 +2,13 @@ // Use of this source code is governed by the 3-Clause BSD // license that can be found in the LICENSE file. -package main +package jdowser import ( "bufio" "encoding/csv" "encoding/json" "fmt" - "io/ioutil" "os" "strconv" "strings" @@ -39,7 +38,7 @@ const ( func NewStatus(config *Config) *Status { hostname, _ := os.Hostname() var args []string - if config.command == CMD_START { + if config.Command == CMD_START { args = os.Args[1 : len(os.Args)-1] } @@ -55,7 +54,7 @@ func NewStatus(config *Config) *Status { } func ReadStatus(config *Config) *Status { - data, e := ioutil.ReadFile(config.StatusFilePath()) + data, e := os.ReadFile(config.StatusFilePath()) if e != nil { return nil } @@ -85,19 +84,16 @@ func (status *Status) SetState(state StateType) { switch state { case Running: status.StartTime = time.Now().Unix() - break case Finished, Terminated: status.EndTime = time.Now().Unix() - break case Unknown: status.EndTime = -2 - break } status.State = state f, _ := os.Create(status.Config.StatusFilePath()) txt, _ := json.Marshal(status) - _, _ = fmt.Fprintln(f, string(txt)) + fmt.Fprintln(f, string(txt)) } func endTime(status *Status) string { @@ -134,4 +130,3 @@ func (status *Status) Report() { } } } - diff --git a/src/utils.go b/jdowser/utils.go similarity index 97% rename from src/utils.go rename to jdowser/utils.go index ea21057..bd295ef 100644 --- a/src/utils.go +++ b/jdowser/utils.go @@ -2,12 +2,11 @@ // Use of this source code is governed by the 3-Clause BSD // license that can be found in the LICENSE file. -package main +package jdowser import ( "bufio" "io" - "io/ioutil" "os" "os/exec" "path" @@ -107,7 +106,7 @@ func fileIsEmpty(f *os.File) bool { func findInUseLibJVM() map[string]int { res := make(map[string]int) - procDir, e := ioutil.ReadDir("/proc") + procDir, e := os.ReadDir("/proc") if e != nil { return res } diff --git a/main.go b/main.go new file mode 100644 index 0000000..92158ec --- /dev/null +++ b/main.go @@ -0,0 +1,69 @@ +// Copyright 2020 Azul Systems, Inc. All rights reserved. +// Use of this source code is governed by the 3-Clause BSD +// license that can be found in the LICENSE file. + +package main + +import ( + "flag" + "fmt" + "jdowser/jdowser" + "os" + "path/filepath" +) + +func main() { + + outjson := flag.Bool("json", false, "dump output in JSON format") + outcsv := flag.Bool("csv", false, "dump output in CSV format") + root := flag.String("root", "/", "root scan directory") + skipfs := flag.String("skipfs", "nfs,tmp,proc", "list of filesystem types to skip.") + nojvmrun := flag.Bool("nojvmrun", false, "do not run java -version to detect version") + wait := flag.Bool("wait", false, "wait completion of scan process") + version := flag.Bool("version", false, "show version and exit") + + givenFlags := jdowser.GivenFlags{ + OutJson: *outjson, + OutCsv: *outcsv, + Root: *root, + SkipFs: *skipfs, + NoJVMRun: *nojvmrun, + Wait: *wait, + Version: *version, + } + + flag.Usage = func() { + name := filepath.Base(os.Args[0]) + fmt.Println(name, "- Utility to find JVMs/JDKs and report their versions") + fmt.Println("Version:", jdowser.VERSION) + fmt.Println() + fmt.Printf("Usage: %s [-json|-csv] [-skipfs=fstype[,fstype..]] [-nojvmrun] [-wait] [-root=] %s\n", name, jdowser.CMD_START) + fmt.Printf(" %s [-json|-csv] [-wait] %s\n", name, jdowser.CMD_STATUS) + fmt.Printf(" %s [-json|-csv] [-wait] %s\n", name, jdowser.CMD_REPORT) + fmt.Printf(" %s [-json|-csv] %s\n", name, jdowser.CMD_STOP) + fmt.Printf(" %s [-json|-csv] -version\n", name) + flag.PrintDefaults() + } + + flag.Parse() + + config := jdowser.InitConfig(givenFlags) + + if config != nil { + switch config.Command { + case jdowser.CMD_START: + jdowser.CmdStart(config) + case jdowser.CMD_STOP: + jdowser.CmdStop(config) + case jdowser.CMD_STATUS: + jdowser.CmdStatus(config) + case jdowser.CMD_REPORT: + jdowser.CmdReport(config) + + default: + fmt.Println("Unknown command:", config.Command) + os.Exit(1) + } + } + +} diff --git a/src/LICENSE b/src/LICENSE deleted file mode 100644 index 5619573..0000000 --- a/src/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -Copyright 2020 Azul Systems, Inc. - -jdowser is licensed under the 3-Clause BSD License: - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, this - list of conditions and the following disclaimer in the documentation and/or - other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. diff --git a/src/version.sh b/version.sh similarity index 100% rename from src/version.sh rename to version.sh From 89651f7dcf7183419726ee93b5715bac3e168b69 Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Tue, 31 Oct 2023 11:59:54 +0200 Subject: [PATCH 02/17] fix: call flags.Parse before getting flags --- Makefile | 5 +++++ jdowser/commands.go | 22 +++++++++---------- jdowser/config.go | 44 +++++++++++++++++++------------------- jdowser/jvminstallation.go | 2 +- jdowser/scanlock.go | 5 +++-- jdowser/status.go | 4 ++-- jdowser/utils.go | 8 +++---- main.go | 20 ++++++++--------- 8 files changed, 58 insertions(+), 52 deletions(-) diff --git a/Makefile b/Makefile index 9e4f950..740fe6e 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,11 @@ # Use of this source code is governed by the 3-Clause BSD # license that can be found in the LICENSE file. +# ./jdowser start +# ./jdowser -json report > output_file.json +# ./jdowser -csv report > output_file.csv + + build-dist: rm -rf dist GOOS=linux GOARCH=amd64 go build -o dist/jdowser_linux main.go diff --git a/jdowser/commands.go b/jdowser/commands.go index 38a4b25..9d42d8c 100644 --- a/jdowser/commands.go +++ b/jdowser/commands.go @@ -14,7 +14,7 @@ import ( ) func CmdReport(config *Config) { - if config.wait { + if config.Wait { lock, e := ScanLock(config) if e != nil { fmt.Println(e.Error()) @@ -36,7 +36,7 @@ func CmdReport(config *Config) { defer closeFile(f) if fileIsEmpty(f) { - if config.json { + if config.Json { fmt.Println("[]") } else { fmt.Println("No results found") @@ -48,7 +48,7 @@ func CmdReport(config *Config) { scanner := bufio.NewScanner(f) - if config.json { + if config.Json { aw := NewJSONArrayWriter(os.Stdout) defer aw.Close() enc := json.NewEncoder(aw) @@ -58,7 +58,7 @@ func CmdReport(config *Config) { _ = enc.Encode(info) } } - } else if config.csv { + } else if config.CSV { DumpCSVHeader(os.Stdout) for scanner.Scan() { if info, e := unmarshalInfo(scanner.Bytes(), inUseLibJVM); e == nil { @@ -93,10 +93,10 @@ func unmarshalInfo(bytes []byte, inUseLibJVM map[string]int) (*JVMInstallation, func CmdStart(config *Config) { cookie := os.Getenv("SCANJVM_COOKIE") - _ = os.Setenv("LC_ALL", "C") - _ = os.Setenv("SCANJVM_COOKIE", strings.Split(config.cookie, "=")[1]) + os.Setenv("LC_ALL", "C") + os.Setenv("SCANJVM_COOKIE", strings.Split(config.Cookie, "=")[1]) - if !config.wait && cookie == "" { + if !config.Wait && cookie == "" { signals := make(chan os.Signal, 1) started := make(chan bool, 1) signal.Notify(signals, syscall.SIGUSR1) @@ -157,7 +157,7 @@ func CmdStart(config *Config) { if e = lock.TryLock(); e != nil { // Another scan is in progress reportStatus() - if config.wait { + if config.Wait { _ = lock.Lock() reportStatus() } @@ -198,7 +198,7 @@ func CmdStart(config *Config) { status.SetState(Finished) } - if config.wait { + if config.Wait { status.Report() } } @@ -210,7 +210,7 @@ func CmdStatus(config *Config) { return } - if config.wait { + if config.Wait { e = lock.Lock() } else { e = lock.TryLock() @@ -252,7 +252,7 @@ func CmdStop(config *Config) { } envFile := path.Join("/proc", pidStr, "environ") processStringsFromFile(envFile, 0, math.MaxInt64, func(str string) bool { - if strings.HasPrefix(str, config.cookie) { + if strings.HasPrefix(str, config.Cookie) { syscall.Kill(pid, syscall.SIGTERM) return false } diff --git a/jdowser/config.go b/jdowser/config.go index b83e221..6aef3bf 100644 --- a/jdowser/config.go +++ b/jdowser/config.go @@ -31,28 +31,28 @@ const ( ) type Config struct { - libjvmFileName string - nojvmrun bool - json bool - csv bool - skipfs []string - root string + LibJVMFileName string + NoJVMRun bool + Json bool + CSV bool + SkipFs []string + Root string Command CommandType - cookie string - wait bool - logdir string + Cookie string + Wait bool + LogDir string } func (c *Config) OutputFilePath() string { - return path.Join(c.logdir, "jdowser.out") + return path.Join(c.LogDir, "jdowser.out") } func (c *Config) ErrorFilePath() string { - return path.Join(c.logdir, "jdowser.err") + return path.Join(c.LogDir, "jdowser.err") } func (c *Config) StatusFilePath() string { - return path.Join(c.logdir, "jdowser.status") + return path.Join(c.LogDir, "jdowser.status") } type GivenFlags struct { @@ -69,7 +69,7 @@ func InitConfig(givenFlags GivenFlags) *Config { config := Config{ Command: CMD_UNDEFINED, } - config.libjvmFileName = getLibJVMFileName() + config.LibJVMFileName = getLibJVMFileName() if givenFlags.Version { if givenFlags.OutJson { @@ -105,15 +105,15 @@ func InitConfig(givenFlags GivenFlags) *Config { for _, fs := range strings.Split(givenFlags.SkipFs, ",") { if fs != "" { - config.skipfs = append(config.skipfs, fs) + config.SkipFs = append(config.SkipFs, fs) } } - config.nojvmrun = givenFlags.NoJVMRun - config.json = givenFlags.OutJson - config.csv = givenFlags.OutCsv - config.root = givenFlags.Root - config.wait = givenFlags.Wait + config.NoJVMRun = givenFlags.NoJVMRun + config.Json = givenFlags.OutJson + config.CSV = givenFlags.OutCsv + config.Root = givenFlags.Root + config.Wait = givenFlags.Wait u, err := user.Current() checkError(err) @@ -121,13 +121,13 @@ func InitConfig(givenFlags GivenFlags) *Config { h, err := os.Hostname() checkError(err) - config.cookie = fmt.Sprintf("SCANJVM_COOKIE=%s", u.Username) + config.Cookie = fmt.Sprintf("SCANJVM_COOKIE=%s", u.Username) cacheDir, err := os.UserCacheDir() checkError(err) - config.logdir = path.Join(cacheDir, "jdowser", h, u.Username) - err = os.MkdirAll(config.logdir, 0700) + config.LogDir = path.Join(cacheDir, "jdowser", h, u.Username) + err = os.MkdirAll(config.LogDir, 0700) checkError(err) return &config diff --git a/jdowser/jvminstallation.go b/jdowser/jvminstallation.go index 3d9595f..3ad6b1b 100644 --- a/jdowser/jvminstallation.go +++ b/jdowser/jvminstallation.go @@ -89,7 +89,7 @@ func InitJVMInstallation(libjvm string, config *Config) *JVMInstallation { } for { - if !config.nojvmrun && inst.JavaHome != "" && readVersionInfoFromOutput(&inst) { + if !config.NoJVMRun && inst.JavaHome != "" && readVersionInfoFromOutput(&inst) { break } if readVersionInfoFromStrings(&inst) { diff --git a/jdowser/scanlock.go b/jdowser/scanlock.go index c3fd356..67e530f 100644 --- a/jdowser/scanlock.go +++ b/jdowser/scanlock.go @@ -5,9 +5,10 @@ package jdowser import ( - "golang.org/x/sys/unix" "os" "path" + + "golang.org/x/sys/unix" ) type FLock struct { @@ -17,7 +18,7 @@ type FLock struct { func ScanLock(config *Config) (*FLock, error) { return &FLock{ - path.Join(config.logdir, ".lck"), + path.Join(config.LogDir, ".lck"), nil, }, nil } diff --git a/jdowser/status.go b/jdowser/status.go index c879900..3c99eda 100644 --- a/jdowser/status.go +++ b/jdowser/status.go @@ -105,11 +105,11 @@ func endTime(status *Status) string { } func (status *Status) Report() { - if status.Config.json { + if status.Config.Json { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") _ = enc.Encode(status) - } else if status.Config.csv { + } else if status.Config.CSV { w := csv.NewWriter(os.Stdout) w.Write([]string{"host", "state", "start_time", "end_time", "args"}) w.Write([]string{ diff --git a/jdowser/utils.go b/jdowser/utils.go index bd295ef..057ccca 100644 --- a/jdowser/utils.go +++ b/jdowser/utils.go @@ -50,9 +50,9 @@ func (w *JSONArrayWriter) Close() { } func findFiles(config *Config, callback func(fname string)) error { - command := []string{config.root} - l := len(config.skipfs) - fs := &config.skipfs + command := []string{config.Root} + l := len(config.SkipFs) + fs := &config.SkipFs if l > 0 { command = append(command, "(") for i := 0; i < l-1; i++ { @@ -60,7 +60,7 @@ func findFiles(config *Config, callback func(fname string)) error { } command = append(command, "-fstype", (*fs)[l-1], ")", "-prune", "-o") } - command = append(command, "-xdev", "-type", "f", "-name", config.libjvmFileName, "-print") + command = append(command, "-xdev", "-type", "f", "-name", config.LibJVMFileName, "-print") cmd := exec.Command("find", command...) diff --git a/main.go b/main.go index 92158ec..6dae819 100644 --- a/main.go +++ b/main.go @@ -22,16 +22,6 @@ func main() { wait := flag.Bool("wait", false, "wait completion of scan process") version := flag.Bool("version", false, "show version and exit") - givenFlags := jdowser.GivenFlags{ - OutJson: *outjson, - OutCsv: *outcsv, - Root: *root, - SkipFs: *skipfs, - NoJVMRun: *nojvmrun, - Wait: *wait, - Version: *version, - } - flag.Usage = func() { name := filepath.Base(os.Args[0]) fmt.Println(name, "- Utility to find JVMs/JDKs and report their versions") @@ -47,6 +37,16 @@ func main() { flag.Parse() + givenFlags := jdowser.GivenFlags{ + OutJson: *outjson, + OutCsv: *outcsv, + Root: *root, + SkipFs: *skipfs, + NoJVMRun: *nojvmrun, + Wait: *wait, + Version: *version, + } + config := jdowser.InitConfig(givenFlags) if config != nil { From 27d1f4c20f32a3803f5f550e1049330ec13aa521 Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Tue, 31 Oct 2023 14:38:31 +0200 Subject: [PATCH 03/17] feat: added a github action to release binaries on new tag --- .github/workflows/release.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fc168a5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,28 @@ +name: Generate release-artifacts + +on: + release: + types: + - created + +jobs: + generate: + name: Generate cross-platform builds + runs-on: ubuntu-latest + steps: + - name: Checkout the repository + uses: actions/checkout@v2 + - name: Generate build files + uses: thatisuday/go-cross-build@v1 + with: + platforms: 'linux/amd64, darwin/amd64, windows/amd64' + package: '' + name: 'jdowser' + compress: 'true' + dest: 'dist' + + + + + + From f4a689b87aef1c30c6fd097cf81cab7f2a6c7f58 Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Tue, 31 Oct 2023 15:26:53 +0200 Subject: [PATCH 04/17] chore: update gh action --- .github/workflows/release.yml | 49 ++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fc168a5..123d0f5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,28 +1,35 @@ -name: Generate release-artifacts +name: goreleaser on: - release: - types: - - created + release: + types: + - created + + +permissions: + contents: write jobs: - generate: - name: Generate cross-platform builds + goreleaser: runs-on: ubuntu-latest steps: - - name: Checkout the repository - uses: actions/checkout@v2 - - name: Generate build files - uses: thatisuday/go-cross-build@v1 + - + name: Checkout + uses: actions/checkout@v4 with: - platforms: 'linux/amd64, darwin/amd64, windows/amd64' - package: '' - name: 'jdowser' - compress: 'true' - dest: 'dist' - - - - - - + fetch-depth: 0 + - + name: Set up Go + uses: actions/setup-go@v4 + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + # either 'goreleaser' (default) or 'goreleaser-pro' + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution + # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} From 2b5babcfee03d807f0b2bf992609e6cc59359b9b Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Tue, 31 Oct 2023 16:06:01 +0200 Subject: [PATCH 05/17] chore: update gomod version --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index d7ba60a..6421de4 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module jdowser -go 1.21.3 +go 1.21 require golang.org/x/sys v0.13.0 From 3165565a2337bfe2885748c8f856c4c3fedd161d Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Wed, 1 Nov 2023 08:02:49 +0200 Subject: [PATCH 06/17] chore: limit binaries to linux, windows, mac, arm64 and amd64 arch --- .github/workflows/release.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 123d0f5..c90441e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,4 @@ +# https://goreleaser.com/customization/builds/ name: goreleaser on: @@ -25,11 +26,16 @@ jobs: name: Run GoReleaser uses: goreleaser/goreleaser-action@v5 with: - # either 'goreleaser' (default) or 'goreleaser-pro' distribution: goreleaser version: latest args: release --clean env: + CGO_ENABLED: 0 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution - # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} + goos: + linux + windows + darwin + goarch: + amd64 + arm64 From 4689887d24f3c9f866d244418714578b6a4bfe5b Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Wed, 1 Nov 2023 08:06:57 +0200 Subject: [PATCH 07/17] chore: bad specify envs --- .github/workflows/release.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c90441e..3f9cb80 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,10 +32,5 @@ jobs: env: CGO_ENABLED: 0 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - goos: - linux - windows - darwin - goarch: - amd64 - arm64 + goos: linux, windows, darwin + goarch: amd64, arm64 From 85ac15755c207349947084b8a19beab15c3fd0a3 Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Wed, 1 Nov 2023 08:20:42 +0200 Subject: [PATCH 08/17] fix: cleared gh action, create maxint64 manually depending on system cpu --- .github/workflows/release.yml | 2 -- jdowser/commands.go | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3f9cb80..58a169a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,5 +32,3 @@ jobs: env: CGO_ENABLED: 0 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - goos: linux, windows, darwin - goarch: amd64, arm64 diff --git a/jdowser/commands.go b/jdowser/commands.go index 9d42d8c..bb557e7 100644 --- a/jdowser/commands.go +++ b/jdowser/commands.go @@ -4,7 +4,6 @@ import ( "bufio" "encoding/json" "fmt" - "math" "os" "os/signal" "path" @@ -243,6 +242,8 @@ func CmdStop(config *Config) { return } + maxInt64 := (1 << 63) - 1 + for _, entry := range procDir { if entry.IsDir() { pidStr := entry.Name() @@ -251,7 +252,7 @@ func CmdStop(config *Config) { continue } envFile := path.Join("/proc", pidStr, "environ") - processStringsFromFile(envFile, 0, math.MaxInt64, func(str string) bool { + processStringsFromFile(envFile, 0, maxInt64, func(str string) bool { if strings.HasPrefix(str, config.Cookie) { syscall.Kill(pid, syscall.SIGTERM) return false From b11bb8b8764dc9ec032a077a0ed068690c7f0217 Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Wed, 1 Nov 2023 08:26:09 +0200 Subject: [PATCH 09/17] chore: trying generic maxInt --- jdowser/commands.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/jdowser/commands.go b/jdowser/commands.go index bb557e7..777966a 100644 --- a/jdowser/commands.go +++ b/jdowser/commands.go @@ -4,6 +4,7 @@ import ( "bufio" "encoding/json" "fmt" + "math" "os" "os/signal" "path" @@ -242,8 +243,6 @@ func CmdStop(config *Config) { return } - maxInt64 := (1 << 63) - 1 - for _, entry := range procDir { if entry.IsDir() { pidStr := entry.Name() @@ -252,7 +251,7 @@ func CmdStop(config *Config) { continue } envFile := path.Join("/proc", pidStr, "environ") - processStringsFromFile(envFile, 0, maxInt64, func(str string) bool { + processStringsFromFile(envFile, 0, math.MaxInt, func(str string) bool { if strings.HasPrefix(str, config.Cookie) { syscall.Kill(pid, syscall.SIGTERM) return false From 5d49cb3a6c2489e13a5205c6a48904d37d951ce1 Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Wed, 1 Nov 2023 08:51:46 +0200 Subject: [PATCH 10/17] chore: trying int32 for offset fail on 386 systems --- jdowser/commands.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdowser/commands.go b/jdowser/commands.go index 777966a..1caa66a 100644 --- a/jdowser/commands.go +++ b/jdowser/commands.go @@ -251,7 +251,7 @@ func CmdStop(config *Config) { continue } envFile := path.Join("/proc", pidStr, "environ") - processStringsFromFile(envFile, 0, math.MaxInt, func(str string) bool { + processStringsFromFile(envFile, 0, math.MaxInt32, func(str string) bool { if strings.HasPrefix(str, config.Cookie) { syscall.Kill(pid, syscall.SIGTERM) return false From f900b970783d99205be9d51c5c80e45053f5d48d Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Wed, 1 Nov 2023 09:11:42 +0200 Subject: [PATCH 11/17] chore: revert to int64 limit build only ro 64 systems --- .github/workflows/release.yml | 1 - .goreleaser.yaml | 12 ++++++++++++ jdowser/commands.go | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 58a169a..1dc8958 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,5 +30,4 @@ jobs: version: latest args: release --clean env: - CGO_ENABLED: 0 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..03c829d --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,12 @@ +version: 1 + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + - windows + goarch: + - amd64 + - arm64 diff --git a/jdowser/commands.go b/jdowser/commands.go index 1caa66a..9d42d8c 100644 --- a/jdowser/commands.go +++ b/jdowser/commands.go @@ -251,7 +251,7 @@ func CmdStop(config *Config) { continue } envFile := path.Join("/proc", pidStr, "environ") - processStringsFromFile(envFile, 0, math.MaxInt32, func(str string) bool { + processStringsFromFile(envFile, 0, math.MaxInt64, func(str string) bool { if strings.HasPrefix(str, config.Cookie) { syscall.Kill(pid, syscall.SIGTERM) return false From 282d6cbe27aab981d93f88de3da8411fa442f460 Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Wed, 1 Nov 2023 09:25:29 +0200 Subject: [PATCH 12/17] chore: trying with premade build settings --- .gitignore | 4 +++- .goreleaser.yaml | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 53c37a1..c4b126d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -dist \ No newline at end of file +dist +goreleaser +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 03c829d..fed0c2f 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,12 +1,47 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +# The lines bellow are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + version: 1 +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + builds: - env: - CGO_ENABLED=0 goos: - linux - - darwin - windows + - darwin goarch: - amd64 - arm64 + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" From e152a5d58b84a20fb11b5175aacdb58087caa9af Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Wed, 1 Nov 2023 09:31:38 +0200 Subject: [PATCH 13/17] fix: removed version spec from goreleaser.yml --- .goreleaser.yaml | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index fed0c2f..d5076f4 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,44 +1,30 @@ # This is an example .goreleaser.yml file with some sensible defaults. # Make sure to check the documentation at https://goreleaser.com - -# The lines bellow are called `modelines`. See `:help modeline` -# Feel free to remove those if you don't want/need to use them. -# yaml-language-server: $schema=https://goreleaser.com/static/schema.json -# vim: set ts=2 sw=2 tw=0 fo=cnqoj - -version: 1 - before: hooks: - # You may remove this if you don't use go modules. - go mod tidy builds: - env: - CGO_ENABLED=0 - goos: - - linux - - windows - - darwin - goarch: - - amd64 - - arm64 + targets: + - darwin_amd64 + - darwin_arm64 + - linux_amd64 + - linux_arm64 + - windows_amd64 + - windows_arm64 archives: - format: tar.gz - # this name template makes the OS and Arch compatible with the results of `uname`. - name_template: >- - {{ .ProjectName }}_ - {{- title .Os }}_ - {{- if eq .Arch "amd64" }}x86_64 - {{- else if eq .Arch "386" }}i386 - {{- else }}{{ .Arch }}{{ end }} - {{- if .Arm }}v{{ .Arm }}{{ end }} # use zip for windows archives format_overrides: - goos: windows format: zip - +checksum: + name_template: "checksums.txt" +snapshot: + name_template: "{{ incpatch .Version }}-next" changelog: sort: asc filters: From 2556aef51b0fa7f8a6d9b5c93c7cce77139fd99e Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Wed, 1 Nov 2023 09:35:05 +0200 Subject: [PATCH 14/17] fix: removed before hook --- .goreleaser.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index d5076f4..c9aeb41 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,8 +1,5 @@ # This is an example .goreleaser.yml file with some sensible defaults. # Make sure to check the documentation at https://goreleaser.com -before: - hooks: - - go mod tidy builds: - env: From 286738ba517e605fcacf8435a9e088ed923799c5 Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Wed, 1 Nov 2023 09:37:52 +0200 Subject: [PATCH 15/17] fix: removed windows arm code doesn't support it --- .goreleaser.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index c9aeb41..e6866e8 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -10,7 +10,7 @@ builds: - linux_amd64 - linux_arm64 - windows_amd64 - - windows_arm64 + # - windows_arm64 archives: - format: tar.gz From 485d6bf42ec268f7a74d2ad240c86341faafbeb6 Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Wed, 1 Nov 2023 09:41:22 +0200 Subject: [PATCH 16/17] fix: just keep linux --- .goreleaser.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index e6866e8..180622c 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -5,11 +5,12 @@ builds: - env: - CGO_ENABLED=0 targets: - - darwin_amd64 - - darwin_arm64 - linux_amd64 - linux_arm64 - - windows_amd64 + # NOTE: errors on build + # - darwin_arm64 + # - darwin_amd64 + # - windows_amd64 # - windows_arm64 archives: From 156303121a57065073d3d81920dbe679d8dc3fa8 Mon Sep 17 00:00:00 2001 From: ClimenteA Date: Wed, 1 Nov 2023 10:03:18 +0200 Subject: [PATCH 17/17] chore: updated docs and the makefile --- Makefile | 6 +++--- README.md | 34 +++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 740fe6e..df7f3b3 100644 --- a/Makefile +++ b/Makefile @@ -3,13 +3,13 @@ # license that can be found in the LICENSE file. # ./jdowser start +# ./jdowser status # ./jdowser -json report > output_file.json # ./jdowser -csv report > output_file.csv build-dist: rm -rf dist - GOOS=linux GOARCH=amd64 go build -o dist/jdowser_linux main.go - GOOS=darwin GOARCH=amd64 go build -o dist/jdowser_mac main.go - GOOS=windows GOARCH=amd64 go build -o dist/jdowser_windows.exe main.go + CGO_ENABLED=0 go build -o dist/jdowser main.go + cp ansible-jdowser dist/ansible-jdowser.sh diff --git a/README.md b/README.md index 640d229..860e3cb 100644 --- a/README.md +++ b/README.md @@ -25,18 +25,14 @@ The application is written in Golang, so you need to have a Golang package [inst To build JDowser: 1. Clone the JDowser project from the GitHub repository. -2. In your terminal, `cd` to the JDowser project directory. -3. Run `make`: +2. In your terminal run `make build-dist`: ```shell - $ make + $ make build-dist ``` - This generates the `jdowser` executable file. + This will generate the `jdowser` executable file in the `dist` folder. + +You can also use the already built binaries from the **Releases** section. -4. (Optional) If you observe dependency errors, run: - ```shell - $ make resolve; \ - make - ``` ## JDowser usage @@ -77,10 +73,20 @@ If you specify this parameter, the default values are ignored. ## Sample JDowser run +Start scanning filesystem, this will run in background. + ```shell $ ./jdowser -root=/opt start ``` +Or + +```shell +$ ./jdowser start +``` + +Get scanning status Running/Finished. + ```shell $ ./jdowser status @@ -91,6 +97,8 @@ end_time: -1 args: -root=/opt ``` +You can output the status to json format + ```shell $ ./jdowser -json status @@ -105,6 +113,8 @@ $ ./jdowser -json status } ``` +And, finally you can get a report simple (as below) in json or csv format. + ```shell $ ./jdowser report @@ -122,6 +132,12 @@ java_vm_version: 11.0.7+10-LTS java_vm_vendor: Azul Systems, Inc. ``` +These commands will save data into specified files: +```shell +$ ./jdowser -json report > output_file.json +$ ./jdowser -csv report > output_file.csv +``` + ## Use JDowser with Ansible