@@ -28,7 +28,7 @@ const (
2828
2929var (
3030 regexpPhpFile = regexp .MustCompile (`(?://)?(/[^ ]*\.php)` )
31- regexpFilename = regexp .MustCompile (`filename=["]?file://(\S+)/Data/Temporary/([^/]*(/SubContext[^/]*)?) /Cache/Code/Flow_Object_Classes/([^"]*)\.php` )
31+ regexpFilename = regexp .MustCompile (`filename=["]?file://(\S+)/Data/Temporary/.+? /Cache/Code/Flow_Object_Classes/([^"]*)\.php` )
3232 regexpPathAndFilename = regexp .MustCompile (`(?m)^# PathAndFilename: (.*)$` )
3333 regexpPackageClass = regexp .MustCompile (`(.*?)/Packages/[^/]*/(.*?)/Classes/(.*).php` )
3434 regexpDot = regexp .MustCompile (`[\./]` )
@@ -92,15 +92,20 @@ func (p *PathMapper) doTextPathMapping(message []byte) []byte {
9292
9393func (p * PathMapper ) getCachePath (base , filename string ) string {
9494 cachePath := strings .Replace (cachePathPattern , "@base@" , base , 1 )
95- contextPath := strings .Replace (p .config .Context , "/" , "/SubContext" , 1 )
96- cachePath = strings .Replace (cachePath , "@context@" , contextPath , 1 )
95+ context := p .config .Context
96+ if strings .Contains (context , "/" ) {
97+ contextParts := strings .Split (context , "/" )
98+ contextParts [1 ] = "SubContext" + contextParts [1 ]
99+ context = strings .Join (contextParts , "/" )
100+ }
101+ cachePath = strings .Replace (cachePath , "@context@" , context , 1 )
97102 return strings .Replace (cachePath , "@filename@" , filename , 1 )
98103}
99104
100105func (p * PathMapper ) doXMLPathMapping (b []byte ) []byte {
101106 var processedMapping = map [string ]string {}
102107 for _ , match := range regexpFilename .FindAllStringSubmatch (string (b ), - 1 ) {
103- path := p .getCachePath (match [1 ], match [4 ])
108+ path := p .getCachePath (match [1 ], match [2 ])
104109 if _ , ok := processedMapping [path ]; ok == false {
105110 if originalPath , exist := p .pathMapping .Get (path ); exist {
106111 if p .config .VeryVerbose {
@@ -109,7 +114,7 @@ func (p *PathMapper) doXMLPathMapping(b []byte) []byte {
109114 processedMapping [path ] = originalPath
110115 p .logger .Debug ("doXMLPathMapping mapping exist %s >>> %s" , path , originalPath )
111116 } else {
112- originalPath = p .readOriginalPathFromCache (path )
117+ originalPath = p .readOriginalPathFromCache (path , match [ 1 ] )
113118 processedMapping [path ] = originalPath
114119 p .logger .Debug ("doXMLPathMapping missing mapping %s >>> %s" , path , originalPath )
115120 }
@@ -135,7 +140,11 @@ func (p *PathMapper) mapPath(originalPath string) string {
135140 p .logger .Debug ("Path %s is a Flow Package file" , originalPath )
136141 cachePath := p .getCachePath (p .buildClassNameFromPath (originalPath ))
137142 realPath := p .getRealFilename (cachePath )
138- if _ , err := os .Stat (realPath ); err == nil {
143+ var err error
144+ if len (p .config .LocalRoot ) == 0 {
145+ _ , err = os .Stat (realPath )
146+ }
147+ if err == nil {
139148 return p .setPathMapping (realPath , originalPath )
140149 }
141150 }
@@ -155,13 +164,20 @@ func (p *PathMapper) setPathMapping(path string, originalPath string) string {
155164 return path
156165}
157166
158- func (p * PathMapper ) readOriginalPathFromCache (path string ) string {
159- dat , err := ioutil .ReadFile (path )
167+ func (p * PathMapper ) readOriginalPathFromCache (path , basePath string ) string {
168+ localPath := path
169+ if len (p .config .LocalRoot ) > 0 {
170+ localPath = strings .Replace (path , basePath , p .config .LocalRoot , 1 )
171+ }
172+ dat , err := ioutil .ReadFile (localPath )
160173 errorhandler .PanicHandling (err , p .logger )
161174 match := regexpPathAndFilename .FindStringSubmatch (string (dat ))
162- p .logger .Debug ("readOriginalPathFromCache %s" , path )
175+ p .logger .Debug ("readOriginalPathFromCache %s" , localPath )
163176 if len (match ) == 2 {
164177 originalPath := match [1 ]
178+ if len (p .config .LocalRoot ) > 0 {
179+ originalPath = strings .Replace (strings .Replace (originalPath , "\\ " , "/" , - 1 ), p .config .LocalRoot , basePath , 1 )
180+ }
165181 if p .config .VeryVerbose {
166182 p .logger .Info ("Umpa Lumpa need to work harder, need to reverse this one\n >>> %s\n >>> %s\n " , p .logger .Colorize (fmt .Sprintf (h , path ), "yellow" ), p .logger .Colorize (fmt .Sprintf (h , originalPath ), "green" ))
167183 }
0 commit comments