19
19
20
20
package org.ossreviewtoolkit.plugins.packagemanagers.maven
21
21
22
+ import io.kotest.assertions.throwables.shouldThrow
22
23
import io.kotest.core.TestConfiguration
23
24
import io.kotest.core.spec.style.WordSpec
24
25
import io.kotest.engine.spec.tempdir
25
26
import io.kotest.engine.spec.tempfile
27
+ import io.kotest.inspectors.forAll
26
28
import io.kotest.matchers.collections.beEmpty
27
29
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
28
30
import io.kotest.matchers.should
@@ -48,6 +50,7 @@ import org.ossreviewtoolkit.model.Severity
48
50
import org.ossreviewtoolkit.model.utils.DependencyGraphBuilder
49
51
import org.ossreviewtoolkit.plugins.packagemanagers.maven.utils.DependencyTreeMojoNode
50
52
import org.ossreviewtoolkit.plugins.packagemanagers.maven.utils.JSON
53
+ import org.ossreviewtoolkit.plugins.packagemanagers.maven.utils.identifier
51
54
52
55
class TychoTest : WordSpec ({
53
56
" mapDefinitionFiles()" should {
@@ -116,6 +119,73 @@ class TychoTest : WordSpec({
116
119
117
120
subResults.single().issues should beEmpty()
118
121
}
122
+
123
+ " throw an exception if the root project could not be built" {
124
+ val definitionFile = tempfile()
125
+ val rootProject = createMavenProject("root", definitionFile)
126
+ val subProject1 = createMavenProject("sub1")
127
+ val subProject2 = createMavenProject("sub2")
128
+
129
+ val buildOutput = listOf(subProject2, rootProject, subProject1).toJson()
130
+
131
+ val tycho = spyk(Tycho ("Tycho ", tempdir(), mockk(relaxed = true), mockk(relaxed = true)))
132
+ injectCliMock(tycho, buildOutput, listOf(subProject1, subProject2))
133
+
134
+ val exception = shouldThrow<TychoBuildException > {
135
+ tycho.resolveDependencies(definitionFile, emptyMap())
136
+ }
137
+
138
+ exception.message shouldContain " Tycho root project could not be built."
139
+ }
140
+
141
+ " generate an issue if the Maven build had a non-zero exit code" {
142
+ val definitionFile = tempfile()
143
+ val rootProject = createMavenProject("root", definitionFile)
144
+ val subProject = createMavenProject("sub")
145
+ val projectsList = listOf(rootProject, subProject)
146
+
147
+ val tycho = spyk(Tycho ("Tycho ", tempdir(), mockk(relaxed = true), mockk(relaxed = true)))
148
+ injectCliMock(tycho, projectsList.toJson(), projectsList, exitCode = 1)
149
+
150
+ val results = tycho.resolveDependencies(definitionFile, emptyMap())
151
+
152
+ val rootResults = results.single { it.project.id.name == " root" }
153
+ with(rootResults.issues.single()) {
154
+ severity shouldBe Severity .ERROR
155
+ message shouldContain " Maven build failed"
156
+ source shouldBe " Tycho"
157
+ }
158
+ }
159
+
160
+ " generate issues for sub projects that do not occur in the build output" {
161
+ val definitionFile = tempfile()
162
+ val rootProject = createMavenProject("root", definitionFile)
163
+ val subProject1 = createMavenProject("sub1")
164
+ val subProject2 = createMavenProject("sub2")
165
+ val subProject3 = createMavenProject("sub3")
166
+ val projectsList = listOf(rootProject, subProject1, subProject2, subProject3)
167
+
168
+ val tycho = spyk(Tycho ("Tycho ", tempdir(), mockk(relaxed = true), mockk(relaxed = true)))
169
+ injectCliMock(tycho, projectsList.take(2).toJson(), projectsList, exitCode = 1)
170
+
171
+ val results = tycho.resolveDependencies(definitionFile, emptyMap())
172
+
173
+ val rootResults = results.single { it.project.id.name == " root" }
174
+ rootResults.issues.forAll { issue ->
175
+ issue.source shouldBe " Tycho"
176
+ issue.severity shouldBe Severity .ERROR
177
+ }
178
+
179
+ val regExBuildProjectError = Regex (".*for project '(.*)'.*")
180
+ val projectIssues = rootResults.issues.mapNotNull { issue ->
181
+ regExBuildProjectError.matchEntire(issue.message)?.groupValues?.get(1)
182
+ }
183
+
184
+ projectIssues shouldContainExactlyInAnyOrder listOf(
185
+ subProject2.identifier("Tycho ").toCoordinates(),
186
+ subProject3.identifier("Tycho ").toCoordinates()
187
+ )
188
+ }
119
189
}
120
190
})
121
191
0 commit comments