Skip to content

Commit c64b12d

Browse files
Launcher app dir improvements (#943)
* Launcher app dir imprs * Launcher with app dir fixes
1 parent fb9745b commit c64b12d

10 files changed

Lines changed: 94 additions & 37 deletions

File tree

README.MD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
<img src="docs/logo.png" alt="Gradle AEM Plugin"/>
88
</p>
99

10+
11+
---
12+
13+
TL;DR
14+
15+
To add an automated AEM environment setup to the AEM Maven project [click here](https://github.com/wttech/gradle-aem-plugin/blob/main/docs/launcher.md).
16+
17+
---
18+
1019
## Table of contents
1120

1221
* [About](#about)

docs/launcher.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Simply, using e.g bash script - download the GAP launcher run it with regular GA
3030

3131
| GAP Launcher | AEM Project Archetype |
3232
|--------------|-----------------------|
33-
| 16.0.1 | 39 |
33+
| 16.0.4 | 39 |
3434

3535
See also [plugin compatibility](../README.MD#compatibility).
3636

@@ -53,10 +53,34 @@ Below there are some sample usages of standalone launcher.
5353

5454
### Enhancing Maven build
5555

56-
To add Gradle/GAP support to existing Maven build generated from Adobe AEM Archetype, run command below:
56+
To add Gradle/GAP support to existing Maven build generated from Adobe AEM Archetype...
57+
58+
Choose one of the available options:
59+
60+
A) Gradle files added to the project directly (recommended):
61+
62+
```shell
63+
curl -OJL https://github.com/Cognifide/gradle-aem-plugin/releases/download/16.0.4/gap.jar && java -jar gap.jar && rm gap.jar
64+
```
65+
Consequences:
66+
67+
* newly scaffolded files will be VCS-tracked by the Maven project,
68+
* there will be a single code repository with Maven files supplemented by only a few extra Gradle environment files,
69+
* on fresh setups cloning only a single code repository is needed to set up an automated AEM environment.
70+
71+
B) Gradle files at the root, Maven files nested into the `maven` directory
72+
73+
Consequences:
74+
75+
* newly scaffolded files will be NOT VCS-tracked by the Maven project,
76+
* there will be 2 code repositories:
77+
* existing one with Maven files (moved to sub dir `maven`),
78+
* dedicated one for Gradle environment files (root dir/parent of `maven`),
79+
* the advantage is separation of concerns (dedicate repository for environment files and the second one for application code),
80+
* on a fresh setup, cloning both code repositories is required to set up an automated AEM environment.
5781

5882
```shell
59-
curl -OJL https://github.com/Cognifide/gradle-aem-plugin/releases/download/15.5.3/gap.jar && java -jar gap.jar && rm gap.jar
83+
curl -OJL https://github.com/Cognifide/gradle-aem-plugin/releases/download/16.0.4/gap.jar && java -jar gap.jar --app-dir=maven && rm gap.jar
6084
```
6185

6286
Demo (to play again refresh the page):
@@ -149,7 +173,7 @@ It is using `sh gradlew props` task to provide AEM instance files details, howev
149173
To set up and turn on AEM instance(s) by single command, consider running:
150174

151175
```bash
152-
curl -OJL https://github.com/Cognifide/gradle-aem-plugin/releases/download/15.5.3/gap.jar \
176+
curl -OJL https://github.com/Cognifide/gradle-aem-plugin/releases/download/16.0.4/gap.jar \
153177
&& java -jar gap.jar --save-props \
154178
-PfileTransfer.user=foo -PfileTransfer.password=pass \
155179
-PlocalInstance.quickstart.jarUrl=http://company-share.com/aem/cq-quickstart-6.5.0.jar \
@@ -170,7 +194,7 @@ sh gradlew down
170194
For deploying to AEM instance CRX package from any source consider using command:
171195

172196
```shell
173-
curl -OJL https://github.com/Cognifide/gradle-aem-plugin/releases/download/15.5.3/gap.jar && java -jar gap.jar && rm gap.jar
197+
curl -OJL https://github.com/Cognifide/gradle-aem-plugin/releases/download/16.0.4/gap.jar && java -jar gap.jar && rm gap.jar
174198
sh gradlew instanceDeploy -Pinstance.author -Pinstance.deploy.packageUrl=https://github.com/neva-dev/felix-search-webconsole-plugin/releases/download/search-webconsole-plugin-1.3.0/search-webconsole-plugin-1.3.0.jar
175199
```
176200

@@ -188,7 +212,7 @@ Also instead of URL, dependency notation could be used to resolve package from M
188212
To interactively monitor logs of any AEM instances using task [`instanceTail`](instance-plugin.md#task-instancetail), consider running command:
189213

190214
```bash
191-
curl -OJL https://github.com/Cognifide/gradle-aem-plugin/releases/download/15.5.3/gap.jar \
215+
curl -OJL https://github.com/Cognifide/gradle-aem-plugin/releases/download/16.0.4/gap.jar \
192216
&& java -jar gap.jar --save-props \
193217
-Pinstance.dev-author.httpUrl=http://foo:pass@10.11.12.1:4502 \
194218
-Pinstance.dev-publish.httpUrl=http://foo:pass@10.11.12.2:4503 \
@@ -203,7 +227,7 @@ Assuming instance running at URL *http://localhost:4502* or *http://localhost:45
203227
Consider appending parameter e.g `-Pinstance.list=http://admin:admin@localhost:4502` to customize the instance to work with.
204228

205229
```bash
206-
curl -OJL https://github.com/Cognifide/gradle-aem-plugin/releases/download/15.5.3/gap.jar && java -jar gap.jar && rm gap.jar
230+
curl -OJL https://github.com/Cognifide/gradle-aem-plugin/releases/download/16.0.4/gap.jar && java -jar gap.jar && rm gap.jar
207231
sh gradlew packageSync -Pfilter.roots=[/content/example,/content/dam/example]
208232
```
209233

@@ -212,7 +236,7 @@ sh gradlew packageSync -Pfilter.roots=[/content/example,/content/dam/example]
212236
To copy JCR content between any AEM instances using task [`instanceRcp`](instance-plugin.md#task-instancercp), consider running commands:
213237

214238
```bash
215-
curl -OJL https://github.com/Cognifide/gradle-aem-plugin/releases/download/15.5.3/gap.jar && java -jar gap.jar && rm gap.jar
239+
curl -OJL https://github.com/Cognifide/gradle-aem-plugin/releases/download/16.0.4/gap.jar && java -jar gap.jar && rm gap.jar
216240
sh gradlew instanceRcp \
217241
-Pinstance.rcp.source=http://foo:pass@10.11.12.1:4502 \
218242
-Pinstance.rcp.target=http://foo:pass@10.11.12.2:4503 \

launcher/src/main/kotlin/com/cognifide/gradle/aem/launcher/EnvCloudScaffolder.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class EnvCloudScaffolder(private val launcher: Launcher) {
3333
println("Saving root Gradle build script file '$this'")
3434

3535
val mavenRootDir = when {
36-
launcher.appDirPath.isBlank() -> ""
37-
else -> """rootDir("${launcher.appDirPath}")"""
36+
launcher.appDirNested -> """rootDir("${launcher.appDirPath}")"""
37+
else -> ""
3838
}
3939

4040
writeText(
@@ -271,7 +271,7 @@ class EnvCloudScaffolder(private val launcher: Launcher) {
271271
load("dispatcherImage") { aem.localInstanceManager.dispatcherImage }
272272
resolve { listOf("cache", "logs").forEach { ensureDir(aem.localInstanceManager.dispatcherDir.resolve(it)) } }
273273
reload { cleanDir("/mnt/var/www/html") }
274-
dev { watchRootDir("${launcher.appDirPath}/dispatcher/src") }
274+
dev { watchRootDir("${launcher.appDirPath("dispatcher/src")}") }
275275
}
276276
}
277277
}
@@ -339,7 +339,7 @@ class EnvCloudScaffolder(private val launcher: Launcher) {
339339
- COMMERCE_ENDPOINT=http://localhost/graphql
340340
volumes:
341341
# Use project-specific dispatcher config
342-
- {{ rootPath }}/${launcher.appDirPath}/dispatcher/src:/mnt/dev/src:ro
342+
- {{ rootPath }}/${launcher.appDirPath("dispatcher/src")}:/mnt/dev/src:ro
343343
- {{ rootPath }}/env/.gradle/aem/localInstance/sdk/dispatcher/lib:/usr/lib/dispatcher-sdk:ro
344344
- {{ rootPath }}/env/.gradle/aem/localInstance/sdk/dispatcher/lib/import_sdk_config.sh:/docker_entrypoint.d/zzz-import-sdk-config.sh:ro
345345
# Enable invalidation by any client

launcher/src/main/kotlin/com/cognifide/gradle/aem/launcher/EnvInstanceOnlyScaffolder.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class EnvInstanceOnlyScaffolder(private val launcher: Launcher) {
3232
println("Saving root Gradle build script file '$this'")
3333

3434
val mavenRootDir = when {
35-
launcher.appDirPath.isBlank() -> ""
36-
else -> """rootDir("${launcher.appDirPath}")"""
35+
launcher.appDirNested -> """rootDir("${launcher.appDirPath}")"""
36+
else -> ""
3737
}
3838

3939
writeText(

launcher/src/main/kotlin/com/cognifide/gradle/aem/launcher/EnvOnPremScaffolder.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class EnvOnPremScaffolder(private val launcher: Launcher) {
3535
println("Saving root Gradle build script file '$this'")
3636

3737
val mavenRootDir = when {
38-
launcher.appDirPath.isBlank() -> ""
39-
else -> """rootDir("${launcher.appDirPath}")"""
38+
launcher.appDirNested -> """rootDir("${launcher.appDirPath}")"""
39+
else -> ""
4040
}
4141

4242
writeText(
@@ -319,9 +319,10 @@ class EnvOnPremScaffolder(private val launcher: Launcher) {
319319
}
320320
dev {
321321
watchRootDir(
322-
"${launcher.appDirPath}/dispatcher/src/conf.d",
323-
"${launcher.appDirPath}/dispatcher/src/conf.dispatcher.d",
324-
"env/src/environment/httpd")
322+
"${launcher.appDirPath("dispatcher/src/conf.d")}",
323+
"${launcher.appDirPath("dispatcher/src/conf.dispatcher.d")}",
324+
"env/src/environment/httpd",
325+
)
325326
}
326327
}
327328
}
@@ -378,8 +379,8 @@ class EnvOnPremScaffolder(private val launcher: Launcher) {
378379
ports:
379380
- 80:80
380381
volumes:
381-
- "{{ rootPath }}/${launcher.appDirPath}/dispatcher/src/conf.d:/etc/httpd/conf.d"
382-
- "{{ rootPath }}/${launcher.appDirPath}/dispatcher/src/conf.dispatcher.d:/etc/httpd/conf.dispatcher.d"
382+
- "{{ rootPath }}/${launcher.appDirPath("dispatcher/src/conf.d:/etc/httpd/conf.d")}/"
383+
- "{{ rootPath }}/${launcher.appDirPath("dispatcher/src/conf.dispatcher.d:/etc/httpd/conf.dispatcher.d")}"
383384
- "{{ sourcePath }}/httpd:/etc/httpd.extra"
384385
- "{{ workPath }}/httpd/modules/mod_dispatcher.so:/etc/httpd/modules/mod_dispatcher.so"
385386
- "{{ workPath }}/httpd/logs:/etc/httpd/logs"
@@ -441,7 +442,7 @@ class EnvOnPremScaffolder(private val launcher: Launcher) {
441442
writeText("".trimIndent())
442443
}
443444

444-
launcher.workFileBackupOnce("${launcher.appDirPath}/dispatcher/src/conf.dispatcher.d/cache/ams_author_invalidate_allowed.any") {
445+
launcher.workFileBackupOnce(launcher.appDirPath("dispatcher/src/conf.dispatcher.d/cache/ams_author_invalidate_allowed.any")) {
445446
println("Creating author flush config file '$this'")
446447
writeText(
447448
"""
@@ -454,7 +455,7 @@ class EnvOnPremScaffolder(private val launcher: Launcher) {
454455
)
455456
}
456457

457-
launcher.workFileBackupOnce("${launcher.appDirPath}/dispatcher/src/conf.dispatcher.d/cache/ams_publish_invalidate_allowed.any") {
458+
launcher.workFileBackupOnce(launcher.appDirPath("dispatcher/src/conf.dispatcher.d/cache/ams_publish_invalidate_allowed.any")) {
458459
println("Creating publish flush config file '$this'")
459460
writeText(
460461
"""
@@ -467,7 +468,7 @@ class EnvOnPremScaffolder(private val launcher: Launcher) {
467468
)
468469
}
469470

470-
launcher.workFileBackupOnce("${launcher.appDirPath}/dispatcher/src/conf.d/rewrites/xforwarded_forcessl_rewrite.rules") {
471+
launcher.workFileBackupOnce(launcher.appDirPath("dispatcher/src/conf.d/rewrites/xforwarded_forcessl_rewrite.rules")) {
471472
println("Creating X-Forwarded-For SSL rewrite config file '$this'")
472473
writeText(
473474
"""
@@ -482,7 +483,7 @@ class EnvOnPremScaffolder(private val launcher: Launcher) {
482483
/**
483484
* Replacing md5 checksums in dispatcher's pom.xml for the files that are being replaced
484485
*/
485-
launcher.workFileBackupAndReplaceStrings("${launcher.appDirPath}/dispatcher/pom.xml",
486+
launcher.workFileBackupAndReplaceStrings(launcher.appDirPath("dispatcher/pom.xml"),
486487
// Replacing md5 checksum for xforwarded_forcessl_rewrite.rules file
487488
"cd1373a055f245de6e9ed78f74f974a6" to "3f6158d0fd659071fa29c50c9a509804",
488489
// Replacing md5 checksum for ams_author_invalidate_allowed.any and ams_publish_invalidate_allowed.any files

launcher/src/main/kotlin/com/cognifide/gradle/aem/launcher/Launcher.kt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ import kotlin.system.exitProcess
77

88
class Launcher(val args: Array<String>) {
99

10+
val gradleArgs get() = args.filterNot { ARGS.containsArg(it) || WRAPPER_ARGS.containsArg(it) }
11+
12+
val wrapperArgs get() = args.filter { WRAPPER_ARGS.containsArg(it) }
13+
1014
val printStackTrace get() = args.contains(ARG_PRINT_STACKTRACE)
1115

1216
val colorOutput get() = !args.contains(ARG_NO_COLOR_OUTPUT)
1317

1418
val workDirPath get() = args.firstOrNull { it.startsWith("$ARG_WORK_DIR=") }?.substringAfter("=")
1519

16-
val appDirPath get() = args.firstOrNull { it.startsWith("$ARG_APP_DIR=") }?.substringAfter("=") ?: "maven"
17-
18-
val gradleArgs get() = args.filterNot { ARGS.containsArg(it) || WRAPPER_ARGS.containsArg(it) }
20+
val appDirPath get() = args.firstOrNull { it.startsWith("$ARG_APP_DIR=") }?.substringAfter("=") ?: ""
1921

20-
val wrapperArgs get() = args.filter { WRAPPER_ARGS.containsArg(it) }
22+
fun appDirPath(subPath: String) = if (appDirPath.isNotBlank()) "$appDirPath/$subPath" else subPath
2123

2224
val buildConfig get() = Properties().apply {
2325
load(Launcher::class.java.getResourceAsStream("/build.properties"))
@@ -32,14 +34,18 @@ class Launcher(val args: Array<String>) {
3234

3335
val workDir get() = (if (workDirPath != null) currentDir.resolve(workDirPath!!) else currentDir).canonicalFile
3436

35-
val appDir get() = appDirPath.let { workDir.resolve(it) }
37+
val appDir get() = appDirPath.takeIf { it.isNotBlank() }?.let { workDir.resolve(it) } ?: workDir
38+
39+
val appDirNested get() = appDir != workDir
3640

3741
val eol get() = System.lineSeparator()
3842

3943
val buildScaffolder by lazy { BuildScaffolder(this) }
4044

4145
val miscScaffolder by lazy { MiscScaffolder(this) }
4246

47+
val selfJar get() = File(javaClass.protectionDomain.codeSource.location.toURI())
48+
4349
fun launch() {
4450
nestWorkDirAsAppDir()
4551
scaffold()
@@ -49,6 +55,9 @@ class Launcher(val args: Array<String>) {
4955
}
5056

5157
private fun nestWorkDirAsAppDir() {
58+
if (!appDirNested) {
59+
return
60+
}
5261
if (!appDir.canonicalPath.contains(workDir.canonicalPath)) {
5362
println("Work dir must nest an app dir!")
5463
exitProcess(1)
@@ -60,7 +69,7 @@ class Launcher(val args: Array<String>) {
6069
} else {
6170
println("Nesting a work dir '$workDir' inside an app dir '$appDir'")
6271
appDir.mkdirs()
63-
workDir.listFiles()?.forEach { it.renameTo(appDir.resolve(it.name)) }
72+
workDir.listFiles()?.filter { it != selfJar }?.forEach { it.renameTo(appDir.resolve(it.name)) }
6473
}
6574
}
6675

@@ -164,7 +173,7 @@ class Launcher(val args: Array<String>) {
164173

165174
const val ARG_SAVE_PREFIX = "-P"
166175

167-
val ARGS = setOf(ARG_SAVE_PROPS, ARG_PRINT_STACKTRACE, ARG_NO_COLOR_OUTPUT, ARG_WORK_DIR)
176+
val ARGS = setOf(ARG_SAVE_PROPS, ARG_PRINT_STACKTRACE, ARG_NO_COLOR_OUTPUT, ARG_APP_DIR, ARG_WORK_DIR)
168177

169178
val WRAPPER_ARGS = setOf("--gradle-version", "--distribution-type", "--gradle-distribution-url", "--gradle-distribution-sha256-sum")
170179

launcher/src/main/kotlin/com/cognifide/gradle/aem/launcher/MiscScaffolder.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,24 @@ class MiscScaffolder(private val launcher: Launcher) {
77
}
88

99
private fun appendGitIgnore() = launcher.workFile(".gitignore") {
10-
val content = """
10+
val content = if (launcher.appDirNested) {
11+
"""
1112
### Gradle/GAP ###
1213
.gradle/
1314
build/
1415
/gradle.properties
1516
/gap.jar
1617
/${launcher.appDirPath}
17-
""".trimIndent()
18+
""".trimIndent()
19+
} else {
20+
"""
21+
### Gradle/GAP ###
22+
.gradle/
23+
build/
24+
/gradle.properties
25+
/gap.jar
26+
""".trimIndent()
27+
}
1828

1929
if (!exists()) {
2030
println("Saving Git ignore file '$this'")

src/main/kotlin/com/cognifide/gradle/aem/common/instance/action/AwaitUpAction.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ class AwaitUpAction(aem: AemExtension) : DefaultAction(aem) {
166166
}
167167

168168
companion object {
169-
fun quickOptions(): AwaitUpAction.() -> Unit = {
169+
/**
170+
* Simplified options to more quickly check condition of AEM instances
171+
* assuming that no package deployment was performed before running checks.
172+
*/
173+
fun noPackageDeployOptions(): AwaitUpAction.() -> Unit = {
170174
runner { doneTimes.set(1) }
171175
unchanged { enabled.set(false) }
172176
}

src/main/kotlin/com/cognifide/gradle/aem/instance/tasks/InstanceProvision.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ open class InstanceProvision : Instance() {
1717
}
1818
}
1919

20-
private var awaitUpOptions = AwaitUpAction.quickOptions()
20+
private var awaitUpOptions = AwaitUpAction.noPackageDeployOptions()
2121

2222
fun awaitUp(options: AwaitUpAction.() -> Unit) {
2323
this.awaitUpOptions = options

src/main/kotlin/com/cognifide/gradle/aem/instance/tasks/InstanceUp.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.gradle.api.tasks.TaskAction
88

99
open class InstanceUp : LocalInstance() {
1010

11-
private var awaitOptions = AwaitUpAction.quickOptions()
11+
private var awaitOptions = AwaitUpAction.noPackageDeployOptions()
1212

1313
/**
1414
* Controls instance awaiting.

0 commit comments

Comments
 (0)