Skip to content

Commit 0280638

Browse files
authored
Merge pull request #177 from Cognifide/4.0.0-final
Final fixes (4.0.0)
2 parents 76935bd + 41ca87f commit 0280638

14 files changed

Lines changed: 96 additions & 44 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pluginManagement {
119119
resolutionStrategy {
120120
eachPlugin {
121121
if (requested.id.namespace == 'com.cognifide.aem') {
122-
useModule('com.cognifide.gradle:aem-plugin:4.0.0-beta2')
122+
useModule('com.cognifide.gradle:aem-plugin:4.0.0-beta3')
123123
}
124124
}
125125
}

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
plugins {
22
id 'java-gradle-plugin'
33
id 'maven-publish'
4-
id "org.jetbrains.kotlin.jvm" version "1.2.41"
5-
id "com.jfrog.bintray" version "1.7.3"
4+
id 'org.jetbrains.kotlin.jvm' version '1.2.41'
5+
id 'com.jfrog.bintray' version '1.8.0'
66
}
77

88
group 'com.cognifide.gradle'
9-
version '4.0.0-beta2'
9+
version '4.0.0-beta3'
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
@@ -133,6 +133,14 @@ class AemConfig(
133133
@Input
134134
var bundleManifestAttributes: Boolean = true
135135

136+
/**
137+
* Bundle configuration file location consumed by BND tool.
138+
*
139+
* @see <https://bnd.bndtools.org>
140+
*/
141+
@Input
142+
var bundleBndPath: String = "${project.file("bnd.bnd")}"
143+
136144
/**
137145
* Automatically determine local package to be uploaded.
138146
*/
@@ -415,6 +423,18 @@ class AemConfig(
415423
@get:JsonIgnore
416424
var awaitHealthCheck: (InstanceState) -> Boolean = { it.checkComponentState(10000) }
417425

426+
/**
427+
* Repeat health check when failed (brute-forcing).
428+
*/
429+
@Input
430+
var awaitHealthRetryTimes = props.long("aem.await.health.retry.times", 3L)
431+
432+
/**
433+
* Time to wait after repeating failed health check.
434+
*/
435+
@Input
436+
var awaitHealthRetryDelay = props.long("aem.await.health.retry.delay", TimeUnit.SECONDS.toMillis(30))
437+
418438
/**
419439
* Time in milliseconds to postpone instance stability checks after triggering instances restart.
420440
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AemNotifier private constructor(private val project: Project) {
1515
now(title, message)
1616
}
1717

18-
project.logger.info(if (message.isNotBlank()) {
18+
project.logger.lifecycle(if (message.isNotBlank()) {
1919
"${title.removeSuffix(".")}. $message"
2020
} else {
2121
title

src/main/kotlin/com/cognifide/gradle/aem/bundle/BundlePlugin.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.gradle.api.tasks.SourceSet
1414
import org.gradle.api.tasks.bundling.Jar
1515
import org.gradle.api.tasks.compile.JavaCompile
1616
import org.gradle.api.tasks.testing.Test
17+
import java.io.File
1718

1819
class BundlePlugin : Plugin<Project> {
1920

@@ -48,6 +49,15 @@ class BundlePlugin : Plugin<Project> {
4849

4950
ensureJarBaseNameIfNotCustomized(jar)
5051
ensureJarManifestAttributes(jar)
52+
ensureJarEmbedded(jar)
53+
}
54+
}
55+
56+
private fun Project.ensureJarEmbedded(jar: Jar) {
57+
val embedJars = configurations.getByName(CONFIG_EMBED).files.map { it.name }.sorted()
58+
if (embedJars.isNotEmpty()) {
59+
logger.info("Bundle '${jar.archiveName}' has configured embedded jars: $embedJars.")
60+
logger.info("For each one, ensure to have its packages exported by JAR manifest attribute 'Export-Package' or 'Private-Package' using DSL: 'aem { bundle { exportPackage('x.y.z') } }'.")
5161
}
5262
}
5363

@@ -85,12 +95,6 @@ class BundlePlugin : Plugin<Project> {
8595
attributes["Bundle-SymbolicName"] = config.bundlePackage
8696
}
8797

88-
attributes["Bundle-ClassPath"] = mutableSetOf<String>().apply {
89-
add(".")
90-
addAll(configurations.getByName(CONFIG_EMBED).files.sortedBy { it.name }.map { it.name })
91-
addAll((attributes["Bundle-ClassPath"]?.toString() ?: "").split(",").map { it.trim() })
92-
}.joinToString(",")
93-
9498
attributes["Export-Package"] = mutableSetOf<String>().apply {
9599
if (config.bundlePackage.isNotBlank()) {
96100
add(if (config.bundlePackageOptions.isNotBlank()) {
@@ -116,7 +120,7 @@ class BundlePlugin : Plugin<Project> {
116120

117121
convention.plugins[BND_CONVENTION_PLUGIN] = bundleConvention
118122

119-
val bndFile = file(BND_FILE)
123+
val bndFile = File(AemConfig.of(project).bundleBndPath)
120124
if (bndFile.isFile) {
121125
bundleConvention.setBndfile(bndFile)
122126
}
@@ -165,8 +169,6 @@ class BundlePlugin : Plugin<Project> {
165169

166170
const val CONFIG_EMBED = "aemEmbed"
167171

168-
const val BND_FILE = "bnd.bnd"
169-
170172
const val BND_CONVENTION_PLUGIN = "bundle"
171173
}
172174

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ open class AwaitTask : AemDefaultTask() {
1919
val instances = Instance.filter(project)
2020

2121
AwaitAction(project, instances).perform()
22-
notifier.default("Instance(s) stable and healthy", "Which: ${instances.names}")
2322
}
2423

2524
}

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

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,21 @@ open class AwaitAction(project: Project, val instances: List<Instance>) : Abstra
4141
}
4242

4343
if (fast) {
44-
ProgressCountdown(project, "Waiting for instance(s): ${instances.names}", fastDelay).run()
44+
awaitDelay()
4545
}
4646

47+
awaitStable()
48+
49+
if (!fast) {
50+
awaitHealthy()
51+
}
52+
}
53+
54+
private fun awaitDelay() {
55+
ProgressCountdown(project, "Waiting for instance(s): ${instances.names}", fastDelay).run()
56+
}
57+
58+
private fun awaitStable() {
4759
val progressLogger = ProgressLogger(project, "Awaiting stable instance(s): ${instances.names}")
4860
progressLogger.started()
4961

@@ -100,36 +112,16 @@ open class AwaitAction(project: Project, val instances: List<Instance>) : Abstra
100112
}
101113

102114
if (unstableInstances.isEmpty()) {
103-
// Skip assurance and health checking.
104-
if (fast) {
105-
return@waitUntil false
106-
}
107-
108115
// Assure that expected moment is not accidental, remember it
109-
if (stableAssurances > 0 && sinceStableTicks == -1L) {
116+
if (!fast && stableAssurances > 0 && sinceStableTicks == -1L) {
110117
progressLogger.progress("Instance(s) seems to be stable. Assuring.")
111118
sinceStableTicks = timer.ticks
112119
}
113120

114121
// End if assurance is not configured or this moment remains a little longer
115-
if (stableAssurances <= 0 || (sinceStableTicks >= 0 && (timer.ticks - sinceStableTicks) >= stableAssurances)) {
116-
progressLogger.progress("Instance(s) are stable. Checking health.")
117-
118-
// Detect unhealthy instances
119-
val unhealthyInstances = instanceStates.parallelStream()
120-
.filter { !healthCheck(it) }
121-
.map { it.instance }
122-
.collect(Collectors.toList())
123-
124-
if (unhealthyInstances.isEmpty()) {
125-
return@waitUntil false
126-
} else {
127-
if (!resume) {
128-
throw InstanceException("Instances not healthy: ${unhealthyInstances.names}.")
129-
} else {
130-
notifier.default("Instances not healthy", "Problem with: ${unhealthyInstances.names}.")
131-
}
132-
}
122+
if (fast || (stableAssurances <= 0) || (sinceStableTicks >= 0 && (timer.ticks - sinceStableTicks) >= stableAssurances)) {
123+
notifier.default("Instance(s) stable", "Which: ${instances.names}")
124+
return@waitUntil false
133125
}
134126
} else {
135127
// Reset assurance, because no longer stable
@@ -142,6 +134,38 @@ open class AwaitAction(project: Project, val instances: List<Instance>) : Abstra
142134
progressLogger.completed()
143135
}
144136

137+
private fun awaitHealthy() {
138+
logger.lifecycle("Checking health of instance(s): ${instances.names}")
139+
140+
val synchronizers = prepareSynchronizers()
141+
for (i in 0..config.awaitHealthRetryTimes) {
142+
val unhealthyInstances = synchronizers.parallelStream()
143+
.map { it.determineInstanceState() }
144+
.filter { !healthCheck(it) }
145+
.map { it.instance }
146+
.collect(Collectors.toList())
147+
148+
if (unhealthyInstances.isEmpty()) {
149+
notifier.default("Instance(s) healthy", "Which: ${instances.names}")
150+
return
151+
}
152+
153+
if (i < config.awaitHealthRetryTimes) {
154+
logger.warn("Unhealthy instances detected: ${unhealthyInstances.names}")
155+
156+
val header = "Retrying health check (${i + 1}/${config.awaitHealthRetryTimes}) after delay."
157+
val countdown = ProgressCountdown(project, header, config.awaitHealthRetryDelay)
158+
countdown.run()
159+
} else if (i == config.awaitHealthRetryTimes) {
160+
if (!resume) {
161+
throw InstanceException("Instances not healthy: ${unhealthyInstances.names}.")
162+
} else {
163+
notifier.default("Instances not healthy", "Problem with: ${unhealthyInstances.names}.")
164+
}
165+
}
166+
}
167+
}
168+
145169
private fun prepareSynchronizers(): List<InstanceSync> {
146170
return instances.map { instance ->
147171
val init = instance.isBeingInitialized(project)

src/test/kotlin/com/cognifide/gradle/aem/test/DebugTaskTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class DebugTaskTest : AemTest() {
2020
add(Customization("packageProperties.config.vaultFilesPath", PathValueMatcher()))
2121
add(Customization("packageProperties.config.createFilesPath", PathValueMatcher()))
2222
add(Customization("packageProperties.config.createPath", PathValueMatcher()))
23+
add(Customization("packageProperties.config.bundleBndPath", PathValueMatcher()))
2324
}
2425
}
2526
}

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:4.0.0-beta2'
9+
classpath 'com.cognifide.gradle:aem-plugin:4.0.0-beta3'
1010
classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:3.5.0'
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.21"
1212
}

src/test/resources/com/cognifide/gradle/aem/test/compose/bundle-and-content/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pluginManagement {
88
resolutionStrategy {
99
eachPlugin {
1010
if (requested.id.namespace == 'com.cognifide.aem') {
11-
useModule('com.cognifide.gradle:aem-plugin:4.0.0-beta2')
11+
useModule('com.cognifide.gradle:aem-plugin:4.0.0-beta3')
1212
}
1313
}
1414
}

0 commit comments

Comments
 (0)