2024-03-04 13:11:06 +00:00
|
|
|
package paths
|
|
|
|
|
|
|
|
import (
|
2024-03-04 18:50:13 +00:00
|
|
|
"github.com/1f349/gomvn/database/types"
|
2024-03-04 13:11:06 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2024-03-04 18:50:13 +00:00
|
|
|
func GetRepositories(basePath string, repository []string) map[string][]*types.Artifact {
|
|
|
|
result := map[string][]*types.Artifact{}
|
2024-03-04 13:11:06 +00:00
|
|
|
for _, repo := range repository {
|
2024-03-04 18:50:13 +00:00
|
|
|
result[repo] = []*types.Artifact{}
|
2024-03-04 13:11:06 +00:00
|
|
|
repoPath := filepath.Join(basePath, repo)
|
|
|
|
_ = filepath.Walk(repoPath, func(path string, info os.FileInfo, err error) error {
|
|
|
|
if strings.HasSuffix(path, ".pom") {
|
|
|
|
path = strings.Replace(path, "\\", "/", -1)
|
|
|
|
path = strings.Replace(path, repoPath+"/", "", 1)
|
2024-03-04 18:50:13 +00:00
|
|
|
|
|
|
|
parts := strings.Split(path, "/")
|
|
|
|
last := len(parts) - 1
|
|
|
|
artifact := &types.Artifact{
|
|
|
|
MvnGroup: strings.Join(parts[0:last-2], "."),
|
|
|
|
Artifact: parts[last-2],
|
|
|
|
Version: parts[last-1],
|
|
|
|
Modified: info.ModTime(),
|
|
|
|
}
|
2024-03-04 13:11:06 +00:00
|
|
|
result[repo] = append(result[repo], artifact)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|