From 0c360c65cf6239e4e6b7233692f39e4ca6669d60 Mon Sep 17 00:00:00 2001 From: Bert Frees Date: Sat, 26 Oct 2024 12:27:58 +0200 Subject: [PATCH] Delete updater subrepos --- README.md | 3 - pom.xml | 1 - updater/.build/after_success.sh | 9 - updater/.build/assembly.xml | 18 -- updater/.build/settings.xml | 116 -------- updater/.gitignore | 16 -- updater/.gitrepo | 11 - updater/.travis.yml | 17 -- updater/Makefile | 67 ----- updater/README.md | 45 --- updater/artifacts.go | 230 --------------- updater/artifacts_test.go | 346 ----------------------- updater/diff.go | 82 ------ updater/diff_test.go | 106 ------- updater/log.go | 16 -- updater/log_test.go | 37 --- updater/pom.xml | 72 ----- updater/release_descriptor.go | 176 ------------ updater/release_descriptor_test.go | 267 ----------------- updater/testserver/main.go | 13 - updater/testserver/releaseDescriptor.xml | 145 ---------- updater/updater.go | 113 -------- updater/updater_test.go | 83 ------ updater/xml_test.go | 52 ---- 24 files changed, 2041 deletions(-) delete mode 100755 updater/.build/after_success.sh delete mode 100644 updater/.build/assembly.xml delete mode 100644 updater/.build/settings.xml delete mode 100644 updater/.gitignore delete mode 100644 updater/.gitrepo delete mode 100644 updater/.travis.yml delete mode 100644 updater/Makefile delete mode 100644 updater/README.md delete mode 100644 updater/artifacts.go delete mode 100644 updater/artifacts_test.go delete mode 100644 updater/diff.go delete mode 100644 updater/diff_test.go delete mode 100644 updater/log.go delete mode 100644 updater/log_test.go delete mode 100644 updater/pom.xml delete mode 100644 updater/release_descriptor.go delete mode 100644 updater/release_descriptor_test.go delete mode 100644 updater/testserver/main.go delete mode 100644 updater/testserver/releaseDescriptor.xml delete mode 100644 updater/updater.go delete mode 100644 updater/updater_test.go delete mode 100644 updater/xml_test.go diff --git a/README.md b/README.md index 0fc6e9f3fd..a6ddb6c768 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,6 @@ The tree below shows the structure of the project: - [liblouis-java](https://github.com/liblouis/liblouis-java) - [osgi-libs](https://github.com/daisy/osgi-libs) - [modules](https://github.com/daisy/pipeline-modules) -- updater - - [cli](https://github.com/daisy/pipeline-updater) - - [gui](https://github.com/daisy/pipeline-updater-gui) - [ui](https://github.com/daisy/pipeline-ui) - utils - [build-utils](https://github.com/daisy/pipeline-build-utils) diff --git a/pom.xml b/pom.xml index 49bce5f4a0..191c9b55a3 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,6 @@ framework modules cli - updater assembly website/target/maven clientlib/java diff --git a/updater/.build/after_success.sh b/updater/.build/after_success.sh deleted file mode 100755 index 69d2dce848..0000000000 --- a/updater/.build/after_success.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then - make cover-deploy - make dist - mvn deploy -DskipTests -Dinvoker.skip=true --settings .build/settings.xml -else - echo "Skipping deploy tasks." -fi diff --git a/updater/.build/assembly.xml b/updater/.build/assembly.xml deleted file mode 100644 index 7a1884bdda..0000000000 --- a/updater/.build/assembly.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - ${item} - - zip - - false - - - build/bin/${item} - - pipeline-updater* - - / - 0755 - - - diff --git a/updater/.build/settings.xml b/updater/.build/settings.xml deleted file mode 100644 index 2dce989447..0000000000 --- a/updater/.build/settings.xml +++ /dev/null @@ -1,116 +0,0 @@ - - - - - - - - - - sonatype-nexus-snapshots - ${env.CI_DEPLOY_USERNAME} - ${env.CI_DEPLOY_PASSWORD} - - - - - - - standard-with-extra-repos - - true - - - - sonatype - OSS Sonatype repo (releases) - - true - always - warn - - - false - never - fail - - https://oss.sonatype.org/content/repositories/releases/ - - - sonatype-snapshots - OSS Sonatype repo (snapshots) - - false - always - warn - - - true - never - fail - - https://oss.sonatype.org/content/repositories/snapshots/ - - - sonatype-apache - Apache repo (releases) - - true - always - warn - - - false - never - fail - - https://repository.apache.org/releases/ - - - apache-snapshots - ASF repo (snapshots) - - false - never - warn - - - true - always - fail - - https://repository.apache.org/snapshots/ - - - codehaus-snapshots - Codehaus (snapshots) - - false - always - warn - - - true - never - fail - - https://nexus.codehaus.org/snapshots/ - - - - - staging-repos - - - sonatype-staging - https://oss.sonatype.org/content/groups/staging - - - - - - - staging-repos - - - diff --git a/updater/.gitignore b/updater/.gitignore deleted file mode 100644 index 807edd2fe6..0000000000 --- a/updater/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -#test builds -*.test - -#coverage files -coverage.* -#vim files -*.sw? - -#ctags files -tags -#bins - -#build directories -build -target - diff --git a/updater/.gitrepo b/updater/.gitrepo deleted file mode 100644 index 16871f0d05..0000000000 --- a/updater/.gitrepo +++ /dev/null @@ -1,11 +0,0 @@ -; DO NOT EDIT (unless you know what you are doing) -; -; This subdirectory is a git "subrepo", and this file is maintained by the -; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme -; -[subrepo] - remote = git@github.com:daisy/pipeline-updater.git - branch = master - commit = 1f7e137ae26f89156c1ec183978ed6a90ac83d34 - parent = 2f79dd24f7215cac73dcf6248966eb9a002cc3c7 - cmdver = 0.3.1 diff --git a/updater/.travis.yml b/updater/.travis.yml deleted file mode 100644 index aaa294954f..0000000000 --- a/updater/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -language: go - -go: - - 1.5 - -after_success: - - .build/after_success.sh - -# whitelist; only deploy master branch -branches: - only: - - master - -env: - global: - - secure: "fh6uYTjqFq6J9sT2XeAIjSMNRaycbcD4hgqBhOm3GbZsrUP90G24RwkI+lglccC27h/TwgdMvS8uljFgPkZW8gSX08wIvuEBRhZnvf95Z4Bm6DOBH7MpYH46UKTqYe0MswwU0dwEJz98yAPd9+Ohte+lL5tkJnEUFVLDjUQYkUo=" - - secure: "DadC/IxfZk1dOCB3aXuxajJtFMnb1c0dgPWeJOLxySQdER23pxIQYI5OjCJIr/bSmMV39K9aaYK/fc237wr3nveR7jkID+WAz4xJSTK13igeVAr5OSca5lrxAqSJWJkrVz8+qiJnw8restG3uwQ4QJm0OagaHCBjKr5314Rn5ZY=" diff --git a/updater/Makefile b/updater/Makefile deleted file mode 100644 index 7e2d777f09..0000000000 --- a/updater/Makefile +++ /dev/null @@ -1,67 +0,0 @@ -BUILDDIR := ${CURDIR}/build -GOPATH := ${BUILDDIR} -GO := env GOPATH="${GOPATH}" go -GOX := env GOPATH="${GOPATH}" ${GOPATH}/bin/gox -GOVERALLS := env GOPATH="${GOPATH}" ${GOPATH}/bin/goveralls - - -define HELP_TEXT -Available targets: - help this help - clean clean up - all build binaries - build build all - build-updater build dp2 tool - dist build x-platform binaries - test run tests with coverage - cover-deploy deploy test coverage results -endef -export HELP_TEXT - -.PHONY: help clean build-setup build dist test cover-deploy all - -all: build - -help: - @echo "$$HELP_TEXT" - -clean: - -rm -rf "${BUILDDIR}" - -build: test build-updater - -build-setup: - @export GOPATH="${GOPATH}" - @echo "Getting dependencies..." - @mkdir -p "${GOPATH}/src/github.com/capitancambio" - @test -d "${GOPATH}/src/github.com/capitancambio/pipeline-updater" || ln -s "${CURDIR}" "${GOPATH}/src/github.com/capitancambio/pipeline-updater" - @${GO} get github.com/kardianos/osext - @${GO} get github.com/blang/semver - @${GO} get github.com/smartystreets/goconvey - @${GO} get golang.org/x/tools/cmd/cover - -build-updater: build-setup - @echo "Building updater..." - @${GO} install ${GOBUILD_FLAGS} github.com/capitancambio/pipeline-updater - - -dist: build-setup test - @echo "Building for x-platform..." - @${GO} get github.com/mitchellh/gox - #@${GOX} -build-toolchain \ - #-osarch="linux/amd64 linux/386 darwin/386 darwin/amd64 windows/386 windows/amd64" - @${GOX} -output="${GOPATH}/bin/{{.OS}}_{{.Arch}}/pipeline-updater" \ - -osarch="linux/amd64 linux/386 darwin/386 darwin/amd64 windows/386 windows/amd64" \ - - -test: build-setup - @echo "Running tests..." - @${GO} test -covermode=atomic -coverprofile=${BUILDDIR}/profile.cov \ - github.com/capitancambio/pipeline-updater - -cover-deploy: test - @${GO} get github.com/modocache/gover - @${GO} get github.com/mattn/goveralls - @${GOVERALLS} \ - -coverprofile=${BUILDDIR}/profile.cov \ - -service=travis-ci diff --git a/updater/README.md b/updater/README.md deleted file mode 100644 index b0757725ad..0000000000 --- a/updater/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# pipeline-updater - -Pipeline automatic updater program - -## How it works - -The **release descriptor** contains the list of artefacts for a release. It is an XML file that is generated in pipeline-assembly. - -- `href` is the address of this file -- `version` is the version linked to this releases -- `time` is the moment that this release descriptor was built - -Nested to the releaseDescriptor we find elements of the type artifacts, with the following attributes: - -- `href` where to get this artefact, usually a maven central URL. -- `id` formed using `${groupId}/${artifactId}` -- `deployPath` where to store the artefact, e.g. `system/framework/org.daisy.libs.jing-1.0.3.jar` -- `extract` a boolean value indicating if this file should extract in the deploy path instead of just copying it -- `overwrite-path` -- `artifactId` -- `groupId` -- `version` -- `classifier` - -pipeline-assembly has a script for publishing the descriptor to http://daisy.github.io/pipeline-assembly/releases/. - -The structure is the following: http://daisy.github.io/pipeline-assembly/releases/ contains all the release descriptors, each identified by its version, e.g. "10.0.1-SNAPSHOT", and two special releases called "current" for the latest release and "snapshot" for the latest snapshot. (Apparently "latest" has some kind of special meaning for Github pages, and will not allow accessing resources that name, thus the current key word.) - -The updater CLI is in https://github.com/daisy/pipeline-updater, and it's also used by the GUI. This is the help: - - Usage of ./pipeline-updater: - -descriptor string - Current descriptor - -force - Forces to update without comparing the versions, use if updating to nightly builds - -install-dir string - Pipeline install directory - -service string - Url of the update service (default "http://defaultservice.com") - -version string - Version to update to (default "current") - -Basically what the CLI does is to compare the local descriptor with the version passed as parameter and will compute the differences, deleting and updating the need artefacts. In the special case of updating the snapshots, that are nightly builds, force the update as the version of the release descriptor will be the same in the local release descriptor and the remote snapshot. - -The GUI for the updater consists of a simple wrapper for the CLI. In Windows it has to be in a separate executable due to the permissions restrictions that break the user experience. In Linux and MacOs it is in the same GUI as the Pipeline itself. diff --git a/updater/artifacts.go b/updater/artifacts.go deleted file mode 100644 index af6b500b3f..0000000000 --- a/updater/artifacts.go +++ /dev/null @@ -1,230 +0,0 @@ -package main - -import ( - "archive/zip" - "encoding/xml" - "fmt" - "io" - "log" - "net/http" - "os" - "path/filepath" - "time" -) - -//Downloader contract -type Downloader interface { - Download(o io.Writer) error -} - -//Struct that contains the information about an artifact -type Artifact struct { - XMLName xml.Name `xml:"artifact"` - Id string `xml:"id,attr"` //the artifact id - Href string `xml:"href,attr"` //Artifact address - Version string `xml:"version,attr"` //version - DeployPath string `xml:"deployPath,attr"` //relative path where to copy the artifact file - Extract bool `xml:"extract,attr"` //tells if the artifact should be extracted - Classifier string `xml:"classifier,attr"` //classifier -} - -//downloads the artifact from href -func (a Artifact) Download(w io.Writer) error { - //check sanity - if a.DeployPath == "" { - Error("%s no deploy path", a) - return fmt.Errorf("DeployPath not set") - } - if a.Href == "" { - Error("%s no href", a) - return fmt.Errorf("No Href not set") - } - Info("%s downloading from %s", a, a.Href) - t := time.Now() - resp, err := http.Get(a.Href) - if err != nil { - Error("%s error while downloading", a) - return err - } - if resp.StatusCode > 300 { - Error("%s error while downloading", a) - return fmt.Errorf("Server %v returned an invalid status %d", a.Href, resp.StatusCode) - } - defer resp.Body.Close() - _, err = io.Copy(w, resp.Body) - Info("%s downloaded in %v", a, time.Since(t)) - return err -} - -//String for logging -func (a Artifact) String() string { - return fmt.Sprintf("Artifact %v:%v :", a.Id, a.Version) -} - -//An artifact that is present in the local fs -type LocalArtifact struct { - Artifact - Path string -} - -//Removes this copy of the artifact -func (la LocalArtifact) Clean() error { - Info("%s deleting", la) - return os.Remove(la.Path) - -} - -func (la LocalArtifact) Unzip(path string) error { - absolute := filepath.Join(path, la.DeployPath) - os.MkdirAll(filepath.Dir(absolute), 0755) - z, err := zip.OpenReader(la.Path) - if err != nil { - return err - } - for _, zEntry := range z.File { - zC, err := zEntry.Open() - if err != nil { - return err - } - defer zC.Close() - extrPath := filepath.Join(absolute, zEntry.Name) - Info("extracting %s to %s", zEntry.Name, extrPath) - os.MkdirAll(filepath.Dir(extrPath), 0755) - f, err := os.Create(extrPath) - if err != nil { - return err - } - defer f.Close() - err = os.Chmod(extrPath, zEntry.Mode()) - if err != nil { - Error("%s setting file permissions", err) - } - _, err = io.Copy(f, zC) - if err != nil { - return err - } - } - - return nil -} - -//Copies the artifact having as root directory the path -func (la LocalArtifact) Copy(path string) error { - absolute := filepath.Join(path, la.DeployPath) - Info("%s copying to %s", la, absolute) - os.MkdirAll(filepath.Dir(absolute), 0755) - out, err := os.Create(absolute) - if err != nil { - Error("%s could not create file %s", la, absolute) - return err - } - defer out.Close() - in, err := os.Open(la.Path) - if err != nil { - Error("%s could not open local file %s", la, la.Path) - return err - } - defer in.Close() - _, err = io.Copy(out, in) - if err != nil { - Error("%s copying file", la) - } else { - Info("%s copied", la) - } - - return err -} - -//convienice struct for storing download results -type downloadResult struct { - la LocalArtifact - err error -} - -//downloads the artifacts to the given path -func Download(path string, as ...Artifact) ([]LocalArtifact, error) { - locals := make([]LocalArtifact, 0, len(as)) - errors := []error{} - - chanArts := make(chan downloadResult) - chanFiles := make(chan bool, 100) // max 100 downloads at a time - //do it async to go faster!! - for _, artifact := range as { - //local copy - a := artifact - go func(chanFiles chan bool) { - result := downloadResult{ - la: LocalArtifact{ - Artifact: a, - }, - } - - //create file - path := filepath.Join(path, a.DeployPath) - os.MkdirAll(filepath.Dir(path), 0755) - chanFiles <- true - f, err := os.Create(path) - defer func(f *os.File, chanFiles chan bool) { - f.Close() - <-chanFiles - }(f, chanFiles) - if err != nil { - result.err = err - chanArts <- result - return - } - log.Println("Downloading ", a.Id, "to", path) - //download file - if err := a.Download(f); err != nil { - result.err = err - chanArts <- result - } - //store the file name - result.la.Path = f.Name() - chanArts <- result - }(chanFiles) - - } - for i := 0; i < len(as); i++ { - res := <-chanArts - if res.err == nil { - locals = append(locals, res.la) - } else { - errors = append(errors, res.err) - } - } - if len(errors) != 0 { - return []LocalArtifact{}, fmt.Errorf("Errors while downloading %v", errors) - } - return locals, nil -} - -func Remove(las []LocalArtifact) (ok bool, errs []error) { - fn := func(l LocalArtifact) error { - return l.Clean() - } - return apply(las, fn) -} - -//Deploys a local artifact, it copies the file or extracts it to the given path -//depending on whether the artifact is marked to do so -func Deploy(las []LocalArtifact, path string) (ok bool, errs []error) { - fn := func(l LocalArtifact) error { - if l.Extract { - return l.Unzip(path) - } else { - return l.Copy(path) - } - } - return apply(las, fn) -} - -func apply(las []LocalArtifact, fn func(LocalArtifact) error) (ok bool, errs []error) { - errs = []error{} - for _, la := range las { - if err := fn(la); err != nil { - errs = append(errs, err) - } - } - return len(errs) == 0, errs -} diff --git a/updater/artifacts_test.go b/updater/artifacts_test.go deleted file mode 100644 index d7f0f995f8..0000000000 --- a/updater/artifacts_test.go +++ /dev/null @@ -1,346 +0,0 @@ -package main - -import ( - "archive/zip" - "bytes" - "fmt" - "io/ioutil" - "net/http" - "net/http/httptest" - "os" - "path/filepath" - "strings" - "testing" - - . "github.com/smartystreets/goconvey/convey" -) - -func TestDownloadArtifact(t *testing.T) { - Convey("Let's try to download some artifacts", t, func() { - Convey("First we need to check the artifiact's sanity", func() { - w := bytes.NewBuffer([]byte{}) - Convey("If no href is set we get a error", func() { - a := Artifact{ - Id: "1", - Version: "2.0.1", - DeployPath: "dir", - } - So(a.Download(w), ShouldNotBeNil) - }) - Convey("If no deploy path is set we get a error", func() { - a := Artifact{ - Id: "1", - Version: "2.0.1", - Href: "www.google.com", - } - So(a.Download(w), ShouldNotBeNil) - }) - - }) - Convey("We simulate an error by connecting a nonexisting server", func() { - - Convey("And try to download the artifact data from it", func() { - a := Artifact{ - DeployPath: "folder", - Href: "www.nonexisitingurlfortestingpurporses.com/artifact", - } - buf := bytes.NewBuffer([]byte{}) - err := a.Download(buf) - Convey("We get an error", func() { - So(err, ShouldNotBeNil) - - }) - - }) - - }) - Convey("Let's start a test server", func() { - testMsg := "hola caracola!" - - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - fmt.Fprint(w, testMsg) - })) - defer ts.Close() - Convey("And download the artifact data from it", func() { - a := Artifact{ - DeployPath: "folder", - Href: ts.URL, - } - buf := bytes.NewBuffer([]byte{}) - err := a.Download(buf) - So(err, ShouldBeNil) - Convey("Check that the data is ok", func() { - So(buf.String(), ShouldEqual, testMsg) - - }) - - }) - - }) - Convey("We start a test server that returns a HTTP error", func() { - - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(404) - })) - defer ts.Close() - Convey("And try to data from it", func() { - a := Artifact{ - DeployPath: "folder", - Href: ts.URL, - } - buf := bytes.NewBuffer([]byte{}) - err := a.Download(buf) - Convey("We get an error", func() { - So(err, ShouldNotBeNil) - }) - - }) - - }) - - }) -} -func TestDownload(t *testing.T) { - Convey("Having a test server", t, func() { - id1Hit := false - id2Hit := false - fail := false - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if fail { - w.WriteHeader(500) - return - } - id := r.URL.Query().Get("id") - if id == "1" { - id1Hit = true - } - if id == "2" { - id2Hit = true - } - w.Write([]byte(id)) - })) - Convey("We create a couple of artifacts", func() { - as := []Artifact{ - Artifact{ - Id: "1", - DeployPath: "arts/1.txt", - Href: ts.URL + "?id=1", - }, - Artifact{ - Id: "2", - DeployPath: "arts/2.txt", - Href: ts.URL + "?id=2", - }, - } - - Convey("And a temporal directory", func() { - fail = false - path := os.TempDir() - Convey("And we download the local artifacts", func() { - las, err := Download(path, as...) - So(err, ShouldBeNil) - Convey("Both artifacts have been hit", func() { - So(id2Hit, ShouldBeTrue) - So(id1Hit, ShouldBeTrue) - Convey("We check the content of the local artifacts", func() { - - for _, la := range las { - //check the path - So(la.Path, ShouldEqual, filepath.Join(path, la.DeployPath)) - //the content of the file - f, err := os.Open(la.Path) - So(err, ShouldBeNil) - data, err := ioutil.ReadAll(f) - So(err, ShouldBeNil) - //the content is the id - So(string(data), ShouldEqual, la.Id) - - } - }) - - }) - - }) - Convey("And we download the local artifacts but foricing an error", func() { - fail = true - _, err := Download(path, as...) - So(err, ShouldNotBeNil) - Convey("Both artifacts have been hit", func() { - So(id2Hit, ShouldBeFalse) - So(id1Hit, ShouldBeFalse) - - }) - - }) - - }) - }) - Convey("An artifact with a bad DeplymentPath", func() { - as := []Artifact{ - Artifact{ - Id: "1", - DeployPath: "", - Href: ts.URL + "?id=1", - }, - } - - Convey("Try to download it", func() { - _, err := Download("", as...) - Convey("Error ensues!", func() { - So(err, ShouldNotBeNil) - - }) - }) - }) - }) -} - -func TestLocalArtifact(t *testing.T) { - Convey("Having a local artifact pointing to a file", t, func() { - f, err := ioutil.TempFile("", "pipeline-updater") - So(err, ShouldBeNil) - _, err = f.WriteString("HOLA") - So(err, ShouldBeNil) - err = f.Close() - So(err, ShouldBeNil) - la := LocalArtifact{ - Artifact: Artifact{ - Id: "1", - DeployPath: "larts/1.txt", - Href: "localhost.com/?id=1", - }, - Path: f.Name(), - } - Convey("We Copy the file", func() { - dir := os.TempDir() - la.Copy(dir) - Convey("Open the copy", func() { - f, err := os.Open(filepath.Join(dir, la.DeployPath)) - So(err, ShouldBeNil) - fmt.Printf("f.Name() %+v\n", f.Name()) - data, err := ioutil.ReadAll(f) - Convey("The contents should be equal", func() { - So(string(data), ShouldEqual, "HOLA") - Convey("Then clean the artifact", func() { - err := la.Clean() - So(err, ShouldBeNil) - Convey("The file is not there anymore", func() { - _, err := os.Stat(la.Path) - So(err, ShouldNotBeNil) - - }) - - }) - - }) - }) - }) - - }) - Convey("Having a local artifact pointing to a zipfile", t, func() { - f, err := ioutil.TempFile("", "pipeline-updater") - So(err, ShouldBeNil) - z := zip.NewWriter(f) - //one entry - zw, err := z.Create("one") - So(err, ShouldBeNil) - _, err = zw.Write([]byte("one")) - So(err, ShouldBeNil) - //second entry - zw, err = z.Create("two") - So(err, ShouldBeNil) - _, err = zw.Write([]byte("two")) - So(err, ShouldBeNil) - err = z.Close() - So(err, ShouldBeNil) - err = f.Close() - So(err, ShouldBeNil) - - la := LocalArtifact{ - Artifact: Artifact{ - Id: "1", - DeployPath: "zipped", - Href: "localhost.com/?id=1", - Extract: true, - }, - Path: f.Name(), - } - Convey("We extract the file", func() { - dir := os.TempDir() - la.Unzip(dir) - Convey("Walk the dir", func() { - files := map[string]string{} - err := filepath.Walk( - filepath.Join(dir, la.DeployPath), - func(path string, info os.FileInfo, err error) error { - if info != nil && info.IsDir() { - return nil - } - f, err := os.Open(path) - if err != nil { - return err - } - defer f.Close() - data, err := ioutil.ReadAll(f) - if err != nil { - return nil - } - files[strings.Trim(filepath.Base(path), string(filepath.Separator))] = string(data) - - return nil - }, - ) - So(err, ShouldBeNil) - Convey("Check that the files are extracted", func() { - f1, ok := files["one"] - So(ok, ShouldBeTrue) - So(f1, ShouldEqual, "one") - f2, ok := files["two"] - So(ok, ShouldBeTrue) - So(f2, ShouldEqual, "two") - - }) - }) - }) - - }) -} - -func TestApply(t *testing.T) { - Convey("Test the apply function", t, func() { - Convey("Having a bunch of local artifacts and a visting function", func() { - hits := 0 - fn := func(LocalArtifact) error { - hits++ - return nil - } - las := []LocalArtifact{ - LocalArtifact{}, - LocalArtifact{}, - LocalArtifact{}, - } - Convey("Make sure that visit them all", func() { - hits = 0 - ok, errs := apply(las, fn) - So(ok, ShouldBeTrue) - So(len(errs), ShouldEqual, 0) - So(hits, ShouldEqual, 3) - Convey("Let's error inside the function", func() { - hits := 0 - fn := func(LocalArtifact) error { - hits++ - return fmt.Errorf("Error!") - } - ok, errs := apply(las, fn) - So(ok, ShouldBeFalse) - So(len(errs), ShouldEqual, 3) - So(hits, ShouldEqual, 3) - - }) - }) - - }) - - }) -} diff --git a/updater/diff.go b/updater/diff.go deleted file mode 100644 index 7a818bbf47..0000000000 --- a/updater/diff.go +++ /dev/null @@ -1,82 +0,0 @@ -package main - -import "path/filepath" -import "runtime" -import "strings" - -//Differences between two release descriptors -type Diff struct { - New *Artifact - Old *Artifact -} - -//Gets the artifact to be downloaded from this difference -func (d Diff) ToDownload() (a Artifact, ok bool) { - if d.New != nil { - if strings.HasPrefix(d.New.Classifier, "linux") { - if runtime.GOOS != "linux" { - Info("Skipping %s with classifier %s since you're not running Linux", d.New.Id, d.New.Classifier) - ok = false - return - } - } else if (strings.HasPrefix(d.New.Classifier, "darwin") || strings.HasPrefix(d.New.Classifier, "mac")) { - if runtime.GOOS != "darwin" { - Info("Skipping %s with classifier %s since you're not running Mac OS", d.New.Id, d.New.Classifier) - ok = false - return - } - } else if strings.HasPrefix(d.New.Classifier, "win") { - if runtime.GOOS != "windows" { - Info("Skipping %s with classifier %s since you're not running Windows", d.New.Id, d.New.Classifier) - ok = false - return - } - } else if d.New.Classifier != "" { - Info("Including %s even though it has an unknown classifier: %s", d.New.Id, d.New.Classifier) - } - - a = *d.New - ok = true - } - return - -} - -//Gets the artifact that needs to be uninstalled from this diff -func (d Diff) ToRemove() (a Artifact, ok bool) { - if d.Old != nil { - a = *d.Old - ok = true - } - return -} - -//set of differences -type DiffSet []Diff - -//set of artifacts that need to be downloaded from the difference set -func (ds DiffSet) ToDownload() []Artifact { - as := []Artifact{} - for _, d := range ds { - if a, ok := d.ToDownload(); ok { - as = append(as, a) - } - } - return as - -} - -//set of artifacts that need to deleted from the local installation -func (ds DiffSet) ToRemove(installPath string) []LocalArtifact { - las := []LocalArtifact{} - for _, d := range ds { - if a, ok := d.ToRemove(); ok { - la := LocalArtifact{ - Artifact: a, - Path: filepath.Join(installPath, a.DeployPath), - } - las = append(las, la) - } - } - return las -} diff --git a/updater/diff_test.go b/updater/diff_test.go deleted file mode 100644 index 8eb7a4ddf5..0000000000 --- a/updater/diff_test.go +++ /dev/null @@ -1,106 +0,0 @@ -package main - -import ( - "path/filepath" - "testing" - - . "github.com/smartystreets/goconvey/convey" -) - -func TestDiff(t *testing.T) { - Convey("Having different diffs", t, func() { - Convey("If we have both new and old artifacts", func() { - d := Diff{ - New: &Artifact{Id: "new"}, - Old: &Artifact{Id: "old"}, - } - Convey("We need to download the new artifact", func() { - a, ok := d.ToDownload() - So(ok, ShouldBeTrue) - So(a, ShouldResemble, *d.New) - Convey("And remove the old artifact", func() { - a, ok := d.ToRemove() - So(ok, ShouldBeTrue) - So(a, ShouldResemble, *d.Old) - }) - - }) - - }) - - Convey("If have only a new artifact", func() { - d := Diff{ - New: &Artifact{Id: "new"}, - } - Convey("We need to download the new artifact", func() { - a, ok := d.ToDownload() - So(ok, ShouldBeTrue) - So(a, ShouldResemble, *d.New) - Convey("And we do NOT have to delete the old one", func() { - _, ok := d.ToRemove() - So(ok, ShouldBeFalse) - }) - - }) - - }) - Convey("If have only an old artifact", func() { - d := Diff{ - Old: &Artifact{Id: "old"}, - } - Convey("We need to download the new artifact", func() { - _, ok := d.ToDownload() - So(ok, ShouldBeFalse) - Convey("And we do NOT have to delete the old one", func() { - a, ok := d.ToRemove() - So(ok, ShouldBeTrue) - So(a, ShouldResemble, *d.Old) - }) - - }) - - }) - }) -} - -func TestDiffTest(t *testing.T) { - Convey("Having a diff set", t, func() { - ds := DiffSet{ - Diff{ - New: &Artifact{Id: "new1"}, - Old: &Artifact{Id: "old1", DeployPath: "arts1"}, - }, - Diff{ - New: &Artifact{Id: "new2"}, - }, - Diff{ - Old: &Artifact{Id: "old3", DeployPath: "arts3"}, - }, - } - Convey("Get the artifacts we need to download", func() { - toDownload := ds.ToDownload() - So(len(toDownload), ShouldEqual, 2) - Convey("Check that we have all the elements that we need", func() { - So(toDownload[0], ShouldResemble, Artifact{Id: "new1"}) - So(toDownload[1], ShouldResemble, Artifact{Id: "new2"}) - }) - - }) - Convey("Get the artifacts we need to delete", func() { - p := "rootpath" - toDelete := ds.ToRemove(p) - So(len(toDelete), ShouldEqual, 2) - Convey("Check that we have all the elements that we need", func() { - So(toDelete[0].Artifact, ShouldResemble, Artifact{Id: "old1", DeployPath: "arts1"}) - So(toDelete[1].Artifact, ShouldResemble, Artifact{Id: "old3", DeployPath: "arts3"}) - Convey("The paths should be be ready to clear", func() { - So(toDelete[0].Path, ShouldEqual, filepath.Join(p, "arts1")) - So(toDelete[1].Path, ShouldEqual, filepath.Join(p, "arts3")) - - }) - }) - - }) - - }) -} diff --git a/updater/log.go b/updater/log.go deleted file mode 100644 index 90682e4a5f..0000000000 --- a/updater/log.go +++ /dev/null @@ -1,16 +0,0 @@ -package main - -import ( - "fmt" - "io" - "os" -) - -var Output io.Writer = os.Stdout - -func Info(format string, vals ...interface{}) { - fmt.Fprintf(Output, fmt.Sprintf("[INFO] %s\n", format), vals...) -} -func Error(format string, vals ...interface{}) { - fmt.Fprintf(Output, fmt.Sprintf("[ERROR] %s\n", format), vals...) -} diff --git a/updater/log_test.go b/updater/log_test.go deleted file mode 100644 index f00c57758f..0000000000 --- a/updater/log_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package main - -import ( - "bytes" - "testing" - - . "github.com/smartystreets/goconvey/convey" -) - -func TestLogTest(t *testing.T) { - back := Output - defer func() { - Output = back - }() - Convey("Test different logging", t, func() { - Convey("Test info for an artifact", func() { - buf := bytes.NewBuffer([]byte{}) - Output = buf - a := Artifact{ - Id: "test", - Version: "1.0.0", - } - Info("%s log", a) - So(buf.String(), ShouldEqual, "[INFO] Artifact test:1.0.0 : log\n") - - }) - Convey("Test error for a release descriptor", func() { - buf := bytes.NewBuffer([]byte{}) - Output = buf - rd := NewEmptyReleaseDescriptor() - Error("%s log", rd) - So(buf.String(), ShouldEqual, "[ERROR] ReleaseDescriptor 0.0.0 log\n") - - }) - - }) -} diff --git a/updater/pom.xml b/updater/pom.xml deleted file mode 100644 index 3df887c614..0000000000 --- a/updater/pom.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - 4.0.0 - - - org.daisy - daisy - 4 - - - - org.daisy.pipeline - updater - 1.0.3-SNAPSHOT - pom - DAISY Pipeline 2 :: Updater Tool - This tools helps to fetch different libraries and dependencies in order to maintain the pipeline up to date. - - - - - org.codehaus.mojo - exec-maven-plugin - 1.5.0 - - - make-binaries - compile - - exec - - - make - dist - - - - - - com.soebes.maven.plugins - iterator-maven-plugin - 0.4 - - - package - - iterator - - - build/bin/ - - - single - - org.apache.maven.plugins - maven-assembly-plugin - - - - .build/assembly.xml - - - - - - - - - - - diff --git a/updater/release_descriptor.go b/updater/release_descriptor.go deleted file mode 100644 index c50170e8a4..0000000000 --- a/updater/release_descriptor.go +++ /dev/null @@ -1,176 +0,0 @@ -package main - -import ( - "encoding/xml" - "fmt" - "log" - "os" - "io/ioutil" - "github.com/blang/semver" -) - -//Artifact map type to custom unmarshal it -type ArtifactMap map[string]Artifact - -//evertime a artifact is found in the xml it gets decoded using this function, it -//unmarshals the artifact struct and stores it in the map -func (am ArtifactMap) UnmarshalXML(e *xml.Decoder, start xml.StartElement) error { - a := Artifact{} - err := e.DecodeElement(&a, &start) - if err != nil { - return err - } - am[a.Id] = a - return nil -} -func (am ArtifactMap) MarshalXML(e *xml.Encoder, start xml.StartElement) error { - - for _, a := range am { - err := e.Encode(a) - if err != nil { - return err - } - } - return nil -} - -//Semver type to be able to custom unmarshal it -type Version struct { - semver.Version -} - -//Get the version string an create a semver from it -func (v *Version) UnmarshalXMLAttr(attr xml.Attr) error { - str := attr.Value - parsed, err := semver.New(str) - if err != nil { - return err - } - v.Version = *parsed - - return nil -} - -//Get the version string an create a semver from it -func (v Version) MarshalXMLAttr(name xml.Name) (xml.Attr, error) { - return xml.Attr{Name: name, Value: v.String()}, nil -} - -//Collection of artifacts -type ReleaseDescriptor struct { - XMLName xml.Name `xml:"releaseDescriptor"` - Href string `xml:"href,attr"` //href where to get this descriptor - Version Version `xml:"version,attr"` //version of the this release - Artifacts ArtifactMap `xml:"artifact"` //artifacts associated to this descriptor, the key is the artifact id - Time string `xml:"time"` //timestamp of the desciptor generation -} - -//Create a new descriptor from all the info -func NewReleaseDescriptor(href string, version string, artifacts ...Artifact) (rd ReleaseDescriptor, err error) { - sver, err := semver.Parse(version) - if err != nil { - return - } - rd = ReleaseDescriptor{ - Href: href, - Version: Version{sver}, - Artifacts: map[string]Artifact{}, - } - for _, a := range artifacts { - rd.Artifacts[a.Id] = a - } - return - -} - -//Create a new empty relase descriptor -func NewEmptyReleaseDescriptor() ReleaseDescriptor { - return ReleaseDescriptor{ - Artifacts: map[string]Artifact{}, - } - -} - -//Compares two indeces Returning a list of differences -func (i ReleaseDescriptor) IsDiff(old ReleaseDescriptor) (is bool, diffs DiffSet) { - //no changes - if i.Version.Compare(old.Version.Version) <= 0 { - - return - } - - news := i.Artifacts - olds := old.Artifacts - //range the new artifacts to find differences - for id, n := range news { - newArt := n - oldArt, ok := olds[id] - //there's no old version - if !ok { - diffs = append(diffs, Diff{New: &newArt, Old: nil}) - } else if newArt.Version != oldArt.Version { - diffs = append(diffs, Diff{New: &newArt, Old: &oldArt}) - } - - } - //range the old artifacts to find deleted artifacts - for id, o := range olds { - if _, ok := news[id]; !ok { - oldArt := o - diffs = append(diffs, Diff{New: nil, Old: &oldArt}) - } - - } - return true, diffs -} - -func (r ReleaseDescriptor) UpdateFrom(local ReleaseDescriptor, installationPath string) (success bool, err error) { - changes, diffSet := r.IsDiff(local) - if !changes { - Info("There are no new versions") - //nothing to do! - return false, nil - } - Info("Updating to version %s", r.Version) - tempDir, err := ioutil.TempDir("", "pipeline-updater") - if err != nil { - return false, err - } - toDeploy, err := Download(tempDir, diffSet.ToDownload()...) - if err != nil { - os.RemoveAll(tempDir) - return false, err - } - ok, errs := Remove(diffSet.ToRemove(installationPath)) - if !ok { - //warn - log.Printf("errs %+v\n", errs) - } - ok, errs = Deploy(toDeploy, installationPath) - if !ok { - //warn - log.Printf("errs %+v\n", errs) - } - err = os.RemoveAll(tempDir) - if err != nil { - //warn - log.Printf("err %+v\n", err) - } - return true, nil -} - -//String for logging -func (rd ReleaseDescriptor) String() string { - return fmt.Sprintf("ReleaseDescriptor %v", rd.Version.String()) -} - -func (rd ReleaseDescriptor) Save(path string) error { - data, err := xml.Marshal(rd) - f, err := os.Create(path) - defer f.Close() - if err != nil { - return err - } - _, err = f.Write(data) - return err -} diff --git a/updater/release_descriptor_test.go b/updater/release_descriptor_test.go deleted file mode 100644 index df57dbd564..0000000000 --- a/updater/release_descriptor_test.go +++ /dev/null @@ -1,267 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "net/http" - "net/http/httptest" - "os" - "path/filepath" - "testing" - - "github.com/blang/semver" - . "github.com/smartystreets/goconvey/convey" -) - -func GenerateArtifacts() []Artifact { - return []Artifact{ - Artifact{ - Id: "1", - Href: "localhost/art", - Version: "1.0.0", - DeployPath: "data/arts", - }, - Artifact{ - Id: "2", - Href: "localhost/art2", - Version: "1.0.0", - DeployPath: "data/arts", - }, - } -} -func TestNewReleaseDescriptor(t *testing.T) { - Convey("So we create a new descriptor", t, func() { - href := "localhost" - version := "1.0.1-beta2+SNAPSHOT-a1b2c3" - artifacts := GenerateArtifacts() - rd, err := NewReleaseDescriptor(href, version, artifacts...) - So(err, ShouldBeNil) - Convey("The href is correctly set", func() { - So(rd.Href, ShouldEqual, href) - }) - Convey("The version is set and parsed", func() { - So(rd.Version.Major, ShouldEqual, 1) - So(rd.Version.Minor, ShouldEqual, 0) - So(rd.Version.Patch, ShouldEqual, 1) - So(rd.Version.Pre[0].String(), ShouldEqual, "beta2") - So(rd.Version.Build[0], ShouldEqual, "SNAPSHOT-a1b2c3") - So(rd.Version.String(), ShouldEqual, "1.0.1-beta2+SNAPSHOT-a1b2c3") - So(rd.Version.String(), ShouldEqual, semver.MustParse(version).String()) - }) - Convey("The artifacts are set", func() { - So(rd.Artifacts["1"], ShouldResemble, artifacts[0]) - So(rd.Artifacts["2"], ShouldResemble, artifacts[1]) - }) - Convey("An error is returned if the version can't be parsed", func() { - _, err := NewReleaseDescriptor(href, "notavalidaversion1=2", artifacts...) - So(err, ShouldNotBeNil) - }) - - }) -} - -func TestCompareReleaseDescriptors(t *testing.T) { - Convey("Having a descriptor", t, func() { - href := "localhost" - version := "1.0.1" - rd, err := NewReleaseDescriptor(href, version, GenerateArtifacts()...) - Convey("Error should be nil", func() { - So(err, ShouldBeNil) - }) - Convey("If we compare it with the same descriptor", func() { - is, diffs := rd.IsDiff(rd) - Convey("It shouldn't be different", func() { - So(is, ShouldBeFalse) - }) - Convey("And the differences are empty", func() { - So(diffs, ShouldBeEmpty) - }) - - }) - Convey("If we have a second descriptor with other version and a newer artifact", func() { - artifacts := GenerateArtifacts() - artifacts[0].Version = "2.0.0" - newer, err := NewReleaseDescriptor(href, "1.0.2", artifacts...) - - Convey("Error should be nil", func() { - So(err, ShouldBeNil) - }) - Convey("and we calculate the difference", func() { - is, diffs := newer.IsDiff(rd) - Convey("they are different", func() { - So(is, ShouldBeTrue) - }) - Convey("We get a difference", func() { - So(len(diffs), ShouldEqual, 1) - Convey("The different is the artifact with id 1", func() { - diff := diffs[0] - So(diff.New.Id, ShouldEqual, "1") - Convey("The diff contains the two versions", func() { - - diffNew := artifacts[0] - diffOld := GenerateArtifacts()[0] - So(*diff.New, ShouldResemble, diffNew) - So(*diff.Old, ShouldResemble, diffOld) - - }) - - }) - }) - - }) - - }) - Convey("If we have a second descriptor with other version and a new artifact", func() { - artifacts := GenerateArtifacts() - artifacts = append(artifacts, Artifact{Version: "0.0.1", Id: "3"}) - newer, err := NewReleaseDescriptor(href, "1.0.2", artifacts...) - - Convey("Error should be nil", func() { - So(err, ShouldBeNil) - }) - Convey("and we calculate the difference", func() { - is, diffs := newer.IsDiff(rd) - Convey("they are different", func() { - So(is, ShouldBeTrue) - }) - Convey("We get a difference", func() { - So(len(diffs), ShouldEqual, 1) - Convey("The different is that the artifact 3 is missing in the old release", func() { - diff := diffs[0] - So(diff.Old, ShouldBeNil) - So(diff.New.Id, ShouldEqual, "3") - - }) - }) - - }) - - }) - Convey("If we have a second descriptor with other version and one of the artifacts has disappeared", func() { - artifacts := GenerateArtifacts()[1:] - newer, err := NewReleaseDescriptor(href, "1.0.2", artifacts...) - - Convey("Error should be nil", func() { - So(err, ShouldBeNil) - }) - Convey("and we calculate the difference", func() { - is, diffs := newer.IsDiff(rd) - Convey("they are different", func() { - So(is, ShouldBeTrue) - }) - Convey("We get a difference", func() { - So(len(diffs), ShouldEqual, 1) - Convey("The different is that the artifact 1 is missing in the new release", func() { - diff := diffs[0] - So(diff.New, ShouldBeNil) - So(diff.Old.Id, ShouldEqual, "1") - - }) - }) - - }) - - }) - - }) - -} -func TestIntegrationUpdate(t *testing.T) { - //fake server for artifacts - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "ARTIFACT CONTENT") - })) - //init a couple of release descriptors - newArtifacts := []Artifact{ - Artifact{ - Id: "1", - Href: ts.URL, - DeployPath: "dir1/art-1.0.1", - Version: "1.0.1", - }, - Artifact{ - Id: "3", - Href: ts.URL, - DeployPath: "dir3/art-1.0.0", - Version: "1.0.1", - }, - } - oldArtifacts := []Artifact{ - Artifact{ - Id: "1", - Href: ts.URL, - DeployPath: "dir1/art-1.0.0", - Version: "1.0.0", - }, - Artifact{ - Id: "2", - Href: ts.URL, - DeployPath: "dir2/art-1.0.0", - Version: "1.0.0", - }, - } - installDir, err := ioutil.TempDir("", "install") - if err != nil { - t.Errorf("Unexpected error %v", err) - return - } - for _, o := range oldArtifacts { - path := filepath.Join(installDir, o.DeployPath) - os.MkdirAll(filepath.Dir(path), 0755) - f, err := os.Create(path) - if err != nil { - t.Errorf("Unexpected error %v", err) - } - f.WriteString("content") - f.Close() - } - - remote, err := NewReleaseDescriptor("http://daisy.org", "1.0.1", newArtifacts...) - if err != nil { - t.Errorf("Unexpected error %v", err) - } - local, err := NewReleaseDescriptor("http://daisy.org", "1.0.0", oldArtifacts...) - if err != nil { - t.Errorf("Unexpected error %v", err) - } - - Convey("This is more of an integration test", t, func() { - Convey("We have set a fake installation environment and an artifact server", func() { - Convey("Check existing files", func() { - info, err := os.Stat(filepath.Join(installDir, oldArtifacts[0].DeployPath)) - So(err, ShouldBeNil) - So(info.Size(), ShouldNotEqual, 0) - info, err = os.Stat(filepath.Join(installDir, oldArtifacts[1].DeployPath)) - So(err, ShouldBeNil) - So(info.Size(), ShouldNotEqual, 0) - Convey("Call update", func() { - - _, err := remote.UpdateFrom(local, installDir) - So(err, ShouldBeNil) - Convey("Check the installation structure", func() { - Convey("New intalled artifacts", func() { - info, err := os.Stat(filepath.Join(installDir, newArtifacts[0].DeployPath)) - So(err, ShouldBeNil) - So(info.Size(), ShouldNotEqual, 0) - info, err = os.Stat(filepath.Join(installDir, newArtifacts[1].DeployPath)) - So(err, ShouldBeNil) - So(info.Size(), ShouldNotEqual, 0) - Convey("Old artifacts are gone", func() { - _, err := os.Stat(filepath.Join(installDir, oldArtifacts[0].DeployPath)) - So(err, ShouldNotBeNil) - _, err = os.Stat(filepath.Join(installDir, oldArtifacts[1].DeployPath)) - So(err, ShouldNotBeNil) - - }) - - }) - }) - - }) - - }) - - }) - - }) -} diff --git a/updater/testserver/main.go b/updater/testserver/main.go deleted file mode 100644 index 5190cb3da6..0000000000 --- a/updater/testserver/main.go +++ /dev/null @@ -1,13 +0,0 @@ -package main - -import "net/http" - -func main() { - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - println("Serving") - http.ServeFile(w, r, "releaseDescriptor.xml") - - }) - println("Listening") - panic(http.ListenAndServe(":9090", nil)) -} diff --git a/updater/testserver/releaseDescriptor.xml b/updater/testserver/releaseDescriptor.xml deleted file mode 100644 index f73126a270..0000000000 --- a/updater/testserver/releaseDescriptor.xml +++ /dev/null @@ -1,145 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - javax.xml.crypto - jsr105-api - 1.0.1 - - - javax.xml.parsers - jaxp-api - 1.4.5 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/updater/updater.go b/updater/updater.go deleted file mode 100644 index bde04533c8..0000000000 --- a/updater/updater.go +++ /dev/null @@ -1,113 +0,0 @@ -package main - -import ( - "encoding/xml" - "flag" - "fmt" - "log" - "net/http" - "os" - "path/filepath" - "time" - - "github.com/kardianos/osext" -) - -const ( - Latest = "current" -) - -var ( - env = os.Getenv("DP2_HOME") -) - -var service = flag.String("service", "", "Url of the update service") -var version = flag.String("version", Latest, "Version to update to") -var installDir = flag.String("install-dir", env, "Pipeline install directory, defaults to value of DP2_HOME") -var localDescriptor = flag.String("descriptor", "", "Current descriptor") -var force = flag.Bool("force", false, "Forces to update without comparing the versions, use if updating to nightly builds") - -func main() { - flag.Parse() - exePath, err := osext.Executable() - if err != nil { - Error(err.Error()) - os.Exit(-1) - } - logfile, err := os.Create(filepath.Join(filepath.Dir(exePath), "log.txt")) - if err != nil { - Error(err.Error()) - os.Exit(-1) - } - log.SetOutput(logfile) - if *service == "" { - Error("Please specify the url of the update service. Run %s --help for more information.", os.Args[0]) - os.Exit(-1) - } - if *installDir == "" { - Error("Please specify the Pipeline install directory. Run %s --help for more information.", os.Args[0]) - os.Exit(-1) - } - remote, err := LoadRemote(*service, *version) - if err != nil { - Error(err.Error()) - log.Println(err) - os.Exit(-1) - } - local, err := LoadLocal(*localDescriptor, *force) - if err != nil { - Error(err.Error()) - log.Println(err) - os.Exit(-1) - } - updated, err := remote.UpdateFrom(local, *installDir) - if err != nil { - Error(err.Error()) - log.Println(err) - os.Exit(-1) - } - if updated || *force { - if err := Backup(*localDescriptor); err != nil { - Error(err.Error()) - log.Println(err) - os.Exit(-1) - } - if err := remote.Save(*localDescriptor); err != nil { - Error(err.Error()) - log.Println(err) - os.Exit(-1) - } - Info("Updated to version %s", remote.Version) - } -} -func LoadRemote(service, version string) (rd ReleaseDescriptor, err error) { - rd = NewEmptyReleaseDescriptor() - resp, err := http.Get(fmt.Sprintf("%s/%s", service, version)) - if err != nil { - return - } - if resp.StatusCode > 300 { - return rd, fmt.Errorf("Invalid status %v", resp.Status) - } - err = xml.NewDecoder(resp.Body).Decode(&rd) - return - -} -func LoadLocal(path string, force bool) (rd ReleaseDescriptor, err error) { - rd = NewEmptyReleaseDescriptor() - if force || path == "" { - return - } - f, err := os.Open(path) - if err != nil { - return - } - defer f.Close() - err = xml.NewDecoder(f).Decode(&rd) - return - -} - -func Backup(path string) error { - return os.Rename(path, fmt.Sprintf("%s_%s", path, time.Now().Format("200601021504050.000"))) -} diff --git a/updater/updater_test.go b/updater/updater_test.go deleted file mode 100644 index 32bd3ed442..0000000000 --- a/updater/updater_test.go +++ /dev/null @@ -1,83 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "net/http" - "net/http/httptest" - "strings" - "testing" - - . "github.com/smartystreets/goconvey/convey" -) - -const XmlTest = ` - - - - -` - -func TestLoadRemote(t *testing.T) { - Convey("Test getting remote descriptors", t, func() { - Convey("Start a working remote server", func() { - ver := "" - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - ver = strings.Trim(r.URL.Path, "/") - fmt.Fprintf(w, "%v", XmlTest) - })) - Convey("And try to get the descriptor", func() { - ver = "" - rd, err := LoadRemote(ts.URL, Latest) - So(err, ShouldBeNil) - Convey("Check the remote rd", func() { - So(rd.Version.String(), ShouldEqual, "1.0.0") - Convey("And the ver sent to the server", func() { - So(ver, ShouldEqual, Latest) - }) - - }) - - }) - - }) - Convey("Errors are propagated", func() { - _, err := LoadRemote("http://nonexistinghost.com/", Latest) - So(err, ShouldNotBeNil) - - }) - - }) -} -func TestLoadLocal(t *testing.T) { - Convey("Test loading the local desciptor", t, func() { - Convey("If no local descriptor is indicated return an empty descriptor", func() { - rd, err := LoadLocal("", false) - So(err, ShouldBeNil) - So(rd.Version.String(), ShouldEqual, "0.0.0") - }) - Convey("If forced update return empty descriptor", func() { - rd, err := LoadLocal("", false) - So(err, ShouldBeNil) - So(rd.Version.String(), ShouldEqual, "0.0.0") - }) - Convey("Errors are propagated", func() { - _, err := LoadLocal("lkjaslkjaslkjasdl", false) - So(err, ShouldNotBeNil) - }) - Convey("it loads the release descriptor from a file", func() { - ft, err := ioutil.TempFile("", "rd-test") - So(err, ShouldBeNil) - ft.WriteString(XmlTest) - err = ft.Close() - So(err, ShouldBeNil) - rd, err := LoadLocal(ft.Name(), false) - So(err, ShouldBeNil) - Convey("Check the remote rd", func() { - So(rd.Version.String(), ShouldEqual, "1.0.0") - }) - - }) - - }) -} diff --git a/updater/xml_test.go b/updater/xml_test.go deleted file mode 100644 index 362e58d8b3..0000000000 --- a/updater/xml_test.go +++ /dev/null @@ -1,52 +0,0 @@ -package main - -import ( - "bytes" - "encoding/xml" - "testing" - - . "github.com/smartystreets/goconvey/convey" -) - -const XmlTestData = ` - - - - -` - -func TestUnmarshal(t *testing.T) { - Convey("Try to unmarshal a release descriptor", t, func() { - buf := bytes.NewBufferString(XmlTestData) - r := NewEmptyReleaseDescriptor() - err := xml.NewDecoder(buf).Decode(&r) - So(err, ShouldBeNil) - Convey("Check that the struct has been populated", func() { - So(r.Href, ShouldEqual, "http://daisy.org/pipeline-release/latest") - So(r.Version.String(), ShouldEqual, "1.0.0") - Convey("Check that the artifacts have been inserted in the map", func() { - Convey("artifact_1", func() { - art, ok := r.Artifacts["artifact_1"] - So(ok, ShouldBeTrue) - So(art.Href, ShouldEqual, "http://daisy.org/pipeline-release/artifacts/artifact_1/1.0.0") - So(art.Version, ShouldEqual, "1.0.0") - So(art.Id, ShouldEqual, "artifact_1") - So(art.DeployPath, ShouldEqual, "libs/pipeline/artifact_1") - - }) - Convey("artifact_2", func() { - art, ok := r.Artifacts["artifact_2"] - So(ok, ShouldBeTrue) - So(art.Href, ShouldEqual, "http://daisy.org/pipeline-release/artifacts/artifact_2/2.0.0") - So(art.Version, ShouldEqual, "2.0.0") - So(art.Id, ShouldEqual, "artifact_2") - So(art.DeployPath, ShouldEqual, "libs/pipeline/artifact_2") - - }) - - }) - - }) - - }) -}