Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/jackrabbit #495

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ typings/

# next.js build output
.next

# Files generated dynamically when this plugin is run
target/
src/pom.xml
2 changes: 2 additions & 0 deletions .remarkignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Exclude auto-generated files
CHANGELOG.md
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": {...}
}
Expand All @@ -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/<groupId>/<artifactId>/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.
Expand Down
9 changes: 8 additions & 1 deletion aem-packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
74 changes: 65 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [
Expand Down
4 changes: 3 additions & 1 deletion src/defaults.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"options": {
"srcDir": "dist",
"buildDir": "target"
"buildDir": "target",
"packager": "jackrabbit",
"legacyCRXSupport": false
},
"defines": {
"name": "My Project",
Expand Down
55 changes: 55 additions & 0 deletions src/template.js
Original file line number Diff line number Diff line change
@@ -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
}
23 changes: 23 additions & 0 deletions src/templates/jackrabbit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<plugin>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>filevault-package-maven-plugin</artifactId>
<version>1.3.4</version>
<extensions>true</extensions>
<configuration>
<name>${project.name}</name>
<group>${project.groupId}</group>
<validatorsSettings>
<jackrabbit-filter>
<options>
<severityForUndefinedFilterRootAncestors>warn</severityForUndefinedFilterRootAncestors>
</options>
</jackrabbit-filter>
</validatorsSettings>
<filters>
<filter>
<mode>replace</mode>
<root>${project.jcrPath}</root>
</filter>
</filters>
</configuration>
</plugin>
17 changes: 17 additions & 0 deletions src/templates/jcrvault.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<version>0.0.24</version>
<extensions>true</extensions>
<configuration>
<name>${project.name}</name>
<group>${project.groupId}</group>
<failOnError>true</failOnError>
<filters>
<filter>
<mode>replace</mode>
<root>${project.jcrPath}</root>
</filter>
</filters>
</configuration>
</plugin>
6 changes: 6 additions & 0 deletions src/templates/legacyCRXSupport.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<plugin>
<!-- this plugin is only needed for crx package manager deployment -->
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<version>1.0.4</version>
</plugin>
20 changes: 2 additions & 18 deletions src/pom.xml → src/templates/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,7 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<version>0.0.24</version>
<extensions>true</extensions>
<configuration>
<name>${project.name}</name>
<group>${project.groupId}</group>
<failOnError>true</failOnError>
<filters>
<filter>
<mode>replace</mode>
<root>${project.jcrPath}</root>
</filter>
</filters>
</configuration>
</plugin>
<!-- plugin for package building inserts here -->
</plugins>
</build>

Expand All @@ -93,4 +77,4 @@
</build>
</profile>
</profiles>
</project>
</project>