jdaugherty commented on code in PR #15087: URL: https://github.com/apache/grails-core/pull/15087#discussion_r2371949138
########## gradle/sbom-config.gradle: ########## @@ -0,0 +1,242 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +import groovy.json.JsonOutput +import groovy.json.JsonSlurper +import org.cyclonedx.gradle.CycloneDxTask +import org.cyclonedx.model.ExternalReference +import org.cyclonedx.model.LicenseChoice +import org.cyclonedx.model.License +import org.cyclonedx.model.OrganizationalContact +import org.cyclonedx.model.OrganizationalEntity +import org.cyclonedx.model.Component + +import java.nio.charset.StandardCharsets +import java.time.format.DateTimeFormatter +import java.time.temporal.ChronoUnit + +apply plugin: 'org.cyclonedx.bom' + +project.ext.setProperty('sbomOutputLocation', project.layout.buildDirectory.file("${findProperty('pomArtifactId') ?: project.name}-${projectVersion}-sbom.json")) + +def sbomTask = tasks.named('cyclonedxBom', CycloneDxTask) +sbomTask.configure { CycloneDxTask it -> + // the 2.x version of Cyclonedx uses a legacy syntax & helpers for setting inputs so the syntax below + // is required until the 3.x version is GA + it.setProjectType(findProperty('sbomProjectType') ?: Component.Type.FRAMEWORK.name()) + [email protected](findProperty('pomArtifactId') ?: project.name) + [email protected](new OrganizationalEntity().tap { + name = 'Apache Software Foundation' + urls = ['https://www.apache.org/', 'https://security.apache.org/'] + addContact(new OrganizationalContact().tap { + name = 'Apache Grails Development Team' + email = '[email protected]' + }) + }) + [email protected](new LicenseChoice().tap { + addLicense(new License().tap { + name = 'Apache-2.0' + url = 'https://www.apache.org/licenses/LICENSE-2.0.txt' + }) + }) + + [email protected]([ + new ExternalReference().tap { + url = 'https://grails.apache.org/' + type = ExternalReference.Type.WEBSITE + } + ]) + + // sboms are published for the purposes of vulnerability analysis so only include the runtime classpath + [email protected](['runtimeClasspath']) + [email protected](['compileClasspath', 'testRuntimeClasspath']) + + // turn off license text since it's base64 encoded & will inflate the jar sizes + [email protected](false) + + // disable xml output + it.xmlOutput.unsetConvention() + + def sbomOutputLocation = findProperty('sbomOutputLocation') + it.jsonOutput.set(sbomOutputLocation.get()) + it.outputs.file(sbomOutputLocation) + + // cyclonedx does not support "choosing" the license placed in the sbom + // see: https://github.com/CycloneDX/cyclonedx-gradle-plugin/issues/16 + it.doLast { + // ordered so that first value is the most preferred, this list is from https://www.apache.org/legal/resolved.html + def preferredLicenses = ['Apache-2.0', 'EPL-1.0', 'BSD-3-Clause', 'EPL-2.0', 'MIT', 'MIT-0', '0BSD', 'UPL-1.0', 'CC0-1.0', 'ICU', 'Xnet', 'NCSA', 'W3C', 'Zlib', 'AFL-3.0', 'MS-PL', 'PSF-2.0', 'APAFML', 'BSL-1.0', 'WTFPL', 'Unlicense', 'HPND', 'EPICS', 'TCL'] + + // licenses are standardized @ https://spdx.org/licenses/ + def licenses = [ + 'Apache-2.0' : [ + id: 'Apache-2.0', + url: 'https://www.apache.org/licenses/LICENSE-2.0' + ], + 'BSD-2-Clause' : [ + id: 'BSD-2-Clause', + url: 'https://opensource.org/license/bsd-3-clause/' + ], + 'BSD-3-Clause' : [ + id: 'BSD-3-Clause', + url: 'https://opensource.org/license/bsd-3-clause/' + ], + // Variant of Apache 1.1 license. Approved by legal LEGAL-707 + 'OpenSymphony' : [ + // id is optional and the opensymphony license doesn't have an SPDX id + name: 'The OpenSymphony Software License, Version 1.1', + url: 'https://raw.githubusercontent.com/sitemesh/sitemesh2/refs/heads/master/LICENSE.txt' + ], + 'UPL-1.0' : [ + id: 'UPL-1.0', + url: 'https://oss.oracle.com/licenses/upl/' + ], + ] + + def licenseMapping = [ + 'pkg:maven/org.antlr/[email protected]?type=jar' : 'BSD-3-Clause', // maps incorrectly because of https://github.com/CycloneDX/cyclonedx-core-java/issues/205 + 'pkg:maven/jline/[email protected]?type=jar' : 'BSD-2-Clause', // maps incorrectly because of https://github.com/CycloneDX/cyclonedx-core-java/issues/205 + 'pkg:maven/org.jline/[email protected]?type=jar' : 'BSD-2-Clause', // maps incorrectly because of https://github.com/CycloneDX/cyclonedx-core-java/issues/205 + 'pkg:maven/org.liquibase.ext/[email protected]?type=jar' : 'Apache-2.0', // maps incorrectly because of https://github.com/liquibase/liquibase/issues/2445 & the base pom does not define a license + 'pkg:maven/com.oracle.coherence.ce/[email protected]?type=pom' : 'UPL-1.0', // does not have map based on license id + 'pkg:maven/com.oracle.coherence.ce/[email protected]?type=pom' : 'UPL-1.0', // does not have map based on license id + 'pkg:maven/opensymphony/[email protected]?type=jar' : 'OpenSymphony', // custom license approved by legal LEGAL-707 + 'pkg:maven/org.jruby/[email protected]?type=jar': 'BSD-3-Clause'// https://web.archive.org/web/20240822213507/http://www.jcraft.com/jzlib/LICENSE.txt shows it's a 3 clause + ] + + // we don't distribute these so these licenses are considered acceptable, but we still prefer ASF licenses. + // Require a whitelist of any case of category X licenses to prevent accidental inclusion in a distributed artifact + // this list will need to be updated anytime we change versions so we can revise the licenses + def licenseExceptions = [ + 'grails-data-hibernate5-core': [ + 'pkg:maven/org.hibernate.common/[email protected]?type=jar': 'LGPL-2.1-only', // hibernate 5 is LGPL, we are migrating to ASF license in hibernate 7 + 'pkg:maven/org.hibernate/[email protected]?type=jar': 'LGPL-2.1-only', // hibernate 5 is LGPL, we are migrating to ASF license in hibernate 7 + ], + 'grails-data-hibernate5': [ + 'pkg:maven/org.hibernate.common/[email protected]?type=jar': 'LGPL-2.1-only', // hibernate 5 is LGPL, we are migrating to ASF license in hibernate 7 + 'pkg:maven/org.hibernate/[email protected]?type=jar': 'LGPL-2.1-only', // hibernate 5 is LGPL, we are migrating to ASF license in hibernate 7 + ], + 'grails-data-hibernate5-spring-boot': [ + 'pkg:maven/org.hibernate.common/[email protected]?type=jar': 'LGPL-2.1-only', // hibernate 5 is LGPL, we are migrating to ASF license in hibernate 7 + 'pkg:maven/org.hibernate/[email protected]?type=jar': 'LGPL-2.1-only', // hibernate 5 is LGPL, we are migrating to ASF license in hibernate 7 + ], + 'grails-data-hibernate5-dbmigration': [ + 'pkg:maven/javax.xml.bind/[email protected]?type=jar': 'CDDL-1.1', // api export + ], + ] + + def pickLicense = { String bomRef, List licenseChoices -> + if(!bomRef) { Review Comment: I would have assumed codenarc was applied to our gradle files, but apparently not. Do you know if it's possible to apply our code style rules to gradle files? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
