Skip to content

Commit 82c01d7

Browse files
authored
Merge pull request #147 from Cognifide/develop
Release 3.1.0
2 parents f2397d1 + e73cca2 commit 82c01d7

23 files changed

Lines changed: 313 additions & 131 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ buildscript {
115115
}
116116
117117
dependencies {
118-
classpath 'com.cognifide.gradle:aem-plugin:3.0.9'
118+
classpath 'com.cognifide.gradle:aem-plugin:3.1.0'
119119
}
120120
}
121121
@@ -145,6 +145,7 @@ aem {
145145
deployParallel = true
146146
deploySnapshots = []
147147
deployDistributed = false
148+
deployTrustingAllSSLCertificates = true
148149
uploadForce = true
149150
uploadRetryTimes = 6
150151
uploadRetryDelay = 30000

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.9'
9+
version '3.1.0'
1010
description = 'Gradle AEM Plugin'
1111
defaultTasks = ['clean', 'build', 'publishToMavenLocal']
1212

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,21 @@ class AemConfig(
7070
* will be performed (only if distributed deploy is enabled).
7171
*/
7272
@Input
73-
var deployInstanceAuthorName: String = propParser.string("aem.deploy.instance.author.name", "$deployEnvironment-${InstanceType.AUTHOR.type}")
73+
var deployInstanceAuthorName: String = propParser.string("aem.deploy.instance.author.name", "$deployEnvironment-${InstanceType.AUTHOR}*")
7474

7575
/**
7676
* Defines maximum time after which initializing connection to AEM will be aborted (e.g on upload, install).
7777
*/
7878
@Input
7979
var deployConnectionTimeout: Int = propParser.int("aem.deploy.connectionTimeout", 5000)
8080

81+
/**
82+
* Determines if connection to untrusted (e.g. self-signed) SSL certificates should be allowed.
83+
* By default allows all SSL connections.
84+
*/
85+
@Input
86+
var deployConnectionUntrustedSsl: Boolean = propParser.boolean("aem.deploy.connectionUntrustedSsl", true)
87+
8188
/**
8289
* Perform deploy action (upload, install or activate) in parallel to multiple instances at once.
8390
*/
@@ -114,7 +121,7 @@ class AemConfig(
114121
*/
115122
@Input
116123
var uploadRetryDelay: Long = propParser.long("aem.upload.retry.delay", TimeUnit.SECONDS.toMillis(30))
117-
124+
118125
/**
119126
* Determines if when on package install, sub-packages included in CRX package content should be also installed.
120127
*/
@@ -132,7 +139,7 @@ class AemConfig(
132139
*/
133140
@Input
134141
var installRetryDelay: Long = propParser.long("aem.install.retry.delay", TimeUnit.SECONDS.toMillis(30))
135-
142+
136143
/**
137144
* Defines behavior for access control handling included in rep:policy nodes being a part of CRX package content.
138145
*
@@ -304,13 +311,6 @@ class AemConfig(
304311
@Input
305312
var instanceFilesExpanded: MutableList<String> = mutableListOf("**/*.properties", "**/*.sh", "**/*.bat", "**/*.xml", "**/start", "**/stop")
306313

307-
/**
308-
* Time in milliseconds to postpone instance stability checks to avoid race condition related with
309-
* actual operation being performed on AEM like starting JCR package installation or even creating launchpad.
310-
*/
311-
@Input
312-
var awaitDelay: Long = propParser.long("aem.await.delay", TimeUnit.SECONDS.toMillis(1))
313-
314314
/**
315315
* Time in milliseconds used as interval between next instance stability checks being performed.
316316
* Optimization could be necessary only when instance is heavily loaded.
@@ -340,9 +340,10 @@ class AemConfig(
340340

341341
/**
342342
* Number of intervals / additional instance stability checks to assure all stable instances.
343+
* This mechanism protect against temporary stable states.
343344
*/
344345
@Input
345-
var awaitAssurances: Long = propParser.long("aem.await.assurances", 3L)
346+
var awaitAssurances: Long = propParser.long("aem.await.assurances", 5L)
346347

347348
/**
348349
* Hook for customizing condition being an instance stability check.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package com.cognifide.gradle.aem.api
22

3+
import com.cognifide.gradle.aem.internal.PropertyParser
34
import org.gradle.api.DefaultTask
5+
import org.gradle.api.tasks.Internal
46
import org.gradle.api.tasks.Nested
57

68
abstract class AemDefaultTask : DefaultTask(), AemTask {
79

810
@Nested
911
final override val config = AemConfig.of(project)
1012

13+
@Internal
14+
protected val propertyParser = PropertyParser(project)
15+
1116
init {
1217
group = AemTask.GROUP
1318
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ open class CreateTask : SyncTask() {
2828

2929
instanceFileResolver.attach(this)
3030
instanceFileFromProperties()
31-
32-
project.afterEvaluate {
33-
synchronizeLocalInstances { outputs.file(it.lock) }
34-
}
31+
project.afterEvaluate { Instance.handles(project).forEach { outputs.file(it.lock) } }
3532
}
3633

3734
private fun instanceFileFromProperties() {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ interface Instance : Serializable {
110110
return filter(project, LocalInstance::class)
111111
}
112112

113+
fun handles(project: Project): List<LocalHandle> {
114+
return Instance.locals(project).map { LocalHandle(project, it) }
115+
}
116+
113117
fun remotes(project: Project): List<RemoteInstance> {
114118
return filter(project, RemoteInstance::class)
115119
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.cognifide.gradle.aem.instance
2+
3+
interface InstanceAction {
4+
5+
fun perform()
6+
7+
}

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class InstancePlugin : Plugin<Project> {
3333
private fun setupTasks(project: Project) {
3434
val clean = project.tasks.getByName(LifecycleBasePlugin.CLEAN_TASK_NAME)
3535

36+
val resolve = project.tasks.create(ResolveTask.NAME, ResolveTask::class.java)
3637
val create = project.tasks.create(CreateTask.NAME, CreateTask::class.java)
3738
val destroy = project.tasks.create(DestroyTask.NAME, DestroyTask::class.java)
3839
val up = project.tasks.create(UpTask.NAME, UpTask::class.java)
@@ -41,22 +42,23 @@ class InstancePlugin : Plugin<Project> {
4142
val satisfy = project.tasks.create(SatisfyTask.NAME, SatisfyTask::class.java)
4243
val await = project.tasks.create(AwaitTask.NAME, AwaitTask::class.java)
4344
val collect = project.tasks.create(CollectTask.NAME, CollectTask::class.java)
45+
val setup = project.tasks.create(SetupTask.NAME, SetupTask::class.java)
4446

4547
create.mustRunAfter(clean)
46-
up.mustRunAfter(clean)
47-
up.dependsOn(create)
48+
up.dependsOn(create).mustRunAfter(clean)
49+
reload.mustRunAfter(satisfy)
4850
destroy.mustRunAfter(down)
49-
satisfy.mustRunAfter(create, up)
51+
resolve.mustRunAfter(clean).shouldRunAfter(create)
52+
satisfy.dependsOn(resolve).mustRunAfter(create, up)
5053
collect.mustRunAfter(satisfy)
54+
setup.dependsOn(create, up, satisfy, await)
5155

5256
project.plugins.withId(PackagePlugin.ID, {
53-
val setup = project.tasks.create(SetupTask.NAME, SetupTask::class.java)
5457
val deploy = project.tasks.getByName(DeployTask.NAME)
5558

56-
setup.dependsOn(create, up, satisfy, deploy, await)
57-
59+
setup.dependsOn(deploy)
5860
deploy.mustRunAfter(create, up, satisfy)
59-
reload.mustRunAfter(deploy, satisfy)
61+
reload.mustRunAfter(deploy)
6062
await.mustRunAfter(deploy)
6163
})
6264

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import org.apache.commons.lang3.builder.HashCodeBuilder
66
import org.apache.http.client.config.RequestConfig
77
import org.gradle.api.Project
88

9-
class InstanceState(val project: Project, val instance: Instance) {
9+
class InstanceState(val project: Project, val instance: Instance, val timeout: Int) {
1010

1111
val config = AemConfig.of(project)
1212

1313
val bundleState by lazy {
1414
InstanceSync(project, instance).determineBundleState({ method ->
1515
method.config = RequestConfig.custom()
16-
.setConnectTimeout(config.awaitTimeout)
17-
.setSocketTimeout(config.awaitTimeout)
16+
.setConnectTimeout(timeout)
17+
.setSocketTimeout(timeout)
1818
.build()
1919
})
2020
}

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ import org.apache.http.client.entity.UrlEncodedFormEntity
1919
import org.apache.http.client.methods.HttpGet
2020
import org.apache.http.client.methods.HttpPost
2121
import org.apache.http.client.methods.HttpRequestBase
22+
import org.apache.http.conn.ssl.NoopHostnameVerifier
23+
import org.apache.http.conn.ssl.SSLConnectionSocketFactory
2224
import org.apache.http.entity.mime.MultipartEntityBuilder
2325
import org.apache.http.impl.client.BasicCredentialsProvider
2426
import org.apache.http.impl.client.HttpClientBuilder
2527
import org.apache.http.message.BasicNameValuePair
28+
import org.apache.http.ssl.SSLContextBuilder
2629
import org.gradle.api.Project
2730
import org.jsoup.Jsoup
2831
import org.jsoup.parser.Parser
@@ -112,7 +115,7 @@ class InstanceSync(val project: Project, val instance: Instance) {
112115
}
113116

114117
fun createHttpClient(): HttpClient {
115-
return HttpClientBuilder.create()
118+
val httpClientBuilder = HttpClientBuilder.create()
116119
.addInterceptorFirst(PreemptiveAuthInterceptor())
117120
.setDefaultRequestConfig(RequestConfig.custom()
118121
.setConnectTimeout(config.deployConnectionTimeout)
@@ -122,7 +125,18 @@ class InstanceSync(val project: Project, val instance: Instance) {
122125
.setDefaultCredentialsProvider(BasicCredentialsProvider().apply {
123126
setCredentials(AuthScope.ANY, UsernamePasswordCredentials(instance.user, instance.password))
124127
})
128+
if (config.deployConnectionUntrustedSsl) {
129+
httpClientBuilder.setSSLSocketFactory(createSslConnectionSocketFactory())
130+
}
131+
132+
return httpClientBuilder.build()
133+
}
134+
135+
private fun createSslConnectionSocketFactory(): SSLConnectionSocketFactory {
136+
val sslContext = SSLContextBuilder()
137+
.loadTrustMaterial(null, { _, _ -> true })
125138
.build()
139+
return SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE)
126140
}
127141

128142
private fun createEntityUrlencoded(params: Map<String, Any>): HttpEntity {
@@ -316,26 +330,18 @@ class InstanceSync(val project: Project, val instance: Instance) {
316330
}
317331
}
318332

319-
fun satisfyPackage(file: File, action: () -> Unit): Boolean {
320-
val pkg = determineRemotePackage(file, config.satisfyRefreshing)
333+
fun isSnapshot(file: File): Boolean {
334+
return Patterns.wildcard(file, config.deploySnapshots)
335+
}
321336

322-
return if (pkg == null) {
323-
action()
324-
true
337+
fun deployPackage(file: File = determineLocalPackage(), distributed: Boolean) {
338+
if (distributed) {
339+
distributePackage(file)
325340
} else {
326-
if (!pkg.installed || isSnapshot(file)) {
327-
action()
328-
true
329-
} else {
330-
false
331-
}
341+
deployPackage(file)
332342
}
333343
}
334344

335-
fun isSnapshot(file: File): Boolean {
336-
return Patterns.wildcard(file, config.deploySnapshots)
337-
}
338-
339345
fun deployPackage(file: File = determineLocalPackage()): InstallResponse {
340346
return installPackage(uploadPackage(file).path)
341347
}
@@ -450,13 +456,13 @@ class InstanceSync(val project: Project, val instance: Instance) {
450456
}
451457
}
452458

453-
fun reload() {
459+
fun reload(delay: Long = config.reloadDelay) {
454460
try {
455461
logger.info("Triggering instance(s) shutdown")
456462
postUrlencoded(vmStatUrl, mapOf("shutdown_type" to "Restart"))
457463

458464
logger.info("Awaiting instance(s) shutdown")
459-
Behaviors.waitFor(config.reloadDelay)
465+
Behaviors.waitFor(delay)
460466
} catch (e: DeployException) {
461467
throw InstanceException("Cannot reload instance $instance", e)
462468
}

0 commit comments

Comments
 (0)