Skip to content

Commit b9e49c2

Browse files
author
krystian.panek
committed
Improvements set
1 parent 8215865 commit b9e49c2

File tree

6 files changed

+44
-22
lines changed

6 files changed

+44
-22
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ open class AemConfig(project: Project) : Serializable {
8484
@Input
8585
var deployParallel: Boolean = false
8686

87+
/**
88+
* CRX package name conventions indicating that package can change over time while having
89+
* same version specified.
90+
*/
91+
@Input
92+
var deploySnapshots: List<String> = mutableListOf("**/*-SNAPSHOT.zip")
93+
8794
/**
8895
* Force upload CRX package regardless if it was previously uploaded.
8996
*/
@@ -256,7 +263,7 @@ open class AemConfig(project: Project) : Serializable {
256263
* actual operation being performed on AEM like starting JCR package installation or even creating launchpad.
257264
*/
258265
@Input
259-
var awaitDelay: Int = 3000
266+
var awaitDelay: Int = 5000
260267

261268
/**
262269
* Time in milliseconds used as interval between next instance stability checks being performed.

src/main/kotlin/com/cognifide/gradle/aem/AemPackagePlugin.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ class AemPackagePlugin : Plugin<Project> {
114114
val desiredTaskName = if (project == project.rootProject) {
115115
BuildTask.NAME
116116
} else {
117-
"aem${CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, project.path.replace(":", "-"))}Build"
117+
val projectPath = project.path
118+
.replace(":", "-")
119+
.replace(".", "-")
120+
"aem${CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, projectPath)}Build"
118121
}
119122

120123
if (taskName == desiredTaskName) {

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,12 @@ object InstanceActions {
1212
val config = AemConfig.of(project)
1313
val logger = project.logger
1414

15-
if (config.awaitDelay > 0) {
16-
logger.info("Delaying instance stability checking")
17-
Behaviors.waitFor(config.awaitDelay)
18-
}
19-
2015
val progressLogger = ProgressLogger(project, "Awaiting stable instance(s)")
2116

2217
progressLogger.started()
2318

2419
var lastInstanceStates = -1
2520
Behaviors.waitUntil(config.awaitInterval, { timer ->
26-
if (config.awaitTimes > 0 && timer.ticks > config.awaitTimes) {
27-
logger.warn("Instance(s) are not stable. Timeout reached after ${Formats.duration(timer.elapsed)}")
28-
return@waitUntil false
29-
}
30-
3121
val instanceStates = instances.map { InstanceState(project, it) }
3222
if (instanceStates.hashCode() != lastInstanceStates) {
3323
lastInstanceStates = instanceStates.hashCode()
@@ -37,6 +27,15 @@ object InstanceActions {
3727
val instanceProgress = instanceStates.joinToString(" | ") { progressFor(it, timer.ticks, config.awaitTimes) }
3828
progressLogger.progress(instanceProgress)
3929

30+
if (config.awaitDelay > 0 && timer.elapsed < config.awaitDelay) {
31+
return@waitUntil true
32+
}
33+
34+
if (config.awaitTimes > 0 && timer.ticks > config.awaitTimes) {
35+
logger.warn("Instance(s) are not stable. Timeout reached after ${Formats.duration(timer.elapsed)}")
36+
return@waitUntil false
37+
}
38+
4039
if (instanceStates.all { it.stable }) {
4140
logger.info("Instance(s) are stable after ${Formats.duration(timer.elapsed)}")
4241
return@waitUntil false

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.cognifide.gradle.aem.instance
33
import com.cognifide.gradle.aem.AemConfig
44
import com.cognifide.gradle.aem.AemPackagePlugin
55
import com.cognifide.gradle.aem.deploy.*
6+
import com.cognifide.gradle.aem.internal.Patterns
67
import org.apache.commons.httpclient.HttpClient
78
import org.apache.commons.httpclient.HttpMethod
89
import org.apache.commons.httpclient.HttpStatus
@@ -173,15 +174,15 @@ class InstanceSync(val project: Project, val instance: Instance) {
173174
try {
174175
val json = sync.post(url, mapOf(
175176
"package" to file,
176-
"force" to config.uploadForce
177+
"force" to (config.uploadForce || isSnapshot(file))
177178
))
178179
val response = UploadResponse.fromJson(json)
179180

180181
if (response.isSuccess) {
181182
logger.info(response.msg)
182183
} else {
183184
logger.error(response.msg)
184-
throw DeployException(response.msg.orEmpty())
185+
throw DeployException(response.msg)
185186
}
186187

187188
return response
@@ -237,15 +238,19 @@ class InstanceSync(val project: Project, val instance: Instance) {
237238
deployPackage(file)
238239
true
239240
} else {
240-
if (pkg.installed) {
241-
false
242-
} else {
241+
if (!pkg.installed || isSnapshot(file)) {
243242
deployPackage(file)
244243
true
244+
} else {
245+
false
245246
}
246247
}
247248
}
248249

250+
fun isSnapshot(file: File): Boolean {
251+
return Patterns.wildcard(file, config.deploySnapshots)
252+
}
253+
249254
fun deployPackage(file: File = determineLocalPackage()): InstallResponse {
250255
return installPackage(uploadPackage(file).path)
251256
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class RemoteInstance(
1616
httpUrl,
1717
Instance.USER_DEFAULT,
1818
Instance.PASSWORD_DEFAULT,
19-
InstanceType.byUrl(httpUrl).name,
19+
InstanceType.byUrl(httpUrl).name.toLowerCase(),
2020
environment
2121
)
2222

src/main/kotlin/com/cognifide/gradle/aem/internal/PropertyParser.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.cognifide.gradle.aem.internal
22

3-
import com.mitchellbosecke.pebble.PebbleEngine
4-
import com.mitchellbosecke.pebble.lexer.Syntax
5-
import com.mitchellbosecke.pebble.loader.StringLoader
63
import com.cognifide.gradle.aem.AemConfig
74
import com.cognifide.gradle.aem.AemException
85
import com.cognifide.gradle.aem.vlt.SyncTask
6+
import com.mitchellbosecke.pebble.PebbleEngine
7+
import com.mitchellbosecke.pebble.lexer.Syntax
8+
import com.mitchellbosecke.pebble.loader.StringLoader
99
import org.apache.commons.lang3.BooleanUtils
1010
import org.apache.commons.lang3.ClassUtils
1111
import org.apache.commons.lang3.text.StrSubstitutor
@@ -53,6 +53,10 @@ class PropertyParser(val project: Project) {
5353
return value
5454
}
5555

56+
fun flag(name: String) : Boolean {
57+
return project.properties.containsKey(name) && BooleanUtils.toBoolean(project.properties[name] as String?)
58+
}
59+
5660
fun prop(name: String, defaultValue: () -> String): String {
5761
return prop(name) ?: defaultValue()
5862
}
@@ -136,8 +140,12 @@ class PropertyParser(val project: Project) {
136140

137141
private fun isUniqueProjectName() = project == project.rootProject || project.name == project.rootProject.name
138142

143+
fun isForce(): Boolean {
144+
return flag(FORCE_PROP)
145+
}
146+
139147
fun checkForce(message: String = FORCE_MESSAGE) {
140-
if (!project.properties.containsKey(FORCE_PROP) || !BooleanUtils.toBoolean(project.properties[FORCE_PROP] as String?)) {
148+
if (!isForce()) {
141149
throw AemException("Warning! This task execution must be confirmed by specifying explicitly parameter '-P$FORCE_PROP=true'. $message")
142150
}
143151
}

0 commit comments

Comments
 (0)