package segments

type Mvn struct {
	Language
}

func (m *Mvn) Enabled() bool {
	m.extensions = []string{"pom.xml"}
	m.tooling = map[string]*cmd{
		"mvn": {
			executable: "mvn",
			args:       []string{"--version"},
			regex:      `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)(?:-(?P<prerelease>[a-z]+-[0-9]+))?))`,
		},
	}
	m.defaultTooling = []string{"mvn"}
	m.versionURLTemplate = "https://github.com/apache/maven/releases/tag/maven-{{ .Full }}"

	mvnw, err := m.env.HasParentFilePath("mvnw", false)
	if err == nil {
		m.tooling["mvn"].executable = mvnw.Path
	}

	return m.Language.Enabled()
}

func (m *Mvn) Template() string {
	return languageTemplate
}
