Skip to content

Commit

Permalink
added update property to push command
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Przybyl committed Nov 12, 2024
1 parent d843a8e commit a0faffb
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 2 deletions.
11 changes: 11 additions & 0 deletions cmd/aem/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ func (c *CLI) contentPushCmd() *cobra.Command {
filterRoots := determineFilterRoots(cmd)
excludePatterns := determineExcludePatterns(cmd)
clean, _ := cmd.Flags().GetBool("clean")
filterMode := determineFilterMode(cmd)
if err = c.aem.ContentManager().Push(instances, clean, pkg.PackageCreateOpts{
PID: fmt.Sprintf("aemc:content-push:%s-SNAPSHOT", timex.FileTimestampForNow()),
FilterRoots: filterRoots,
ExcludePatterns: excludePatterns,
ContentPath: path,
FilterMode: filterMode,
}); err != nil {
c.Error(err)
return
Expand All @@ -222,6 +224,7 @@ func (c *CLI) contentPushCmd() *cobra.Command {
cmd.Flags().StringP("path", "p", "", "JCR root path or local file path")
cmd.MarkFlagsOneRequired("dir", "file", "path")
cmd.Flags().Bool("clean", false, "Normalize content while uploading")
cmd.Flags().Bool("update", false, "Existing content on running instance is updated, new content is added and none is deleted")
return cmd
}

Expand Down Expand Up @@ -370,3 +373,11 @@ func determineExcludePatterns(cmd *cobra.Command) []string {
}
return excludePatterns
}

func determineFilterMode(cmd *cobra.Command) string {
update, _ := cmd.Flags().GetBool("update")
if update {
return "update"
}
return ""
}
2 changes: 2 additions & 0 deletions pkg/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func copyPackageAllFiles(targetTmpDir string, opts PackageCreateOpts) error {
"Version": pidConfig.Version,
"FilterRoots": opts.FilterRoots,
"ExcludePatterns": opts.ExcludePatterns,
"FilterMode": opts.FilterMode,
}
if err = pathx.DeleteIfExists(targetTmpDir); err != nil {
return fmt.Errorf("cannot delete temporary dir '%s': %w", targetTmpDir, err)
Expand Down Expand Up @@ -201,6 +202,7 @@ type PackageCreateOpts struct {
FilterFile string
ExcludePatterns []string
ContentPath string
FilterMode string
}

func (pm *PackageManager) Create(opts PackageCreateOpts) (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/pkg/vault/META-INF/vault/filter.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">[[if .ExcludePatterns]]
<filter root="[[index .FilterRoots 0]]">[[range .ExcludePatterns]]
<filter root="[[index .FilterRoots 0]]"[[if .FilterMode]] mode="[[.FilterMode]]"[[end]]>[[range .ExcludePatterns]]
<exclude pattern="[[.]]"/>[[end]]
</filter>[[else]][[range .FilterRoots]]
<filter root="[[.]]"/>[[end]][[end]]
<filter root="[[.]]"[[if $.FilterMode]] mode="[[$.FilterMode]]"[[end]]/>[[end]][[end]]
</workspaceFilter>
19 changes: 19 additions & 0 deletions test/filter_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,22 @@ func TestExcludePatterns(t *testing.T) {
},
)
}

func TestFilterRootsUpdate(t *testing.T) {
testFilterFile(t, "vault/META-INF/vault/filter.xml", "resources/filter_roots_update.xml",
map[string]any{
"FilterRoots": []string{"/apps/my_site", "/content/my_site"},
"FilterMode": "update",
},
)
}

func TestExcludePatternsUpdate(t *testing.T) {
testFilterFile(t, "vault/META-INF/vault/filter.xml", "resources/exclude_patterns_update.xml",
map[string]any{
"FilterRoots": []string{"/apps/my_site", "/content/my_site"},
"ExcludePatterns": []string{"/apps/my_site/cq:dialog(/.*)?", "/apps/my_site/rep:policy(/.*)?"},
"FilterMode": "update",
},
)
}
7 changes: 7 additions & 0 deletions test/resources/exclude_patterns_update.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
<filter root="/apps/my_site" mode="update">
<exclude pattern="/apps/my_site/cq:dialog(/.*)?"/>
<exclude pattern="/apps/my_site/rep:policy(/.*)?"/>
</filter>
</workspaceFilter>
5 changes: 5 additions & 0 deletions test/resources/filter_roots_update.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
<filter root="/apps/my_site" mode="update"/>
<filter root="/content/my_site" mode="update"/>
</workspaceFilter>

0 comments on commit a0faffb

Please sign in to comment.