@@ -32,6 +32,9 @@ import io.kotest.matchers.shouldNot
3232
3333import java.io.File
3434
35+ import org.ossreviewtoolkit.model.ArtifactProvenance
36+ import org.ossreviewtoolkit.model.Identifier
37+ import org.ossreviewtoolkit.model.RemoteArtifact
3538import org.ossreviewtoolkit.model.RepositoryProvenance
3639import org.ossreviewtoolkit.model.VcsInfo
3740import org.ossreviewtoolkit.model.VcsType
@@ -50,6 +53,10 @@ private val PROVENANCE = RepositoryProvenance(
5053 resolvedRevision = " 0000000000000000000000000000000000000000"
5154)
5255
56+ private val ARTIFACT_PROVENANCE = ArtifactProvenance (
57+ sourceArtifact = RemoteArtifact .EMPTY
58+ )
59+
5360class FileArchiverTest : StringSpec () {
5461 private lateinit var workingDir: File
5562 private lateinit var storageDir: File
@@ -84,7 +91,7 @@ class FileArchiverTest : StringSpec() {
8491 createFile(" path/LICENSE" )
8592
8693 val archiver = FileArchiver (setOf (" **/LICENSE" ), storage)
87- archiver.archive(workingDir, PROVENANCE )
94+ archiver.archive(workingDir, PROVENANCE , Identifier . EMPTY )
8895 val result = archiver.unarchive(targetDir, PROVENANCE )
8996
9097 result shouldBe true
@@ -101,7 +108,7 @@ class FileArchiverTest : StringSpec() {
101108 createFile(" d/LiCeNsE" )
102109
103110 val archiver = FileArchiver (setOf (" **/LICENSE" ), storage)
104- archiver.archive(workingDir, PROVENANCE )
111+ archiver.archive(workingDir, PROVENANCE , Identifier . EMPTY )
105112 val result = archiver.unarchive(targetDir, PROVENANCE )
106113
107114 result shouldBe true
@@ -121,7 +128,7 @@ class FileArchiverTest : StringSpec() {
121128
122129 val archiver = FileArchiver (setOf (" a" , " **/a" ), storage)
123130
124- archiver.archive(workingDir, PROVENANCE )
131+ archiver.archive(workingDir, PROVENANCE , Identifier . EMPTY )
125132 val result = archiver.unarchive(targetDir, PROVENANCE )
126133
127134 result shouldBe true
@@ -144,7 +151,7 @@ class FileArchiverTest : StringSpec() {
144151 createFile(" c/b" )
145152
146153 val archiver = FileArchiver (setOf (" **" ), storage)
147- archiver.archive(workingDir, PROVENANCE )
154+ archiver.archive(workingDir, PROVENANCE , Identifier . EMPTY )
148155
149156 val result = archiver.unarchive(targetDir, PROVENANCE )
150157
@@ -160,7 +167,7 @@ class FileArchiverTest : StringSpec() {
160167 " Empty archives can be handled" {
161168 val archiver = FileArchiver (LicenseFilePatterns .DEFAULT .allLicenseFilenames, storage)
162169
163- archiver.archive(workingDir, PROVENANCE )
170+ archiver.archive(workingDir, PROVENANCE , Identifier . EMPTY )
164171
165172 archiver.unarchive(targetDir, PROVENANCE ) shouldBe true
166173 targetDir shouldContainNFiles 0
@@ -170,7 +177,7 @@ class FileArchiverTest : StringSpec() {
170177 createFile(" License" ) { writeBytes(byteArrayOf(0xFF .toByte(), 0xD8 .toByte())) }
171178
172179 val archiver = FileArchiver (LicenseFilePatterns .DEFAULT .allLicenseFilenames, storage)
173- archiver.archive(workingDir, PROVENANCE )
180+ archiver.archive(workingDir, PROVENANCE , Identifier . EMPTY )
174181 val result = archiver.unarchive(targetDir, PROVENANCE )
175182
176183 result shouldBe true
@@ -181,7 +188,7 @@ class FileArchiverTest : StringSpec() {
181188 createFile(" License" ) { writeText(" ぁあぃいぅうぇえぉおかが" ) }
182189
183190 val archiver = FileArchiver (LicenseFilePatterns .DEFAULT .allLicenseFilenames, storage)
184- archiver.archive(workingDir, PROVENANCE )
191+ archiver.archive(workingDir, PROVENANCE , Identifier . EMPTY )
185192 val result = archiver.unarchive(targetDir, PROVENANCE )
186193
187194 result shouldBe true
@@ -192,11 +199,37 @@ class FileArchiverTest : StringSpec() {
192199 createFile(" License.md" ) { writeText(" # Heading level 1" ) }
193200
194201 val archiver = FileArchiver (LicenseFilePatterns .DEFAULT .allLicenseFilenames, storage)
195- archiver.archive(workingDir, PROVENANCE )
202+ archiver.archive(workingDir, PROVENANCE , Identifier . EMPTY )
196203 val result = archiver.unarchive(targetDir, PROVENANCE )
197204
198205 result shouldBe true
199206 targetDir should containFile(" License.md" )
200207 }
208+
209+ " LICENSE files from source artifacts are archived" {
210+ createFile(" LICENSE" )
211+
212+ val archiver = FileArchiver (LicenseFilePatterns .DEFAULT .allLicenseFilenames, storage)
213+ archiver.archive(workingDir, ARTIFACT_PROVENANCE , Identifier .EMPTY )
214+ val result = archiver.unarchive(targetDir, ARTIFACT_PROVENANCE )
215+
216+ result shouldBe true
217+ with (targetDir) {
218+ shouldContainFileWithContent(" LICENSE" )
219+ }
220+ }
221+
222+ " LICENSE files from Maven artifacts with META-INF are archived" {
223+ createFile(" META-INF/LICENSE" )
224+
225+ val archiver = FileArchiver (LicenseFilePatterns .DEFAULT .allLicenseFilenames, storage)
226+ archiver.archive(workingDir, ARTIFACT_PROVENANCE , Identifier (" Maven:::" ))
227+ val result = archiver.unarchive(targetDir, ARTIFACT_PROVENANCE )
228+
229+ result shouldBe true
230+ with (targetDir) {
231+ shouldContainFileWithContent(" META-INF/LICENSE" )
232+ }
233+ }
201234 }
202235}
0 commit comments