66 "github.com/murphysecurity/fix-tools/fix/xml/parser"
77 "io"
88 "net/http"
9+ "path/filepath"
910 "strings"
1011)
1112
@@ -29,8 +30,13 @@ func FindPropertiesLine(pomPath, targetElement, value string) int {
2930
3031 input , _ := antlr .NewFileStream (pomPath )
3132 lexer := parser .NewXMLLexer (input )
33+ liste := & MyErrorListener {suppress : true }
34+ lexer .RemoveErrorListeners ()
35+ lexer .AddErrorListener (liste )
3236 stream := antlr .NewCommonTokenStream (lexer , antlr .TokenDefaultChannel )
3337 p := parser .NewXMLParser (stream )
38+ p .RemoveErrorListeners ()
39+ p .AddErrorListener (liste )
3440 listener := & SimpleXMLListener {
3541 targetElement : targetElement ,
3642 value : value ,
@@ -84,13 +90,14 @@ func (l *ChildXMLListener) EnterElement(ctx *parser.ElementContext) {
8490 if propertyModel , ok := l .modelMap [model .OldVersion ]; ok {
8591 for _ , m := range propertyModel {
8692 if m .OldVersion == l .compVersion {
93+
8794 newModel := FixModel {
8895 Line : m .Line ,
8996 OldVersion : model .OldVersion ,
9097 NewVersion : l .newVersion ,
9198 CompName : l .compName ,
92- PomPath : l .pomPath ,
93- relativePomPath : l . relativePomPath ,
99+ PomPath : filepath . Join ( strings . ReplaceAll ( filepath . ToSlash ( l .pomPath ), l . relativePomPath , "" ), m . PomPath ) ,
100+ relativePomPath : m . PomPath ,
94101 }
95102 l .fixModelList = append (l .fixModelList , newModel )
96103 }
@@ -113,8 +120,13 @@ func GetFixModelList(pomPath, relativePomPath, compName, compVersion, newVersion
113120
114121 input , _ := antlr .NewFileStream (pomPath )
115122 lexer := parser .NewXMLLexer (input )
123+ liste := & MyErrorListener {suppress : true }
124+ lexer .RemoveErrorListeners ()
125+ lexer .AddErrorListener (liste )
116126 stream := antlr .NewCommonTokenStream (lexer , antlr .TokenDefaultChannel )
117127 p := parser .NewXMLParser (stream )
128+ p .RemoveErrorListeners ()
129+ p .AddErrorListener (liste )
118130 listener := & ChildXMLListener {
119131 pomPath : pomPath ,
120132 relativePomPath : relativePomPath ,
@@ -176,8 +188,8 @@ func (l *ParentXMLListener) EnterElement(ctx *parser.ElementContext) {
176188 OldVersion : model .OldVersion ,
177189 NewVersion : l .newVersion ,
178190 CompName : l .compName ,
179- PomPath : l .pomPath ,
180- relativePomPath : l . relativePomPath ,
191+ PomPath : filepath . Join ( strings . ReplaceAll ( filepath . ToSlash ( l .pomPath ), l . relativePomPath , "" ), m . PomPath ) ,
192+ relativePomPath : m . PomPath ,
181193 }
182194 l .fixModelList = append (l .fixModelList , newModel )
183195 }
@@ -198,8 +210,13 @@ func GetExtensionFixModelList(pomPath, relativePomPath, compName, compVersion, n
198210
199211 input , _ := antlr .NewFileStream (pomPath )
200212 lexer := parser .NewXMLLexer (input )
213+ liste := & MyErrorListener {suppress : true }
214+ lexer .RemoveErrorListeners ()
215+ lexer .AddErrorListener (liste )
201216 stream := antlr .NewCommonTokenStream (lexer , antlr .TokenDefaultChannel )
202217 p := parser .NewXMLParser (stream )
218+ p .RemoveErrorListeners ()
219+ p .AddErrorListener (liste )
203220 listener := & ChildXMLListener {
204221 pomPath : pomPath ,
205222 relativePomPath : relativePomPath ,
@@ -407,8 +424,13 @@ func GetInheritFixModelList(pomPath, relativePomPath, compName, compVersion, new
407424 models := make ([]FixModel , 0 )
408425 input , _ := antlr .NewFileStream (pomPath )
409426 lexer := parser .NewXMLLexer (input )
427+ liste := & MyErrorListener {suppress : true }
428+ lexer .RemoveErrorListeners ()
429+ lexer .AddErrorListener (liste )
410430 stream := antlr .NewCommonTokenStream (lexer , antlr .TokenDefaultChannel )
411431 p := parser .NewXMLParser (stream )
432+ p .RemoveErrorListeners ()
433+ p .AddErrorListener (liste )
412434 listener := & InheritParentXMLListener {
413435 pomPath : pomPath ,
414436 relativePomPath : relativePomPath ,
@@ -439,3 +461,15 @@ func GetInheritFixModelList(pomPath, relativePomPath, compName, compVersion, new
439461
440462 return models
441463}
464+
465+ type MyErrorListener struct {
466+ antlr.DefaultErrorListener
467+ suppress bool
468+ }
469+
470+ func (e * MyErrorListener ) SyntaxError (recognizer antlr.Recognizer , offendingSymbol interface {}, line , column int , msg string , an antlr.RecognitionException ) {
471+ if e .suppress {
472+ // 打印详细的错误信息
473+ //fmt.Printf("xxxxcccccc line %d:%d %s\n", line, column, msg)
474+ }
475+ }
0 commit comments