Skip to content

Commit

Permalink
Merge branch 'main' into dependabot
Browse files Browse the repository at this point in the history
  • Loading branch information
cuixq authored Dec 18, 2024
2 parents 00f9c9f + 3890182 commit 155ad6c
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 76 deletions.
11 changes: 5 additions & 6 deletions api/v3/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ go 1.20

require (
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1
google.golang.org/grpc v1.56.3
google.golang.org/protobuf v1.33.0
google.golang.org/grpc v1.69.0
google.golang.org/protobuf v1.36.0
)

require (
github.com/golang/protobuf v1.5.3 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
)
48 changes: 30 additions & 18 deletions api/v3/go.sum
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE=
go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE=
go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY=
go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk=
go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08KsbbO5BPT0=
go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4JjxTeYusH7zMc=
go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8=
go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys=
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A=
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU=
google.golang.org/grpc v1.56.3 h1:8I4C0Yq1EjstUzUJzpcRVbuYA2mODtEmpWiQoN/b2nc=
google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/grpc v1.69.0 h1:quSiOM1GJPmPH5XtU+BCoVXcDVJJAzNcoyfC2cCjGkI=
google.golang.org/grpc v1.69.0/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
11 changes: 5 additions & 6 deletions api/v3alpha/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ go 1.20

require (
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1
google.golang.org/grpc v1.56.3
google.golang.org/protobuf v1.33.0
google.golang.org/grpc v1.69.0
google.golang.org/protobuf v1.36.0
)

require (
github.com/golang/protobuf v1.5.3 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
)
48 changes: 30 additions & 18 deletions api/v3alpha/go.sum
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE=
go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE=
go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY=
go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk=
go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08KsbbO5BPT0=
go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4JjxTeYusH7zMc=
go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8=
go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys=
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A=
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU=
google.golang.org/grpc v1.56.3 h1:8I4C0Yq1EjstUzUJzpcRVbuYA2mODtEmpWiQoN/b2nc=
google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/grpc v1.69.0 h1:quSiOM1GJPmPH5XtU+BCoVXcDVJJAzNcoyfC2cCjGkI=
google.golang.org/grpc v1.69.0/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
2 changes: 1 addition & 1 deletion util/maven/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Dependency struct {
Classifier String `xml:"classifier,omitempty"`
Scope String `xml:"scope,omitempty"`
Exclusions []Exclusion `xml:"exclusions>exclusion,omitempty"`
Optional BoolString `xml:"optional,omitempty"`
Optional FalsyBool `xml:"optional,omitempty"`
}

type Exclusion struct {
Expand Down
4 changes: 2 additions & 2 deletions util/maven/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Profile struct {
// Activation contains information to decide if a build profile is activated or not.
// https://maven.apache.org/guides/introduction/introduction-to-profiles.html#details-on-profile-activation=
type Activation struct {
ActiveByDefault BoolString `xml:"activeByDefault,omitempty"`
ActiveByDefault FalsyBool `xml:"activeByDefault,omitempty"`
JDK String `xml:"jdk,omitempty"`
OS ActivationOS `xml:"os,omitempty"`
Property ActivationProperty `xml:"property,omitempty"`
Expand Down Expand Up @@ -185,7 +185,7 @@ func (p *Project) MergeProfiles(jdk string, os ActivationOS) (err error) {
if act {
activeProfiles = append(activeProfiles, prof)
}
if prof.Activation.ActiveByDefault == "true" {
if prof.Activation.ActiveByDefault.Boolean() {
defaultProfiles = append(defaultProfiles, prof)
}
}
Expand Down
4 changes: 2 additions & 2 deletions util/maven/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (p *PluginManagement) merge(parent PluginManagement) {

type Plugin struct {
ProjectKey
Inherited BoolString `xml:"inherited,omitempty"`
Inherited TruthyBool `xml:"inherited,omitempty"`
Dependencies []Dependency `xml:"dependencies>dependency,omitempty"`
}

Expand Down Expand Up @@ -215,7 +215,7 @@ func (r *Repository) interpolate(properties map[string]string) bool {
}

type RepositoryPolicy struct {
Enabled String `xml:"enabled"`
Enabled TruthyBool `xml:"enabled"`
}

func (rp *RepositoryPolicy) interpolate(properties map[string]string) bool {
Expand Down
66 changes: 57 additions & 9 deletions util/maven/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,82 @@ func (s *String) interpolate(dictionary map[string]string) bool {
return ok
}

// BoolString represents a string field that holds a boolean value.
// BoolString may contain placeholders which need to be interpolated.
type BoolString string
// TruthyBool represents a string field that holds a boolean value,
// and the default value is true.
// TruthyBool may contain placeholders which need to be interpolated.
type TruthyBool String

func (bs *BoolString) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
func (tb *TruthyBool) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var str string
err := d.DecodeElement(&str, &start)
if err != nil {
return err
}

// Maven accepts only "", "true", "false" or a placeholder "${...}".
str = strings.TrimSpace(str)
if strings.Contains(str, "${") && strings.Contains(str, "}") {
*bs = BoolString(str)
*tb = TruthyBool(str)
return nil
}
if ss := strings.ToLower(str); ss == "true" || ss == "false" || ss == "" {
*bs = BoolString(ss)
*tb = TruthyBool(ss)
return nil
}
return fmt.Errorf("unrecognized boolean %q", str)
}

func (bs *BoolString) interpolate(dictionary map[string]string) bool {
result, ok := interpolating(string(*bs), dictionary, make(map[string]bool))
*bs = BoolString(result)
func (tb *TruthyBool) interpolate(dictionary map[string]string) bool {
result, ok := interpolating(string(*tb), dictionary, make(map[string]bool))
*tb = TruthyBool(result)
return ok
}

func (tb *TruthyBool) Boolean() bool {
if *tb == "" {
return true
}
return *tb == "true"
}

// FalsyBool represents a string field that holds a boolean value,
// and the default value is false.
// FalsyBool may contain placeholders which need to be interpolated.
type FalsyBool String

func (fb *FalsyBool) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var str string
err := d.DecodeElement(&str, &start)
if err != nil {
return err
}

// Maven accepts only "", "true", "false" or a placeholder "${...}".
str = strings.TrimSpace(str)
if strings.Contains(str, "${") && strings.Contains(str, "}") {
*fb = FalsyBool(str)
return nil
}
if ss := strings.ToLower(str); ss == "true" || ss == "false" || ss == "" {
*fb = FalsyBool(ss)
return nil
}
return fmt.Errorf("unrecognized boolean %q", str)
}

func (fb *FalsyBool) interpolate(dictionary map[string]string) bool {
result, ok := interpolating(string(*fb), dictionary, make(map[string]bool))
*fb = FalsyBool(result)
return ok
}

func (fb *FalsyBool) Boolean() bool {
if *fb == "" {
return false
}
return *fb == "true"
}

// interpolating resolves all property placeholders in s with their
// values defined in dictionary.
// resolving stores the key strings being resolved, it is used to detect cycles.
Expand Down
55 changes: 46 additions & 9 deletions util/maven/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,68 @@ func TestString(t *testing.T) {
}
}

func TestBoolString(t *testing.T) {
func TestTruthyBool(t *testing.T) {
var got struct {
Str BoolString `xml:"bool"`
Str TruthyBool `xml:"bool"`
}
err := xml.Unmarshal([]byte(`<xml><bool>haha</bool></xml>`), &got)
if err == nil {
t.Errorf("expected error %v but got %v", fmt.Errorf("unrecognized boolean"), err)
}

tests := []struct {
xml String
want BoolString
xml String
want TruthyBool
wantBool bool
}{
{"<xml><bool> true </bool></xml>", "true"},
{"<xml><bool>TRue</bool></xml>", "true"},
{"<xml><bool>FalSE</bool></xml>", "false"},
{"<xml><bool></bool></xml>", ""},
{"<xml><bool> true </bool></xml>", "true", true},
{"<xml><bool>TRue</bool></xml>", "true", true},
{"<xml><bool>FalSE</bool></xml>", "false", false},
{"<xml><bool></bool></xml>", "", true},
}
for _, test := range tests {
err = xml.Unmarshal([]byte(test.xml), &got)
if err != nil {
t.Errorf("failed to unmarshal: %v", err)
}
if got.Str != test.want {
t.Fatalf("unmarshal string want: %s, got: %s", test.want, got.Str)
t.Errorf("unmarshal string want: %s, got: %s", test.want, got.Str)
}
if got.Str.Boolean() != test.wantBool {
t.Errorf("Boolean(): got %v, want: %v", got.Str.Boolean(), test.wantBool)
}
}
}

func TestFalsyBool(t *testing.T) {
var got struct {
Str FalsyBool `xml:"bool"`
}
err := xml.Unmarshal([]byte(`<xml><bool>haha</bool></xml>`), &got)
if err == nil {
t.Errorf("expected error %v but got %v", fmt.Errorf("unrecognized boolean"), err)
}

tests := []struct {
xml String
want FalsyBool
wantBool bool
}{
{"<xml><bool> true </bool></xml>", "true", true},
{"<xml><bool>TRue</bool></xml>", "true", true},
{"<xml><bool>FalSE</bool></xml>", "false", false},
{"<xml><bool></bool></xml>", "", false},
}
for _, test := range tests {
err = xml.Unmarshal([]byte(test.xml), &got)
if err != nil {
t.Errorf("failed to unmarshal: %v", err)
}
if got.Str != test.want {
t.Errorf("unmarshal string want: %s, got: %s", test.want, got.Str)
}
if got.Str.Boolean() != test.wantBool {
t.Errorf("Boolean(): got %v, want: %v", got.Str.Boolean(), test.wantBool)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions util/resolve/maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func mavenRequirementsToProject(pk maven.ProjectKey, req *pb.Requirements_Maven)
Type: maven.String(d.Type),
Classifier: maven.String(d.Classifier),
Scope: maven.String(d.Scope),
Optional: maven.BoolString(d.Optional),
Optional: maven.FalsyBool(d.Optional),
Exclusions: exs,
})
}
Expand All @@ -226,8 +226,8 @@ func mavenRequirementsToProject(pk maven.ProjectKey, req *pb.Requirements_Maven)
ID: maven.String(r.Id),
URL: maven.String(r.Url),
Layout: maven.String(r.Layout),
Releases: maven.RepositoryPolicy{Enabled: maven.String(r.ReleasesEnabled)},
Snapshots: maven.RepositoryPolicy{Enabled: maven.String(r.SnapshotsEnabled)},
Releases: maven.RepositoryPolicy{Enabled: maven.TruthyBool(r.ReleasesEnabled)},
Snapshots: maven.RepositoryPolicy{Enabled: maven.TruthyBool(r.SnapshotsEnabled)},
})
}
return result
Expand All @@ -236,7 +236,7 @@ func mavenRequirementsToProject(pk maven.ProjectKey, req *pb.Requirements_Maven)
var profiles []maven.Profile
for _, p := range req.Profiles {
activation := maven.Activation{
ActiveByDefault: maven.BoolString(p.Activation.ActiveByDefault),
ActiveByDefault: maven.FalsyBool(p.Activation.ActiveByDefault),
}
if p.Activation.Jdk != nil {
activation.JDK = maven.String(p.Activation.Jdk.Jdk)
Expand Down
2 changes: 1 addition & 1 deletion util/resolve/maven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func TestDepType(t *testing.T) {

tests := []struct {
typ, scope maven.String
optional maven.BoolString
optional maven.FalsyBool
exclusions []maven.Exclusion
want dep.Type
}{
Expand Down

0 comments on commit 155ad6c

Please sign in to comment.