Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen committed Jun 18, 2024
1 parent 4d67e6f commit 8c54d0a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 8 additions & 6 deletions pkg/dependency/parser/java/pom/metadata.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package pom

type Metadata struct {
GroupId string `xml:"groupId"`
ArtifactId string `xml:"artifactId"`
Versioning struct {
SnapshotVersions []SnapshotVersion `xml:"snapshotVersions>snapshotVersion"`
} `xml:"versioning"`
Version string `xml:"version"`
GroupId string `xml:"groupId"`
ArtifactId string `xml:"artifactId"`
Versioning Versioning `xml:"versioning"`
Version string `xml:"version"`
}

type Versioning struct {
SnapshotVersions []SnapshotVersion `xml:"snapshotVersions>snapshotVersion"`
}

type SnapshotVersion struct {
Expand Down
10 changes: 5 additions & 5 deletions pkg/dependency/parser/java/pom/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ func (p *Parser) fetchPOMFromRemoteRepositories(paths []string, snapshot bool) (
return nil, xerrors.Errorf("the POM was not found in remote remoteRepositories")
}

func (p *Parser) repoRequest(repo string, paths []string) (*http.Request, error) {
func (p *Parser) remoteRepoRequest(repo string, paths []string) (*http.Request, error) {
repoURL, err := url.Parse(repo)
if err != nil {
p.logger.Error("URL parse error", log.String("repo", repo))
Expand Down Expand Up @@ -707,7 +707,7 @@ func (p *Parser) fetchPomFileNameFromMavenMetadata(repo string, paths []string)
mavenMetadataPaths := slices.Clone(paths[:len(paths)-1]) // Clone slice to avoid shadow overwriting last element of `paths`
mavenMetadataPaths = append(mavenMetadataPaths, "maven-metadata.xml")

req, err := p.repoRequest(repo, mavenMetadataPaths)
req, err := p.remoteRepoRequest(repo, mavenMetadataPaths)
if err != nil {
return "", xerrors.Errorf("unable to create request for maven-metadata.xml file")
}
Expand All @@ -722,13 +722,13 @@ func (p *Parser) fetchPomFileNameFromMavenMetadata(repo string, paths []string)

mavenMetadata, err := parseMavenMetadata(resp.Body)
if err != nil {
return "", xerrors.Errorf("failed to parse the remote POM: %w", err)
return "", xerrors.Errorf("failed to parse maven-metadata.xml file: %w", err)
}

var pomFileName string
for _, sv := range mavenMetadata.Versioning.SnapshotVersions {
if sv.Extension == "pom" {
// mavenMetadataPaths[len(mavenMetadataPaths)-3] is artifactID
// mavenMetadataPaths[len(mavenMetadataPaths)-3] is always artifactID
pomFileName = fmt.Sprintf("%s-%s.pom", mavenMetadataPaths[len(mavenMetadataPaths)-3], sv.Value)
}
}
Expand All @@ -737,7 +737,7 @@ func (p *Parser) fetchPomFileNameFromMavenMetadata(repo string, paths []string)
}

func (p *Parser) fetchPOMFromRemoteRepository(repo string, paths []string) (*pom, error) {
req, err := p.repoRequest(repo, paths)
req, err := p.remoteRepoRequest(repo, paths)
if err != nil {
return nil, xerrors.Errorf("unable to create request for pom file")
}
Expand Down

0 comments on commit 8c54d0a

Please sign in to comment.