-
Notifications
You must be signed in to change notification settings - Fork 16
/
evaluator.rules.kts
1696 lines (1523 loc) · 74.1 KB
/
evaluator.rules.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2019 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort-config/blob/main/NOTICE>)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* License-Filename: LICENSE
*/
/******************************************************************************
* DISCLAIMER: This file only illustrates how to write evaluator rules, it is *
* no recommendation in any way. It is recommended to consult *
* your own legal counsel(s) for setting up your evaluator rules. *
******************************************************************************/
/**
* Variables defining the organization using ORT.
*/
val orgName = "Example Inc."
val orgScanIssueTrackerName = "FOSS JIRA"
val orgScanIssueTrackerMdLink = "[$orgScanIssueTrackerName](https://jira.example.com/FOSS)"
/**
* Import the license classifications from license-classifications.yml.
*/
fun getLicensesForCategory(category: String): Set<SpdxSingleLicenseExpression> =
checkNotNull(licenseClassifications.licensesByCategory[category]) {
"Failed to obtain the license for category '$category', because that category does not exist."
}
val claLicenses = getLicensesForCategory("cla")
val commercialLicenses = getLicensesForCategory("commercial")
val copyleftLicenses = getLicensesForCategory("copyleft")
val copyleftLimitedLicenses = getLicensesForCategory("copyleft-limited")
val freeRestrictedLicenses = getLicensesForCategory("free-restricted")
val genericLicenses = getLicensesForCategory("generic")
val patentLicenses = getLicensesForCategory("patent-license")
val permissiveLicenses = getLicensesForCategory("permissive")
val proprietaryFreeLicenses = getLicensesForCategory("proprietary-free")
val publicDomainLicenses = getLicensesForCategory("public-domain")
val unknownLicenses = getLicensesForCategory("unknown")
val unstatedLicenses = getLicensesForCategory("unstated-license")
// Set of licenses, which are not acted upon by the below policy rules.
val ignoredLicenses = listOf(
/**
* 'generic' category:
*/
// Contributor License agreement are not relevant for the "use" of open source.
"LicenseRef-scancode-generic-cla",
// Permissive licenses are not flagged anyway.
"LicenseRef-scancode-other-permissive",
// Public domain licenses are not flagged anyway.
"LicenseRef-scancode-public-domain",
// Disclaimers are not relevant because they have no obligations.
"LicenseRef-scancode-public-domain-disclaimer",
// Public domain licenses are not flagged anyway.
"LicenseRef-scancode-us-govt-public-domain",
// Disclaimers are not relevant because they have no obligations.
"LicenseRef-scancode-warranty-disclaimer",
/**
* 'unknown' category:
*/
"LicenseRef-scancode-license-file-reference",
// References to files do not matter, because the target files are also scanned.
"LicenseRef-scancode-see-license",
// References to files do not matter, because the target files are also scanned.
"LicenseRef-scancode-unknown-license-reference"
).map { SpdxSingleLicenseExpression.parse(it) }.toSet()
/**
* The complete set of licenses covered by policy rules.
*
* // TODO: Update the handled licenses to cover all recently added categories. This requires adding
* policy rules for new (offinding) categories, if any.
*/
val handledLicenses = listOf(
claLicenses,
commercialLicenses,
copyleftLicenses,
copyleftLimitedLicenses,
freeRestrictedLicenses,
genericLicenses,
patentLicenses,
permissiveLicenses,
proprietaryFreeLicenses,
publicDomainLicenses,
unknownLicenses,
unstatedLicenses
).flatten().let {
it.getDuplicates().let { duplicates ->
require(duplicates.isEmpty()) {
"The classifications for the following licenses overlap: $duplicates"
}
}
it.toSet()
}
/**
* List of licenses approved by organization to be used for its open source projects.
*/
val orgOssProjectsApprovedLicenses = listOf(
"Apache-2.0",
"BSD-2-Clause",
"BSD-3-Clause",
"MIT"
).map { it.toSpdx() as SpdxSingleLicenseExpression }.toSortedSet(compareBy { it.toString() })
/**
* Variables used to generate MarkDown text of howToFixDefault()
*/
val doNotWorryText = "_Note_: Do not worry about creating a perfect curation or exclude. Reviewers will provide feedback."
val globTutorialMdLink = "[reference documentation](https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob)"
val ortConfigContributingMdLink = "[CONTRIBUTING.md](https://github.com/oss-review-toolkit/ort-config/blob/main/CONTRIBUTING.md)"
val ortConfigVcsMdLink = "[ort-config repository](https://github.com/oss-review-toolkit/ort-config)"
val ortCurationsYmlFileConcludedLicenseMdLink = "[concluded license curation](https://oss-review-toolkit.org/ort/docs/configuration/ort-yml#curations)"
val ortCurationsYmlFileDeclaredLicenseMdLink = "[declared license curation](https://oss-review-toolkit.org/ort/docs/configuration/ort-yml#curations)"
val ortCurationsYmlVcsPathMdLink = "[VCS path curation](https://oss-review-toolkit.org/ort/docs/configuration/ort-yml#curations)"
val ortCurationsYmlVcsUrlMdLink = "[VCS URL curation](https://oss-review-toolkit.org/ort/docs/configuration/ort-yml#curations)"
var ortLicenseFindingCurationReasonMdLink = "[LicenseFindingCurationReason.kt](https://github.com/oss-review-toolkit/ort/blob/main/model/src/main/kotlin/config/LicenseFindingCurationReason.kt)"
val ortPackageConfigurationFileMdLink = "[package configuration](https://oss-review-toolkit.org/ort/docs/configuration/package-configurations)"
var ortPathExcludeReasonMdLink = "[PathExcludeReason.kt](https://github.com/oss-review-toolkit/ort/blob/main/model/src/main/kotlin/config/PathExcludeReason.kt)"
val ortResolutionsYmlRuleViolationMdLink = "[rule violation resolution](https://oss-review-toolkit.org/ort/docs/configuration/resolutions#resolving-policy-rule-violations)"
val ortScopeExcludeReasonMdLink = "[ScopeExcludeReason.kt](https://github.com/oss-review-toolkit/ort/blob/main/model/src/main/kotlin/config/ScopeExcludeReason.kt)"
val ortYmlFileMdLink = "[.ort.yml file](https://oss-review-toolkit.org/ort/docs/configuration/ort-yml)"
val ortYmlFilePathExcludeMdLink = "[path exclude](https://oss-review-toolkit.org/ort/docs/configuration/package-configurations#defining-path-excludes-and-license-finding-curations)"
val ortYmlFileScopeExcludeMdLink = "[scope exclude](https://oss-review-toolkit.org/ort/docs/configuration/ort-yml#excluding-scopes)"
val ortYmlFileLicenseFindingCurationMdLink = "[license finding curation](https://oss-review-toolkit.org/ort/docs/configuration/ort-yml#curations)"
val ortYmlFileRuleViolationResolutionMdLink = "[rule violation resolution](https://oss-review-toolkit.org/ort/docs/configuration/ort-yml#resolutions)"
val relatesToIssueText = "Relates-to: [Insert related issue number]".takeIf { ortResult.labels["jira"].isNullOrEmpty() } ?: "Relates-to: ${ortResult.labels["jira"]}"
enum class PolicyRules {
OSS_PROJECT,
PROPRIETARY_PROJECT
}
fun getArtifactOrUrlName(url: String): String =
"name of the artifact".takeIf { url.isBlank() } ?: url.substringAfterLast("/")
fun getArtifactMavenSourcesMdLink(pkg: Package): String {
if (pkg.binaryArtifact.url.isEmpty()) return "URL of the binary"
val binaryUrl = pkg.binaryArtifact.url
val binaryName = binaryUrl.substringAfterLast("/").substringBeforeLast(".")
val sourcesName = binaryName.plus("-sources")
val sourcesUrl = binaryUrl.replace(binaryName, sourcesName)
return "[$sourcesName.jar]($sourcesUrl)"
}
fun getArtifactMdLink(url: String): String =
"URL of the artifact".takeIf { url.isBlank() } ?: "[${url.substringAfterLast("/")}]($url)"
/**
* Return set of policy rules based on project label passed to ORT.
*/
fun getEnabledPolicyRules(): PolicyRules =
when {
ortResult.hasLabel("project", "oss-project") -> PolicyRules.OSS_PROJECT
else -> PolicyRules.PROPRIETARY_PROJECT
}
val enablePriorToOssRules = ortResult.hasLabel("enable-prior-to-oss-rules")
/**
* Return file path of package configuration in the ORT configuration repository for package [id].
*
* For example, if 'PyPI::flower:0.9.7' is found in your scan,
* then this function will return: 'package-configurations/PyPI/_/flower/0.9.7/vcs.yml'
*
*/
fun getPackageConfigurationFilePath(id: Identifier): String =
"package-configurations/${id.toPath(emptyValue = "_")}/"
/**
* Return the package configuration matcher for package [id].
*
* For example, if 'PyPI::flower:0.9.7' is found in your scan,
* then this function will return:
*
* id: "PyPI::flower:0.9.7"
* vcs:
* type: "Git"
* url: "https://github.com/mher/flower.git"
* revision: "26d19a816a362cdce32fd125596ed3bd238b40b4"
*
*/
fun getPackageConfigurationMatcherText(id: Identifier): String {
if (!ortResult.isPackage(id)) return "|"
val provenance = ortResult.getScanResultsForId(id).firstOrNull()?.provenance
if (provenance is ArtifactProvenance) {
return """
| id: "${id.toCoordinates()}"
| source_artifact_url: "${provenance.sourceArtifact.url}"
""".trim()
}
if (provenance is RepositoryProvenance) {
val vcsInfo = provenance.vcsInfo
return buildString {
"""
| id: "${id.toCoordinates()}"
| vcs:
| type: "${vcsInfo.type}"
| url: "${vcsInfo.url}"
| revision: "${provenance.resolvedRevision}"
""".trim().let{ appendLine(it) }
"""
| path: "${vcsInfo.path}"
""".trim().takeIf { vcsInfo.type == VcsType.GIT_REPO }?.let { appendLine(it) }
}.trim()
}
return "|"
}
/**
* Return the file path within ORT's configuration curations directory for [id].
*
* For example, if 'NPM::acorn:7.1.1' is found in your scan,
* then this function will return 'curations/NPM/_/acorn.yml'.
*
*/
fun getPackageCurationsFilePath(id: Identifier): String =
"curations/${id.type}/${id.namespace.ifBlank { "_" }}/${id.name}.yml"
/**
* Return a MarkDown link to the code repository for package [pkg].
*/
fun getVcsMdLink(pkg: Package) : String {
if (pkg.vcsProcessed.url.isEmpty()) {
return "URL of the source code repository"
}
val vcsUrl = pkg.vcsProcessed.url.replaceCredentialsInUri()
return "[${vcsUrl.substringAfterLast("/")} repository](${vcsUrl.replace("ssh", "http")})"
}
/**
* Return true if [license] is on the list of the organization's approved licenses for its open source projects.
*/
fun isApprovedOrgOssProjectLicense(license: SpdxSingleLicenseExpression) = license in orgOssProjectsApprovedLicenses
/**
* Return true if the [ortResult] contains a scan result for the source artifact of the package denoted by [id].
*/
fun isSourceArtifactScanned(id: Identifier): Boolean =
ortResult.getScanResultsForId(id).any { it.provenance is ArtifactProvenance }
/**
* Return true if the [ortResult] contains a scan result for the VCS of the package denoted by [id].
*/
fun isVcsScanned(id: Identifier): Boolean =
ortResult.getScanResultsForId(id).any { it.provenance is RepositoryProvenance }
/**
* Return the coordinates without the version.
*
* For example, this function will return 'PyPI:flower' for package id 'PyPI::flower:0.9.7'
* and 'Maven:org.antlr:antlr4' for 'Maven:org.antlr:antlr4:4.0.0'.
*
*/
fun Identifier.toCoordinatesWithoutVersion() = "$type:$namespace:$name"
/**
* Return Markdown-formatted text to aid users with resolving violations.
*/
fun PackageRule.howToFixDefault() = """
A text written in MarkDown to help users resolve policy violations
which may link to additional resources.
""".trimIndent()
fun PackageRule.howToFixLicenseViolationDefault(
license: String,
licenseSource: LicenseSource
): String {
if (ortResult.isProject(pkg.metadata.id)) {
// Violation is flagged for the project scanned.
if (licenseSource == LicenseSource.DETECTED) {
// License is detected by the scanner in the source code of the project.
return resolveViolationInSourceCodeText(pkg.metadata, license).trimMargin()
}
// License is declared in project's package manifest file (pom, package.json, etc.).
return "For this violation, there is no recommended solution.".trimMargin()
}
// Violation is thrown for one of the project's dependencies.
if (licenseSource == LicenseSource.DETECTED) {
// Violation thrown for license detected by the scanner in the source code of the dependency.
return resolveViolationInDependencySourceCodeText(pkg.metadata, license).trimMargin()
}
// Violation thrown for declared license in dependency's package manifest file (pom, package.json, etc.).
return resolveViolationInDependencyDeclaredLicenseText(pkg.metadata).trimMargin()
}
fun PackageRule.howToFixUnhandledLicense(
license: String,
licenseSource: LicenseSource
) : String {
val createIssueText = """
|1. If an issue to add this license does not already exist in $orgScanIssueTrackerMdLink, please create it.
|2. Set the _Summary_ field to 'Add new license $license'.
|3. Set the _Component/s_ field to _licenses_.
|4. Set the _Description_ field to something like 'Please add this license to the review tooling.'
|"""
if (ortResult.isProject(pkg.metadata.id)) {
// Unhandled license is found in the project under review.
if (licenseSource == LicenseSource.DETECTED) {
// Unhandled license is detected by the scanner in the source code of the project.
return """
|${resolveViolationInSourceCodeText(pkg.metadata, license)}
|
|If the license identification is correct and can not be excluded, then
|follow the steps below to have Open Source Office add $license to the review tooling:
|
$createIssueText
|""".trimMargin()
}
// Unhandled license is declared in project's package manifest file (pom, package.json, etc.).
return """
|Follow the steps below to have Open Source Office add $license to the review tooling:
|
$createIssueText
|""".trimMargin()
} else {
// Unhandled license is found in project's dependency.
if (licenseSource == LicenseSource.DETECTED) {
// Unhandled license is detected by the scanner in the source code of the dependency.
return """
|${resolveViolationInDependencySourceCodeText(pkg.metadata, license)}
|
|If the license identification is correct and can not be excluded, then
|follow the steps below to add $license to the review tooling:
|
$createIssueText
|""".trimMargin()
}
// Unhandled license is declared in dependency's package manifest file (pom, package.json, etc.).
return """
|Follow the steps below to add $license to the review tooling:
|
$createIssueText
|""".trimMargin()
}
}
fun PackageRule.howToFixOssProjectDefault() = """
A text written in MarkDown to help users resolve policy violations
which may link to additional resources.
""".trimIndent()
fun PackageRule.howToFixUnmappedDeclaredLicense(license: String): String {
val genericDeclaredLicenses = setOf(
"BSD License",
"The BSD License"
)
return if (license in genericDeclaredLicenses) {
val binaryUrlMdLink = getArtifactMdLink(pkg.metadata.binaryArtifact.url)
val vcsUrlMdLink = getVcsMdLink(pkg.metadata)
"""
|Try to resolve this violation by following the advice below:
|
|1. Clone $ortConfigVcsMdLink using Git.
|2. Map declared license '$license' to an [SPDX license expression](https://spdx.github.io/spdx-spec/appendix-IV-SPDX-license-expressions/):
| - Open or create using a text editor `${getPackageCurationsFilePath(pkg.metadata.id)}`.
| - Determine the declared licenses for $binaryUrlMdLink by looking for the main license files in the $vcsUrlMdLink.
| Use the the following template, changing the text in square brackets (`[...]`) as appropriate.
|
| ```
|
| - id: "${pkg.metadata.id.toCoordinatesWithoutVersion()}"
| curations:
| comment: "Mapping declared license based on \
| [https://url-to-repository/tag-or-revision-for-version-${pkg.metadata.id.version}/LICENSE] and \
| [https://url-to-repository/tag-or-revision-for-version-${pkg.metadata.id.version}/package-metadata-file]."
| declared_license_mapping:
| "$license": "[SPDX license expression for the declared license.]"
|
| ```
|
| - Submit the above change to the $ortConfigVcsMdLink (see $ortConfigContributingMdLink for guidance) with a commit message as shown below.
| Reviewers are set automatically.
|
| ```
|
| feat(curations): Map declared license for ${pkg.metadata.id.toCoordinatesWithoutVersion()}
|
| $relatesToIssueText
|
| ```
|
| - Once your $ortCurationsYmlFileDeclaredLicenseMdLink is merged, re-scan to see if the violation has been resolved.
|""".trimMargin()
} else {
"""
|Follow the steps below to add the $license to the review tooling:
|
|1. If a ticket to add this license does not already exist in $orgScanIssueTrackerMdLink, please create it.
|2. Set the _Summary_ field to 'Add new license mapping for license $license'.
|3. Set the _Component/s_ field to _licenses_.
|4. Set the _Description_ field to something like 'Please add a new declared license mapping for this license.'
|""".trimMargin()
}
}
fun resolveViolationInDependencyDeclaredLicenseText(pkg: Package) : String {
val sourcesUrlMdLink = when (pkg.id.type) {
"Maven" -> getArtifactMavenSourcesMdLink(pkg)
"PIP", "PyPI" -> getArtifactMdLink(pkg.sourceArtifact.url)
else -> "the source artifact"
}
if (isSourceArtifactScanned(pkg.id) && pkg.binaryArtifact.url.isNotEmpty()) {
val binaryName = getArtifactOrUrlName(pkg.binaryArtifact.url)
val binaryUrlMdLink = getArtifactMdLink(pkg.binaryArtifact.url)
return """
|Try to resolve this violation by following the advice below:
|
|1. Exclude the package scope if the package is not part of the released artifacts:
| - Check _Paths_ > _Scope_ for '${pkg.id.toCoordinates()}' in `*-scan-report-web-app.html`
| - If _Scope_ indicates the package is used for building or testing your code (e.g. 'compile' or 'test'),
| exclude it by adding a $ortYmlFileScopeExcludeMdLink to your $ortYmlFileMdLink.
|
|2. Otherwise, add a curation for the package if its declared license includes a license choice:
| - Clone $ortConfigVcsMdLink using Git.
| - Open or create using a text editor `${getPackageCurationsFilePath(pkg.id)}`.
| - Find the licenses applicable to $binaryUrlMdLink by comparing its contents with the scan results for $sourcesUrlMdLink.
| (A license does not apply if the scan results show it to be in a particular file, but that file is absent in $binaryUrlMdLink.)
| - For each license that applies, create an entry for '${pkg.id.toCoordinates()}' in `${getPackageCurationsFilePath(pkg.id)}`, setting `concluded_license`
| to show the appropriate [SPDX license expression](https://spdx.github.io/spdx-spec/appendix-IV-SPDX-license-expressions/).
| Use the following template, changing the text in square brackets (`[...]`) as appropriate.
|
| ```
|
| - id: "${pkg.id.toCoordinates()}"
| curations:
| comment: "[The artifact declares as licensed under '${pkg.declaredLicensesProcessed.spdxExpression}', see \
| https://url-to-repository/tag-or-revision-for-version-${pkg.id.version}/LICENSE and \
| https://url-to-repository/tag-or-revision-for-version-${pkg.id.version}/package-metadata-file \.
| Additionally the scanner detects ...]"
| # FIXME: The real concluded license expression, taking into account both declared and detected licenses, is
| # concluded_license: "[Applicable licenses for $binaryName as a SPDX license expression.]"
| # However, as we do not have a mechanism to record a license choice yet, misuse the concluded
| # license to perform the choice until we have a proper mechanism implemented:
| concluded_license: "[Chosen licenses for $binaryName as a SPDX license expression.]"
|
| ```
|
| - Submit the above change to the $ortConfigVcsMdLink (see $ortConfigContributingMdLink for guidance) with a commit message as shown below.
| Note that reviewers are set automatically.
|
| ```
|
| feat(curations): Conclude license for `${pkg.id.toCoordinates()}`
|
| $relatesToIssueText
|
| ```
|
| - Once your $ortCurationsYmlFileConcludedLicenseMdLink is merged, re-scan to see if the violation has been resolved.
|"""
}
val binaryName = getArtifactOrUrlName(pkg.binaryArtifact.url)
val binaryUrlMdLink = getArtifactMdLink(pkg.binaryArtifact.url)
val vcsUrlMdLink = getVcsMdLink(pkg)
if (isVcsScanned(pkg.id) && pkg.binaryArtifact.url.isNotEmpty()) {
return """
|Try to resolve this violation by following the advice below:
|
|1. Exclude the package scope if the package is not part of the released artifacts:
| - Check _Paths_ > _Scope_ for '${pkg.id.toCoordinates()}' in `*-scan-report-web-app.html`
| - If _Scope_ indicates the package is used for building or testing your code (e.g. 'compile' or 'test'),
| exclude it by adding a $ortYmlFileScopeExcludeMdLink to your $ortYmlFileMdLink.
|
|2. Otherwise, add a curation for the package if its declared license includes a license choice:
| - Clone $ortConfigVcsMdLink using Git.
| - Open or create using a text editor `${getPackageCurationsFilePath(pkg.id)}`.
| - Find the licenses applicable to $binaryUrlMdLink by comparing its contents with the scan results for $sourcesUrlMdLink.
| (A license does not apply if the scan results show it to be in a particular file, but that file is absent in $binaryUrlMdLink.)
| - For each license that applies, create an entry for '${pkg.id.toCoordinates()}' in `${getPackageCurationsFilePath(pkg.id)}`, setting `concluded_license`
| to show the appropriate [SPDX license expression](https://spdx.github.io/spdx-spec/appendix-IV-SPDX-license-expressions/).
| Use the following template, changing the text in square brackets (`[...]`) as appropriate.
|
| ```
|
| - id: "${pkg.id.toCoordinates()}"
| curations:
| comment: "[The artifact declares as licensed under '${pkg.declaredLicensesProcessed.spdxExpression}', see \
| https://url-to-repository/tag-or-revision-for-version-${pkg.id.version}/LICENSE and \
| https://url-to-repository/tag-or-revision-for-version-${pkg.id.version}/package-metadata-file \.
| Additionally the scanner detects ...]"
| # FIXME: The real concluded license expression, taking into account both declared and detected licenses, is
| # concluded_license: "[Applicable licenses for $binaryName as SPDX license expression.]"
| # However, as we do not have a mechanism to record a license choice yet (see OSS-1163), misuse the concluded
| # license to perform the choice until we have a proper mechanism implemented:
| concluded_license: "[Chosen licenses for $binaryName as a SPDX license expression.]"
|
| ```
|
| - Submit the above change to the $ortConfigVcsMdLink (see $ortConfigContributingMdLink for guidance) with a commit message as shown below.
| Note that reviewers are set automatically.
|
| ```
|
| feat(curations): Conclude license for `${pkg.id.toCoordinates()}`
|
| $relatesToIssueText
|
| ```
|
| - Once your $ortCurationsYmlFileConcludedLicenseMdLink is merged, re-scan to see if the violation has been resolved.
|"""
} else {
val vcsName = getArtifactOrUrlName(pkg.vcsProcessed.url)
return """
|It may be possible to resolve this violation as follows:
|
|1. Try to exclude the scope of the package if it is not part of the released artifacts:
| - Check the _Paths_ section for '${pkg.id.toCoordinates()}' in the Web App scan report for the scopes where the package was found.
| - If a scope is only for packages used for building or testing your code,
| exclude it by adding a $ortYmlFileScopeExcludeMdLink to your $ortYmlFileMdLink.
|
|2. Otherwise, add a curation for the package if its declared license includes a license choice:
| - Clone $ortConfigVcsMdLink using Git.
| - Open or create using a text editor `${getPackageCurationsFilePath(pkg.id)}`.
| - Find the licenses applicable to $vcsUrlMdLink which are included in your release artifacts.
| (A license does not apply if the scan results show it to be in a particular file, but that file is absent in $vcsUrlMdLink).
| - For each license that is not compiled in your release artifacts, create an entry for '${pkg.id.toCoordinates()}' in `${getPackageCurationsFilePath(pkg.id)}`, setting `concluded_license`
| to show the appropriate [SPDX license expression](https://spdx.github.io/spdx-spec/appendix-IV-SPDX-license-expressions/).
| Use the following template, changing the text in square brackets (`[...]`) as appropriate.
|
| ```
|
| - id: "${pkg.id.toCoordinates()}"
| curations:
| comment: "[The artifact declares as licensed under '${pkg.declaredLicensesProcessed.spdxExpression}', see \
| https://url-to-repository/tag-or-revision-for-version-${pkg.id.version}/LICENSE and \
| https://url-to-repository/tag-or-revision-for-version-${pkg.id.version}/package-metadata-file \.
| Additionally the scanner detects ...]"
| # FIXME: The real concluded license expression, taking into account both declared and detected licenses, is
| # concluded_license: "[Applicable licenses for $vcsName repository as a SPDX license expression.]"
| # However, as we do not have a mechanism to record a license choice yet (see OSS-1163), misuse the concluded
| # license to perform the choice until we have a proper mechanism implemented:
| concluded_license: "[Chosen licenses for $vcsName repository as a SPDX license expression.]"
|
| ```
|
| - Submit the above change to the $ortConfigVcsMdLink (see $ortConfigContributingMdLink for guidance) with a commit message as shown below.
| Note that reviewers are set automatically.
|
| ```
|
| feat(curations): Conclude license for `${pkg.id.toCoordinates()}`
|
| $relatesToIssueText
|
| ```
|
| - Once your $ortCurationsYmlFileConcludedLicenseMdLink is merged, re-scan to see if the violation has been resolved.
|"""
}
}
fun resolveViolationInDependencySourceCodeText(pkg: Package, license: String) : String {
val sourcesUrlMdLink = when (pkg.id.type) {
"Maven" -> getArtifactMavenSourcesMdLink(pkg)
"PIP", "PyPI" -> getArtifactMdLink(pkg.sourceArtifact.url)
else -> "the source artifact"
}
if (isSourceArtifactScanned(pkg.id) && pkg.binaryArtifact.url.isNotEmpty()) {
val binaryName = getArtifactOrUrlName(pkg.binaryArtifact.url)
val binaryUrlMdLink = getArtifactMdLink(pkg.binaryArtifact.url)
return """
|Try to resolve this violation by following the advice below:
|
|1. Clone $ortConfigVcsMdLink using Git.
|2. Download and extract:
| - $binaryUrlMdLink
| - $sourcesUrlMdLink
|4. Find the lines which triggered this violation:
| - Expand the _Scan Results_ section under '${pkg.id.toCoordinates()}' in `*-scan-report-web-app.html`
| - Filter the _Value_ column, selecting only the license to which the violation refers
|5. If there are license file findings for this package in directories in (extracted) $sourcesUrlMdLink but not $binaryUrlMdLink:
| - Create a directory `${getPackageConfigurationFilePath(pkg.id)}` with a file named `source-artifact.yml`.
| - Open the file `source-artifact.yml` in a text editor
| - Add a $ortPackageConfigurationFileMdLink entry with a $ortYmlFilePathExcludeMdLink
| for each _directory_ found in the (extracted) $sourcesUrlMdLink but not $binaryUrlMdLink.
| Use the following template, changing the text in square brackets (`[...]`) as appropriate.
|
| ```
|
| ---
${getPackageConfigurationMatcherText(pkg.id)}
| path_excludes:
| - pattern: "[A glob pattern matching files or paths.]"
| reason: "[One of PathExcludeReason e.g. BUILD_TOOL_OF, DOCUMENTATION_OF, EXAMPLE_OF or TEST_OF.]"
|
| ```
|
| For information on how to write a glob pattern, please see this $globTutorialMdLink.
| The available options for the `reason` field are defined in $ortPathExcludeReasonMdLink.
|
| - Submit the above change to the $ortConfigVcsMdLink (see $ortConfigContributingMdLink for guidance) with a commit message as shown below.
| Reviewers are set automatically.
|
| ```
|
| packages: Add excludes for `${pkg.id.toCoordinates()}`
|
| $relatesToIssueText
|
| ```
|
| - Once your $ortYmlFilePathExcludeMdLink is merged, re-scan to see if the violation has been resolved.
|
|6. For each file where the license was found, check if the scanner correctly identified the license.
| If a license identification is incorrect:
|
| - Create a directory `${getPackageConfigurationFilePath(pkg.id)}` with a file named `source-artifact.yml`.
| - Open `source-artifact.yml` in a text editor.
| - Add a $ortPackageConfigurationFileMdLink entry with a $ortYmlFileLicenseFindingCurationMdLink.
| Use the following template, changing the text in square brackets (`[...]`) as appropriate.
|
| ```
|
| ---
${getPackageConfigurationMatcherText(pkg.id)}
| license_finding_curations:
| - path: "[A glob pattern matching files or paths.]"
| start_lines: "[String with comma-separated list of starting line integers.]"
| line_count: [Integer for number of lines to match.]
| detected_license: "$license"
| concluded_license: "[SPDX license expression for the correct license or use NONE to remove the detected license.]"
| reason: "INCORRECT"
| comment: "[A comment explaining why the scanner is incorrect.]"
|
| ```
|
| For information on how to write a glob pattern, visit $globTutorialMdLink.
| The available options for the `reason` field are defined in $ortLicenseFindingCurationReasonMdLink.
|
| - Submit the above change to the $ortConfigVcsMdLink (see $ortConfigContributingMdLink for guidance) with a commit message as shown below.
| Note that reviewers are set automatically.
|
| ```
|
| packages: Add curations for `${pkg.id.toCoordinates()}`
|
| $relatesToIssueText
|
| ```
| - Once your $ortYmlFileLicenseFindingCurationMdLink is merged, re-scan to see if the violation has been resolved.
| |
|7. If '${pkg.id.toCoordinates()}' includes license choices or a large number of findings to be excluded or curated:
| - Open or create using a text editor `${getPackageCurationsFilePath(pkg.id)}`.
| - Determine the applicable licenses for $binaryUrlMdLink by comparing its contents with the scan result findings.
| (A license does not apply if the scan results show it to be in a particular file, but that file is absent in $binaryUrlMdLink).
| - For each license that applies to $binaryUrlMdLink, create an entry for '${pkg.id.toCoordinates()}' in `${getPackageCurationsFilePath(pkg.id)}`, setting `concluded_license`
| to show the appropriate [SPDX license expression](https://spdx.github.io/spdx-spec/appendix-IV-SPDX-license-expressions/).
| Use the following template, changing the text in square brackets (`[...]`) as appropriate.
|
| ```
|
| - id: "${pkg.id.toCoordinates()}"
| curations:
| comment: "[The artifact declares as licensed under '${pkg.declaredLicensesProcessed.spdxExpression}', see \
| https://url-to-repository/tag-or-revision-for-version-${pkg.id.version}/LICENSE and \
| https://url-to-repository/tag-or-revision-for-version-${pkg.id.version}/package-metadata-file \.
| Additionally the scanner detects ...]"
| concluded_license: "[Applicable licenses for $binaryName as a SPDX license expression.]"
|
| ```
|
| - Submit the above change to the $ortConfigVcsMdLink (see $ortConfigContributingMdLink for guidance) with a commit message as shown below.
| Note that reviewers are set automatically.
|
| ```
|
| feat(curations): Conclude license for `${pkg.id.toCoordinates()}`
|
| $relatesToIssueText
|
| ```
|
| - Once your $ortCurationsYmlFileConcludedLicenseMdLink is merged, re-scan to see if the violation has been resolved.
| - $doNotWorryText
|"""
}
val binaryName = getArtifactOrUrlName(pkg.binaryArtifact.url)
val binaryUrlMdLink = getArtifactMdLink(pkg.binaryArtifact.url)
val vcsUrlMdLink = getVcsMdLink(pkg)
if (isVcsScanned(pkg.id) && pkg.binaryArtifact.url.isNotEmpty()) {
return """
|Try to resolve this violation by following the advice below:
|
|1. Clone $ortConfigVcsMdLink using Git.
|2. Download and extract $binaryUrlMdLink.
|3. Find the lines which triggered this violation:
! - Expand the _Scan Results_ section under '${pkg.id.toCoordinates()}' in `*-scan-report-web-app.html`
| - Filter the _Value_ column, selecting only the licenses to which the violation refers
|4. Open the $vcsUrlMdLink in a web browser and find the source code for version `${pkg.id.version}`.
|5. If the extracted $binaryUrlMdLink contains fewer files or directories than shown under
| the _Scan Results_ for '${pkg.id.toCoordinates()}' in `*-scan-report-web-app.html`, you may need to
| limit the number of files/directories the scanner scans. For example, if the repository contains other
| packages and not just '${pkg.id.toCoordinates()}':
| - Open or create using a text editor `${getPackageCurationsFilePath(pkg.id)}`.
| - Add an entry for '${pkg.id.toCoordinates()}' setting the `path` under `vcs`
| to the repository directory that contains the source code for the $binaryUrlMdLink.
| (To find the correct directory, search the names of files in the extracted $binaryUrlMdLink within $vcsUrlMdLink.)
| Use the following template, replacing the `path` field as appropriate.
|
| ```
|
| - id: "${pkg.id.toCoordinatesWithoutVersion()}"
| curations:
| comment: "Package resides in its own directory within repo."
| vcs:
| path: "[File path to package e.g. ${pkg.id.name}.]"
|
| ```
|
| - Submit the above change to the $ortConfigVcsMdLink (see $ortConfigContributingMdLink for guidance) with a commit message as shown below.
| Reviewers are set automatically.
|
| ```
|
| feat(curations): Set VCS path for `${pkg.id.toCoordinatesWithoutVersion()}`
|
| $relatesToIssueText
|
| ```
|
| - Once your $ortCurationsYmlVcsUrlMdLink is merged, re-scan to see if the violation has been resolved.
|
|6. If there are license file findings for '${pkg.id.toCoordinates()}' in directories in $vcsUrlMdLink but not in the extracted $binaryUrlMdLink:
| - Create a directory `${getPackageConfigurationFilePath(pkg.id)}` with a file named `vcs.yml`.
| - Open `vcs.yml` in a text editor.
| - For each _directory_ found in the $vcsUrlMdLink but not in extracted $binaryUrlMdLink, add a $ortPackageConfigurationFileMdLink entry
| with a $ortYmlFilePathExcludeMdLink.
| .
| Use the following template, changing the text in square brackets (`[...]`) as appropriate.
|
| ```
|
| ---
${getPackageConfigurationMatcherText(pkg.id)}
| path_excludes:
| - pattern: "[A glob pattern matching files or paths.]"
| reason: "[One of PathExcludeReason e.g. BUILD_TOOL_OF, DOCUMENTATION_OF, EXAMPLE_OF or TEST_OF.]"
|
| ```
|
| For information on how to write a glob pattern, please see this $globTutorialMdLink.
| The available options for the `reason` field are defined in $ortPathExcludeReasonMdLink.
|
| - Submit the above change to the $ortConfigVcsMdLink (see $ortConfigContributingMdLink for guidance) with a commit message as shown below.
| Reviewers are set automatically.
|
| ```
|
| packages: Add excludes for `${pkg.id.toCoordinates()}`
|
| $relatesToIssueText
|
| ```
|
| - Once your $ortYmlFilePathExcludeMdLink is merged, re-scan to see if the violation has been resolved.
|
|7. For each file where the license was found, check if the scanner correctly identified the license.
| If a license identification is incorrect:
|
| - Create a directory `${getPackageConfigurationFilePath(pkg.id)}` with a file named `source-artifact.yml`.
| - Open the file `source-artifact.yml` in a text editor.
| - Add a $ortPackageConfigurationFileMdLink entry with a $ortYmlFileLicenseFindingCurationMdLink.
| Use the following template, changing the text in square brackets (`[...]`) as appropriate.
|
| ```
|
| ---
${getPackageConfigurationMatcherText(pkg.id)}
| license_finding_curations:
| - path: "[A glob pattern matching files or paths.]"
| start_lines: "[String with comma-separated list of starting line integers.]"
| line_count: [Integer for number of lines to match.]
| detected_license: "$license"
| concluded_license: "[SPDX license expression for the correct license or use NONE to remove the detected license.]"
| reason: "INCORRECT"
| comment: "[A comment explaining why the scanner is incorrect.]"
|
| ```
|
| For information on how to write a glob pattern, please see this $globTutorialMdLink.
| The available options for the `reason` field are defined in $ortLicenseFindingCurationReasonMdLink.
|
| - Submit the above change to the $ortConfigVcsMdLink (see $ortConfigContributingMdLink for guidance) with a commit message as shown below.
| Reviewers are set automatically.
|
| ```
|
| packages: Add curations for `${pkg.id.toCoordinates()}`
|
| $relatesToIssueText
|
| ```
|
| - Once your $ortYmlFileLicenseFindingCurationMdLink is merged, re-scan to see if the violation has been resolved.
|
|8. If '${pkg.id.toCoordinates()}' includes license choices or a large number of findings to be excluded or curated:
| - Open or create using a text editor `${getPackageCurationsFilePath(pkg.id)}`.
| - Determine the applicable licenses for $binaryUrlMdLink by comparing its contents with the scan result findings.
| (A license does not apply if the scan results show it to be in a particular file, but that file is absent in $binaryUrlMdLink).
| - For each license that applies to $binaryUrlMdLink, create an entry for '${pkg.id.toCoordinates()}' in `${getPackageCurationsFilePath(pkg.id)}`, setting `concluded_license`
| to show the appropriate [SPDX license expression](https://spdx.github.io/spdx-spec/appendix-IV-SPDX-license-expressions/).
| Use the following template, changing the text in square brackets (`[...]`) as appropriate.
|
| ```
|
| - id: "${pkg.id.toCoordinates()}"
| curations:
| comment: "[The artifact declares as licensed under '${pkg.declaredLicensesProcessed.spdxExpression}', see \
| https://url-to-repository/tag-or-revision-for-version-${pkg.id.version}/LICENSE and \
| https://url-to-repository/tag-or-revision-for-version-${pkg.id.version}/package-metadata-file \.
| Additionally the scanner detects ...]"
| concluded_license: "[Applicable licenses for $binaryName as a SPDX license expression.]"
|
| ```
|
| - Submit the above change to the $ortConfigVcsMdLink (see $ortConfigContributingMdLink for guidance) with a commit message as shown below.
| Reviewers are set automatically.
|
| ```
|
| feat(curations): Conclude license for `${pkg.id.toCoordinates()}`
|
| $relatesToIssueText
|
| ```
|
| - Once your $ortCurationsYmlFileConcludedLicenseMdLink is merged, re-scan to see if the violation has been resolved.
| - $doNotWorryText
|"""
} else {
return """
|Try to resolve this violation by following the advice below:
|
|1. Clone $ortConfigVcsMdLink using Git.
|2. Find the lines which triggered this violation:
| - Expand the _Scan Results_ section under '${pkg.id.toCoordinates()}' in `*-scan-report-web-app.html`
| - Filter the _Value_ column, selecting only the licenses to which the violation refers
|3. Open the $vcsUrlMdLink in a web browser and find the code for version `${pkg.id.version}`.
|4. If this package is in a repository containing other packages beside '${pkg.id.toCoordinates()}':
| - Open or create using a text editor `${getPackageCurationsFilePath(pkg.id)}`.
| - Add an entry for '${pkg.id.toCoordinates()}' setting the `path` under `vcs`
| to the repository directory that contains the source code for the package.
| Use the following template, changing the value of `path` as appropriate.
|
| ```
|
| - id: "${pkg.id.toCoordinatesWithoutVersion()}"
| curations:
| comment: "Package resides in its own directory within repo."
| vcs:
| path: "[File path to package e.g. ${pkg.id.name}.]"
|
| ```
|
| - Submit the above change to the $ortConfigVcsMdLink (see $ortConfigContributingMdLink for guidance) with a commit message as shown below.
| Reviewers are set automatically.
|
| ```
|
| feat(curations): Set VCS path for `${pkg.id.toCoordinatesWithoutVersion()}`
|
| $relatesToIssueText
|
| ```
|
| - Once your $ortCurationsYmlVcsUrlMdLink is merged, re-scan to see if the violation has been resolved.
|
|5. If there are license findings for '${pkg.id.toCoordinates()}' in directories in $vcsUrlMdLink used only for building or testing the code:
| - Create a directory `${getPackageConfigurationFilePath(pkg.id)}` with a file named `vcs.yml`.
| - Open `vcs.yml` in a text editor.
| - For each _directory_ found in the $vcsUrlMdLink, but not in extracted $binaryUrlMdLink, add a
| $ortPackageConfigurationFileMdLink entry with a $ortYmlFilePathExcludeMdLink.
| Use the following template, changing the text in square brackets (`[...]`) as appropriate.
|
| ```
|
| ---
${getPackageConfigurationMatcherText(pkg.id)}
| path_excludes:
| - pattern: "[A glob pattern matching files or paths.]"
| reason: "[One of PathExcludeReason e.g. BUILD_TOOL_OF, DOCUMENTATION_OF, EXAMPLE_OF or TEST_OF.]"
|
| ```
|
| For information on how to write a glob pattern, please see this $globTutorialMdLink.
| The available options for the `reason` field are defined in $ortPathExcludeReasonMdLink.
|
| - Submit the above change to the $ortConfigVcsMdLink (see $ortConfigContributingMdLink for guidance) with a commit message as shown below.
| Reviewers are set automatically.
|
| ```
|
| packages: Add excludes for `${pkg.id.toCoordinates()}`
|
| $relatesToIssueText
|
| ```
|
| - Once your $ortYmlFilePathExcludeMdLink is merged, re-scan to see if the violation has been resolved.
|
|6. For each file where the license was found, check if the scanner identified the license correctly.
| If a license identification is incorrect:
| - Create a directory `${getPackageConfigurationFilePath(pkg.id)}` with a file named `vcs.yml`.
| - Open `vcs.yml` in a text editor.
| - Add a $ortPackageConfigurationFileMdLink entry with a $ortYmlFileLicenseFindingCurationMdLink.
| Use the following template, changing the text in square brackets (`[...]`) as appropriate.
|
| ```
|
| ---
${getPackageConfigurationMatcherText(pkg.id)}
| license_finding_curations:
| - path: "[A glob pattern matching files or paths.]"
| start_lines: "[String with comma-separated list of starting line integers.]"
| line_count: [Integer for number of lines to match.]
| detected_license: "$license"
| concluded_license: "[SPDX license expression for the correct license or use NONE to remove the detected license.]"
| reason: "INCORRECT"
| comment: "[A comment explaining why the scanner is incorrect.]"
|
| ```
|
| For information on how to write a glob pattern, please see this $globTutorialMdLink.
| The available options for the `reason` field are defined in $ortLicenseFindingCurationReasonMdLink.
|
| - Submit the above change to the $ortConfigVcsMdLink (see $ortConfigContributingMdLink for guidance) with a commit message as shown below.
| Reviewers are set automatically.
|
| ```
|
| packages: Add curations for `${pkg.id.toCoordinates()}`
|
| $relatesToIssueText
|
| ```
|
| - Once your $ortYmlFileLicenseFindingCurationMdLink is merged, re-scan to see if the violation has been resolved.
| - $doNotWorryText
|"""
}
}
fun resolveViolationInSourceCodeText(pkg: Package, license: String) : String {
return """
|Try to resolve this violation by following the advice below:
|
|1. Find the lines which triggered this violation:
| - expand the _Scan Results_ section under '${pkg.id.toCoordinates()}' in `*-web-app.html`
| - filter the _Value_ column, selecting only the license to which the violation refers.
|2. Try to exclude the files or directories to which the violation refers but which are not part of the release artifacts
| of your project by adding a $ortYmlFilePathExcludeMdLink to your $ortYmlFileMdLink.
|
|3. For each file finding for the license, verify if the scanner correctly identified the license.
| If a license identification is incorrect:
|
| - Open your $ortYmlFileMdLink in a text editor.
| - Add a $ortYmlFileLicenseFindingCurationMdLink.