Ejemplo n.º 1
0
func main() {
	r, err := mavencentral.GetArtifact("com.google.inject", "guice", "3.0", "javadoc")
	if err != nil {
		panic(err)
	}
	defer r.Close()
	file, err := os.Create("/tmp/dl")
	if err != nil {
		panic(err)
	}
	defer file.Close()
	io.Copy(file, r)
}
Ejemplo n.º 2
0
func Create(groupId, artifactId, version string, w io.WriteCloser) error {
	defer w.Close()

	log.Infof("Creating docset for %s:%s:%s", groupId, artifactId, version)
	stream, err := mavencentral.GetArtifact(groupId, artifactId, version, "javadoc")
	if err != nil {
		return err
	}
	defer stream.Close()
	file, err := ioutil.TempFile("", "javadocsetartifact")
	if err != nil {
		return err
	}
	defer file.Close()
	defer os.Remove(file.Name())

	io.Copy(file, stream)

	javadocDir, err := ioutil.TempDir("", "javadocsetartifact")
	if err != nil {
		return err
	}
	defer os.RemoveAll(javadocDir)

	docsetDir, err := ioutil.TempDir("", "javadocset")
	if err != nil {
		return err
	}
	defer os.RemoveAll(docsetDir)

	log.Debugf("Unzipping javadoc from %s into %s", file.Name(), javadocDir)
	if err := unzip(file.Name(), javadocDir); err != nil {
		return err
	}

	log.Debug("Building javadocset in ", docsetDir)
	if err := javadocset.Build(javadocDir, docsetDir, artifactId); err != nil {
		return err
	}

	gw := gzip.NewWriter(w)
	defer gw.Close()

	return tarDir(filepath.Join(docsetDir, artifactId+".docset"), gw)
}