DownloadPomFromRepo 从maven仓库下载pom dep: pom的dependency内容 do: 对http.Response.Body的操作 repos: 额外使用的maven仓库
(dep PomDependency, do func(r io.Reader), repos ...common.RepoConfig)
| 480 | // do: 对http.Response.Body的操作 |
| 481 | // repos: 额外使用的maven仓库 |
| 482 | func DownloadPomFromRepo(dep PomDependency, do func(r io.Reader), repos ...common.RepoConfig) { |
| 483 | |
| 484 | if !dep.Check() { |
| 485 | return |
| 486 | } |
| 487 | |
| 488 | // 正式版本 |
| 489 | pom := fmt.Sprintf("%s/%s/%s/%s-%s.pom", strings.ReplaceAll(dep.GroupId, ".", "/"), dep.ArtifactId, dep.Version, dep.ArtifactId, dep.Version) |
| 490 | common.DownloadUrlFromRepos(pom, func(repo common.RepoConfig, r io.Reader) { do(r) }, append(defaultMavenRepo, repos...)...) |
| 491 | |
| 492 | // 快照版本 |
| 493 | if !strings.HasSuffix(strings.ToLower(dep.Version), "-snapshot") { |
| 494 | return |
| 495 | } |
| 496 | snap := fmt.Sprintf("%s/%s/%s/maven-metadata.xml", strings.ReplaceAll(dep.GroupId, ".", "/"), dep.ArtifactId, dep.Version) |
| 497 | common.DownloadUrlFromRepos(snap, func(repo common.RepoConfig, r io.Reader) { |
| 498 | |
| 499 | metadata := struct { |
| 500 | LastTime string `xml:"versioning>lastUpdated"` |
| 501 | SnapVersions []struct { |
| 502 | Version string `xml:"value"` |
| 503 | Time string `xml:"updated"` |
| 504 | } `xml:"versioning>snapshotVersions>snapshotVersion"` |
| 505 | }{} |
| 506 | |
| 507 | err := xml.NewDecoder(r).Decode(&metadata) |
| 508 | if err != nil { |
| 509 | logs.Warn(err) |
| 510 | } |
| 511 | |
| 512 | if metadata.LastTime == "" { |
| 513 | return |
| 514 | } |
| 515 | |
| 516 | for _, snap := range metadata.SnapVersions { |
| 517 | if snap.Time == metadata.LastTime { |
| 518 | snapom := fmt.Sprintf("%s/%s/%s/%s-%s.pom", strings.ReplaceAll(dep.GroupId, ".", "/"), dep.ArtifactId, snap.Version, dep.ArtifactId, snap.Version) |
| 519 | common.DownloadUrlFromRepos(snapom, func(repo common.RepoConfig, r io.Reader) { do(r) }, repo) |
| 520 | break |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | }, append(defaultMavenRepo, repos...)...) |
| 525 | |
| 526 | } |
| 527 | |
| 528 | // MvnTree 调用mvn dependency:tree解析依赖 |
| 529 | // pom: pom文件信息 |