@@ -13,14 +13,12 @@ import (
1313 "strings"
1414
1515 "github.com/aws/amazon-cloudwatch-agent/internal/detector"
16+ "github.com/aws/amazon-cloudwatch-agent/internal/detector/common"
1617 "github.com/aws/amazon-cloudwatch-agent/internal/detector/util"
1718 "github.com/aws/amazon-cloudwatch-agent/internal/util/collections"
1819)
1920
2021const (
21- extJAR = ".jar"
22- extWAR = ".war"
23-
2422 // metaManifestFile is the path to the Manifest in the Java archive.
2523 metaManifestFile = "META-INF/MANIFEST.MF"
2624 // metaManifestSeparator is the separator of the key/value pairs in the file.
@@ -186,7 +184,7 @@ func newArchiveManifestNameExtractor(logger *slog.Logger) argNameExtractor {
186184// Extract opens the archive and reads the manifest file. Tries to extract the name from values of specific keys in the
187185// manifest. Prioritizes keys in the order defined in the extractor.
188186func (e * archiveManifestNameExtractor ) Extract (ctx context.Context , process detector.Process , arg string ) (string , error ) {
189- if ! strings .HasSuffix (arg , extJAR ) && ! strings .HasSuffix (arg , extWAR ) {
187+ if ! strings .HasSuffix (arg , common . ExtJAR ) && ! strings .HasSuffix (arg , common . ExtWAR ) {
190188 return "" , detector .ErrIncompatibleExtractor
191189 }
192190 fallback := strings .TrimSuffix (filepath .Base (arg ), filepath .Ext (arg ))
@@ -232,11 +230,12 @@ func (e *archiveManifestNameExtractor) readManifest(jarPath string) (string, err
232230
233231func parseManifest (r io.Reader , fieldPriority []string , fieldLookup collections.Set [string ]) string {
234232 manifest := make (map [string ]string , len (fieldPriority ))
235- _ = util .ReadProperties (r , metaManifestSeparator , func (key , value string ) bool {
233+ _ = util .ScanProperties (r , metaManifestSeparator , func (key , value string ) bool {
236234 if ! fieldLookup .Contains (key ) || value == "" {
237235 return true
238236 }
239237 manifest [key ] = value
238+ // stop scanning if the highest priority field is found.
240239 return key != fieldPriority [0 ]
241240 })
242241 for _ , field := range fieldPriority {
0 commit comments