From f9f1f14d447d87c3c3be0453cac938b11694a9bc Mon Sep 17 00:00:00 2001 From: Mahidhar Chaluvadi Date: Thu, 21 Sep 2023 23:27:41 -0500 Subject: [PATCH 1/6] feat: jackrabbit package plugin - Content Package Plugin version is too old - Replacing its usage with Jackrabbit Package Plugin - Disabled validation to ensure maven build doesnt throw errors Fixes #488 --- src/pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pom.xml b/src/pom.xml index 454a5db..793adc3 100644 --- a/src/pom.xml +++ b/src/pom.xml @@ -66,14 +66,14 @@ - com.day.jcr.vault - content-package-maven-plugin - 0.0.24 + org.apache.jackrabbit + filevault-package-maven-plugin + 1.3.4 true + true ${project.name} ${project.groupId} - true replace From 61ed2da472be2581eef0e09e0a5a08bf9689980c Mon Sep 17 00:00:00 2001 From: Mahidhar Chaluvadi Date: Sat, 7 Oct 2023 17:52:28 -0500 Subject: [PATCH 2/6] feat: jackrabbit package plugin - Content Package Plugin version is bumped and not removed completely - Jackrabbit Package Plugin: - Updated validator settings - Enabled validation, just excluded filter path validation --- src/pom.xml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/pom.xml b/src/pom.xml index 793adc3..0d9cb5b 100644 --- a/src/pom.xml +++ b/src/pom.xml @@ -65,15 +65,22 @@ + org.apache.jackrabbit filevault-package-maven-plugin 1.3.4 true - true ${project.name} ${project.groupId} + + + + warn + + + replace @@ -82,6 +89,12 @@ + + + com.day.jcr.vault + content-package-maven-plugin + 1.0.4 + From 2b2e7ca67153374b2b0c9a96c1b8bb6f6e538445 Mon Sep 17 00:00:00 2001 From: Anthony McLin Date: Sat, 7 Oct 2023 21:15:20 -0700 Subject: [PATCH 3/6] feat: switch to jackrabbit for content packaging Switches out the deprecated JCR Valut plugin for content packages with the newer Jackrabbit. Should speed up package installations, and reduce the amount network or security errors around using an old unmaintained plugin. BREAKING CHANGE: no longer contains the necessary maven plugins for CRX deployment functionalitty. To add legacy CRX support on top of Jackrabbit, set the new option `legacyCRXSupport` to true. To restore the old `aem-packager` functionality entirely, set the new option `packager` to `jcrvault` --- .gitignore | 4 ++ README.md | 27 ++++++++++- aem-packager.js | 9 +++- package-lock.json | 74 ++++++++++++++++++++++++++---- package.json | 5 +- src/defaults.json | 4 +- src/template.js | 55 ++++++++++++++++++++++ src/templates/jackrabbit.xml | 23 ++++++++++ src/templates/jcrvault.xml | 17 +++++++ src/templates/legacyCRXSupport.xml | 6 +++ src/{ => templates}/pom.xml | 20 +------- 11 files changed, 212 insertions(+), 32 deletions(-) create mode 100644 src/template.js create mode 100644 src/templates/jackrabbit.xml create mode 100644 src/templates/jcrvault.xml create mode 100644 src/templates/legacyCRXSupport.xml rename src/{ => templates}/pom.xml (82%) diff --git a/.gitignore b/.gitignore index ad46b30..93db1c3 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,7 @@ typings/ # next.js build output .next + +# Files generated dynamically when this plugin is run +target/ +src/pom.xml diff --git a/README.md b/README.md index d2447d8..9c204ba 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,9 @@ The settings for running the packager are populated through the `options` object "options": { "srcDir": "dist", "buildDir": "target" - "jcrPath": "/apps/mygroup/myapp/clientlibs" + "jcrPath": "/apps/mygroup/myapp/clientlibs", + "packager": "jackrabbit", + "legacyCRXSupport": false }, "defines": {...} } @@ -168,6 +170,29 @@ The working directory that Maven will use for compiling the build package. Defau The path in the JCR (AEM's storage system) where the module will be installed. Since most npm projects will likely be generating JS, CSS, and HTML assets, the default here when left blank, this will use the [`groupId`](#groupId) and [`artifactId`](#artifactId) to complete generate the full pattern `/apps///clientlibs` +#### packager (string) + +Switches which plugin to use for building the content package. Defaults to `jackrabbit` when not provided: +- `jackrabbit`: Will use the more modern [jackrabbit plugin](#jackrabbit-plugin) +- `jcrvault`: Will use the legacy [jcr vault](#jcr-vault-plugin) + +These two plugins work slightly differently. + +##### Jackrabbit Plugin + +The `filevault-package-maven-plugin` from [Apache Jackrabbit](https://jackrabbit.apache.org/filevault-package-maven-plugin/) is faster during package installation because it doesn't need to copy files. However, it doesn't have full backwards compatibility and does not support CRX deployment. It will not work with AEM 6.3 or earlier. If using `jackrabbit` with AEM 6.3, make sure also turn on `legacyCRXSupport` so that the JCR Vault plugin can also be included. + +##### JCR Vault Plugin + +While Adobe [provides documentation](https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/developer-tools/maven-plugin.html) on using the JCR Vault plugin, it is no longer maintained. There were significant compatibility issues between AEM 6.1 and 6.3. In addition, there have been reports of various network setups blocking it due to some historical issues involving HTTP URLs for registries and SSL certis. + +Choose this option if youChoosing this option is consistent with how `aem-packager` worked previous to v4.0 + +#### crxCompatibility + +Enables backwards compatibility for CRX when using Jackrabbit for `packager`. Set boolean `true` or `false`. Defaults to `false`. When enabled, it includes the JCR Vault `content-package-maven-plugin` so that built packages have the necessary goals needed for CRX deployment. Has no effect if `packager` is set to `jcrvault`. + + ### Defines In addition to [configuring how the packager runs](#Options), you can also set Maven **defines** which provide specific values in the resulting installable AEM package. The primary required values for generating an AEM package will be automatically be extracted from your project's `package.json`, but they can be overridden by adding a `defines` object to your project's `package.json` as a `aem-packager.defines` section. diff --git a/aem-packager.js b/aem-packager.js index 01a66c8..e1533c7 100755 --- a/aem-packager.js +++ b/aem-packager.js @@ -16,6 +16,7 @@ const { // Define default fallbacks for all unset configs const defaults = require('./src/defaults.json') +const { assemblePom, writePom } = require('./src/template.js') defaults.options.jcrPath = undefined // Set here so it exists when we loop later. Cannot be declared undefined in JSON // Merge configurations from various sources @@ -103,7 +104,13 @@ const getDefines = function (configs) { * @param {Object} configs Fully processed configuration object */ const runMvn = function (configs) { - const pomPath = path.resolve(__dirname, 'src/pom.xml') + writePom( + assemblePom({ + ...configs.options + }) + ) + + const pomPath = path.resolve(__dirname, 'src', 'pom.xml') const commands = getCommands(pomPath) let defines = getDefines(configs) // Prepare the variables for the pom.xml diff --git a/package-lock.json b/package-lock.json index c297d68..8c51547 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,19 @@ { "name": "aem-packager", - "version": "3.1.4", + "version": "3.1.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "aem-packager", - "version": "3.1.4", + "version": "3.1.5", "hasInstallScript": true, "license": "MIT", "dependencies": { "command-line-args": "^5.1.1", "maven": "^5.0.0", - "read-config-file": "^6.0.0" + "read-config-file": "^6.0.0", + "xmlbuilder2": "^3.1.1" }, "bin": { "aem-packager": "aem-packager.js" @@ -1467,6 +1468,50 @@ "@octokit/openapi-types": "^19.0.0" } }, + "node_modules/@oozcitak/dom": { + "version": "1.15.10", + "resolved": "https://registry.npmjs.org/@oozcitak/dom/-/dom-1.15.10.tgz", + "integrity": "sha512-0JT29/LaxVgRcGKvHmSrUTEvZ8BXvZhGl2LASRUgHqDTC1M5g1pLmVv56IYNyt3bG2CUjDkc67wnyZC14pbQrQ==", + "dependencies": { + "@oozcitak/infra": "1.0.8", + "@oozcitak/url": "1.0.4", + "@oozcitak/util": "8.3.8" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/@oozcitak/infra": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@oozcitak/infra/-/infra-1.0.8.tgz", + "integrity": "sha512-JRAUc9VR6IGHOL7OGF+yrvs0LO8SlqGnPAMqyzOuFZPSZSXI7Xf2O9+awQPSMXgIWGtgUf/dA6Hs6X6ySEaWTg==", + "dependencies": { + "@oozcitak/util": "8.3.8" + }, + "engines": { + "node": ">=6.0" + } + }, + "node_modules/@oozcitak/url": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@oozcitak/url/-/url-1.0.4.tgz", + "integrity": "sha512-kDcD8y+y3FCSOvnBI6HJgl00viO/nGbQoCINmQ0h98OhnGITrWR3bOGfwYCthgcrV8AnTJz8MzslTQbC3SOAmw==", + "dependencies": { + "@oozcitak/infra": "1.0.8", + "@oozcitak/util": "8.3.8" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/@oozcitak/util": { + "version": "8.3.8", + "resolved": "https://registry.npmjs.org/@oozcitak/util/-/util-8.3.8.tgz", + "integrity": "sha512-T8TbSnGsxo6TDBJx/Sgv/BlVJL3tshxZP7Aq5R1mSnM5OcHY2dQaxLMu2+E8u3gN0MLOzdjurqN4ZRVuzQycOQ==", + "engines": { + "node": ">=8.0" + } + }, "node_modules/@pnpm/config.env-replace": { "version": "1.1.0", "dev": true, @@ -2762,7 +2807,6 @@ }, "node_modules/argparse": { "version": "1.0.10", - "dev": true, "license": "MIT", "dependencies": { "sprintf-js": "~1.0.2" @@ -4782,7 +4826,6 @@ }, "node_modules/esprima": { "version": "4.0.1", - "dev": true, "license": "BSD-2-Clause", "bin": { "esparse": "bin/esparse.js", @@ -6654,9 +6697,9 @@ "license": "MIT" }, "node_modules/js-yaml": { - "version": "3.13.1", - "dev": true, - "license": "MIT", + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", + "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", "dependencies": { "argparse": "^1.0.7", "esprima": "^4.0.0" @@ -14129,7 +14172,6 @@ }, "node_modules/sprintf-js": { "version": "1.0.3", - "dev": true, "license": "BSD-3-Clause" }, "node_modules/standard": { @@ -15531,6 +15573,20 @@ "node": ">=8" } }, + "node_modules/xmlbuilder2": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/xmlbuilder2/-/xmlbuilder2-3.1.1.tgz", + "integrity": "sha512-WCSfbfZnQDdLQLiMdGUQpMxxckeQ4oZNMNhLVkcekTu7xhD4tuUDyAPoY8CwXvBYE6LwBHd6QW2WZXlOWr1vCw==", + "dependencies": { + "@oozcitak/dom": "1.15.10", + "@oozcitak/infra": "1.0.8", + "@oozcitak/util": "8.3.8", + "js-yaml": "3.14.1" + }, + "engines": { + "node": ">=12.0" + } + }, "node_modules/xtend": { "version": "4.0.2", "dev": true, diff --git a/package.json b/package.json index 9f5ed13..ece9172 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "test": "nyc mocha", "lint": "run-p lint:*", "lint:md": "remark .", - "lint:js": "standard" + "lint:js": "standard --fix" }, "devDependencies": { "@commitlint/cli": "^17.0.0", @@ -64,7 +64,8 @@ "dependencies": { "command-line-args": "^5.1.1", "maven": "^5.0.0", - "read-config-file": "^6.0.0" + "read-config-file": "^6.0.0", + "xmlbuilder2": "^3.1.1" }, "remarkConfig": { "plugins": [ diff --git a/src/defaults.json b/src/defaults.json index bc7d4ed..58b80bf 100644 --- a/src/defaults.json +++ b/src/defaults.json @@ -1,7 +1,9 @@ { "options": { "srcDir": "dist", - "buildDir": "target" + "buildDir": "target", + "packager": "jackrabbit", + "legacyCRXSupport": false }, "defines": { "name": "My Project", diff --git a/src/template.js b/src/template.js new file mode 100644 index 0000000..3609e72 --- /dev/null +++ b/src/template.js @@ -0,0 +1,55 @@ +const Console = console +const { create } = require('xmlbuilder2') +const path = require('path') +const fs = require('fs') + +const templateList = [ + 'pom', 'jcrvault', 'jackrabbit', 'legacyCRXSupport' +] + +const loadTemplate = (template) => { + const file = path.resolve(__dirname, 'templates', `${template}.xml`) + const xmlStr = fs.readFileSync(file, 'utf8') + const xmlDoc = create(xmlStr) + return xmlDoc +} + +const assemblePom = ({ mode = 'jackrabbit', legacyCRXSupport = false }) => { + try { + Console.debug(`Asembling a pom.xml that will use ${mode}`) + + // load the templates + const templates = Object.fromEntries( + templateList.map((el) => [el, loadTemplate(el)]) + ) + + const doc = templates.pom.root() + // Insertion goes after the last plugin in project.build.plugins + const plugins = doc.find(el => el.node.nodeName === 'build') + .find(el => el.node.nodeName === 'plugins') + + // Toggle package + plugins.import(templates[mode]) + + // Toggle compatibility mode + if (mode === 'jackrabbit' && legacyCRXSupport) { + plugins.import(templates.legacyCRXSupport) + } + + return doc + } catch (err) { + Console.error('Failed to asemble pom.xml from templates.', err) + throw err + } +} + +const writePom = (xmlDoc) => { + const xml = xmlDoc.end({ prettyPrint: true }) + const pomPath = path.resolve(__dirname, 'pom.xml') + fs.writeFileSync(pomPath, xml, 'utf8') +} + +module.exports = { + assemblePom, + writePom +} diff --git a/src/templates/jackrabbit.xml b/src/templates/jackrabbit.xml new file mode 100644 index 0000000..def3b17 --- /dev/null +++ b/src/templates/jackrabbit.xml @@ -0,0 +1,23 @@ + + org.apache.jackrabbit + filevault-package-maven-plugin + 1.3.4 + true + + ${project.name} + ${project.groupId} + + + + warn + + + + + + replace + ${project.jcrPath} + + + + \ No newline at end of file diff --git a/src/templates/jcrvault.xml b/src/templates/jcrvault.xml new file mode 100644 index 0000000..4fb2bd8 --- /dev/null +++ b/src/templates/jcrvault.xml @@ -0,0 +1,17 @@ + + com.day.jcr.vault + content-package-maven-plugin + 0.0.24 + true + + ${project.name} + ${project.groupId} + true + + + replace + ${project.jcrPath} + + + + \ No newline at end of file diff --git a/src/templates/legacyCRXSupport.xml b/src/templates/legacyCRXSupport.xml new file mode 100644 index 0000000..15205c6 --- /dev/null +++ b/src/templates/legacyCRXSupport.xml @@ -0,0 +1,6 @@ + + + com.day.jcr.vault + content-package-maven-plugin + 1.0.4 + \ No newline at end of file diff --git a/src/pom.xml b/src/templates/pom.xml similarity index 82% rename from src/pom.xml rename to src/templates/pom.xml index 454a5db..6316640 100644 --- a/src/pom.xml +++ b/src/templates/pom.xml @@ -65,23 +65,7 @@ - - com.day.jcr.vault - content-package-maven-plugin - 0.0.24 - true - - ${project.name} - ${project.groupId} - true - - - replace - ${project.jcrPath} - - - - + @@ -93,4 +77,4 @@ - + \ No newline at end of file From a15ef0375d0df7b941d2fa7d768561c37d0861c9 Mon Sep 17 00:00:00 2001 From: Anthony McLin Date: Sat, 7 Oct 2023 21:16:04 -0700 Subject: [PATCH 4/6] test: prevent linting of autogenerated markdown --- .remarkignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .remarkignore diff --git a/.remarkignore b/.remarkignore new file mode 100644 index 0000000..60bcd1f --- /dev/null +++ b/.remarkignore @@ -0,0 +1,2 @@ +# Exclude auto-generated files +CHANGELOG.md \ No newline at end of file From ac170b8304014605abc5c27c2cf4297c641fd55d Mon Sep 17 00:00:00 2001 From: Mahidhar Chaluvadi Date: Sun, 8 Oct 2023 00:53:49 -0500 Subject: [PATCH 5/6] fix: options mapped properly --- src/defaults.json | 2 +- src/template.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/defaults.json b/src/defaults.json index 58b80bf..f738661 100644 --- a/src/defaults.json +++ b/src/defaults.json @@ -3,7 +3,7 @@ "srcDir": "dist", "buildDir": "target", "packager": "jackrabbit", - "legacyCRXSupport": false + "crxCompatibility": false }, "defines": { "name": "My Project", diff --git a/src/template.js b/src/template.js index 3609e72..c4452fb 100644 --- a/src/template.js +++ b/src/template.js @@ -14,7 +14,7 @@ const loadTemplate = (template) => { return xmlDoc } -const assemblePom = ({ mode = 'jackrabbit', legacyCRXSupport = false }) => { +const assemblePom = ({ packager: mode = 'jackrabbit', crxCompatibility: legacyCRXSupport = false }) => { try { Console.debug(`Asembling a pom.xml that will use ${mode}`) From a1a39e16ad6d12ff53786271ad5e74053e2da442 Mon Sep 17 00:00:00 2001 From: Mahidhar Chaluvadi Date: Sun, 8 Oct 2023 01:43:46 -0500 Subject: [PATCH 6/6] fix: updated docs instead of var def --- README.md | 2 +- src/defaults.json | 2 +- src/template.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9c204ba..4dd7af3 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,7 @@ While Adobe [provides documentation](https://experienceleague.adobe.com/docs/exp Choose this option if youChoosing this option is consistent with how `aem-packager` worked previous to v4.0 -#### crxCompatibility +#### legacyCRXSupport Enables backwards compatibility for CRX when using Jackrabbit for `packager`. Set boolean `true` or `false`. Defaults to `false`. When enabled, it includes the JCR Vault `content-package-maven-plugin` so that built packages have the necessary goals needed for CRX deployment. Has no effect if `packager` is set to `jcrvault`. diff --git a/src/defaults.json b/src/defaults.json index f738661..58b80bf 100644 --- a/src/defaults.json +++ b/src/defaults.json @@ -3,7 +3,7 @@ "srcDir": "dist", "buildDir": "target", "packager": "jackrabbit", - "crxCompatibility": false + "legacyCRXSupport": false }, "defines": { "name": "My Project", diff --git a/src/template.js b/src/template.js index c4452fb..44a8f86 100644 --- a/src/template.js +++ b/src/template.js @@ -14,7 +14,7 @@ const loadTemplate = (template) => { return xmlDoc } -const assemblePom = ({ packager: mode = 'jackrabbit', crxCompatibility: legacyCRXSupport = false }) => { +const assemblePom = ({ packager: mode = 'jackrabbit', legacyCRXSupport = false }) => { try { Console.debug(`Asembling a pom.xml that will use ${mode}`)