Skip to content

Commit

Permalink
Auto export of nodetypes cnd
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian.panek committed Nov 4, 2019
1 parent fe6531d commit dd6d1c8
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 48 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ repositories {
}

dependencies {
implementation("com.cognifide.gradle:aem-plugin:8.0.1")
implementation("com.cognifide.gradle:aem-plugin:8.1.0")
}
```

Expand Down
Binary file modified dists/gradle-aem-tailer.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion dists/gradle-aem-tailer/buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ repositories {
}

dependencies {
implementation("com.cognifide.gradle:aem-plugin:8.0.1")
implementation("com.cognifide.gradle:aem-plugin:8.1.0")
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=8.0.1
version=8.1.0
release.useAutomaticVersion=true
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class BuildScope {
cache[key] = value
}

fun doOnce(operation: String, action: () -> Unit) = tryGetOrPut(operation) {
action()
true
}

companion object {

fun of(project: Project): BuildScope {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.cognifide.gradle.aem.common.http.HttpClient
import com.cognifide.gradle.aem.common.http.ResponseException
import org.apache.http.HttpResponse

@Suppress("MagicNumber")
open class InstanceHttpClient(aem: AemExtension, val instance: Instance) : HttpClient(aem) {

init {
Expand All @@ -13,7 +14,13 @@ open class InstanceHttpClient(aem: AemExtension, val instance: Instance) : HttpC
basicPassword = instance.password
authorizationPreemptive = true

apply { aem.instanceOptions.httpOptions(this, instance) }
connectionTimeout = aem.props.int("instance.http.connectionTimeout") ?: 30000
connectionRetries = aem.props.boolean("instance.http.connectionRetries") ?: true
connectionIgnoreSsl = aem.props.boolean("instance.http.connectionIgnoreSsl") ?: true

proxyHost = aem.props.string("instance.http.proxyHost")
proxyPort = aem.props.int("instance.http.proxyPort")
proxyScheme = aem.props.string("instance.http.proxyScheme")
}

override fun throwStatusException(response: HttpResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,14 @@ open class InstanceOptions(private val aem: AemExtension) : Serializable {
val defined: MutableMap<String, Instance> = mutableMapOf()

/**
* Customize HTTP connection to AEM instances.
*
* Allows to e.g
* - set using HTTP proxy,
* - customize maximum time after which initializing connection to AEM will be aborted (e.g on upload, install),
* - customize any options offered by Apache HTTP Client builder (use its API directly).
* Customize default options for instance services.
*/
fun http(options: InstanceHttpClient.(Instance) -> Unit) {
httpOptions = options
fun sync(options: InstanceSync.() -> Unit) {
syncOptions = { options(); }
}

@get:JsonIgnore
internal var httpOptions: InstanceHttpClient.(Instance) -> Unit = {
connectionTimeout = aem.props.int("instance.http.connectionTimeout") ?: 30000
connectionRetries = aem.props.boolean("instance.http.connectionRetries") ?: true
connectionIgnoreSsl = aem.props.boolean("instance.http.connectionIgnoreSsl") ?: true

proxyHost = aem.props.string("instance.http.proxyHost")
proxyPort = aem.props.int("instance.http.proxyPort")
proxyScheme = aem.props.string("instance.http.proxyScheme")
}

/**
* Allows to control automatic system properties (and product version) gathering from running instance to defined.
* Essential for correctly working features that are using timestamps like instance tail and instance events check.
*/
var statusProperties: Boolean = aem.props.boolean("instance.statusProperties") ?: !aem.offline

/**
* Allows to control automatic node types gathering from running instance to defined.
* Essential for correctly working package validation.
*/
var crxNodeTypes: Boolean = aem.props.boolean("instance.crxNodeTypes") ?: !aem.offline
internal var syncOptions: InstanceSync.() -> Unit = {}

/**
* Define local instance (created on local file system).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ open class InstanceService(val sync: InstanceSync) {
val instance = sync.instance

val project = sync.aem.project

val logger = aem.logger
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ class InstanceSync(val aem: AemExtension, val instance: Instance) {
* CRX DE Endpoints accessor (node types etc).
*/
fun <T> crx(callback: Crx.() -> T): T = crx.run(callback)

init {
aem.instanceOptions.syncOptions(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class Crx(sync: InstanceSync) : InstanceService(sync) {
*/
val nodeTypes: String
get() {
if (!aem.instanceOptions.crxNodeTypes) {
if (aem.offline) {
return NODE_TYPES_UNKNOWN
}

return aem.buildScope.tryGetOrPut(EXPORT_NODE_TYPE_PATH) {
return aem.buildScope.tryGetOrPut("${instance.httpUrl}$EXPORT_NODE_TYPE_PATH") {
try {
readNodeTypes().apply {
aem.logger.info("Successfully read CRX node types of $instance")
Expand All @@ -47,7 +47,5 @@ class Crx(sync: InstanceSync) : InstanceService(sync) {
const val NODE_TYPES_UNKNOWN = ""

const val EXPORT_NODE_TYPE_PATH = "/crx/de/exportnodetype.jsp"


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Status(sync: InstanceSync) : InstanceService(sync) {
*/
val systemProperties: Map<String, String>
get() {
if (!aem.instanceOptions.statusProperties) {
if (aem.offline) {
return mapOf()
}

Expand Down Expand Up @@ -54,7 +54,7 @@ class Status(sync: InstanceSync) : InstanceService(sync) {
*/
val productVersion: String
get() {
if (!aem.instanceOptions.statusProperties) {
if (aem.offline) {
return PRODUCT_VERSION_UNKNOWN
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class PackageValidator(val aem: AemExtension) {
FileOperations.zipUnpackAll(file, workDir)
}

configDirs.filter { it.exists() }.forEach {configDir ->
configDirs.filter { it.exists() }.forEach { configDir ->
logger.info("Using project-specific OakPAL Opear configuration files from file '$configDir' to directory '$workDir'")

FileUtils.copyDirectory(configDir, workDir)
Expand Down Expand Up @@ -147,6 +147,7 @@ class PackageValidator(val aem: AemExtension) {
}
}

@Suppress("ComplexMethod")
private fun analyzeReports(packages: Iterable<File>, reports: List<CheckReport>) {
val violatedReports = reports.filter { !it.violations.isEmpty() }
val shouldFail = violatedReports.any { !it.getViolations(severity).isEmpty() }
Expand Down Expand Up @@ -193,7 +194,6 @@ class PackageValidator(val aem: AemExtension) {
throw PackageException(failMessage)
} else {
logger.error(failMessage)

}
} else {
violationLogger.logTo(logger)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.cognifide.gradle.aem.common.pkg.vlt

import com.cognifide.gradle.aem.AemException
import com.cognifide.gradle.aem.AemExtension
import org.apache.commons.lang3.StringUtils
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import java.io.File
Expand Down Expand Up @@ -71,6 +73,10 @@ open class VltDefinition(private val aem: AemExtension) {
@Internal
var nodeTypeLines: MutableList<String> = mutableListOf()

@InputFile
@Optional
var nodeTypeExported: File = File(aem.configCommonDir, "package/META-INF/vault/nodetypes.exported.cnd")

@get:Input
val nodeTypes: String
get() = StringUtils.join(
Expand Down Expand Up @@ -121,8 +127,18 @@ open class VltDefinition(private val aem: AemExtension) {
version = aem.project.version.toString()
}

aem.availableInstance?.sync {
nodeTypes(crx.nodeTypes)
aem.buildScope.doOnce("crxNodeTypesExported") {
aem.availableInstance?.sync {
try {
nodeTypeExported.writeText(crx.nodeTypes)
} catch (e: AemException) {
aem.logger.debug("Cannot export and save node types from $instance! Cause: ${e.message}", e)
}
} ?: aem.logger.debug("No available instances to export node types!")
}

nodeTypeExported.takeIf { it.exists() }?.let {
nodeTypes(it)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.cognifide.gradle.aem.pkg.tasks.compose.PackageDependency
import com.cognifide.gradle.aem.pkg.tasks.compose.ProjectMergingOptions
import com.fasterxml.jackson.annotation.JsonIgnore
import java.io.File
import java.util.regex.Pattern
import org.apache.commons.io.FileUtils
import org.apache.commons.lang3.StringUtils
import org.gradle.api.Project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package com.cognifide.gradle.aem.tooling.sync

import com.cognifide.gradle.aem.AemDefaultTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ repositories {
}

dependencies {
implementation("com.cognifide.gradle:aem-plugin:8.0.1")
implementation("com.cognifide.gradle:aem-plugin:8.1.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ repositories {
}

dependencies {
implementation("com.cognifide.gradle:aem-plugin:8.0.1")
implementation("com.cognifide.gradle:aem-plugin:8.1.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ repositories {
}

dependencies {
implementation("com.cognifide.gradle:aem-plugin:8.0.1")
implementation("com.cognifide.gradle:aem-plugin:8.1.0")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.41")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ repositories {
}

dependencies {
implementation("com.cognifide.gradle:aem-plugin:8.0.1")
implementation("com.cognifide.gradle:aem-plugin:8.1.0")
}

0 comments on commit dd6d1c8

Please sign in to comment.