diff --git a/core/src/main/resources/com/devonfw/tools/solicitor/config/solicitor_base.cfg b/core/src/main/resources/com/devonfw/tools/solicitor/config/solicitor_base.cfg index c7fe425e..a94128b3 100644 --- a/core/src/main/resources/com/devonfw/tools/solicitor/config/solicitor_base.cfg +++ b/core/src/main/resources/com/devonfw/tools/solicitor/config/solicitor_base.cfg @@ -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" + } } - }] - + ] } \ No newline at end of file diff --git a/core/src/main/resources/com/devonfw/tools/solicitor/sql/statistics.sql b/core/src/main/resources/com/devonfw/tools/solicitor/sql/statistics.sql new file mode 100644 index 00000000..0aac44bc --- /dev/null +++ b/core/src/main/resources/com/devonfw/tools/solicitor/sql/statistics.sql @@ -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"; diff --git a/core/src/main/resources/com/devonfw/tools/solicitor/templates/Statistics.vm b/core/src/main/resources/com/devonfw/tools/solicitor/templates/Statistics.vm new file mode 100644 index 00000000..0f9d2456 --- /dev/null +++ b/core/src/main/resources/com/devonfw/tools/solicitor/templates/Statistics.vm @@ -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 + } +} diff --git a/documentation/master-solicitor.asciidoc b/documentation/master-solicitor.asciidoc index 4326fee1..d9fa7883 100644 --- a/documentation/master-solicitor.asciidoc +++ b/documentation/master-solicitor.asciidoc @@ -1810,6 +1810,54 @@ Using the <> it is possible to qualify whether a rul Due the automatic mapping of scancode based `RawLicenses` to `NormalizedLicenses` (see <>) 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 @@ -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 <>. Reader `gradle2` deprecated (stage 2). Reader `gradle` removed. diff --git a/solicitor.dict b/solicitor.dict index 93f99e4f..2ea7f287 100644 --- a/solicitor.dict +++ b/solicitor.dict @@ -17,6 +17,7 @@ fas gradle http https +jq jwt licenseRefUrl licenseToIgnoreN