Skip to content

Commit bbdc97a

Browse files
authored
Merge pull request #137 from Cognifide/develop
Release 3.0.8
2 parents ca10c50 + dfe0fba commit bbdc97a

12 files changed

Lines changed: 91 additions & 72 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ buildscript {
113113
}
114114
115115
dependencies {
116-
classpath 'com.cognifide.gradle:aem-plugin:3.0.7'
116+
classpath 'com.cognifide.gradle:aem-plugin:3.0.8'
117117
}
118118
}
119119

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group 'com.cognifide.gradle'
9-
version '3.0.7'
9+
version '3.0.8'
1010
description = 'Gradle AEM Plugin'
1111
defaultTasks = ['clean', 'build', 'publishToMavenLocal']
1212

src/main/kotlin/com/cognifide/gradle/aem/api/AemConfig.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import java.util.concurrent.TimeUnit
2222
*
2323
* Content paths which are used to compose a CRX package are being processed by copy task,
2424
* which automatically mark them as inputs so package is being rebuild on any JCR content or Vault files change.
25+
*
26+
* TODO https://docs.gradle.org/4.6/userguide/custom_tasks.html#sec:declaring_and_using_command_line_options
2527
*/
2628
class AemConfig(
2729
@Transient
@@ -384,6 +386,24 @@ class AemConfig(
384386
@Input
385387
var satisfyGroupName = propParser.string("aem.satisfy.group.name", "*")
386388

389+
/**
390+
* Determines a Vault filter used to checkout JCR content from running AEM instance.
391+
*
392+
* By default it points to same filter being used to build CRX package,
393+
* but could be customized to filter out files being checked out.
394+
*/
395+
@Input
396+
var checkoutFilterPath: String = propParser.string("aem.checkout.filterPath", vaultPath)
397+
398+
/**
399+
* Determines which files will be deleted within running cleaning
400+
* (e.g after checking out JCR content).
401+
*/
402+
@Input
403+
var cleanFilesDeleted: MutableList<String> = mutableListOf(
404+
"**/.vlt"
405+
)
406+
387407
/**
388408
* Initialize defaults that depends on concrete type of project.
389409
*/

src/main/kotlin/com/cognifide/gradle/aem/base/vlt/CheckoutTask.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.cognifide.gradle.aem.base.vlt
33
import com.cognifide.gradle.aem.api.AemDefaultTask
44
import org.gradle.api.tasks.TaskAction
55

6+
// TODO https://github.com/Cognifide/gradle-aem-plugin/issues/135
67
open class CheckoutTask : AemDefaultTask() {
78

89
companion object {

src/main/kotlin/com/cognifide/gradle/aem/base/vlt/VltCleaner.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cognifide.gradle.aem.base.vlt
22

3+
import com.cognifide.gradle.aem.internal.Patterns
34
import org.apache.commons.io.FileUtils
45
import org.apache.commons.io.filefilter.NameFileFilter
56
import org.apache.commons.io.filefilter.TrueFileFilter
@@ -13,17 +14,17 @@ import java.util.regex.Pattern
1314
class VltCleaner(val root: File, val logger: Logger) {
1415

1516
companion object {
16-
val VLT_FILE = ".vlt"
17-
18-
val JCR_CONTENT_FILE = ".content.xml"
17+
const val JCR_CONTENT_FILE = ".content.xml"
1918

2019
val CONTENT_PROP_PATTERN = Pattern.compile("([^=]+)=\"([^\"]+)\"")
2120
}
2221

23-
fun removeVltFiles() {
24-
for (file in FileUtils.listFiles(root, NameFileFilter(VLT_FILE), TrueFileFilter.INSTANCE)) {
25-
logger.info("Deleting {}", file.path)
26-
FileUtils.deleteQuietly(file)
22+
fun removeFiles(patterns: List<String>) {
23+
for (file in FileUtils.listFiles(root, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) {
24+
if (Patterns.wildcard(file, patterns)) {
25+
logger.info("Deleting {}", file.path)
26+
FileUtils.deleteQuietly(file)
27+
}
2728
}
2829
}
2930

src/main/kotlin/com/cognifide/gradle/aem/base/vlt/VltCommand.kt

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.gradle.api.Project
88
import org.gradle.api.logging.Logger
99
import java.io.File
1010

11+
// TODO https://github.com/Cognifide/gradle-aem-plugin/issues/135
1112
class VltCommand(val project: Project) {
1213

1314
val logger: Logger = project.logger
@@ -16,65 +17,43 @@ class VltCommand(val project: Project) {
1617

1718
val config = AemConfig.of(project)
1819

19-
fun clean() {
20-
val config = AemConfig.of(project)
21-
val contentDir = File(config.contentPath)
22-
23-
if (!contentDir.exists()) {
24-
logger.warn("JCR content directory to be cleaned does not exist: ${contentDir.absolutePath}")
25-
return
26-
}
20+
fun raw(command: String, props: Map<String, Any> = mapOf()) {
21+
val app = VltApp(project)
22+
val instance = determineInstance()
23+
val allProps = mapOf(
24+
"instance" to instance,
25+
"instances" to config.instances
26+
) + props
27+
val fullCommand = propertyParser.expand("${config.vaultGlobalOptions} $command".trim(), allProps)
2728

28-
val cleaner = VltCleaner(contentDir, logger)
29-
cleaner.removeVltFiles()
30-
cleaner.cleanupDotContent(config.vaultSkipProperties, config.vaultLineSeparatorString)
29+
app.execute(fullCommand)
3130
}
3231

3332
fun checkout() {
34-
val config = AemConfig.of(project)
3533
val contentDir = File(config.contentPath)
36-
3734
if (!contentDir.exists()) {
3835
logger.info("JCR content directory to be checked out does not exist: ${contentDir.absolutePath}")
3936
}
4037

41-
raw("checkout --force --filter {{filter}} {{instance.httpUrl}}/crx/server/crx.default")
42-
}
43-
44-
fun raw(command: String) {
45-
val app = VltApp(project)
46-
val config = AemConfig.of(project)
47-
4838
val filter = determineFilter()
49-
val instance = determineInstance()
50-
51-
val specificProps = mapOf(
52-
"instance" to instance,
53-
"filter" to filter.file.absolutePath
54-
)
55-
val fullCommand = propertyParser.expand("${config.vaultGlobalOptions} $command".trim(), specificProps)
39+
val props = mapOf("filter" to filter.file.absolutePath)
5640

57-
app.execute(fullCommand)
58-
filter.clean()
41+
filter.use {
42+
raw("checkout --force --filter {{filter}} {{instance.httpUrl}}/crx/server/crx.default", props)
43+
}
5944
}
6045

6146
fun determineFilter(): VltFilter {
62-
val config = AemConfig.of(project)
63-
val cmdFilterPath = propertyParser.string("aem.vlt.filter")
64-
val cmdFilterRoots = PropertyParser(project).list("aem.vlt.filterRoots")
65-
66-
return if (!cmdFilterPath.isNullOrBlank()) {
67-
val cmdFilter = FileOperations.find(project, config.vaultPath, cmdFilterPath!!)
68-
?: throw VltException("Vault check out filter file does not exist at path: $cmdFilterPath")
69-
70-
logger.debug("Using VLT filter specified as command line property")
71-
VltFilter(cmdFilter)
72-
} else if (cmdFilterRoots.isNotEmpty()) {
73-
logger.debug("Using VLT filter roots specified as command line property")
47+
val cmdFilterRoots = propertyParser.list("aem.checkout.filterRoots")
48+
49+
return if (cmdFilterRoots.isNotEmpty()) {
50+
logger.info("Using Vault filter roots specified as command line property: $cmdFilterRoots")
7451
VltFilter.temporary(project, cmdFilterRoots)
7552
} else {
76-
logger.debug("Using VLT filter specified in AEM build configuration")
77-
VltFilter(File(config.vaultFilterPath))
53+
val configFilter = FileOperations.find(project, config.vaultPath, config.checkoutFilterPath)
54+
?: throw VltException("Vault check out filter file does not exist at path: ${config.checkoutFilterPath} (or under directory: ${config.vaultPath}).")
55+
logger.info("Using Vault filter specified in configuration: ${config.checkoutFilterPath}")
56+
VltFilter(configFilter)
7857
}
7958
}
8059

@@ -84,23 +63,35 @@ class VltCommand(val project: Project) {
8463
val cmdInstance = Instance.parse(cmdInstanceArg!!).first()
8564
cmdInstance.validate()
8665

87-
logger.debug("Using instance specified by command line parameter: $cmdInstance")
66+
logger.info("Using instance specified by command line parameter: $cmdInstance")
8867
return cmdInstance
8968
}
9069

9170
val namedInstance = Instance.filter(project, config.deployInstanceName).firstOrNull()
9271
if (namedInstance != null) {
93-
logger.debug("Using first instance matching filter '${config.deployInstanceName}': $namedInstance")
72+
logger.info("Using first instance matching filter '${config.deployInstanceName}': $namedInstance")
9473
return namedInstance
9574
}
9675

9776
val anyInstance = Instance.filter(project, Instance.FILTER_ANY).firstOrNull()
9877
if (anyInstance != null) {
99-
logger.debug("Using first instance matching filter '${Instance.FILTER_ANY}': $anyInstance")
78+
logger.info("Using first instance matching filter '${Instance.FILTER_ANY}': $anyInstance")
10079
return anyInstance
10180
}
10281

10382
throw VltException("Vault instance cannot be determined neither by command line parameter nor AEM config.")
10483
}
10584

85+
fun clean() {
86+
val contentDir = File(config.contentPath)
87+
if (!contentDir.exists()) {
88+
logger.warn("JCR content directory to be cleaned does not exist: ${contentDir.absolutePath}")
89+
return
90+
}
91+
92+
val cleaner = VltCleaner(contentDir, logger)
93+
cleaner.removeFiles(config.cleanFilesDeleted)
94+
cleaner.cleanupDotContent(config.vaultSkipProperties, config.vaultLineSeparatorString)
95+
}
96+
10697
}

src/main/kotlin/com/cognifide/gradle/aem/base/vlt/VltFilter.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import com.cognifide.gradle.aem.api.AemTask
44
import com.cognifide.gradle.aem.internal.PropertyParser
55
import com.cognifide.gradle.aem.internal.file.FileOperations
66
import org.gradle.api.Project
7+
import java.io.Closeable
78
import java.io.File
89

9-
class VltFilter(val file: File, private val temporary: Boolean = false) {
10+
class VltFilter(val file: File, private val temporary: Boolean = false) : Closeable {
1011

1112
companion object {
1213

@@ -23,7 +24,7 @@ class VltFilter(val file: File, private val temporary: Boolean = false) {
2324

2425
}
2526

26-
fun clean() {
27+
override fun close() {
2728
if (temporary) {
2829
file.delete()
2930
}

src/main/kotlin/com/cognifide/gradle/aem/instance/InstanceSync.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ import java.util.*
3434
class InstanceSync(val project: Project, val instance: Instance) {
3535

3636
companion object {
37-
private val PACKAGE_MANAGER_SERVICE_SUFFIX = "/crx/packmgr/service"
37+
private const val PACKAGE_MANAGER_SERVICE_SUFFIX = "/crx/packmgr/service"
3838

39-
private val PACKAGE_MANAGER_LIST_SUFFIX = "/crx/packmgr/list.jsp"
39+
private const val PACKAGE_MANAGER_LIST_SUFFIX = "/crx/packmgr/list.jsp"
4040
}
4141

4242
val config = AemConfig.of(project)
@@ -223,7 +223,8 @@ class InstanceSync(val project: Project, val instance: Instance) {
223223
exception = e
224224

225225
if (i < config.uploadRetryTimes) {
226-
logger.warn("Cannot upload package. Retrying (${i+1}/${config.uploadRetryTimes}) after delay.")
226+
logger.warn("Cannot upload package to $instance.")
227+
logger.warn("Retrying (${i+1}/${config.uploadRetryTimes}) after delay.")
227228
Behaviors.waitFor(config.uploadRetryDelay)
228229
}
229230
}
@@ -233,13 +234,12 @@ class InstanceSync(val project: Project, val instance: Instance) {
233234
}
234235

235236
private fun uploadPackageOnce(file: File = determineLocalPackage()): UploadResponse {
236-
val sync = InstanceSync(project, instance)
237-
val url = sync.jsonTargetUrl + "/?cmd=upload"
237+
val url = "$jsonTargetUrl/?cmd=upload"
238238

239239
logger.info("Uploading package at path '{}' to URL '{}'", file.path, url)
240240

241241
try {
242-
val json = sync.postMultipart(url, mapOf(
242+
val json = postMultipart(url, mapOf(
243243
"package" to file,
244244
"force" to (config.uploadForce || isSnapshot(file))
245245
))
@@ -268,7 +268,8 @@ class InstanceSync(val project: Project, val instance: Instance) {
268268
} catch (e: DeployException) {
269269
exception = e
270270
if (i < config.installRetryTimes) {
271-
logger.warn("Cannot install package. Retrying (${i+1}/${config.installRetryTimes}) after delay.")
271+
logger.warn("Cannot install package on $instance.")
272+
logger.warn("Retrying (${i+1}/${config.installRetryTimes}) after delay.")
272273
Behaviors.waitFor(config.installRetryDelay)
273274
}
274275
}
@@ -278,9 +279,9 @@ class InstanceSync(val project: Project, val instance: Instance) {
278279
}
279280

280281
private fun installPackageOnce(uploadedPackagePath: String): InstallResponse {
281-
val url = htmlTargetUrl + uploadedPackagePath + "/?cmd=install"
282+
val url = "$htmlTargetUrl$uploadedPackagePath/?cmd=install"
282283

283-
logger.info("Installing package using command: " + url)
284+
logger.info("Installing package using command: $url")
284285

285286
try {
286287
val json = postMultipart(url, mapOf(
@@ -349,7 +350,7 @@ class InstanceSync(val project: Project, val instance: Instance) {
349350
fun activatePackage(path: String = determineRemotePackagePath()): UploadResponse {
350351
val url = jsonTargetUrl + path + "/?cmd=replicate"
351352

352-
logger.info("Activating package using command: " + url)
353+
logger.info("Activating package using command: $url")
353354

354355
val json: String
355356
try {

src/main/kotlin/com/cognifide/gradle/aem/pkg/ComposeTask.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.jsoup.Jsoup
2323
import org.jsoup.nodes.Element
2424
import org.jsoup.parser.Parser
2525
import java.io.File
26+
import java.io.Serializable
2627

2728
open class ComposeTask : Zip(), AemTask {
2829

@@ -40,7 +41,7 @@ open class ComposeTask : Zip(), AemTask {
4041
get() = filterRoots.joinToString(config.vaultLineSeparatorString) { it.toString() }
4142

4243
@Internal
43-
var filterRootDefault = { subproject: Project, subconfig: AemConfig ->
44+
var filterRootDefault = { _: Project, subconfig: AemConfig ->
4445
"<filter root=\"${subconfig.bundlePath}\"/>"
4546
}
4647

@@ -305,12 +306,15 @@ open class ComposeTask : Zip(), AemTask {
305306
ConfigureUtil.configure(closure, fileFilterOptions)
306307
}
307308

308-
class FileFilterOptions {
309+
class FileFilterOptions : Serializable {
309310

311+
@Input
310312
var excluding: Boolean = true
311313

314+
@Input
312315
var expanding: Boolean = true
313316

317+
@Input
314318
var bundleChecking: Boolean = true
315319

316320
}

src/test/resources/com/cognifide/gradle/aem/test/compose/assembly/gradle/buildscript.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repositories {
66
}
77

88
dependencies {
9-
classpath 'com.cognifide.gradle:aem-plugin:3.0.7'
9+
classpath 'com.cognifide.gradle:aem-plugin:3.0.8'
1010
classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:3.5.0'
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.21"
1212
}

0 commit comments

Comments
 (0)