Skip to content

Commit

Permalink
Refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
Krystian Panek committed Dec 11, 2019
1 parent 97123af commit 13a1709
Show file tree
Hide file tree
Showing 55 changed files with 210 additions and 201 deletions.
70 changes: 35 additions & 35 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ aem {
}
nodeTypesSync("PRESERVE_AUTO")
validator {
enabled = props.boolean("package.validator.enabled") ?: true
verbose = props.boolean("package.validator.verbose") ?: true
planName = props.string("package.validator.plan") ?: "default-plan.json"
enabled = prop.boolean("package.validator.enabled") ?: true
verbose = prop.boolean("package.validator.verbose") ?: true
planName = prop.string("package.validator.plan") ?: "default-plan.json"
severity("MAJOR")
}
// ...
Expand All @@ -273,23 +273,23 @@ aem {
// etc

http { // allows to customize HTTP connection to AEM instances
connectionTimeout = props.int("instance.http.connectionTimeout") ?: 30000
connectionRetries = props.boolean("instance.http.connectionRetries") ?: true
connectionIgnoreSsl = props.boolean("instance.http.connectionIgnoreSsl") ?: true
connectionTimeout = prop.int("instance.http.connectionTimeout") ?: 30000
connectionRetries = prop.boolean("instance.http.connectionRetries") ?: true
connectionIgnoreSsl = prop.boolean("instance.http.connectionIgnoreSsl") ?: true

proxyHost = props.string("instance.http.proxyHost")
proxyPort = props.int("instance.http.proxyPort")
proxyScheme = props.string("instance.http.proxyScheme")
proxyHost = prop.string("instance.http.proxyHost")
proxyPort = prop.int("instance.http.proxyPort")
proxyScheme = prop.string("instance.http.proxyScheme")
}
}
localInstance { // config for AEM instances to be created on local file system
quickstart {
jarUrl = props.string("localInstance.quickstart.jarUrl")
licenseUrl = props.string("localInstance.quickstart.licenseUrl")
jarUrl = prop.string("localInstance.quickstart.jarUrl")
licenseUrl = prop.string("localInstance.quickstart.licenseUrl")
}
backup {
uploadUrl = props.string("localInstance.backup.uploadUrl")
downloadUrl = props.string("localInstance.backup.downloadUrl")
uploadUrl = prop.string("localInstance.backup.uploadUrl")
downloadUrl = prop.string("localInstance.backup.downloadUrl")
}
install {
files { // CRX packages and OSGi bundles to be pre-installed on created AEM instances
Expand All @@ -303,11 +303,11 @@ aem {
// ...
}
}
rootDir = props.string("localInstance.root")
rootDir = prop.string("localInstance.root")
// ...
}
environment { // config for AEM environment running on Docker
rootDir = props.string("environment.rootDir")?.let { project.file(it) } ?: projectMain.file(".aem/environment")
rootDir = prop.string("environment.rootDir")?.let { project.file(it) } ?: projectMain.file(".aem/environment")
hosts { // domains to be appended to hosts file automatically
author("http://author.example.com")
publish("http://demo.example.com") { tag("test") }
Expand Down Expand Up @@ -350,18 +350,18 @@ aem {
}
fileTransfer { // config for resolving CRX packages, AEM Quickstart files and backups using HTTP/SFTP/SMB
sftp {
user = props.string("fileTransfer.sftp.user")
password = props.string("fileTransfer.sftp.password")
user = prop.string("fileTransfer.sftp.user")
password = prop.string("fileTransfer.sftp.password")
}
smb {
user = props.string("fileTransfer.smb.user")
password = props.string("fileTransfer.smb.password")
domain = props.string("fileTransfer.smb.domain")
user = prop.string("fileTransfer.smb.user")
password = prop.string("fileTransfer.smb.password")
domain = prop.string("fileTransfer.smb.domain")
}
http {
client {
basicUser = props.string("fileTransfer.http.user")
basicPassword = props.string("fileTransfer.http.password")
basicUser = prop.string("fileTransfer.http.user")
basicPassword = prop.string("fileTransfer.http.password")
}
}

Expand Down Expand Up @@ -1482,7 +1482,7 @@ aem {
localInstance {
backup {
selector = { // default implementation below
val name = props.string("localInstance.backup.name") ?: ""
val name = prop.string("localInstance.backup.name") ?: ""
when {
name.isNotBlank() -> firstOrNull { it.fileEntry.name == name }
else -> firstOrNull()
Expand Down Expand Up @@ -1525,7 +1525,7 @@ This behavior is controlled by:
```kotlin
aem {
localInstance {
rootDir = props.string("localInstance.root")?.let { project.file(it) } ?: projectMain.file(".aem/instance")
rootDir = prop.string("localInstance.root")?.let { project.file(it) } ?: projectMain.file(".aem/instance")
overridesDir = File(configCommonDir, LocalInstance.FILES_PATH)
expandProperties = mapOf()
expandFiles = listOf(
Expand Down Expand Up @@ -1865,26 +1865,26 @@ aem {
instanceAwait {
awaitUp {
timeout {
stateTime = props.long("instance.awaitUp.timeout.stateTime") ?: TimeUnit.MINUTES.toMillis(2)
constantTime = props.long("instance.awaitUp.timeout.constantTime") ?: TimeUnit.MINUTES.toMillis(10)
stateTime = prop.long("instance.awaitUp.timeout.stateTime") ?: TimeUnit.MINUTES.toMillis(2)
constantTime = prop.long("instance.awaitUp.timeout.constantTime") ?: TimeUnit.MINUTES.toMillis(10)
}
bundles {
symbolicNamesIgnored = props.list("instance.awaitUp.bundles.symbolicNamesIgnored") ?: listOf()
symbolicNamesIgnored = prop.list("instance.awaitUp.bundles.symbolicNamesIgnored") ?: listOf()
}
components {
platformComponents = props.list("instance.awaitUp.components.platform") ?: listOf(
platformComponents = prop.list("instance.awaitUp.components.platform") ?: listOf(
"com.day.crx.packaging.*",
"org.apache.sling.installer.*"
)
specificComponents = props.list("instance.awaitUp.components.specific") ?: javaPackages.map { "$it.*" }
specificComponents = prop.list("instance.awaitUp.components.specific") ?: javaPackages.map { "$it.*" }
}
events {
unstableTopics = props.list("instance.awaitUp.event.unstableTopics") ?: listOf(
unstableTopics = prop.list("instance.awaitUp.event.unstableTopics") ?: listOf(
"org/osgi/framework/ServiceEvent/*",
"org/osgi/framework/FrameworkEvent/*",
"org/osgi/framework/BundleEvent/*"
)
unstableAgeMillis = props.long("instance.awaitUp.event.unstableAgeMillis") ?: TimeUnit.SECONDS.toMillis(5)
unstableAgeMillis = prop.long("instance.awaitUp.event.unstableAgeMillis") ?: TimeUnit.SECONDS.toMillis(5)
}
}
}
Expand Down Expand Up @@ -1924,10 +1924,10 @@ aem {
tasks {
instanceTail {
tailer {
logFilePath = props.string("instance.tail.logFilePath") ?: "/logs/error.log"
logFilePath = prop.string("instance.tail.logFilePath") ?: "/logs/error.log"
logListener = { instance -> /* ... */ }
incidentFilter = props.string("instance.tail.incidentFilter")?.let { project.file(it) } ?: File(configCommonDir, "instanceTail/incidentFilter.txt")
incidentDelay = props.long("instance.tail.incidentDelay") ?: 5000L
incidentFilter = prop.string("instance.tail.incidentFilter")?.let { project.file(it) } ?: File(configCommonDir, "instanceTail/incidentFilter.txt")
incidentDelay = prop.long("instance.tail.incidentDelay") ?: 5000L
}
}
}
Expand Down Expand Up @@ -2572,7 +2572,7 @@ Remember to [encode instance user & password](#instance-url-credentials-encoding
The properties syntax comes from [Pebble Template Engine](https://github.com/PebbleTemplates/pebble) which means that all its features (if statements, for loops, filters etc) can be used inside files being expanded.
Expanding properties could be used separately on any string or file source in any custom task by using method `aem.props.expand()`.
Expanding properties could be used separately on any string or file source in any custom task by using method `aem.prop.expand()`.
### Customize convention for CRX package and OSGi bundle names and paths
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/cognifide/gradle/aem/AemDefaultTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ open class AemDefaultTask : DefaultTask(), AemTask {
fun checkForce() {
taskGraphReady { graph ->
if (graph.hasTask(this)) {
aem.props.checkForce()
aem.prop.checkForce()
}
}
}
Expand Down
34 changes: 19 additions & 15 deletions src/main/kotlin/com/cognifide/gradle/aem/AemExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ class AemExtension(@JsonIgnore val project: Project) : Serializable {
* Allows to read project property specified in command line and system property as a fallback.
*/
@JsonIgnore
val props = PropertyParser(this)
val prop = PropertyParser(this)

@get:JsonIgnore
@Deprecated("Use 'prop' instead!", replaceWith = ReplaceWith("prop"))
val props get() = prop

/**
* Access configuration for local instances or environment from different project (cross-project configuring).
Expand All @@ -73,7 +77,7 @@ class AemExtension(@JsonIgnore val project: Project) : Serializable {
* - single-project build - root project
*/
@JsonIgnore
val projectMain: Project = project.findProject(props.string("projectMainPath") ?: ":aem") ?: project.rootProject
val projectMain: Project = project.findProject(prop.string("projectMainPath") ?: ":aem") ?: project.rootProject

/**
* Project name convention prefixes used to determine default:
Expand All @@ -84,7 +88,7 @@ class AemExtension(@JsonIgnore val project: Project) : Serializable {
*
* in case of multi-project build and assembly packages.
*/
val projectPrefixes: List<String> = props.list("projectPrefixes") ?: listOf("aem.", "aem-", "aem_")
val projectPrefixes: List<String> = prop.list("projectPrefixes") ?: listOf("aem.", "aem-", "aem_")

/**
* Project name with skipped convention prefixes.
Expand All @@ -111,17 +115,17 @@ class AemExtension(@JsonIgnore val project: Project) : Serializable {
* It is more soft offline mode than Gradle's one which does much more.
* It will not use any Maven repository so that CI build will fail which is not expected in e.g integration tests.
*/
val offline = props.flag("offline")
val offline = prop.flag("offline")

/**
* Determines current environment name to be used in e.g package deployment.
*/
val env: String = props.string("env") ?: run { System.getenv("ENV") ?: "local" }
val env: String = prop.string("env") ?: run { System.getenv("ENV") ?: "local" }

/**
* Specify characters to be used as line endings when cleaning up checked out JCR content.
*/
var lineSeparator: String = props.string("lineSeparator") ?: "LF"
var lineSeparator: String = prop.string("lineSeparator") ?: "LF"

@JsonIgnore
val lineSeparatorString: String = LineSeparator.string(lineSeparator)
Expand All @@ -131,7 +135,7 @@ class AemExtension(@JsonIgnore val project: Project) : Serializable {
* - Groovy Scripts to be launched by Groovy Console instance service in tasks defined in project.
*/
val configDir: File
get() = project.file(props.string("configDir") ?: "gradle")
get() = project.file(prop.string("configDir") ?: "gradle")

/**
* Directory for storing common files used by plugin e.g:
Expand All @@ -141,7 +145,7 @@ class AemExtension(@JsonIgnore val project: Project) : Serializable {
* - tail incident filter
*/
val configCommonDir: File
get() = projectMain.file(props.string("configCommonDir") ?: "gradle")
get() = projectMain.file(prop.string("configCommonDir") ?: "gradle")

@get:Internal
val fileTransfer = FileTransferManager(this)
Expand Down Expand Up @@ -278,7 +282,7 @@ class AemExtension(@JsonIgnore val project: Project) : Serializable {
@get:JsonIgnore
val anyInstance: Instance
get() {
val cmdInstanceArg = props.string("instance")
val cmdInstanceArg = prop.string("instance")
if (!cmdInstanceArg.isNullOrBlank()) {
return instance(cmdInstanceArg)
}
Expand All @@ -299,7 +303,7 @@ class AemExtension(@JsonIgnore val project: Project) : Serializable {
*
* If none instances will be found, throws exception.
*/
fun namedInstance(desiredName: String? = props.string("instance.name"), defaultName: String = "$env-*"): Instance {
fun namedInstance(desiredName: String? = prop.string("instance.name"), defaultName: String = "$env-*"): Instance {
val nameMatcher: String = desiredName ?: defaultName

val namedInstance = filterInstances(nameMatcher).firstOrNull()
Expand All @@ -313,7 +317,7 @@ class AemExtension(@JsonIgnore val project: Project) : Serializable {
/**
* Find all instances which names are matching wildcard filter specified via command line parameter 'instance.name'.
*/
fun filterInstances(nameMatcher: String = props.string("instance.name") ?: "$env-*"): List<Instance> {
fun filterInstances(nameMatcher: String = prop.string("instance.name") ?: "$env-*"): List<Instance> {
val all = instanceOptions.defined.values

// Specified by command line should not be filtered
Expand All @@ -325,8 +329,8 @@ class AemExtension(@JsonIgnore val project: Project) : Serializable {
// Defined by build script, via properties or defaults are filterable by name
return all.filter { instance ->
when {
props.flag("instance.author", "instance.authors") -> instance.author
props.flag("instance.publish", "instance.publishes", "instance.publishers") -> instance.publish
prop.flag("instance.author", "instance.authors") -> instance.author
prop.flag("instance.publish", "instance.publishes", "instance.publishers") -> instance.publish
else -> Patterns.wildcard(instance.name, nameMatcher)
}
}
Expand Down Expand Up @@ -558,13 +562,13 @@ class AemExtension(@JsonIgnore val project: Project) : Serializable {
@get:JsonIgnore
val filter: FilterFile
get() {
val cmdFilterRoots = props.list("filter.roots") ?: listOf()
val cmdFilterRoots = prop.list("filter.roots") ?: listOf()
if (cmdFilterRoots.isNotEmpty()) {
logger.debug("Using Vault filter roots specified as command line property: $cmdFilterRoots")
return FilterFile.temporary(project, cmdFilterRoots)
}

val cmdFilterPath = props.string("filter.path") ?: ""
val cmdFilterPath = prop.string("filter.path") ?: ""
if (cmdFilterPath.isNotEmpty()) {
val cmdFilter = FileOperations.find(project, packageOptions.vltDir.toString(), cmdFilterPath)
?: throw VltException("Vault check out filter file does not exist at path: $cmdFilterPath" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@ open class BundleInstall : BundleTask() {
* Check instance(s) health after installing bundles.
*/
@Input
var awaited: Boolean = aem.props.boolean("bundle.install.awaited") ?: true
var awaited: Boolean = aem.prop.boolean("bundle.install.awaited") ?: true

/**
* Controls if bundle after installation should be immediatelly started.
*/
@Input
var start: Boolean = aem.props.boolean("bundle.install.start") ?: true
var start: Boolean = aem.prop.boolean("bundle.install.start") ?: true

/**
* OSGi start level at which installed bundle will be started.
*/
@Input
var startLevel: Int = aem.props.int("bundle.install.startLevel") ?: 20
var startLevel: Int = aem.prop.int("bundle.install.startLevel") ?: 20

/**
* Controls if bundle dependent packages should be refreshed within installation.
*/
@Input
var refreshPackages: Boolean = aem.props.boolean("bundle.install.refreshPackages") ?: true
var refreshPackages: Boolean = aem.prop.boolean("bundle.install.refreshPackages") ?: true

/**
* Repeat install when failed (brute-forcing).
*/
@Internal
@get:JsonIgnore
var retry = aem.retry { afterSquaredSecond(aem.props.long("bundle.install.retry") ?: 2) }
var retry = aem.retry { afterSquaredSecond(aem.prop.long("bundle.install.retry") ?: 2) }

/**
* Hook for preparing instance before installing bundles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ abstract class Resolver<G : FileGroup>(
* Controls count of groups resolved in parallel.
*/
@Internal
var parallelLevel = aem.props.int("resolver.parallelLevel") ?: 3
var parallelLevel = aem.prop.int("resolver.parallelLevel") ?: 3

/**
* Files respected when searching for recent local files.
*/
@Input
var localFilePatterns = aem.props.list("resolver.localFilePatterns") ?: listOf("**/*.zip", "**/*.jar")
var localFilePatterns = aem.prop.list("resolver.localFilePatterns") ?: listOf("**/*.zip", "**/*.jar")

@get:Internal
val groups: List<G>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ class FileTransferManager(private val aem: AemExtension) : FileTransfer {
init {
// override specific credentials if common specified
credentials(
aem.props.string("fileTransfer.user"),
aem.props.string("fileTransfer.password"),
aem.props.string("fileTransfer.domain")
aem.prop.string("fileTransfer.user"),
aem.prop.string("fileTransfer.password"),
aem.prop.string("fileTransfer.domain")
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class HttpFileTransfer(aem: AemExtension, var client: HttpClient = client(aem))
const val NAME = "httpd"

fun client(aem: AemExtension) = HttpClient(aem).apply {
basicUser = aem.props.string("fileTransfer.http.user")
basicPassword = aem.props.string("fileTransfer.http.password")
connectionIgnoreSsl = aem.props.boolean("fileTransfer.http.connectionIgnoreSsl") ?: true
basicUser = aem.prop.string("fileTransfer.http.user")
basicPassword = aem.prop.string("fileTransfer.http.password")
connectionIgnoreSsl = aem.prop.boolean("fileTransfer.http.connectionIgnoreSsl") ?: true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import org.apache.sshd.common.subsystem.sftp.SftpException

class SftpFileTransfer(aem: AemExtension) : ProtocolFileTransfer(aem) {

var user: String? = aem.props.string("fileTransfer.sftp.user")
var user: String? = aem.prop.string("fileTransfer.sftp.user")

@JsonSerialize(using = JsonPassword::class, `as` = String::class)
var password: String? = aem.props.string("fileTransfer.sftp.password")
var password: String? = aem.prop.string("fileTransfer.sftp.password")

var timeout: Long = aem.props.long("fileTransfer.sftp.timeout") ?: 60000L
var timeout: Long = aem.prop.long("fileTransfer.sftp.timeout") ?: 60000L

@JsonIgnore
var clientOptions: SshClient.() -> Unit = {}
Expand Down
Loading

0 comments on commit 13a1709

Please sign in to comment.