Skip to content

Commit 7655ba1

Browse files
oheger-boschsschuberth
authored andcommittedFeb 25, 2025
feat(Maven): Filter out Tycho definition files in Maven
Implement the `mapDefinitionFiles()` function in `Maven` to exclude all definition files belonging to Tycho projects. The upcoming Tycho implementation needs to handle then the projects that are filtered out here. Signed-off-by: Oliver Heger <oliver.heger@bosch.io>
1 parent 10243af commit 7655ba1

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
 

‎plugins/package-managers/maven/src/main/kotlin/Maven.kt

+14
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import org.ossreviewtoolkit.plugins.packagemanagers.maven.utils.LocalProjectWork
4242
import org.ossreviewtoolkit.plugins.packagemanagers.maven.utils.MavenDependencyHandler
4343
import org.ossreviewtoolkit.plugins.packagemanagers.maven.utils.MavenSupport
4444
import org.ossreviewtoolkit.plugins.packagemanagers.maven.utils.getOriginalScm
45+
import org.ossreviewtoolkit.plugins.packagemanagers.maven.utils.isTychoProject
4546
import org.ossreviewtoolkit.plugins.packagemanagers.maven.utils.parseAuthors
4647
import org.ossreviewtoolkit.plugins.packagemanagers.maven.utils.parseLicenses
4748
import org.ossreviewtoolkit.plugins.packagemanagers.maven.utils.parseVcsInfo
@@ -91,6 +92,19 @@ class Maven(
9192
graphBuilder = DependencyGraphBuilder(dependencyHandler)
9293
}
9394

95+
/**
96+
* Map the given [definitionFiles] to a list of files that should be processed. This implementation filters out
97+
* projects that require the Tycho build extension.
98+
*/
99+
override fun mapDefinitionFiles(definitionFiles: List<File>): List<File> {
100+
val tychoRoots = definitionFiles.filter(::isTychoProject).map { it.parentFile }
101+
102+
// All pom files under a Tycho project will be handled by Tycho and therefore need to be excluded.
103+
return definitionFiles.filterNot { file ->
104+
tychoRoots.any { file.startsWith(it) }
105+
}
106+
}
107+
94108
override fun createPackageManagerResult(projectResults: Map<File, List<ProjectAnalyzerResult>>) =
95109
PackageManagerResult(projectResults, graphBuilder.build(), graphBuilder.packages())
96110

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (C) 2025 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
package org.ossreviewtoolkit.plugins.packagemanagers.maven
21+
22+
import io.kotest.core.spec.style.WordSpec
23+
import io.kotest.engine.spec.tempdir
24+
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
25+
26+
import io.mockk.mockk
27+
28+
class MavenTest : WordSpec({
29+
"mapDefinitionFiles()" should {
30+
"filter out Tycho definition files" {
31+
val tychoProjectDir1 = tempdir()
32+
tychoProjectDir1.addTychoExtension()
33+
val tychoDefinitionFile1 = tychoProjectDir1.resolve("pom.xml").also { it.writeText("pom-tycho1") }
34+
val tychoSubProjectDir = tychoProjectDir1.resolve("subproject")
35+
val tychoSubModule = tychoSubProjectDir.resolve("pom.xml")
36+
val tychoProjectDir2 = tempdir()
37+
tychoProjectDir2.addTychoExtension()
38+
val tychoDefinitionFile2 = tychoProjectDir2.resolve("pom.xml").also { it.writeText("pom-tycho2") }
39+
40+
val mavenProjectDir = tempdir()
41+
val mavenDefinitionFile = mavenProjectDir.resolve("pom.xml").also { it.writeText("pom-maven") }
42+
val mavenSubProjectDir = mavenProjectDir.resolve("subproject")
43+
val mavenSubModule = mavenSubProjectDir.resolve("pom.xml")
44+
45+
val definitionFiles = listOf(
46+
tychoDefinitionFile1,
47+
mavenDefinitionFile,
48+
tychoDefinitionFile2,
49+
mavenSubModule,
50+
tychoSubModule
51+
)
52+
53+
val maven = Maven("Maven", tempdir(), mockk(relaxed = true), mockk(relaxed = true))
54+
val mappedDefinitionFiles = maven.mapDefinitionFiles(definitionFiles)
55+
56+
mappedDefinitionFiles shouldContainExactlyInAnyOrder listOf(mavenDefinitionFile, mavenSubModule)
57+
}
58+
}
59+
})

0 commit comments

Comments
 (0)