Skip to content

Instantly share code, notes, and snippets.

@sgykfjsm
Created February 21, 2016 16:20
Show Gist options
  • Save sgykfjsm/c54070ee1b042a9c40ea to your computer and use it in GitHub Desktop.
Save sgykfjsm/c54070ee1b042a9c40ea to your computer and use it in GitHub Desktop.
get plugin information from pom.xml
package main
import (
"encoding/xml"
"fmt"
"io/ioutil"
"log"
"os"
)
type PomXML struct {
XMLName xml.Name `xml:"project"`
BuildPlugin []PluginXML `xml:"build>plugins>plugin"`
ReportPlugin []PluginXML `xml:"reporting>plugins>plugin"`
ProfilesPlugin []PluginXML `xml:"profiles>profile>build>plugins>plugin"`
}
type PluginXML struct {
GroupId string `xml:"groupId"`
ArtifactID string `xml:"artifactId"`
Version string `xml:"version"`
}
func FatalIfNotNil(e error) {
if e != nil {
log.Fatal(e)
}
}
func main() {
xmlFile := "pom.xml"
f, err := os.Open(xmlFile)
FatalIfNotNil(err)
defer f.Close()
content, err := ioutil.ReadAll(f)
FatalIfNotNil(err)
var pomXML PomXML
err = xml.Unmarshal(content, &pomXML)
FatalIfNotNil(err)
for i := range pomXML.BuildPlugin {
fmt.Printf("%#v\n", pomXML.BuildPlugin[i])
}
println("---")
for i := range pomXML.ReportPlugin {
fmt.Printf("%#v\n", pomXML.ReportPlugin[i])
}
println("---")
for i := range pomXML.ProfilesPlugin {
fmt.Printf("%#v\n", pomXML.ProfilesPlugin[i])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment