This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit 7b74b3088d3df3d4f65ab19f99b75e43b8217f2d
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 | 58 +++++++++++++++++++++++++++++---------
 1 file changed, 45 insertions(+), 13 deletions(-)

diff --git a/cayenne-gradle-plugin/build.gradle 
b/cayenne-gradle-plugin/build.gradle
index ec26397ff..5e2f8ba82 100644
--- a/cayenne-gradle-plugin/build.gradle
+++ b/cayenne-gradle-plugin/build.gradle
@@ -16,18 +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_11
 }
@@ -37,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) {
@@ -54,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/")
@@ -70,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) {

Reply via email to