This is an automated email from the ASF dual-hosted git repository. ntimofeev pushed a commit to branch STABLE-4.2 in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit 99c3d61e55893cc196aac04c4c1417bfebe47723 Author: Nikita Timofeev <stari...@gmail.com> AuthorDate: Thu Mar 27 17:50:24 2025 +0400 CAY-2883 License and notice templates are not processed by the Gradle build --- cayenne-gradle-plugin/build.gradle | 57 ++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/cayenne-gradle-plugin/build.gradle b/cayenne-gradle-plugin/build.gradle index 4eb710cf2..dc37d4766 100644 --- a/cayenne-gradle-plugin/build.gradle +++ b/cayenne-gradle-plugin/build.gradle @@ -16,17 +16,20 @@ * specific language governing permissions and limitations * under the License. ****************************************************************/ +buildscript { + dependencies { + classpath 'org.apache.velocity:velocity-engine-core:2.4.1' + } +} + +import org.apache.velocity.VelocityContext +import org.apache.velocity.app.VelocityEngine + plugins { id 'java-gradle-plugin' id 'java' } -def projectVersion = getProjectVersion() - -group 'org.apache.cayenne.plugins' -version projectVersion -def cayenneVersion = version - java { sourceCompatibility = JavaVersion.VERSION_1_8 } @@ -36,6 +39,17 @@ repositories { mavenCentral() } +dependencies { + implementation gradleApi() + implementation localGroovy() +} + +def projectVersion = getProjectVersion() + +group 'org.apache.cayenne.plugins' +version projectVersion +def cayenneVersion = version + def getProjectVersion() { def pomFile = file('pom.xml') if (pomFile.file) { @@ -53,11 +67,6 @@ if (classpathFile.file) { } } -dependencies { - implementation gradleApi() - implementation localGroovy() -} - // Create file with cayenne-gradle-plugin version task versionFile { def resourceOutputDir = file("$buildDir/resources/main/") @@ -69,10 +78,34 @@ task versionFile { } } +def processLicenseFile(fileName) { + def context = new VelocityContext(Map.of("binary", false)) + def outputWriter = new FileWriter(new File("$buildDir/resources/main/META-INF/cayenne/${fileName}.txt")) + def template + def templateFile = new File("$buildDir/resources/tpl/META-INF/cayenne/${fileName}.txt.vm"); + if(templateFile.exists()) { + template = templateFile.text + } else { + throw new RuntimeException("Template file `$buildDir/resources/tpl/META-INF/cayenne/${fileName}.txt.vm` doesn't exist") + } + + try { + new VelocityEngine().evaluate(context, outputWriter, fileName, template) + outputWriter.flush() + } finally { + outputWriter.close() + } +} + // Copy license and notice files task licenseFiles(type: Copy) { from '../build-tools/cayenne-legal/src/main/resources/' - into "$buildDir/resources/main/" + into "$buildDir/resources/tpl/" + doLast { + mkdir("$buildDir/resources/main/META-INF/cayenne/") + processLicenseFile("LICENSE") + processLicenseFile("NOTICE") + } } task sourcesJar(type: Jar, dependsOn: classes) {