Skip to content

Commit

Permalink
fix: Add dependencyManagement exclusions to the child exclusions
Browse files Browse the repository at this point in the history
  • Loading branch information
coheigea committed Jun 21, 2024
1 parent b58d42d commit 7092c74
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 3 deletions.
46 changes: 46 additions & 0 deletions pkg/dependency/parser/java/pom/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,52 @@ func TestPom_Parse(t *testing.T) {
},
},
},
{
name: "exclusions in child and parent dependency management",
inputFile: filepath.Join("testdata", "exclusions-parent-dependency-management", "child", "pom.xml"),
local: true,
want: []ftypes.Package{
{
ID: "com.example:child:3.0.0",
Name: "com.example:child",
Version: "3.0.0",
Licenses: []string{"Apache 2.0"},
Relationship: ftypes.RelationshipRoot,
},
{
ID: "org.example:example-nested:3.3.3",
Name: "org.example:example-nested",
Version: "3.3.3",
Relationship: ftypes.RelationshipDirect,
Locations: ftypes.Locations{
{
StartLine: 26,
EndLine: 35,
},
},
},
{
ID: "org.example:example-dependency:1.2.3",
Name: "org.example:example-dependency",
Version: "1.2.3",
Relationship: ftypes.RelationshipIndirect,
},
},
wantDeps: []ftypes.Dependency{
{
ID: "com.example:child:3.0.0",
DependsOn: []string{
"org.example:example-nested:3.3.3",
},
},
{
ID: "org.example:example-nested:3.3.3",
DependsOn: []string{
"org.example:example-dependency:1.2.3",
},
},
},
},
{
name: "exclusions with wildcards",
inputFile: filepath.Join("testdata", "wildcard-exclusions", "pom.xml"),
Expand Down
5 changes: 2 additions & 3 deletions pkg/dependency/parser/java/pom/pom.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ func (d pomDependency) Resolve(props map[string]string, depManagement, rootDepMa
if !dep.Optional {
dep.Optional = managed.Optional
}
if len(dep.Exclusions.Exclusion) == 0 {
dep.Exclusions = managed.Exclusions
}
// `mvn` always merges exceptions for pom and parent
dep.Exclusions.Exclusion = append(dep.Exclusions.Exclusion, managed.Exclusions.Exclusion...)
}
return dep
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>child</artifactId>
<version>3.0.0</version>

<name>child</name>
<description>Child</description>

<parent>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>2.0.0</version>
</parent>

<licenses>
<license>
<name>Apache 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
<distribution>repo</distribution>
</license>
</licenses>

<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>example-nested</artifactId>
<exclusions>
<exclusion>
<groupId>org.example</groupId>
<artifactId>example-api-common</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>2.0.0</version>

<packaging>pom</packaging>
<name>parent</name>
<description>Parent</description>

<licenses>
<license>
<name>Apache 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
<distribution>repo</distribution>
</license>
</licenses>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>example-nested</artifactId>
<version>3.3.3</version>
<exclusions>
<exclusion>
<groupId>org.example</groupId>
<artifactId>example-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>

</project>

0 comments on commit 7092c74

Please sign in to comment.