Skip to content

Commit

Permalink
Feature/build breaker (#287)
Browse files Browse the repository at this point in the history
* implement Build breaker

* adapt templates/LegalDataReport.vm

* Working state

* Change filenames and paths

* Add tutorial for build-breaker and release note

* Fix JSON

* Add jq to dictionary to fix spellcheck error

* Fix template

* Fix documentation

* Remove project name from statistics.json

* Trim category string

* minor improvements of formatting / whitespaces

---------

Co-authored-by: Mahmoud Alkam <[email protected]>
Co-authored-by: ohecker <[email protected]>
  • Loading branch information
3 people authored Sep 21, 2024
1 parent 2fb45d7 commit f935a91
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,15 @@
"dataTables" : {
"MODELROOT" : "classpath:com/devonfw/tools/solicitor/sql/modelroot.sql",
"ARTIFACTS" : "classpath:com/devonfw/tools/solicitor/sql/scancode_sources.sql"
}
},{
"type": "velo",
"templateSource": "classpath:com/devonfw/tools/solicitor/templates/Statistics.vm",
"target": "${cfgdir}/output/Statistics.json",
"description": "Generates a JSON report of categories and their counts",
"dataTables": {
"STATISTICS": "classpath:com/devonfw/tools/solicitor/sql/statistics.sql"
}
}
}]

]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Selects the category "legal-evaluation" and trims any whitespace
SELECT TRIM('legal-evaluation') AS category, NVL(l."legalApproved", 'blank') AS value, COUNT(*) AS count
FROM NormalizedLicense l
GROUP BY NVL(l."legalApproved", 'blank')

UNION ALL -- Combines the results of this query with the next, including duplicates

-- Selects the category "data-status" and trims any whitespace
SELECT TRIM('data-status') AS category, ac."dataStatus" AS value, COUNT(*) AS count
FROM ApplicationComponent ac
GROUP BY ac."dataStatus";
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#set($previousCategory = "")
#set($firstCategory = true)

## Print JSON Output
{
"Statistics": {
#foreach($row in $STATISTICS)
#set($currentCategory = $row.CATEGORY)
#if($currentCategory != $previousCategory)
#if(!$firstCategory)

},
#end
"$currentCategory": {
#set($previousCategory = $currentCategory)
#set($firstCategory = false)
#else
,
#end
"$row.VALUE": $row.COUNT##
#if($foreach.hasNext)
#else

}
#end
#end
}
}
49 changes: 49 additions & 0 deletions documentation/master-solicitor.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,54 @@ Using the <<Extended comparison syntax>> it is possible to qualify whether a rul

Due the automatic mapping of scancode based `RawLicenses` to `NormalizedLicenses` (see <<Automatic mapping of `RawLicense` data obtained from Scancode to `NormalizedLicense`>>) such explicit mapping rules are only required for licenses not handled by the automatism.

== Chapter 12: Build-Breaker

The Velocity template `Statistics.vm` creates a `Statistics.json` file that currently looks like this:

[source,json]
----
{
"Statistics": {
"legal-evaluation": {
"yes": 100,
"no": 2,
"Conditional": 30,
"blank": 10
},
"data-status": {
"ND:NOT_AVAILABLE": 5,
"ND:PROCESSING_FAILED": 7,
"NL:WITH_ISSUES": 10,
"NL:NO_ISSUES": 2,
"NL:CURATED": 1,
"DA:NO_ISSUES": 70,
"DA:CURATED": 20
}
}
}
----

The individual categories can be customized in the `statistics.sql` template. Using these fields, you can create a Build-Breaker.

For instance, if there are artifacts in your project that have the `legal-evaluation` value `"no"`, you can break the build.

To achieve this, you can use the JSON processor `jq` and add a script like the following:

[source,bash]
----
# Check if the count for "no" is greater than 0
NO_COUNT=$(jq '.["Statistics"]["legal-evaluation"]["no"]' Statistics.json)
# If NO_COUNT is greater than 0, break the build
if [ -n "$NO_COUNT" ] && [ "$NO_COUNT" != "null" ] && [ "$NO_COUNT" -gt 0 ]; then
echo "Build failed: 'no' count in legal-evaluation is $NO_COUNT"
exit 1
else
echo "Build successful"
fi
----


[appendix]
== Default Base Configuration
The builtin default base configuration contains settings for the `rules` and `writers` section
Expand Down Expand Up @@ -1954,6 +2002,7 @@ Spring beans implementing this interface will be called at certain points in the
[appendix]
== Release Notes
Changes in 1.28.0::
https://github.com/devonfw/solicitor/issues/12: New `statistics` Velocity and SQL template which can be used in a build-breaker.

Changes in 1.27.0::
* https://github.com/devonfw/solicitor/issues/283: New Reader for data generated by the Gradle License Report Plugin. See <<Gradle License Report Plugin>>. Reader `gradle2` deprecated (stage 2). Reader `gradle` removed.
Expand Down
1 change: 1 addition & 0 deletions solicitor.dict
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fas
gradle
http
https
jq
jwt
licenseRefUrl
licenseToIgnoreN
Expand Down

0 comments on commit f935a91

Please sign in to comment.