Skip to content

Commit d91f5fd

Browse files
committed
Add PomFiles function to project modules
1 parent 97dab6a commit d91f5fd

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

pomparse/pomparse.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/Graylog2/graylog-project-cli/utils"
88
"io/ioutil"
99
"os"
10+
"path/filepath"
1011
"strings"
1112
)
1213

@@ -135,3 +136,31 @@ func ParseEffectivePom(moduleName string, modulePath string) MavenPom {
135136

136137
return ParsePom(file.Name())
137138
}
139+
140+
// Return pom.xml files for the given module directory and all its submodules. If the given path is empty, the current
141+
// directory is assumed and the pom.xml file paths are relative.
142+
func FindPomFiles(path string) []string {
143+
var files []string
144+
145+
pomFile := "pom.xml"
146+
147+
if path != "" {
148+
pomFile = filepath.Join(path, pomFile)
149+
}
150+
151+
if !utils.FileExists(pomFile) {
152+
return files
153+
}
154+
155+
// First add this pom.xml
156+
files = append(files, pomFile)
157+
158+
// Then check if there are modules
159+
for _, module := range ParsePom(pomFile).Modules {
160+
modulePath := filepath.Join(path, module)
161+
162+
files = append(files, FindPomFiles(modulePath)...)
163+
}
164+
165+
return files
166+
}

project/project.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ func (module *Module) HasSubmodules() bool {
4949
return len(module.Submodules) > 0
5050
}
5151

52+
// Returns a list of pom.xml files for this modules. If the relative parameter
53+
// is set to "true", the path to the pom.xml files will be relative to the
54+
// module root.
55+
func (module *Module) PomFiles(relative bool) []string {
56+
var list []string
57+
if relative {
58+
utils.InDirectory(module.Path, func() {
59+
list = pomparse.FindPomFiles("")
60+
})
61+
} else {
62+
list = pomparse.FindPomFiles(module.Path)
63+
}
64+
return list
65+
}
66+
5267
func (module *Module) RelativePath() string {
5368
// The path in the "<module>" tag needs to be relative to make maven happy!
5469
// Using the GetRelativePathEvalSymlinks function here to make sure the relative path is as short as possible.

0 commit comments

Comments
 (0)