@@ -8,6 +8,7 @@ import org.gradle.api.Project
88import org.gradle.api.logging.Logger
99import java.io.File
1010
11+ // TODO https://github.com/Cognifide/gradle-aem-plugin/issues/135
1112class VltCommand (val project : Project ) {
1213
1314 val logger: Logger = project.logger
@@ -16,65 +17,43 @@ class VltCommand(val project: Project) {
1617
1718 val config = AemConfig .of(project)
1819
19- fun clean ( ) {
20- val config = AemConfig .of (project)
21- val contentDir = File (config.contentPath )
22-
23- if ( ! contentDir.exists()) {
24- logger.warn( " JCR content directory to be cleaned does not exist: ${contentDir.absolutePath} " )
25- return
26- }
20+ fun raw ( command : String , props : Map < String , Any > = mapOf() ) {
21+ val app = VltApp (project)
22+ val instance = determineInstance( )
23+ val allProps = mapOf (
24+ " instance " to instance,
25+ " instances " to config.instances
26+ ) + props
27+ val fullCommand = propertyParser.expand( " ${config.vaultGlobalOptions} $command " .trim(), allProps)
2728
28- val cleaner = VltCleaner (contentDir, logger)
29- cleaner.removeVltFiles()
30- cleaner.cleanupDotContent(config.vaultSkipProperties, config.vaultLineSeparatorString)
29+ app.execute(fullCommand)
3130 }
3231
3332 fun checkout () {
34- val config = AemConfig .of(project)
3533 val contentDir = File (config.contentPath)
36-
3734 if (! contentDir.exists()) {
3835 logger.info(" JCR content directory to be checked out does not exist: ${contentDir.absolutePath} " )
3936 }
4037
41- raw(" checkout --force --filter {{filter}} {{instance.httpUrl}}/crx/server/crx.default" )
42- }
43-
44- fun raw (command : String ) {
45- val app = VltApp (project)
46- val config = AemConfig .of(project)
47-
4838 val filter = determineFilter()
49- val instance = determineInstance()
50-
51- val specificProps = mapOf (
52- " instance" to instance,
53- " filter" to filter.file.absolutePath
54- )
55- val fullCommand = propertyParser.expand(" ${config.vaultGlobalOptions} $command " .trim(), specificProps)
39+ val props = mapOf (" filter" to filter.file.absolutePath)
5640
57- app.execute(fullCommand)
58- filter.clean()
41+ filter.use {
42+ raw(" checkout --force --filter {{filter}} {{instance.httpUrl}}/crx/server/crx.default" , props)
43+ }
5944 }
6045
6146 fun determineFilter (): VltFilter {
62- val config = AemConfig .of(project)
63- val cmdFilterPath = propertyParser.string(" aem.vlt.filter" )
64- val cmdFilterRoots = PropertyParser (project).list(" aem.vlt.filterRoots" )
65-
66- return if (! cmdFilterPath.isNullOrBlank()) {
67- val cmdFilter = FileOperations .find(project, config.vaultPath, cmdFilterPath!! )
68- ? : throw VltException (" Vault check out filter file does not exist at path: $cmdFilterPath " )
69-
70- logger.debug(" Using VLT filter specified as command line property" )
71- VltFilter (cmdFilter)
72- } else if (cmdFilterRoots.isNotEmpty()) {
73- logger.debug(" Using VLT filter roots specified as command line property" )
47+ val cmdFilterRoots = propertyParser.list(" aem.checkout.filterRoots" )
48+
49+ return if (cmdFilterRoots.isNotEmpty()) {
50+ logger.info(" Using Vault filter roots specified as command line property: $cmdFilterRoots " )
7451 VltFilter .temporary(project, cmdFilterRoots)
7552 } else {
76- logger.debug(" Using VLT filter specified in AEM build configuration" )
77- VltFilter (File (config.vaultFilterPath))
53+ val configFilter = FileOperations .find(project, config.vaultPath, config.checkoutFilterPath)
54+ ? : throw VltException (" Vault check out filter file does not exist at path: ${config.checkoutFilterPath} (or under directory: ${config.vaultPath} )." )
55+ logger.info(" Using Vault filter specified in configuration: ${config.checkoutFilterPath} " )
56+ VltFilter (configFilter)
7857 }
7958 }
8059
@@ -84,23 +63,35 @@ class VltCommand(val project: Project) {
8463 val cmdInstance = Instance .parse(cmdInstanceArg!! ).first()
8564 cmdInstance.validate()
8665
87- logger.debug (" Using instance specified by command line parameter: $cmdInstance " )
66+ logger.info (" Using instance specified by command line parameter: $cmdInstance " )
8867 return cmdInstance
8968 }
9069
9170 val namedInstance = Instance .filter(project, config.deployInstanceName).firstOrNull()
9271 if (namedInstance != null ) {
93- logger.debug (" Using first instance matching filter '${config.deployInstanceName} ': $namedInstance " )
72+ logger.info (" Using first instance matching filter '${config.deployInstanceName} ': $namedInstance " )
9473 return namedInstance
9574 }
9675
9776 val anyInstance = Instance .filter(project, Instance .FILTER_ANY ).firstOrNull()
9877 if (anyInstance != null ) {
99- logger.debug (" Using first instance matching filter '${Instance .FILTER_ANY } ': $anyInstance " )
78+ logger.info (" Using first instance matching filter '${Instance .FILTER_ANY } ': $anyInstance " )
10079 return anyInstance
10180 }
10281
10382 throw VltException (" Vault instance cannot be determined neither by command line parameter nor AEM config." )
10483 }
10584
85+ fun clean () {
86+ val contentDir = File (config.contentPath)
87+ if (! contentDir.exists()) {
88+ logger.warn(" JCR content directory to be cleaned does not exist: ${contentDir.absolutePath} " )
89+ return
90+ }
91+
92+ val cleaner = VltCleaner (contentDir, logger)
93+ cleaner.removeFiles(config.cleanFilesDeleted)
94+ cleaner.cleanupDotContent(config.vaultSkipProperties, config.vaultLineSeparatorString)
95+ }
96+
10697}
0 commit comments