Skip to content

Commit

Permalink
Merge branch 'fix-namespace-clean' into vault-cli
Browse files Browse the repository at this point in the history
# Conflicts:
#	pkg/content/content.go
  • Loading branch information
Dominik Przybyl committed Sep 20, 2024
2 parents 468f4a6 + 1ff7fd5 commit 638500d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
![AEM Compose Logo](https://github.com/wttech/aemc-ansible/raw/main/docs/logo-with-text.png)
[![WTT Logo](https://github.com/wttech/aemc-ansible/raw/main/docs/wtt-logo.png)](https://www.wundermanthompson.com/service/technology)

[![GitHub All Releases](https://img.shields.io/github/downloads/wttech/aemc/total)](https://github.com/wttech/aemc/releases)
[![Last Release Version](https://img.shields.io/github/v/release/wttech/aemc?color=lightblue&label=Last%20Release)](https://github.com/wttech/aemc/releases)
![Go Version](https://img.shields.io/github/go-mod/go-version/wttech/aemc)
[![Apache License, Version 2.0, January 2004](https://github.com/wttech/aemc-ansible/raw/main/docs/apache-license-badge.svg)](http://www.apache.org/licenses/)
Expand Down
35 changes: 22 additions & 13 deletions pkg/content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,26 @@ import (
)

const (
JCRRoot = "jcr_root"
JCRContentFile = ".content.xml"
XmlFileSuffix = ".xml"
JCRMixinTypesProp = "jcr:mixinTypes"
JCRRootPrefix = "<jcr:root"
PropPattern = "^\\s*([^ =]+)=\"([^\"]+)\"(.*)$"
NamespacePattern = "^\\w+:(\\w+)=\"[^\"]+\"$"
JCRRoot = "jcr_root"
JCRContentFile = ".content.xml"
XmlFileSuffix = ".xml"
JCRMixinTypesProp = "jcr:mixinTypes"
JCRRootPrefix = "<jcr:root"
PropPattern = "^\\s*([^ =]+)=\"([^\"]+)\"(.*)$"
NamespacePattern = "^\\w+:(\\w+)=\"[^\"]+\"$"
NamespaceFilePattern = "\\\\|/_([a-zA-Z0-9]+)_"
)

var (
propPatternRegex *regexp.Regexp
namespacePatternRegex *regexp.Regexp
propPatternRegex *regexp.Regexp
namespacePatternRegex *regexp.Regexp
namespaceFilePatternRegex *regexp.Regexp
)

func init() {
propPatternRegex = regexp.MustCompile(PropPattern)
namespacePatternRegex = regexp.MustCompile(NamespacePattern)
namespaceFilePatternRegex = regexp.MustCompile(NamespaceFilePattern)
}

type Manager struct {
Expand Down Expand Up @@ -154,25 +157,31 @@ func (c Manager) filterLines(path string, lines []string) []string {
result = result[:len(result)-1]
}
}
return c.cleanNamespaces(result)
return c.cleanNamespaces(path, result)
}

func (c Manager) cleanNamespaces(lines []string) []string {
func (c Manager) cleanNamespaces(path string, lines []string) []string {
if !c.NamespacesSkipped {
return lines
}

var fileNamespace string
groups := namespaceFilePatternRegex.FindStringSubmatch(path)
if groups != nil {
fileNamespace = groups[1]
}

var result []string
for _, line := range lines {
if strings.HasPrefix(line, JCRRootPrefix) {
var rootResult []string
for _, part := range strings.Split(line, " ") {
groups := namespacePatternRegex.FindStringSubmatch(part)
groups = namespacePatternRegex.FindStringSubmatch(part)
if groups == nil {
rootResult = append(rootResult, part)
} else {
flag := lo.SomeBy(lines, func(line string) bool {
return strings.Contains(line, groups[1]+":")
return strings.Contains(line, groups[1]+":") || groups[1] == fileNamespace
})
if flag {
rootResult = append(rootResult, part)
Expand Down
2 changes: 1 addition & 1 deletion pkg/content_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

const (
NamespacePattern = "(\\\\|/)_([a-zA-Z0-9]+)_"
NamespacePattern = "\\\\|/_[a-zA-Z0-9]+_"
)

var (
Expand Down

0 comments on commit 638500d

Please sign in to comment.