mirror of
https://github.com/Graylog2/graylog-project-cli.git
synced 2026-03-13 08:02:57 +08:00
Add PomFiles function to project modules
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/Graylog2/graylog-project-cli/utils"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -135,3 +136,31 @@ func ParseEffectivePom(moduleName string, modulePath string) MavenPom {
|
||||
|
||||
return ParsePom(file.Name())
|
||||
}
|
||||
|
||||
// Return pom.xml files for the given module directory and all its submodules. If the given path is empty, the current
|
||||
// directory is assumed and the pom.xml file paths are relative.
|
||||
func FindPomFiles(path string) []string {
|
||||
var files []string
|
||||
|
||||
pomFile := "pom.xml"
|
||||
|
||||
if path != "" {
|
||||
pomFile = filepath.Join(path, pomFile)
|
||||
}
|
||||
|
||||
if !utils.FileExists(pomFile) {
|
||||
return files
|
||||
}
|
||||
|
||||
// First add this pom.xml
|
||||
files = append(files, pomFile)
|
||||
|
||||
// Then check if there are modules
|
||||
for _, module := range ParsePom(pomFile).Modules {
|
||||
modulePath := filepath.Join(path, module)
|
||||
|
||||
files = append(files, FindPomFiles(modulePath)...)
|
||||
}
|
||||
|
||||
return files
|
||||
}
|
||||
|
||||
@@ -49,6 +49,21 @@ func (module *Module) HasSubmodules() bool {
|
||||
return len(module.Submodules) > 0
|
||||
}
|
||||
|
||||
// Returns a list of pom.xml files for this modules. If the relative parameter
|
||||
// is set to "true", the path to the pom.xml files will be relative to the
|
||||
// module root.
|
||||
func (module *Module) PomFiles(relative bool) []string {
|
||||
var list []string
|
||||
if relative {
|
||||
utils.InDirectory(module.Path, func() {
|
||||
list = pomparse.FindPomFiles("")
|
||||
})
|
||||
} else {
|
||||
list = pomparse.FindPomFiles(module.Path)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func (module *Module) RelativePath() string {
|
||||
// The path in the "<module>" tag needs to be relative to make maven happy!
|
||||
// Using the GetRelativePathEvalSymlinks function here to make sure the relative path is as short as possible.
|
||||
|
||||
Reference in New Issue
Block a user