Skip to content

Commit 9e07638

Browse files
chore: add pre-commit config file
1 parent a740acc commit 9e07638

10 files changed

Lines changed: 408 additions & 360 deletions

File tree

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: goreleaser
33

44
on:
55
release:
6-
types:
6+
types:
77
- created
8-
8+
99

1010
permissions:
1111
contents: write

.pre-commit-config.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
repos:
2+
- repo: https://github.com/oxc-project/mirrors-oxlint
3+
rev: v1.43.0
4+
hooks:
5+
- id: oxlint
6+
verbose: false
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v6.0.0
9+
hooks:
10+
- id: check-added-large-files
11+
args: ["--maxkb=2000"]
12+
- id: check-ast
13+
- id: check-executables-have-shebangs
14+
- id: check-json
15+
- id: check-shebang-scripts-are-executable
16+
- id: check-yaml
17+
args:
18+
- --allow-multiple-documents
19+
- id: detect-private-key
20+
exclude: |
21+
(?x)^(
22+
)$
23+
- id: detect-aws-credentials
24+
args:
25+
- --allow-missing-credentials
26+
- id: end-of-file-fixer
27+
exclude: |
28+
(?x)^(
29+
)$
30+
- id: check-builtin-literals
31+
- id: check-case-conflict
32+
- id: check-docstring-first
33+
- id: check-merge-conflict
34+
- id: check-symlinks
35+
- id: check-toml
36+
- id: check-vcs-permalinks
37+
- id: check-xml
38+
- id: debug-statements
39+
- id: destroyed-symlinks
40+
- id: file-contents-sorter
41+
- id: fix-byte-order-marker
42+
- id: fix-encoding-pragma
43+
- id: forbid-new-submodules
44+
- id: forbid-submodules
45+
- id: mixed-line-ending
46+
- id: name-tests-test
47+
- id: requirements-txt-fixer
48+
- id: sort-simple-yaml
49+
- id: trailing-whitespace
50+
- id: pretty-format-json
51+
args:
52+
- --autofix
53+
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
54+
rev: v9.24.0
55+
hooks:
56+
- id: commitlint
57+
stages: [commit-msg]
58+
additional_dependencies: ["@commitlint/config-conventional"]
59+
- repo: https://github.com/dnephin/pre-commit-golang
60+
rev: v0.5.1
61+
hooks:
62+
- id: go-fmt
63+
# - id: go-vet
64+
# - id: go-lint
65+
- id: go-imports
66+
# - id: go-cyclo
67+
# args: [-over=15]
68+
- id: validate-toml
69+
- id: no-go-testing
70+
# - id: golangci-lint
71+
# - id: go-critic
72+
# - id: go-unit-tests
73+
# - id: go-build
74+
- id: go-mod-tidy
75+
- repo: https://github.com/rhysd/actionlint
76+
rev: v1.7.10
77+
hooks:
78+
- id: actionlint
79+
- repo: https://github.com/reteps/dockerfmt
80+
rev: v0.3.9
81+
hooks:
82+
- id: dockerfmt
83+
args:
84+
- --indent=4

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ build:
55
GOOS=windows GOARCH=amd64 go build -o dist/OJDMCollector-Windows-amd64bit/ojdm-collector.exe main.go
66
GOOS=linux GOARCH=amd64 go build -o dist/OJDMCollector-Linux-amd64bit/ojdm-collector main.go
77
GOOS=darwin GOARCH=amd64 go build -o dist/OJDMCollector-MacOS-amd64bit/ojdm-collector main.go
8-
GOOS=darwin GOARCH=arm64 go build -o dist/OJDMCollector-MacOS-arm64bit/ojdm-collector main.go
8+
GOOS=darwin GOARCH=arm64 go build -o dist/OJDMCollector-MacOS-arm64bit/ojdm-collector main.go

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ On Windows:
1818
On Linux / MacOS:
1919
`./ojdm-collector`
2020

21-
Running the tool on Linux may require to first make it executable by running
21+
Running the tool on Linux may require to first make it executable by running
2222
`chmod +x ojdm-collector`
2323

2424
The report.csv file will be generated in the location from which the program was executed
2525

2626
### Optional arguments
2727
-output-path string
2828
Optional: Path to csv report. (default "report.csv")
29-
29+
3030
-search-paths string
3131
Optional: List of paths separated by comma where to search for java info.
3232

@@ -78,9 +78,9 @@ Example `search-paths.txt` file:
7878
/Volumes/shared-java
7979
\\server\share\java
8080

81-
By default the program searches for Java installations in several specific local locations depending on the operating system.
81+
By default the program searches for Java installations in several specific local locations depending on the operating system.
8282

83-
On Windows:
83+
On Windows:
8484
* C:\\Program Files
8585
* C:\\Program Files (x86)
8686
* AppData\\Local for detected user profiles
@@ -104,7 +104,7 @@ On MacOs:
104104

105105

106106
## Troubleshooting
107-
If no running processes are identified, it may be because the jinfo and jps utilities could not be found on any of the discovered java installations. The easiest way to fix this is to place an OpenJDK in any of the default search paths or to include the location of the OpenJDK in the additional search paths.
107+
If no running processes are identified, it may be because the jinfo and jps utilities could not be found on any of the discovered java installations. The easiest way to fix this is to place an OpenJDK in any of the default search paths or to include the location of the OpenJDK in the additional search paths.
108108

109109
## Mentions
110-
Thanks to the Azul JDowser product which served as the inspiration for this tool.
110+
Thanks to the Azul JDowser product which served as the inspiration for this tool.

go.mod

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
11
module ojdmcollector
22

33
go 1.21
4-
5-
require github.com/shirou/gopsutil v3.21.11+incompatible
6-
7-
require (
8-
github.com/go-ole/go-ole v1.3.0 // indirect
9-
github.com/stretchr/testify v1.8.4 // indirect
10-
github.com/tklauser/go-sysconf v0.3.12 // indirect
11-
github.com/tklauser/numcpus v0.6.1 // indirect
12-
github.com/yusufpapurcu/wmi v1.2.3 // indirect
13-
golang.org/x/sys v0.14.0 // indirect
14-
)

go.sum

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +0,0 @@
1-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
4-
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
5-
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
6-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8-
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
9-
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
10-
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
11-
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
12-
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
13-
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
14-
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
15-
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
16-
github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw=
17-
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
18-
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
19-
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
20-
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
21-
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
22-
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
23-
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
24-
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
25-
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

ojdmcollector/javafullinfo.go

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
1-
package ojdmcollector
2-
3-
import (
4-
"fmt"
5-
"sort"
6-
)
7-
8-
func CollectJavaInfo(searchPaths []string) []JavaInfoRunningProcs {
9-
10-
var javaInfos []JavaInfoRunningProcs
11-
var versionInfos []JavaInfoRunningProcs
12-
javaBasePAths := getJavaSharedLibPaths(searchPaths)
13-
14-
versionInfos = GetJavaVersionInfos(javaBasePAths)
15-
sort.Slice(versionInfos, func(i, j int) bool {
16-
return versionInfos[i].JavaVersion > versionInfos[j].JavaVersion
17-
})
18-
19-
var toolFound *JavaInfoRunningProcs
20-
for _, info := range versionInfos {
21-
if info.JpsJinfoPresent {
22-
toolFound = &info
23-
break
24-
}
25-
}
26-
27-
if toolFound != nil {
28-
javaProcesses := GetJavaProcessInfo(toolFound.JavaHome)
29-
javaInfos = append(javaInfos, javaProcesses...)
30-
} else {
31-
fmt.Println("Did not find the jinfo and jps binaries, running processes will not be identified.")
32-
}
33-
34-
mergedJavaInfo := mergeSlices(javaInfos, versionInfos)
35-
36-
return mergedJavaInfo
37-
}
38-
39-
func mergeSlices(processInfo, versionInfo []JavaInfoRunningProcs) []JavaInfoRunningProcs {
40-
mergedSlice := make([]JavaInfoRunningProcs, 0)
41-
versionMap := make(map[string]*JavaInfoRunningProcs)
42-
processMap := make(map[string]bool)
43-
44-
// Create a map from versionInfo
45-
for i, vInfoItem := range versionInfo {
46-
normalizedJavaHome := normalizePath(vInfoItem.JavaHome)
47-
versionMap[normalizedJavaHome] = &versionInfo[i]
48-
}
49-
50-
// Iterate over processInfo and merge or add unique items
51-
for _, pInfoItem := range processInfo {
52-
normalizedJavaHome := normalizePath(pInfoItem.JavaHome)
53-
if vInfoItem, exists := versionMap[normalizedJavaHome]; exists {
54-
// Merge with versionInfo item
55-
mergedItem := *vInfoItem
56-
mergedItem.ProcessRunning = pInfoItem.ProcessRunning
57-
mergedItem.ProcessPath = pInfoItem.ProcessPath
58-
mergedItem.CommandLine = pInfoItem.CommandLine
59-
mergedSlice = append(mergedSlice, mergedItem)
60-
61-
// Mark as processed
62-
processMap[normalizedJavaHome] = true
63-
} else {
64-
// Add unique processInfo item
65-
mergedSlice = append(mergedSlice, pInfoItem)
66-
}
67-
}
68-
69-
// Add any versionInfo items that weren't merged
70-
for _, vInfoItem := range versionInfo {
71-
normalizedJavaHome := normalizePath(vInfoItem.JavaHome)
72-
if !processMap[normalizedJavaHome] {
73-
mergedSlice = append(mergedSlice, vInfoItem)
74-
}
75-
}
76-
77-
return mergedSlice
78-
}
1+
package ojdmcollector
2+
3+
import (
4+
"fmt"
5+
"sort"
6+
)
7+
8+
func CollectJavaInfo(searchPaths []string) []JavaInfoRunningProcs {
9+
10+
var javaInfos []JavaInfoRunningProcs
11+
var versionInfos []JavaInfoRunningProcs
12+
javaBasePAths := getJavaSharedLibPaths(searchPaths)
13+
14+
versionInfos = GetJavaVersionInfos(javaBasePAths)
15+
sort.Slice(versionInfos, func(i, j int) bool {
16+
return versionInfos[i].JavaVersion > versionInfos[j].JavaVersion
17+
})
18+
19+
var toolFound *JavaInfoRunningProcs
20+
for _, info := range versionInfos {
21+
if info.JpsJinfoPresent {
22+
toolFound = &info
23+
break
24+
}
25+
}
26+
27+
if toolFound != nil {
28+
javaProcesses := GetJavaProcessInfo(toolFound.JavaHome)
29+
javaInfos = append(javaInfos, javaProcesses...)
30+
} else {
31+
fmt.Println("Did not find the jinfo and jps binaries, running processes will not be identified.")
32+
}
33+
34+
mergedJavaInfo := mergeSlices(javaInfos, versionInfos)
35+
36+
return mergedJavaInfo
37+
}
38+
39+
func mergeSlices(processInfo, versionInfo []JavaInfoRunningProcs) []JavaInfoRunningProcs {
40+
mergedSlice := make([]JavaInfoRunningProcs, 0)
41+
versionMap := make(map[string]*JavaInfoRunningProcs)
42+
processMap := make(map[string]bool)
43+
44+
// Create a map from versionInfo
45+
for i, vInfoItem := range versionInfo {
46+
normalizedJavaHome := normalizePath(vInfoItem.JavaHome)
47+
versionMap[normalizedJavaHome] = &versionInfo[i]
48+
}
49+
50+
// Iterate over processInfo and merge or add unique items
51+
for _, pInfoItem := range processInfo {
52+
normalizedJavaHome := normalizePath(pInfoItem.JavaHome)
53+
if vInfoItem, exists := versionMap[normalizedJavaHome]; exists {
54+
// Merge with versionInfo item
55+
mergedItem := *vInfoItem
56+
mergedItem.ProcessRunning = pInfoItem.ProcessRunning
57+
mergedItem.ProcessPath = pInfoItem.ProcessPath
58+
mergedItem.CommandLine = pInfoItem.CommandLine
59+
mergedSlice = append(mergedSlice, mergedItem)
60+
61+
// Mark as processed
62+
processMap[normalizedJavaHome] = true
63+
} else {
64+
// Add unique processInfo item
65+
mergedSlice = append(mergedSlice, pInfoItem)
66+
}
67+
}
68+
69+
// Add any versionInfo items that weren't merged
70+
for _, vInfoItem := range versionInfo {
71+
normalizedJavaHome := normalizePath(vInfoItem.JavaHome)
72+
if !processMap[normalizedJavaHome] {
73+
mergedSlice = append(mergedSlice, vInfoItem)
74+
}
75+
}
76+
77+
return mergedSlice
78+
}

0 commit comments

Comments
 (0)