File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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+
5267func (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.
You can’t perform that action at this time.
0 commit comments