linetracker

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2026 License: Apache-2.0, BSD-3-Clause, MIT Imports: 7 Imported by: 0

Documentation

Overview

Package linetracker provides utilities and custom structs to parse pom.xml files for the purpose of tracking line numbers of dependency declarations.

The default Go XML parser will not track the offset or line numbers of the XML elements, so we need to implement a custom solution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindLineNumber

func FindLineNumber(args FindLineNumberArgs) int

FindLineNumber attempts to find the line number of a resolved dependency in the raw XML.

There are three attempts to do a match:

  1. Exact Match: Scans for a raw dependency matching the exact groupID, artifactID, version (if hardcoded), type, and classifier.
  2. Placeholder Match: Scans for raw dependencies where values use variable placeholders (e.g., org.${group}.common) matching the resolved coordinates.
  3. Parent Fallback: If no match is found (e.g., dependency inherited from a parent POM), attributes the location to the <parent> declaration.

If none of these succeed, the line number is set to 0.

func ParentLine

func ParentLine(content []byte) int

ParentLine scans the raw XML for the <parent> tag. If present, it calculates and returns its starting line number.

Types

type Dependency

type Dependency struct {
	GroupID    string `xml:"groupId"`
	ArtifactID string `xml:"artifactId"`
	Version    string `xml:"version"`
	Type       string `xml:"type"`
	Classifier string `xml:"classifier"`
	Offset     int64  `xml:"-"`
	Line       int    `xml:"-"`
}

Dependency captures the line location and byte offset of a dependency as written in the XML file.

func RawDependencyLinesList

func RawDependencyLinesList(content []byte) []*Dependency

RawDependencyLinesList parses the raw XML content to find all dependency declarations and calculate their line numbers based on their byte offsets.

func (*Dependency) UnmarshalXML

func (td *Dependency) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML is implicitly called by Go's xml.Decoder to parse each <dependency> block. It intercepts decoding to record the tag's exact byte offset in the file.

type FindLineNumberArgs

type FindLineNumberArgs struct {
	GroupID    string
	ArtifactID string
	Version    string
	DepType    string
	Classifier string
	// RawDeps is the list of all raw dependency declarations extracted from the XML file.
	RawDeps []*Dependency
	// UsedRawDeps is a reservation table of raw dependency indices to prevent duplicate mappings.
	UsedRawDeps map[int]bool
	// ParentLine is the starting line of the <parent> block, used as a fallback for inherited dependencies.
	ParentLine int
	// InputPath is the absolute filesystem path of the child pom.xml, used for logging warnings.
	InputPath string
}

FindLineNumberArgs encapsulates all parameters required by the line-matching algorithm.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL