Skip to content

Commit

Permalink
update deps.dev/util/maven (#892)
Browse files Browse the repository at this point in the history
This PR updates `deps.dev/util/maven` to the latest version.
  • Loading branch information
cuixq authored Mar 27, 2024
1 parent 1c01916 commit a851e82
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 34 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.21.8

require (
deps.dev/api/v3 v3.0.0-20240318003216-81f538734eda
deps.dev/util/maven v0.0.0-20240318003216-81f538734eda
deps.dev/util/resolve v0.0.0-20240318003216-81f538734eda
deps.dev/util/semver v0.0.0-20240318003216-81f538734eda
deps.dev/util/maven v0.0.0-20240322043601-ff53416fec6a
deps.dev/util/resolve v0.0.0-20240322043601-ff53416fec6a
deps.dev/util/semver v0.0.0-20240322043601-ff53416fec6a
github.com/BurntSushi/toml v1.3.2
github.com/CycloneDX/cyclonedx-go v0.8.0
github.com/charmbracelet/bubbles v0.18.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
deps.dev/api/v3 v3.0.0-20240318003216-81f538734eda h1:PsXawR2L0l1oqy0mbydQO6KDvELa1rxxh0fb9WzMTOU=
deps.dev/api/v3 v3.0.0-20240318003216-81f538734eda/go.mod h1:k3RHZwAw7ijqoXmVDvcO7ikeTwTC4jtmhCDathV+IKE=
deps.dev/util/maven v0.0.0-20240318003216-81f538734eda h1:7itah956/F9BOpNY1rAmfayhliAUeEONUiLGFq/zV3Y=
deps.dev/util/maven v0.0.0-20240318003216-81f538734eda/go.mod h1:SBW3EribdkZYk6zxi5oVn/ZECvi4ixb7EGgEWfSimNk=
deps.dev/util/resolve v0.0.0-20240318003216-81f538734eda h1:Mi492CiTkpotwyxs4x5GtvvJngMU1luwHz87pgDJjTY=
deps.dev/util/resolve v0.0.0-20240318003216-81f538734eda/go.mod h1:nNVaBL87+SIfv5gk8P26tpiF0+YqpW0gnXMe0066gtE=
deps.dev/util/semver v0.0.0-20240318003216-81f538734eda h1:bSqyDUzYy/rudrbXtD/LGzAeVC5bObcmkje6E12JP8I=
deps.dev/util/semver v0.0.0-20240318003216-81f538734eda/go.mod h1:jkcH+k02gWHBiZ7G4OnUOkSZ6WDq54Pt5DrOA8FN8Uo=
deps.dev/util/maven v0.0.0-20240322043601-ff53416fec6a h1:4WKIvv/Ogb2QKl1pTby5VHuiwZy6UbHj1R21cGqzLUc=
deps.dev/util/maven v0.0.0-20240322043601-ff53416fec6a/go.mod h1:SBW3EribdkZYk6zxi5oVn/ZECvi4ixb7EGgEWfSimNk=
deps.dev/util/resolve v0.0.0-20240322043601-ff53416fec6a h1:znFPMwSoMw79EZOtyyQ431KgbX1IxaxWvE6SeJN/YLg=
deps.dev/util/resolve v0.0.0-20240322043601-ff53416fec6a/go.mod h1:nNVaBL87+SIfv5gk8P26tpiF0+YqpW0gnXMe0066gtE=
deps.dev/util/semver v0.0.0-20240322043601-ff53416fec6a h1:iWYCcAFEsmh5N23VZHrW7HoUE5uR6U25gw8W15C1jto=
deps.dev/util/semver v0.0.0-20240322043601-ff53416fec6a/go.mod h1:jkcH+k02gWHBiZ7G4OnUOkSZ6WDq54Pt5DrOA8FN8Uo=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/CycloneDX/cyclonedx-go v0.8.0 h1:FyWVj6x6hoJrui5uRQdYZcSievw3Z32Z88uYzG/0D6M=
Expand Down
34 changes: 9 additions & 25 deletions internal/resolution/manifest/maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (m MavenManifestIO) Read(df lockfile.DepFile) (Manifest, error) {
var reqsWithProps []resolve.RequirementVersion
addReqsWithProps := func(deps []maven.Dependency, origin string) {
for _, dep := range deps {
if ContainsProperty(dep.Version) {
if dep.Version.ContainsProperty() {
// We only need the original import if the version contains any property.
reqsWithProps = append(reqsWithProps, makeRequirementVersion(dep, origin))
}
Expand All @@ -67,7 +67,7 @@ func (m MavenManifestIO) Read(df lockfile.DepFile) (Manifest, error) {
addReqsWithProps(profile.DependencyManagement.Dependencies, mavenOrigin(OriginProfile, string(profile.ID), OriginManagement))
}
for _, plugin := range project.Build.PluginManagement.Plugins {
addReqsWithProps(plugin.Dependencies, mavenOrigin(OriginPlugin, mavenName(plugin.ProjectKey)))
addReqsWithProps(plugin.Dependencies, mavenOrigin(OriginPlugin, plugin.ProjectKey.Name()))
}

// Interpolate the project to resolve the properties.
Expand All @@ -83,7 +83,7 @@ func (m MavenManifestIO) Read(df lockfile.DepFile) (Manifest, error) {
if dep.Scope != "" {
pk := resolve.PackageKey{
System: resolve.Maven,
Name: mavenDepName(dep),
Name: dep.Name(),
}
groups[pk] = append(groups[pk], string(dep.Scope))
}
Expand All @@ -94,7 +94,7 @@ func (m MavenManifestIO) Read(df lockfile.DepFile) (Manifest, error) {
VersionKey: resolve.VersionKey{
PackageKey: resolve.PackageKey{
System: resolve.Maven,
Name: mavenName(project.Parent.ProjectKey),
Name: project.Parent.ProjectKey.Name(),
},
// Parent version is a concrete version, but we model parent as dependency here.
VersionType: resolve.Requirement,
Expand All @@ -116,7 +116,7 @@ func (m MavenManifestIO) Read(df lockfile.DepFile) (Manifest, error) {
}
}
for _, plugin := range project.Build.PluginManagement.Plugins {
addRequirements(plugin.Dependencies, mavenOrigin(OriginPlugin, mavenName(plugin.ProjectKey)))
addRequirements(plugin.Dependencies, mavenOrigin(OriginPlugin, plugin.ProjectKey.Name()))
}

return Manifest{
Expand All @@ -125,7 +125,7 @@ func (m MavenManifestIO) Read(df lockfile.DepFile) (Manifest, error) {
VersionKey: resolve.VersionKey{
PackageKey: resolve.PackageKey{
System: resolve.Maven,
Name: mavenName(project.ProjectKey),
Name: project.ProjectKey.Name(),
},
VersionType: resolve.Concrete,
Version: string(project.Version),
Expand All @@ -140,14 +140,6 @@ func (m MavenManifestIO) Read(df lockfile.DepFile) (Manifest, error) {
}, nil
}

// ContainsProperty returns whether a string contains property placeholder.
// Any Maven string could contain property placeholders like ${name},
// and the corresponding values are defined in properties section.
func ContainsProperty(str maven.String) bool {
i := strings.Index(string(str), "${")
return i >= 0 && strings.Contains(string(str[i+2:]), "}")
}

// For dependencies in profiles and plugins, we use origin to indicate where they are from.
// The origin is in the format prefix@identifier[@postfix] (where @ is the separator):
// - prefix indicates it is from profile or plugin
Expand All @@ -158,7 +150,7 @@ func makeRequirementVersion(dep maven.Dependency, origin string) resolve.Require
VersionKey: resolve.VersionKey{
PackageKey: resolve.PackageKey{
System: resolve.Maven,
Name: mavenDepName(dep),
Name: dep.Name(),
},
VersionType: resolve.Requirement,
Version: string(dep.Version),
Expand All @@ -167,14 +159,6 @@ func makeRequirementVersion(dep maven.Dependency, origin string) resolve.Require
}
}

func mavenName(key maven.ProjectKey) string {
return fmt.Sprintf("%s:%s", key.GroupID, key.ArtifactID)
}

func mavenDepName(dep maven.Dependency) string {
return fmt.Sprintf("%s:%s", dep.GroupID, dep.ArtifactID)
}

func mavenOrigin(list ...string) string {
result := ""
for _, str := range list {
Expand Down Expand Up @@ -410,7 +394,7 @@ func updateProject(enc *xml.Encoder, raw, prefix, id string, patches map[string]
if err := dec.DecodeElement(&rawPlugin, &tt); err != nil {
return err
}
if err := updateProject(enc, "<plugin>"+rawPlugin.InnerXML+"</plugin>", OriginPlugin, mavenName(rawPlugin.ProjectKey), patches, properties); err != nil {
if err := updateProject(enc, "<plugin>"+rawPlugin.InnerXML+"</plugin>", OriginPlugin, rawPlugin.ProjectKey.Name(), patches, properties); err != nil {
return fmt.Errorf("updating profile: %w", err)
}

Expand Down Expand Up @@ -480,7 +464,7 @@ func updateDependency(enc *xml.Encoder, raw string, patches []DependencyPatch) e
return fmt.Errorf("depTypeToMavenDependency: %w", err)
}
// A Maven dependency key consists of Type and Classifier together with GroupID and ArtifactID.
if patch.Pkg.Name == mavenDepName(rawDep.Dependency) && d.Type == rawDep.Type && d.Classifier == rawDep.Classifier {
if patch.Pkg.Name == rawDep.Dependency.Name() && d.Type == rawDep.Type && d.Classifier == rawDep.Classifier {
req = patch.NewRequire
}
}
Expand Down

0 comments on commit a851e82

Please sign in to comment.