@@ -26,14 +26,19 @@ import io.kotest.engine.spec.tempdir
26
26
import io.kotest.engine.spec.tempfile
27
27
import io.kotest.inspectors.forAll
28
28
import io.kotest.matchers.collections.beEmpty
29
+ import io.kotest.matchers.collections.contain
29
30
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
31
+ import io.kotest.matchers.comparables.shouldBeGreaterThan
30
32
import io.kotest.matchers.should
31
33
import io.kotest.matchers.shouldBe
34
+ import io.kotest.matchers.shouldNot
32
35
import io.kotest.matchers.string.shouldContain
33
36
34
37
import io.mockk.every
35
38
import io.mockk.mockk
39
+ import io.mockk.slot
36
40
import io.mockk.spyk
41
+ import io.mockk.verify
37
42
38
43
import java.io.File
39
44
import java.io.PrintStream
@@ -47,6 +52,11 @@ import org.eclipse.aether.graph.DependencyNode
47
52
import org.ossreviewtoolkit.model.Identifier
48
53
import org.ossreviewtoolkit.model.Package
49
54
import org.ossreviewtoolkit.model.Severity
55
+ import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
56
+ import org.ossreviewtoolkit.model.config.Excludes
57
+ import org.ossreviewtoolkit.model.config.PathExclude
58
+ import org.ossreviewtoolkit.model.config.PathExcludeReason
59
+ import org.ossreviewtoolkit.model.config.RepositoryConfiguration
50
60
import org.ossreviewtoolkit.model.utils.DependencyGraphBuilder
51
61
import org.ossreviewtoolkit.plugins.packagemanagers.maven.utils.DependencyTreeMojoNode
52
62
import org.ossreviewtoolkit.plugins.packagemanagers.maven.utils.JSON
@@ -186,6 +196,99 @@ class TychoTest : WordSpec({
186
196
subProject3.identifier("Tycho ").toCoordinates()
187
197
)
188
198
}
199
+
200
+ " exclude projects from the build according to path excludes" {
201
+ val analysisRoot = tempdir()
202
+ val tychoRoot = analysisRoot.createSubModule("tycho-root")
203
+ tychoRoot.createSubModule("tycho-sub1")
204
+ tychoRoot.createSubModule("tycho-sub2")
205
+ tychoRoot.createSubModule("tycho-excluded-sub1")
206
+ val module = tychoRoot.createSubModule("tycho-excluded-sub2")
207
+ module.createSubModule("tycho-excluded-sub2-sub")
208
+ val rootProject = createMavenProject("root", tychoRoot.pom)
209
+
210
+ val excludes = Excludes (
211
+ paths = listOf(
212
+ PathExclude ("tycho-root/tycho-excluded-sub1", PathExcludeReason .EXAMPLE_OF ),
213
+ PathExclude ("tycho-root/tycho-excluded-sub2/**", PathExcludeReason .TEST_OF ),
214
+ PathExclude ("other-root/**", PathExcludeReason .EXAMPLE_OF )
215
+ )
216
+ )
217
+ val analyzerConfig = AnalyzerConfiguration (skipExcluded = true)
218
+ val repositoryConfig = RepositoryConfiguration (excludes = excludes)
219
+
220
+ val tycho = spyk(Tycho ("Tycho ", analysisRoot, analyzerConfig, repositoryConfig))
221
+ val cli = injectCliMock(tycho, listOf(rootProject).toJson(), listOf(rootProject))
222
+
223
+ tycho.resolveDependencies(tychoRoot.pom, emptyMap())
224
+
225
+ val slotArgs = slot<Array <String >>()
226
+ verify {
227
+ cli.doMain(capture(slotArgs), any(), any(), any())
228
+ }
229
+
230
+ with(slotArgs.captured) {
231
+ val indexPl = indexOf("-pl")
232
+ indexPl shouldBeGreaterThan -1
233
+ val excludedProjects = get(indexPl + 1).split(",")
234
+ excludedProjects shouldContainExactlyInAnyOrder listOf(
235
+ "!tycho-excluded-sub1",
236
+ "!tycho-excluded-sub2",
237
+ "!tycho-excluded-sub2/tycho-excluded-sub2-sub"
238
+ )
239
+ }
240
+ }
241
+
242
+ " not add a -pl option if no projects are excluded" {
243
+ val analysisRoot = tempdir()
244
+ val tychoRoot = analysisRoot.createSubModule("tycho-root")
245
+ tychoRoot.createSubModule("tycho-sub1")
246
+ tychoRoot.createSubModule("tycho-sub2")
247
+ val rootProject = createMavenProject("root", tychoRoot.pom)
248
+
249
+ val excludes = Excludes (paths = listOf(PathExclude ("other-root/**", PathExcludeReason .EXAMPLE_OF )))
250
+ val analyzerConfig = AnalyzerConfiguration (skipExcluded = true)
251
+ val repositoryConfig = RepositoryConfiguration (excludes = excludes)
252
+
253
+ val tycho = spyk(Tycho ("Tycho ", analysisRoot, analyzerConfig, repositoryConfig))
254
+ val cli = injectCliMock(tycho, listOf(rootProject).toJson(), listOf(rootProject))
255
+
256
+ tycho.resolveDependencies(tychoRoot.pom, emptyMap())
257
+
258
+ val slotArgs = slot<Array <String >>()
259
+ verify {
260
+ cli.doMain(capture(slotArgs), any(), any(), any())
261
+ }
262
+
263
+ slotArgs.captured.toList() shouldNot contain("-pl")
264
+ }
265
+
266
+ " not exclude projects if skipExcluded is false" {
267
+ val analysisRoot = tempdir()
268
+ val tychoRoot = analysisRoot.createSubModule("tycho-root")
269
+ tychoRoot.createSubModule("tycho-sub1")
270
+ tychoRoot.createSubModule("tycho-sub2")
271
+ tychoRoot.createSubModule("tycho-excluded-sub1")
272
+ val rootProject = createMavenProject("root", tychoRoot.pom)
273
+
274
+ val excludes = Excludes (
275
+ paths = listOf(PathExclude ("tycho-root/tycho-excluded-sub1", PathExcludeReason .EXAMPLE_OF ))
276
+ )
277
+ val analyzerConfig = AnalyzerConfiguration ()
278
+ val repositoryConfig = RepositoryConfiguration (excludes = excludes)
279
+
280
+ val tycho = spyk(Tycho ("Tycho ", analysisRoot, analyzerConfig, repositoryConfig))
281
+ val cli = injectCliMock(tycho, listOf(rootProject).toJson(), listOf(rootProject))
282
+
283
+ tycho.resolveDependencies(tychoRoot.pom, emptyMap())
284
+
285
+ val slotArgs = slot<Array <String >>()
286
+ verify {
287
+ cli.doMain(capture(slotArgs), any(), any(), any())
288
+ }
289
+
290
+ slotArgs.captured.toList() shouldNot contain("-pl")
291
+ }
189
292
}
190
293
})
191
294
@@ -245,3 +348,19 @@ private fun injectCliMock(
245
348
246
349
return cli
247
350
}
351
+
352
+ /* *
353
+ * Return a reference to the Maven pom file in this folder.
354
+ */
355
+ private val File .pom: File
356
+ get() = resolve(" pom.xml" )
357
+
358
+ /* *
359
+ * Create a sub folder with the given [name] and a pom file to simulate a Maven module. Return the created folder
360
+ * for the module.
361
+ */
362
+ private fun File.createSubModule (name : String ): File =
363
+ resolve(name).apply {
364
+ mkdirs()
365
+ pom.also { it.writeText(" pom-$name " ) }
366
+ }
0 commit comments