diff --git a/go.mod b/go.mod index 67cdb25faf..469983f06c 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index e3678a43ca..039c85e41f 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/resolution/manifest/maven.go b/internal/resolution/manifest/maven.go index 6020cd8b1d..0500339bc9 100644 --- a/internal/resolution/manifest/maven.go +++ b/internal/resolution/manifest/maven.go @@ -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)) } @@ -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. @@ -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)) } @@ -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, @@ -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{ @@ -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), @@ -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 @@ -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), @@ -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 { @@ -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, ""+rawPlugin.InnerXML+"", OriginPlugin, mavenName(rawPlugin.ProjectKey), patches, properties); err != nil { + if err := updateProject(enc, ""+rawPlugin.InnerXML+"", OriginPlugin, rawPlugin.ProjectKey.Name(), patches, properties); err != nil { return fmt.Errorf("updating profile: %w", err) } @@ -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 } }