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

danwatford pushed a commit to branch release22.01
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/release22.01 by this push:
     new b52752b439 Implemented: Use node/npm during gradle build from multiple 
sub-projects (OFBIZ-12789)
b52752b439 is described below

commit b52752b439ecea47982abb293c05bfb75d3ba113
Author: Daniel Watford <dan...@watfordconsulting.com>
AuthorDate: Mon Apr 17 11:17:10 2023 +0100

    Implemented: Use node/npm during gradle build from multiple sub-projects 
(OFBIZ-12789)
    
    Added gradle plugin, ofbiz-node-conventions, to set conventional use of
    the gradle node plugin across OFBiz sub-projects (i.e. components).
    
    Modified common-theme to install and cleanup NPM modules at appropriate
    points in the gradle task lifecycle.
    
    This change will allow multiple components, including plugins, to
    leverage the gradle node plugin in their build process without needing
    updates to the parent build.gradle script.
---
 .dockerignore                                      |   3 +-
 Dockerfile                                         |   1 +
 build.gradle                                       |  30 +-----
 buildSrc/build.gradle                              |  22 ++++
 .../src/main/groovy/ofbiz-node-conventions.gradle  |  70 +++++++++++++
 themes/common-theme/build.gradle                   |  26 +++++
 .../webapp/common/js/package-lock.json             | 116 +++++++++++++++++----
 7 files changed, 217 insertions(+), 51 deletions(-)

diff --git a/.dockerignore b/.dockerignore
index 24f2d41429..521ad04c5d 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -27,4 +27,5 @@ Dockerfile
 /plugins/.svn
 /plugins/.github
 /plugins/.git
-
+/buildSrc/.gradle
+/buildSrc/build
diff --git a/Dockerfile b/Dockerfile
index 23d7470c7e..b67d18d22b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -38,6 +38,7 @@ RUN 
--mount=type=cache,id=gradle-cache,sharing=locked,target=/root/.gradle \
     ["./gradlew", "--console", "plain"]
 
 # Copy all OFBiz sources.
+COPY buildSrc/ buildSrc/
 COPY applications/ applications/
 COPY config/ config/
 COPY framework/ framework/
diff --git a/build.gradle b/build.gradle
index e4a52406a4..f7d8ba0cc6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -37,7 +37,7 @@ plugins {
     id 'com.github.ben-manes.versions' version '0.42.0' apply false
     id "com.github.ManifestClasspath" version "0.1.0-RELEASE"
     id "com.github.jakemarsden.git-hooks" version "0.0.2"
-    id "com.github.node-gradle.node" version "3.5.0"
+    id "com.github.node-gradle.node" version '3.5.1' apply false
 }
 
 /* OWASP plugin
@@ -112,27 +112,6 @@ javadoc {
     }
 }
 
-node {
-    download = true
-    version = "16.13.1"
-    // npmVersion will be the one that comes default with node
-
-    // https://github.com/node-gradle/gradle-node-plugin/blob/2.2.4/README.md
-    // Set the work directory where node_modules should be located
-    nodeModulesDir = 
file("${project.projectDir}/themes/common-theme/webapp/common/js")
-    // If you set a "CI" env var then ci only will be used:
-    // 
https://github.com/node-gradle/gradle-node-plugin/blob/master/docs/faq.md#how-do-i-use-npm-ci-instead-of-npm-install
-    npmInstallCommand = System.getenv("CI") ? 'ci' : 'install'
-}
-
-tasks.getByName("distTar") {
-    dependsOn "npmInstall"
-}
-
-tasks.getByName("distZip") {
-    dependsOn "npmInstall"
-}
-
 java {
     sourceCompatibility(JavaVersion.VERSION_17)
     targetCompatibility(JavaVersion.VERSION_17)
@@ -146,8 +125,6 @@ tasks.withType(JavaCompile) {
     // Exclude varargs warnings which are not silenced by @SafeVarargs.
         options.compilerArgs << "-Xlint:-varargs"
     }
-    // Executes on each compilation so that if dependencies are not downloaded 
yet or some new dependencies are added they get automatically downloaded
-    if (!project.hasProperty('skipNpmInstall')) finalizedBy 'npmInstall'
 }
 
 def getCurrentGitBranch() {
@@ -1056,11 +1033,6 @@ task cleanFooterFiles(group: cleanupGroup, description: 
'clean generated footer
         delete gitFooterFile
     }
 }
-task cleanNpm(group: cleanupGroup, description: 'clean node modules') {
-    doLast {
-        delete 
"${project.projectDir}/themes/common-theme/webapp/common/js/node_modules"
-    }
-}
 /*
  * Keep this task below all other clean tasks  The location of
  * declaration is important because it means that it will automatically
diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
new file mode 100644
index 0000000000..e27ac17318
--- /dev/null
+++ b/buildSrc/build.gradle
@@ -0,0 +1,22 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+
+plugins {
+    id 'groovy-gradle-plugin'
+}
diff --git a/buildSrc/src/main/groovy/ofbiz-node-conventions.gradle 
b/buildSrc/src/main/groovy/ofbiz-node-conventions.gradle
new file mode 100644
index 0000000000..6e5d707748
--- /dev/null
+++ b/buildSrc/src/main/groovy/ofbiz-node-conventions.gradle
@@ -0,0 +1,70 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+
+/*
+ * This plugin defines usage of the node-gradle plugin for OFBiz sub-projects.
+ *
+ * NPM Install (or ci) will be run as a dependency of the classes task. The 
output from NPM Install will be cleaned
+ * up as part of the parent project's cleanAll task.
+ *
+ * Sub projects should apply this plugin and then configure the node block 
with the path to the directory containing
+ * the package.json file. Example:
+ *
+ *  plugins {
+ *      id 'ofbiz-node-conventions'
+ *  }
+ *
+ *  node {
+ *      nodeProjectDir = file('webapp/common-theme/js')
+ *  }
+ */
+
+plugins {
+    id 'base'  // Provides the clean<TaskName> rule for the cleanNpmInstall 
task.
+    id 'com.github.node-gradle.node'
+}
+
+node {
+    download = true
+    version = "16.13.1"
+
+    // If environment variable CI is set, use 'npm ci' instead of 'npm 
install' to populate node_modules.
+    npmInstallCommand = System.getenv("CI") ? 'ci' : 'install'
+}
+
+// Pull NPM dependencies when the classes task is run.
+// Hooking into classes ensures that dependencies are available if OFBiz is
+// started via the Gradle Application Plugin's run task, or if a distribution
+// is being built (distTar, distZip, etc.).
+if (!project.rootProject.hasProperty('skipNpmInstall')) {
+    project.rootProject.tasks.getByName('classes').dependsOn npmInstall
+}
+
+// Task to clean up the output from npmInstall.
+task cleanNpm(group: 'Cleaning', description: 'Clean installed node modules') {
+    dependsOn cleanNpmInstall
+}
+
+// Hook into the root project's cleanAll task to clean up the output from the
+// npmInstall task.
+project.rootProject.tasks.whenTaskAdded { task ->
+    if (task.name == 'cleanAll') {
+        task.dependsOn cleanNpmInstall
+    }
+}
diff --git a/themes/common-theme/build.gradle b/themes/common-theme/build.gradle
new file mode 100644
index 0000000000..80d7058683
--- /dev/null
+++ b/themes/common-theme/build.gradle
@@ -0,0 +1,26 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+
+plugins {
+    id 'ofbiz-node-conventions'
+}
+
+node {
+    nodeProjectDir = file('webapp/common/js')
+}
diff --git a/themes/common-theme/webapp/common/js/package-lock.json 
b/themes/common-theme/webapp/common/js/package-lock.json
index bf5720843a..87703d9f64 100644
--- a/themes/common-theme/webapp/common/js/package-lock.json
+++ b/themes/common-theme/webapp/common/js/package-lock.json
@@ -1,32 +1,104 @@
 {
   "name": "ofbiz-framework",
+  "lockfileVersion": 2,
   "requires": true,
-  "lockfileVersion": 1,
+  "packages": {
+    "": {
+      "name": "ofbiz-framework",
+      "license": "Apache-2.0",
+      "dependencies": {
+        "dompurify": "^2.3.4",
+        "flot": "^4.2.2",
+        "jquery": "^3.6.0",
+        "jquery-migrate": "^3.3.2",
+        "jquery-ui-dist": "^1.13.0",
+        "jquery-validation": "^1.19.5",
+        "jquery.browser": "^0.1.0",
+        "trumbowyg": "^2.25.1"
+      }
+    },
+    "node_modules/dompurify": {
+      "version": "2.4.5",
+      "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.4.5.tgz";,
+      "integrity": 
"sha512-jggCCd+8Iqp4Tsz0nIvpcb22InKEBrGz5dw3EQJMs8HPJDsKbFIO3STYtAvCfDx26Muevn1MHVI0XxjgFfmiSA=="
+    },
+    "node_modules/flot": {
+      "version": "4.2.3",
+      "resolved": "https://registry.npmjs.org/flot/-/flot-4.2.3.tgz";,
+      "integrity": 
"sha512-r1t2gfhILE6dt7cnYDHX/D2VHERyD0YoV0UdFJg5dWbjkcu05MugfhNY7VspfBFTa+hjVNYVZw6/t9ZyYNen+w=="
+    },
+    "node_modules/jquery": {
+      "version": "3.6.4",
+      "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.4.tgz";,
+      "integrity": 
"sha512-v28EW9DWDFpzcD9O5iyJXg3R3+q+mET5JhnjJzQUZMHOv67bpSIHq81GEYpPNZHG+XXHsfSme3nxp/hndKEcsQ=="
+    },
+    "node_modules/jquery-migrate": {
+      "version": "3.4.1",
+      "resolved": 
"https://registry.npmjs.org/jquery-migrate/-/jquery-migrate-3.4.1.tgz";,
+      "integrity": 
"sha512-6RaV23lLAYccu8MtLfy2sIxOvx+bulnWHm/pvffAi7KOzPk1sN9IYglpkl1ZNCj1FSgSNDPS2fSZ1hWsXc200Q==",
+      "peerDependencies": {
+        "jquery": ">=3 <4"
+      }
+    },
+    "node_modules/jquery-ui-dist": {
+      "version": "1.13.2",
+      "resolved": 
"https://registry.npmjs.org/jquery-ui-dist/-/jquery-ui-dist-1.13.2.tgz";,
+      "integrity": 
"sha512-oVDRd1NLtTbBwpRKAYdIRgpWVDzeBhfy7Gu0RmY6JEaZtmBq6kDn1pm5SgDiAotrnDS+RoTRXO6xvcNTxA9tOA==",
+      "dependencies": {
+        "jquery": ">=1.8.0 <4.0.0"
+      }
+    },
+    "node_modules/jquery-validation": {
+      "version": "1.19.5",
+      "resolved": 
"https://registry.npmjs.org/jquery-validation/-/jquery-validation-1.19.5.tgz";,
+      "integrity": 
"sha512-X2SmnPq1mRiDecVYL8edWx+yTBZDyC8ohWXFhXdtqFHgU9Wd4KHkvcbCoIZ0JaSaumzS8s2gXSkP8F7ivg/8ZQ==",
+      "peerDependencies": {
+        "jquery": "^1.7 || ^2.0 || ^3.1"
+      }
+    },
+    "node_modules/jquery.browser": {
+      "version": "0.1.0",
+      "resolved": 
"https://registry.npmjs.org/jquery.browser/-/jquery.browser-0.1.0.tgz";,
+      "integrity": 
"sha512-5GjtLzzEBzxs/nwSVpCbSdk0acssfKsP7Upp43zmdHVV1Vb6E9VayyqPAQlfLrTeZL3YSWocCbkOvKdAc2CN4g==",
+      "engines": {
+        "node": ">= 0.4.0"
+      }
+    },
+    "node_modules/trumbowyg": {
+      "version": "2.27.3",
+      "resolved": 
"https://registry.npmjs.org/trumbowyg/-/trumbowyg-2.27.3.tgz";,
+      "integrity": 
"sha512-mEFhPSrF3dobjnGSSW7BfnmX5Pnv9T4KIoATOHxFOHtb1exE0L2hNPxCr6Bh4iFRJQD4UErleyKCapKf2yImKw==",
+      "peerDependencies": {
+        "jquery": ">=1.8"
+      }
+    }
+  },
   "dependencies": {
     "dompurify": {
-      "version": "2.3.4",
-      "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.3.4.tgz";,
-      "integrity": 
"sha512-6BVcgOAVFXjI0JTjEvZy901Rghm+7fDQOrNIcxB4+gdhj6Kwp6T9VBhBY/AbagKHJocRkDYGd6wvI+p4/10xtQ=="
+      "version": "2.4.5",
+      "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.4.5.tgz";,
+      "integrity": 
"sha512-jggCCd+8Iqp4Tsz0nIvpcb22InKEBrGz5dw3EQJMs8HPJDsKbFIO3STYtAvCfDx26Muevn1MHVI0XxjgFfmiSA=="
     },
     "flot": {
-      "version": "4.2.2",
-      "resolved": "https://registry.npmjs.org/flot/-/flot-4.2.2.tgz";,
-      "integrity": 
"sha512-Strct/A27o0TA25X7Z0pxKhwK4djiP1Kjeqj0tkiqrkRu1qYPqfbp5BYuxEL8CWDNtj85Uc0PnG2E2plo1+VMg=="
+      "version": "4.2.3",
+      "resolved": "https://registry.npmjs.org/flot/-/flot-4.2.3.tgz";,
+      "integrity": 
"sha512-r1t2gfhILE6dt7cnYDHX/D2VHERyD0YoV0UdFJg5dWbjkcu05MugfhNY7VspfBFTa+hjVNYVZw6/t9ZyYNen+w=="
     },
     "jquery": {
-      "version": "3.6.0",
-      "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.0.tgz";,
-      "integrity": 
"sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw=="
+      "version": "3.6.4",
+      "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.4.tgz";,
+      "integrity": 
"sha512-v28EW9DWDFpzcD9O5iyJXg3R3+q+mET5JhnjJzQUZMHOv67bpSIHq81GEYpPNZHG+XXHsfSme3nxp/hndKEcsQ=="
     },
     "jquery-migrate": {
-      "version": "3.3.2",
-      "resolved": 
"https://registry.npmjs.org/jquery-migrate/-/jquery-migrate-3.3.2.tgz";,
-      "integrity": 
"sha512-L3gYhr7yEtLUSAeqXSicVa0vRD4aGwjw/bWY8YzrO2o/qDY1BaMyP3oB3bZf5Auy3Hu9ynliio0CTyDWCBPVDw=="
+      "version": "3.4.1",
+      "resolved": 
"https://registry.npmjs.org/jquery-migrate/-/jquery-migrate-3.4.1.tgz";,
+      "integrity": 
"sha512-6RaV23lLAYccu8MtLfy2sIxOvx+bulnWHm/pvffAi7KOzPk1sN9IYglpkl1ZNCj1FSgSNDPS2fSZ1hWsXc200Q==",
+      "requires": {}
     },
     "jquery-ui-dist": {
-      "version": "1.13.0",
-      "resolved": 
"https://registry.npmjs.org/jquery-ui-dist/-/jquery-ui-dist-1.13.0.tgz";,
-      "integrity": 
"sha512-fgpGOW098swRvTLglH3RLyAjW/8Ecxd35fO7Z1WtBidhZgnPDvTJzZ+XFybAFzv3zZiEESI8TkK6oYXbzu/rKw==",
+      "version": "1.13.2",
+      "resolved": 
"https://registry.npmjs.org/jquery-ui-dist/-/jquery-ui-dist-1.13.2.tgz";,
+      "integrity": 
"sha512-oVDRd1NLtTbBwpRKAYdIRgpWVDzeBhfy7Gu0RmY6JEaZtmBq6kDn1pm5SgDiAotrnDS+RoTRXO6xvcNTxA9tOA==",
       "requires": {
         "jquery": ">=1.8.0 <4.0.0"
       }
@@ -34,17 +106,19 @@
     "jquery-validation": {
       "version": "1.19.5",
       "resolved": 
"https://registry.npmjs.org/jquery-validation/-/jquery-validation-1.19.5.tgz";,
-      "integrity": 
"sha512-X2SmnPq1mRiDecVYL8edWx+yTBZDyC8ohWXFhXdtqFHgU9Wd4KHkvcbCoIZ0JaSaumzS8s2gXSkP8F7ivg/8ZQ=="
+      "integrity": 
"sha512-X2SmnPq1mRiDecVYL8edWx+yTBZDyC8ohWXFhXdtqFHgU9Wd4KHkvcbCoIZ0JaSaumzS8s2gXSkP8F7ivg/8ZQ==",
+      "requires": {}
     },
     "jquery.browser": {
       "version": "0.1.0",
       "resolved": 
"https://registry.npmjs.org/jquery.browser/-/jquery.browser-0.1.0.tgz";,
-      "integrity": "sha1-nHKmCV/SgUtER26o9xZne3Kmors="
+      "integrity": 
"sha512-5GjtLzzEBzxs/nwSVpCbSdk0acssfKsP7Upp43zmdHVV1Vb6E9VayyqPAQlfLrTeZL3YSWocCbkOvKdAc2CN4g=="
     },
     "trumbowyg": {
-      "version": "2.25.1",
-      "resolved": 
"https://registry.npmjs.org/trumbowyg/-/trumbowyg-2.25.1.tgz";,
-      "integrity": 
"sha512-bmmV1qC+fTLfyVpLE5iZjCzHG5DfAwM7p8K2fdq6L1kOi+IrVJk/qGFVEEmYyJ0Ofd1z3g2vavfABpmkVLzV6A=="
+      "version": "2.27.3",
+      "resolved": 
"https://registry.npmjs.org/trumbowyg/-/trumbowyg-2.27.3.tgz";,
+      "integrity": 
"sha512-mEFhPSrF3dobjnGSSW7BfnmX5Pnv9T4KIoATOHxFOHtb1exE0L2hNPxCr6Bh4iFRJQD4UErleyKCapKf2yImKw==",
+      "requires": {}
     }
   }
 }

Reply via email to