Skip to content

Commit f0403bd

Browse files
Merge pull request LambdaTest#9 from LambdaTest/sync-upstream
Sync upstream
2 parents 8d87884 + 5578707 commit f0403bd

File tree

12 files changed

+111
-171
lines changed

12 files changed

+111
-171
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ require (
1414
github.com/stretchr/testify v1.8.4
1515
go.uber.org/zap v1.24.0
1616
golang.org/x/exp v0.0.0-20220407100705-7b9b53b0aca4
17-
golang.org/x/mod v0.11.0
18-
golang.org/x/net v0.11.0
17+
golang.org/x/mod v0.12.0
18+
golang.org/x/net v0.12.0
1919
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
2020
gopkg.in/yaml.v3 v3.0.1
2121
)
@@ -27,5 +27,5 @@ require (
2727
github.com/pmezard/go-difflib v1.0.0 // indirect
2828
go.uber.org/atomic v1.7.0 // indirect
2929
go.uber.org/multierr v1.6.0 // indirect
30-
golang.org/x/text v0.10.0 // indirect
30+
golang.org/x/text v0.11.0 // indirect
3131
)

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
4848
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
4949
golang.org/x/exp v0.0.0-20220407100705-7b9b53b0aca4 h1:K3x+yU+fbot38x5bQbU2QqUAVyYLEktdNH2GxZLnM3U=
5050
golang.org/x/exp v0.0.0-20220407100705-7b9b53b0aca4/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
51-
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
52-
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
53-
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
54-
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
55-
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
56-
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
51+
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
52+
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
53+
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
54+
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
55+
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
56+
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
5757
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
5858
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
5959
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=

pkg/java/pom/artifact.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/aquasecurity/go-dep-parser/pkg/log"
10+
"github.com/samber/lo"
1011
"golang.org/x/exp/slices"
1112
)
1213

@@ -18,20 +19,20 @@ type artifact struct {
1819
GroupID string
1920
ArtifactID string
2021
Version version
21-
License string
22+
Licenses []string
2223

2324
Exclusions map[string]struct{}
2425

2526
Module bool
2627
Root bool
2728
}
2829

29-
func newArtifact(groupID, artifactID, version, license string, props map[string]string) artifact {
30+
func newArtifact(groupID, artifactID, version string, licenses []string, props map[string]string) artifact {
3031
return artifact{
3132
GroupID: evaluateVariable(groupID, props, nil),
3233
ArtifactID: evaluateVariable(artifactID, props, nil),
3334
Version: newVersion(evaluateVariable(version, props, nil)),
34-
License: license,
35+
Licenses: licenses,
3536
}
3637
}
3738

@@ -43,12 +44,26 @@ func (a artifact) Equal(o artifact) bool {
4344
return a.GroupID == o.GroupID || a.ArtifactID == o.ArtifactID || a.Version.String() == o.Version.String()
4445
}
4546

47+
func (a artifact) JoinLicenses() string {
48+
return strings.Join(a.Licenses, ", ")
49+
}
50+
51+
func (a artifact) ToPOMLicenses() pomLicenses {
52+
return pomLicenses{License: lo.Map(a.Licenses, func(lic string, _ int) pomLicense {
53+
return pomLicense{Name: lic}
54+
})}
55+
}
56+
4657
func (a artifact) Inherit(parent artifact) artifact {
4758
// inherited from a parent
4859
if a.GroupID == "" {
4960
a.GroupID = parent.GroupID
5061
}
5162

63+
if len(a.Licenses) == 0 {
64+
a.Licenses = parent.Licenses
65+
}
66+
5267
if a.Version.String() == "" {
5368
a.Version = parent.Version
5469
}

pkg/java/pom/parse.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (e *extendedParser) GetRemoteRepositories() []string {
7070
}
7171

7272
func (e *extendedParser) GetProperties(groupID, artifactID, version string) map[string]string {
73-
art := newArtifact(groupID, artifactID, version, "", nil)
73+
art := newArtifact(groupID, artifactID, version, nil, nil)
7474
result := e.cache.get(art)
7575
if result == nil {
7676
return nil
@@ -233,8 +233,8 @@ func (p *parser) parseRoot(root artifact) ([]types.Library, []types.Dependency,
233233
if !art.IsEmpty() {
234234
// Override the version
235235
uniqArtifacts[art.Name()] = artifact{
236-
Version: art.Version,
237-
License: art.License,
236+
Version: art.Version,
237+
Licenses: art.Licenses,
238238
}
239239
}
240240
}
@@ -244,7 +244,7 @@ func (p *parser) parseRoot(root artifact) ([]types.Library, []types.Dependency,
244244
libs = append(libs, types.Library{
245245
Name: name,
246246
Version: art.Version.String(),
247-
License: art.License,
247+
License: art.JoinLicenses(),
248248
})
249249
}
250250
return libs, deps, nil
@@ -416,7 +416,7 @@ func (p *parser) resolveDepManagement(props map[string]string, depManagement []p
416416
// Managed dependencies with a scope of "import" should be processed after other managed dependencies.
417417
// cf. https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#importing-dependencies
418418
for _, imp := range imports {
419-
art := newArtifact(imp.GroupID, imp.ArtifactID, imp.Version, "", props)
419+
art := newArtifact(imp.GroupID, imp.ArtifactID, imp.Version, nil, props)
420420
result, err := p.resolve(art, nil)
421421
if err != nil {
422422
continue
@@ -466,7 +466,7 @@ func excludeDep(exclusions map[string]struct{}, art artifact) bool {
466466

467467
func (p *parser) parseParent(currentPath string, parent pomParent) (analysisResult, error) {
468468
// Pass nil properties so that variables in <parent> are not evaluated.
469-
target := newArtifact(parent.GroupId, parent.ArtifactId, parent.Version, "", nil)
469+
target := newArtifact(parent.GroupId, parent.ArtifactId, parent.Version, nil, nil)
470470
// if version is property (e.g. ${revision}) - we still need to parse this pom
471471
if target.IsEmpty() && !isProperty(parent.Version) {
472472
return analysisResult{}, nil

pkg/java/pom/parse_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,18 @@ func TestPom_Parse(t *testing.T) {
785785
},
786786
},
787787
},
788+
{
789+
name: "inherit parent license",
790+
inputFile: filepath.Join("testdata", "inherit-license", "module", "submodule", "pom.xml"),
791+
local: true,
792+
want: []types.Library{
793+
{
794+
Name: "com.example.app:submodule",
795+
Version: "1.0.0",
796+
License: "Apache-2.0",
797+
},
798+
},
799+
},
788800
}
789801
for _, tt := range tests {
790802
t.Run(tt.name, func(t *testing.T) {

pkg/java/pom/pom.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func (p *pom) inherit(result analysisResult) {
2525

2626
p.content.GroupId = art.GroupID
2727
p.content.ArtifactId = art.ArtifactID
28+
p.content.Licenses = art.ToPOMLicenses()
2829

2930
if isProperty(art.Version.String()) {
3031
p.content.Version = evaluateVariable(art.Version.String(), p.content.Properties, nil)
@@ -100,17 +101,13 @@ func (p pom) listProperties(val reflect.Value) map[string]string {
100101
}
101102

102103
func (p pom) artifact() artifact {
103-
return newArtifact(p.content.GroupId, p.content.ArtifactId, p.content.Version, p.joinLicenses(), p.content.Properties)
104+
return newArtifact(p.content.GroupId, p.content.ArtifactId, p.content.Version, p.licenses(), p.content.Properties)
104105
}
105106

106-
func (p pom) joinLicenses() string {
107-
var licenses []string
108-
for _, license := range p.content.Licenses.License {
109-
if license.Name != "" {
110-
licenses = append(licenses, license.Name)
111-
}
112-
}
113-
return strings.Join(licenses, ", ")
107+
func (p pom) licenses() []string {
108+
return lo.FilterMap(p.content.Licenses.License, func(lic pomLicense, _ int) (string, bool) {
109+
return lic.Name, lic.Name != ""
110+
})
114111
}
115112

116113
func (p pom) repositories() []string {
@@ -124,16 +121,12 @@ func (p pom) repositories() []string {
124121
}
125122

126123
type pomXML struct {
127-
Parent pomParent `xml:"parent"`
128-
GroupId string `xml:"groupId"`
129-
ArtifactId string `xml:"artifactId"`
130-
Version string `xml:"version"`
131-
Licenses struct {
132-
License []struct {
133-
Name string `xml:"name"`
134-
} `xml:"license"`
135-
} `xml:"licenses"`
136-
Modules struct {
124+
Parent pomParent `xml:"parent"`
125+
GroupId string `xml:"groupId"`
126+
ArtifactId string `xml:"artifactId"`
127+
Version string `xml:"version"`
128+
Licenses pomLicenses `xml:"licenses"`
129+
Modules struct {
137130
Text string `xml:",chardata"`
138131
Module []string `xml:"module"`
139132
} `xml:"modules"`
@@ -169,6 +162,15 @@ type pomParent struct {
169162
RelativePath string `xml:"relativePath"`
170163
}
171164

165+
type pomLicenses struct {
166+
Text string `xml:",chardata"`
167+
License []pomLicense `xml:"license"`
168+
}
169+
170+
type pomLicense struct {
171+
Name string `xml:"name"`
172+
}
173+
172174
type pomDependencies struct {
173175
Text string `xml:",chardata"`
174176
Dependency []pomDependency `xml:"dependency"`
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<project>
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>com.example.app</groupId>
5+
<artifactId>my-app</artifactId>
6+
<version>1.0.0</version>
7+
</parent>
8+
<packaging>pom</packaging>
9+
<artifactId>module</artifactId>
10+
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<project>
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>com.example.app</groupId>
5+
<artifactId>module</artifactId>
6+
<version>1.0.0</version>
7+
</parent>
8+
9+
<artifactId>submodule</artifactId>
10+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<project>
2+
<modelVersion>4.0.0</modelVersion>
3+
<packaging>pom</packaging>
4+
<groupId>com.example.app</groupId>
5+
<artifactId>my-app</artifactId>
6+
<version>1.0.0</version>
7+
8+
<licenses>
9+
<license>
10+
<name>Apache-2.0</name>
11+
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
12+
<distribution>repo</distribution>
13+
</license>
14+
</licenses>
15+
</project>

pkg/nodejs/packagejson/parse_test.go

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,10 @@ func TestParse(t *testing.T) {
4040
OptionalDependencies: map[string]string{
4141
"colors": "^1.4.0",
4242
},
43-
DevDependencies: map[string]string{"@babel/cli": "^7.14.5", "@babel/core": "^7.14.6",
44-
"@babel/preset-env": "^7.14.7", "@popperjs/core": "^2.9.2",
45-
"@rollup/plugin-babel": "^5.3.0", "@rollup/plugin-commonjs": "^19.0.1",
46-
"@rollup/plugin-node-resolve": "^13.0.2", "@rollup/plugin-replace": "^3.0.0",
47-
"autoprefixer": "^10.2.6", "bundlewatch": "^0.3.2", "clean-css-cli": "^5.3.0",
48-
"cross-env": "^7.0.3", "eslint": "^7.31.0", "eslint-config-xo": "^0.36.0",
49-
"eslint-plugin-import": "^2.23.4", "eslint-plugin-unicorn": "^31.0.0",
50-
"find-unused-sass-variables": "^3.1.0", "glob": "^7.1.7", "globby": "^11.0.4",
51-
"hammer-simulator": "0.0.1", "hugo-bin": "^0.73.0", "ip": "^1.1.5",
52-
"jquery": "^3.6.0", "karma": "^6.3.4", "karma-browserstack-launcher": "1.4.0",
53-
"karma-chrome-launcher": "^3.1.0",
54-
"karma-coverage-istanbul-reporter": "^3.0.3",
55-
"karma-detect-browsers": "^2.3.3",
56-
"karma-firefox-launcher": "^2.1.1", "karma-jasmine": "^4.0.1",
57-
"karma-jasmine-html-reporter": "^1.7.0",
58-
"karma-rollup-preprocessor": "^7.0.7", "linkinator": "^2.14.0",
59-
"lockfile-lint": "^4.6.2", "nodemon": "^2.0.12", "npm-run-all": "^4.1.5",
60-
"postcss": "^8.3.5", "postcss-cli": "^8.3.1", "rollup": "^2.53.3",
61-
"rollup-plugin-istanbul": "^3.0.0", "rtlcss": "^3.3.0", "sass": "^1.35.2",
62-
"shelljs": "^0.8.4", "stylelint": "^13.13.1",
63-
"stylelint-config-twbs-bootstrap": "^2.2.3", "terser": "5.1.0", "vnu-jar": "21.6.11"},
43+
DevDependencies: map[string]string{
44+
"@babel/cli": "^7.14.5",
45+
"@babel/core": "^7.14.6",
46+
},
6447
Workspaces: []string{
6548
"packages/*",
6649
"backend",
@@ -78,27 +61,10 @@ func TestParse(t *testing.T) {
7861
License: "ISC",
7962
},
8063
Dependencies: map[string]string{},
81-
DevDependencies: map[string]string{"@babel/cli": "^7.14.5", "@babel/core": "^7.14.6",
82-
"@babel/preset-env": "^7.14.7", "@popperjs/core": "^2.9.2",
83-
"@rollup/plugin-babel": "^5.3.0", "@rollup/plugin-commonjs": "^19.0.1",
84-
"@rollup/plugin-node-resolve": "^13.0.2", "@rollup/plugin-replace": "^3.0.0",
85-
"autoprefixer": "^10.2.6", "bundlewatch": "^0.3.2", "clean-css-cli": "^5.3.0",
86-
"cross-env": "^7.0.3", "eslint": "^7.31.0", "eslint-config-xo": "^0.36.0",
87-
"eslint-plugin-import": "^2.23.4", "eslint-plugin-unicorn": "^31.0.0",
88-
"find-unused-sass-variables": "^3.1.0", "glob": "^7.1.7", "globby": "^11.0.4",
89-
"hammer-simulator": "0.0.1", "hugo-bin": "^0.73.0", "ip": "^1.1.5",
90-
"jquery": "^3.6.0", "karma": "^6.3.4", "karma-browserstack-launcher": "1.4.0",
91-
"karma-chrome-launcher": "^3.1.0",
92-
"karma-coverage-istanbul-reporter": "^3.0.3",
93-
"karma-detect-browsers": "^2.3.3",
94-
"karma-firefox-launcher": "^2.1.1", "karma-jasmine": "^4.0.1",
95-
"karma-jasmine-html-reporter": "^1.7.0",
96-
"karma-rollup-preprocessor": "^7.0.7", "linkinator": "^2.14.0",
97-
"lockfile-lint": "^4.6.2", "nodemon": "^2.0.12", "npm-run-all": "^4.1.5",
98-
"postcss": "^8.3.5", "postcss-cli": "^8.3.1", "rollup": "^2.53.3",
99-
"rollup-plugin-istanbul": "^3.0.0", "rtlcss": "^3.3.0", "sass": "^1.35.2",
100-
"shelljs": "^0.8.4", "stylelint": "^13.13.1",
101-
"stylelint-config-twbs-bootstrap": "^2.2.3", "terser": "5.1.0", "vnu-jar": "21.6.11"},
64+
DevDependencies: map[string]string{
65+
"@babel/cli": "^7.14.5",
66+
"@babel/core": "^7.14.6",
67+
},
10268
},
10369
},
10470
{

0 commit comments

Comments
 (0)