Skip to content

Commit a0faffb

Browse files
author
Dominik Przybyl
committed
added update property to push command
1 parent d843a8e commit a0faffb

File tree

6 files changed

+46
-2
lines changed

6 files changed

+46
-2
lines changed

cmd/aem/content.go

+11
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,13 @@ func (c *CLI) contentPushCmd() *cobra.Command {
200200
filterRoots := determineFilterRoots(cmd)
201201
excludePatterns := determineExcludePatterns(cmd)
202202
clean, _ := cmd.Flags().GetBool("clean")
203+
filterMode := determineFilterMode(cmd)
203204
if err = c.aem.ContentManager().Push(instances, clean, pkg.PackageCreateOpts{
204205
PID: fmt.Sprintf("aemc:content-push:%s-SNAPSHOT", timex.FileTimestampForNow()),
205206
FilterRoots: filterRoots,
206207
ExcludePatterns: excludePatterns,
207208
ContentPath: path,
209+
FilterMode: filterMode,
208210
}); err != nil {
209211
c.Error(err)
210212
return
@@ -222,6 +224,7 @@ func (c *CLI) contentPushCmd() *cobra.Command {
222224
cmd.Flags().StringP("path", "p", "", "JCR root path or local file path")
223225
cmd.MarkFlagsOneRequired("dir", "file", "path")
224226
cmd.Flags().Bool("clean", false, "Normalize content while uploading")
227+
cmd.Flags().Bool("update", false, "Existing content on running instance is updated, new content is added and none is deleted")
225228
return cmd
226229
}
227230

@@ -370,3 +373,11 @@ func determineExcludePatterns(cmd *cobra.Command) []string {
370373
}
371374
return excludePatterns
372375
}
376+
377+
func determineFilterMode(cmd *cobra.Command) string {
378+
update, _ := cmd.Flags().GetBool("update")
379+
if update {
380+
return "update"
381+
}
382+
return ""
383+
}

pkg/package_manager.go

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ func copyPackageAllFiles(targetTmpDir string, opts PackageCreateOpts) error {
166166
"Version": pidConfig.Version,
167167
"FilterRoots": opts.FilterRoots,
168168
"ExcludePatterns": opts.ExcludePatterns,
169+
"FilterMode": opts.FilterMode,
169170
}
170171
if err = pathx.DeleteIfExists(targetTmpDir); err != nil {
171172
return fmt.Errorf("cannot delete temporary dir '%s': %w", targetTmpDir, err)
@@ -201,6 +202,7 @@ type PackageCreateOpts struct {
201202
FilterFile string
202203
ExcludePatterns []string
203204
ContentPath string
205+
FilterMode string
204206
}
205207

206208
func (pm *PackageManager) Create(opts PackageCreateOpts) (string, error) {
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<workspaceFilter version="1.0">[[if .ExcludePatterns]]
3-
<filter root="[[index .FilterRoots 0]]">[[range .ExcludePatterns]]
3+
<filter root="[[index .FilterRoots 0]]"[[if .FilterMode]] mode="[[.FilterMode]]"[[end]]>[[range .ExcludePatterns]]
44
<exclude pattern="[[.]]"/>[[end]]
55
</filter>[[else]][[range .FilterRoots]]
6-
<filter root="[[.]]"/>[[end]][[end]]
6+
<filter root="[[.]]"[[if $.FilterMode]] mode="[[$.FilterMode]]"[[end]]/>[[end]][[end]]
77
</workspaceFilter>

test/filter_file_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,22 @@ func TestExcludePatterns(t *testing.T) {
3939
},
4040
)
4141
}
42+
43+
func TestFilterRootsUpdate(t *testing.T) {
44+
testFilterFile(t, "vault/META-INF/vault/filter.xml", "resources/filter_roots_update.xml",
45+
map[string]any{
46+
"FilterRoots": []string{"/apps/my_site", "/content/my_site"},
47+
"FilterMode": "update",
48+
},
49+
)
50+
}
51+
52+
func TestExcludePatternsUpdate(t *testing.T) {
53+
testFilterFile(t, "vault/META-INF/vault/filter.xml", "resources/exclude_patterns_update.xml",
54+
map[string]any{
55+
"FilterRoots": []string{"/apps/my_site", "/content/my_site"},
56+
"ExcludePatterns": []string{"/apps/my_site/cq:dialog(/.*)?", "/apps/my_site/rep:policy(/.*)?"},
57+
"FilterMode": "update",
58+
},
59+
)
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<workspaceFilter version="1.0">
3+
<filter root="/apps/my_site" mode="update">
4+
<exclude pattern="/apps/my_site/cq:dialog(/.*)?"/>
5+
<exclude pattern="/apps/my_site/rep:policy(/.*)?"/>
6+
</filter>
7+
</workspaceFilter>
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<workspaceFilter version="1.0">
3+
<filter root="/apps/my_site" mode="update"/>
4+
<filter root="/content/my_site" mode="update"/>
5+
</workspaceFilter>

0 commit comments

Comments
 (0)