Skip to content

Commit

Permalink
fix: Add dependencyManagement exclusions to the child exclusions (#6969)
Browse files Browse the repository at this point in the history
Co-authored-by: DmitriyLewen <dmitriy.lewen@smartforce.io>
  • Loading branch information
coheigea and DmitriyLewen authored Jul 9, 2024
1 parent ec3e0ca commit dc68a66
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 3 deletions.
54 changes: 54 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,60 @@ func TestPom_Parse(t *testing.T) {
},
},
},
// ➜ mvn dependency:tree
// ...
// [INFO]
// [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ child ---
// [INFO] com.example:child:jar:3.0.0
// [INFO] \- org.example:example-exclusions:jar:3.0.0:compile
// [INFO] \- org.example:example-nested:jar:3.3.3:compile
// [INFO] ------------------------------------------------------------------------
{
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-exclusions:3.0.0",
Name: "org.example:example-exclusions",
Version: "3.0.0",
Relationship: ftypes.RelationshipDirect,
Locations: ftypes.Locations{
{
StartLine: 26,
EndLine: 35,
},
},
},
{
ID: "org.example:example-nested:3.3.3",
Name: "org.example:example-nested",
Version: "3.3.3",
Relationship: ftypes.RelationshipIndirect,
},
},
wantDeps: []ftypes.Dependency{
{
ID: "com.example:child:3.0.0",
DependsOn: []string{
"org.example:example-exclusions:3.0.0",
},
},
{
ID: "org.example:example-exclusions:3.0.0",
DependsOn: []string{
"org.example:example-nested:3.3.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-exclusions</artifactId>
<exclusions>
<exclusion>
<groupId>org.example</groupId>
<artifactId>example-dependency</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-exclusions</artifactId>
<version>3.0.0</version>
<exclusions>
<exclusion>
<groupId>org.example</groupId>
<artifactId>example-dependency2</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<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>org.example</groupId>
<artifactId>example-exclusions</artifactId>
<version>3.0.0</version>

<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>example-dependency</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>example-dependency2</artifactId>
<version>2.3.4</version>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>example-nested</artifactId>
<version>3.3.3</version>
</dependency>
</dependencies>

</project>

0 comments on commit dc68a66

Please sign in to comment.