Documentation
¶
Overview ¶
Package maven implements Maven build tool support for Java projects. Ported from pombump with enhancements for the unified omnibump architecture.
Index ¶
- Constants
- Variables
- func IsMavenPom(path string) (bool, error)
- func ParsePom(pomPath string) (*gopom.Project, error)
- func PatchProject(ctx context.Context, project *gopom.Project, patches []Patch, ...) (*gopom.Project, error)
- func UpdatePom(ctx context.Context, pomPath string, patches []Patch, ...) ([]byte, error)
- type Maven
- func (m *Maven) Detect(ctx context.Context, dir string) (bool, error)
- func (m *Maven) GetAnalyzer() analyzer.Analyzer
- func (m *Maven) GetManifestFiles() []string
- func (m *Maven) Name() string
- func (m *Maven) Update(ctx context.Context, cfg *languages.UpdateConfig) error
- func (m *Maven) Validate(ctx context.Context, cfg *languages.UpdateConfig) error
- type MavenAnalyzer
- func (ma *MavenAnalyzer) Analyze(ctx context.Context, projectPath string) (*analyzer.AnalysisResult, error)
- func (ma *MavenAnalyzer) AnalyzeRemote(ctx context.Context, files map[string][]byte) (*analyzer.RemoteAnalysisResult, error)
- func (ma *MavenAnalyzer) RecommendStrategy(ctx context.Context, analysis *analyzer.AnalysisResult, ...) (*analyzer.Strategy, error)
- type Patch
- type PatchList
- type PropertyList
- type PropertyPatch
Constants ¶
const ( // MaxPatchFileSize limits patch/properties file size to prevent resource exhaustion. MaxPatchFileSize = 10 * 1024 * 1024 // 10 MB // MaxPomFileSize limits POM file size to prevent resource exhaustion. MaxPomFileSize = 10 * 1024 * 1024 // 10 MB )
Default scope and type for a dependency.
const (
// DefaultManifestFile is the conventional Maven POM filename.
DefaultManifestFile = "pom.xml"
)
Variables ¶
var ( // ErrInvalidVersion is returned when a version string fails validation. ErrInvalidVersion = errors.New("invalid version string") // ErrPomNotFound is returned when pom file is not found. ErrPomNotFound = errors.New("pom file not found") // ErrPropertyValidationFailed is returned when property validation fails. ErrPropertyValidationFailed = errors.New("property validation failed") // ErrRemoteAnalysisNotImplemented is returned when remote analysis is not implemented. ErrRemoteAnalysisNotImplemented = errors.New("remote analysis not yet implemented") // ErrMissingRequiredFields is returned when a dependency is missing groupId or artifactId. ErrMissingRequiredFields = errors.New("missing required fields for dependency") // ErrNotMavenPOM is returned when a file is not a valid Maven POM. ErrNotMavenPOM = errors.New("file is not a valid Maven POM") // ErrNoPOMsFound is returned when no Maven POM files are found in the project tree. ErrNoPOMsFound = errors.New("no Maven POM files found") )
var ( // ErrProjectNil is returned when a POM project is nil. ErrProjectNil = errors.New("project is nil") // ErrFileTooLarge is returned when a file exceeds size limits. ErrFileTooLarge = errors.New("file too large") // ErrInvalidDependencyFormat is returned when a dependency string has invalid format. ErrInvalidDependencyFormat = errors.New("invalid dependencies format") // ErrInvalidPropertyFormat is returned when a property string has invalid format. ErrInvalidPropertyFormat = errors.New("invalid properties format") // ErrPropertyNotFound is returned when a property patch cannot be applied to // the current POM or its local parent POM chain. ErrPropertyNotFound = errors.New("property not found") // ErrUnsafePomPath is returned when an update would write outside the // configured Maven project root. It is an alias for pathutil.ErrUnsafePath. ErrUnsafePomPath = pathutil.ErrUnsafePath // ErrVersionConflict is returned when two updates try to set different // versions for the same dependency or property-backed dependency set. ErrVersionConflict = errors.New("conflicting version update detected") )
Functions ¶
func IsMavenPom ¶
IsMavenPom reports whether path is a Maven POM by parsing the XML and checking that the root element is <project> with the Maven namespace. Returns an error if the file cannot be opened or is not valid XML.
func PatchProject ¶
func PatchProject(ctx context.Context, project *gopom.Project, patches []Patch, propertyPatches map[string]string) (*gopom.Project, error)
PatchProject applies dependency and property patches to a parsed pom.xml. project is a gopom.Project — a Go struct that mirrors the Maven POM XML schema and can be round-tripped back to XML via project.Marshal().
Types ¶
type Maven ¶
type Maven struct{}
Maven implements the BuildTool interface for Maven projects.
func (*Maven) GetAnalyzer ¶
GetAnalyzer returns the Maven analyzer.
func (*Maven) GetManifestFiles ¶
GetManifestFiles returns Maven manifest files.
type MavenAnalyzer ¶
type MavenAnalyzer struct{}
MavenAnalyzer implements the Analyzer interface for Maven projects. Ported from pombump/pkg/analyzer.go.
func (*MavenAnalyzer) Analyze ¶
func (ma *MavenAnalyzer) Analyze(ctx context.Context, projectPath string) (*analyzer.AnalysisResult, error)
Analyze performs dependency analysis on a Maven project.
func (*MavenAnalyzer) AnalyzeRemote ¶
func (ma *MavenAnalyzer) AnalyzeRemote(ctx context.Context, files map[string][]byte) (*analyzer.RemoteAnalysisResult, error)
AnalyzeRemote performs dependency analysis on remotely-fetched Maven pom.xml files. files is a map from relative path (e.g. "pom.xml", "parent/pom.xml") to file content.
func (*MavenAnalyzer) RecommendStrategy ¶
func (ma *MavenAnalyzer) RecommendStrategy(ctx context.Context, analysis *analyzer.AnalysisResult, deps []analyzer.Dependency) (*analyzer.Strategy, error)
RecommendStrategy suggests whether to use properties or direct patches.
type Patch ¶
type Patch struct {
GroupID string `json:"groupId" yaml:"groupId"`
ArtifactID string `json:"artifactId" yaml:"artifactId"`
Version string `json:"version" yaml:"version"`
Scope string `json:"scope,omitempty" yaml:"scope,omitempty"`
Type string `json:"type,omitempty" yaml:"type,omitempty"`
// Classifier selects which classifier variants of an artifact the patch
// governs:
// - unset/empty: every variant — the classifier-less dependency and all
// classifier'd ones (e.g. all of netty's native transports at once).
// - "none" (classifierNone): only the classifier-less dependency. Use this
// to pin just the plain artifact when classifier'd siblings also exist.
// - a value (e.g. osx-x86_64): only that exact classifier.
Classifier string `json:"classifier,omitempty" yaml:"classifier,omitempty"`
}
Patch represents a Maven dependency patch. Ported from pombump/pkg/patch.go.
type PatchList ¶
type PatchList struct {
Patches []Patch `json:"patches" yaml:"patches"`
}
PatchList represents a list of patches from a YAML file.
type PropertyList ¶
type PropertyList struct {
Properties []PropertyPatch `json:"properties" yaml:"properties"`
}
PropertyList represents a list of property patches from a YAML file.
type PropertyPatch ¶
type PropertyPatch struct {
Property string `json:"property" yaml:"property"`
Value string `json:"value" yaml:"value"`
}
PropertyPatch represents a property override.