Skip to content

Commit 4844d95

Browse files
committed
return non-zero exit code on resolving failures
Signed-off-by: Jakub Sokołowski <[email protected]>
1 parent 56601a0 commit 4844d95

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ The package name takes the Maven format: `<groupId>:<artifactId>:<version>`
1515

1616
There's also a few flags available:
1717
```
18-
Usage of go-maven-resolver:
18+
Usage of ./go-maven-resolver:
19+
-exitCode
20+
Set exit code on any resolving failures. (default true)
21+
-ignoreOptional
22+
Ignore optional dependencies. (default true)
1923
-ignoreScopes string
2024
Scopes to ignore. (default "provided,system,test")
2125
-recursive
2226
Should recursive resolution be done (default true)
2327
-reposFile string
2428
Path file with repo URLs to check.
29+
-retries int
30+
HTTP request retries on non-404 codes. (default 2)
2531
-timeout int
2632
HTTP request timeout in seconds. (default 2)
2733
-workers int

finder/finder.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Options struct {
1717
}
1818

1919
type Finder struct {
20+
failed bool /* set to true if any requests failed */
2021
opts Options /* options for handling dependencies */
2122
fetchers fetcher.Fetcher /* pool of workers for HTTP requests */
2223
l *log.Logger /* for logging events */
@@ -109,13 +110,15 @@ func (f *Finder) FindUrls(dep pom.Dependency) {
109110
url, project, err := f.ResolveDep(dep)
110111
if err != nil {
111112
f.l.Printf("error: '%s' for: %s", err, dep)
113+
f.failed = true
112114
return
113115
}
114116

115117
/* This should never happen, since most of the time if ResolveDep()
116118
* fails it is due to an HTTP error or XML parsing error. */
117119
if url == "" {
118120
f.l.Printf("error: 'no URL found' for: %s", dep)
121+
f.failed = true
119122
return
120123
}
121124

@@ -143,3 +146,7 @@ func (f *Finder) Resolve(dep pom.Dependency) {
143146
func (f *Finder) Wait() {
144147
f.wg.Wait()
145148
}
149+
150+
func (f *Finder) Failed() bool {
151+
return f.failed
152+
}

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var (
2222
ignoreScopes string
2323
ignoreOptional bool
2424
recursive bool
25+
exitCode bool
2526
)
2627

2728
const helpMessage string = `
@@ -52,6 +53,7 @@ func flagsInit() {
5253
flag.StringVar(&reposFile, "reposFile", "", "Path file with repo URLs to check.")
5354
flag.StringVar(&ignoreScopes, "ignoreScopes", "provided,system,test", "Scopes to ignore.")
5455
flag.BoolVar(&ignoreOptional, "ignoreOptional", true, "Ignore optional dependencies.")
56+
flag.BoolVar(&exitCode, "exitCode", true, "Set exit code on any resolving failures.")
5557
flag.Parse()
5658
}
5759

@@ -106,4 +108,9 @@ func main() {
106108
/* Each FindUrls() call can spawn more recursive FindUrls() routines.
107109
* To know when to stop the process they also increment the WaitGroup. */
108110
fnr.Wait()
111+
112+
/* If any of the requests failed return a non-0 exit code */
113+
if exitCode && fnr.Failed() {
114+
os.Exit(1)
115+
}
109116
}

0 commit comments

Comments
 (0)