migrate to go mod

This commit is contained in:
Evrins Hu 2020-07-13 14:18:10 +08:00
parent 029cc6bee4
commit 5532b49f7e
47 changed files with 126 additions and 69 deletions

View file

@ -1,7 +1,7 @@
#goadb
[![Build Status](https://travis-ci.org/zach-klippenstein/goadb.svg?branch=master)](https://travis-ci.org/zach-klippenstein/goadb)
[![GoDoc](https://godoc.org/github.com/zach-klippenstein/goadb?status.svg)](https://godoc.org/github.com/zach-klippenstein/goadb)
[![GoDoc](https://godoc.org/goadb?status.svg)](https://godoc.org/goadb)
A Golang library for interacting with the Android Debug Bridge (adb).

View file

@ -3,15 +3,15 @@ package adb
import (
"strconv"
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
"goadb/internal/errors"
"goadb/wire"
)
/*
Adb communicates with host services on the adb server.
Eg.
client := adb.New()
client := New()
client.ListDevices()
See list of services at https://android.googlesource.com/platform/system/core/+/master/adb/SERVICES.TXT.

View file

@ -3,8 +3,9 @@ package adb
import (
"testing"
"goadb/wire"
"github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/wire"
)
func TestGetServerVersion(t *testing.T) {

View file

@ -7,8 +7,8 @@ import (
"strings"
"time"
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
"goadb/internal/errors"
"goadb/wire"
)
// MtimeOfClose should be passed to OpenWrite to set the file modification time to the time the Close

View file

@ -4,7 +4,7 @@ import (
"bufio"
"strings"
"github.com/zach-klippenstein/goadb/internal/errors"
"goadb/internal/errors"
)
type DeviceInfo struct {
@ -66,7 +66,7 @@ func parseDeviceShort(line string) (*DeviceInfo, error) {
func parseDeviceLong(line string) (*DeviceInfo, error) {
fields := strings.Fields(line)
if len(fields) < 5 {
if len(fields) < 4 {
return nil, errors.Errorf(errors.ParseError,
"malformed device line, expected at least 5 fields but found %d", len(fields))
}

View file

@ -1,6 +1,6 @@
package adb
import "github.com/zach-klippenstein/goadb/internal/errors"
import "goadb/internal/errors"
// DeviceState represents one of the 3 possible states adb will report devices.
// A device can be communicated with when it's in StateOnline.
@ -15,12 +15,14 @@ const (
StateDisconnected
StateOffline
StateOnline
StatUnauthorized
)
var deviceStateStrings = map[string]DeviceState{
"": StateDisconnected,
"offline": StateOffline,
"device": StateOnline,
"unauthorized": StatUnauthorized,
}
func parseDeviceState(str string) (DeviceState, error) {

View file

@ -3,9 +3,10 @@ package adb
import (
"testing"
"goadb/internal/errors"
"goadb/wire"
"github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
)
func TestGetAttribute(t *testing.T) {

View file

@ -8,8 +8,8 @@ import (
"sync/atomic"
"time"
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
"goadb/internal/errors"
"goadb/wire"
)
/*

View file

@ -3,9 +3,10 @@ package adb
import (
"testing"
"goadb/internal/errors"
"goadb/wire"
"github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
)
func TestParseDeviceStatesSingle(t *testing.T) {

View file

@ -5,8 +5,8 @@ import (
"net"
"runtime"
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
"goadb/internal/errors"
"goadb/wire"
)
// Dialer knows how to create connections to an adb server.

View file

@ -5,7 +5,7 @@ import (
"os"
"time"
"github.com/zach-klippenstein/goadb/wire"
"goadb/wire"
)
// DirEntry holds information about a directory entry on a device.

View file

View file

@ -1,6 +1,6 @@
package adb
import "github.com/zach-klippenstein/goadb/internal/errors"
import "goadb/internal/errors"
type ErrCode errors.ErrCode

View file

@ -7,8 +7,8 @@ import (
"os/exec"
"strings"
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
"goadb/internal/errors"
"goadb/wire"
)
const (

View file

@ -4,8 +4,8 @@ import (
"io"
"strings"
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
"goadb/internal/errors"
"goadb/wire"
)
// MockServer implements Server, Scanner, and Sender.

View file

@ -4,8 +4,9 @@ import (
"fmt"
"testing"
"goadb/wire"
"github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/wire"
)
func TestNewServer_ZeroConfig(t *testing.T) {

View file

@ -5,8 +5,8 @@ import (
"os"
"time"
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
"goadb/internal/errors"
"goadb/wire"
)
var zeroTime = time.Unix(0, 0).UTC()

View file

@ -7,10 +7,11 @@ import (
"testing"
"time"
"goadb/internal/errors"
"goadb/wire"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
)
var someTime = time.Date(2015, 5, 3, 8, 8, 8, 0, time.UTC)

View file

@ -3,8 +3,8 @@ package adb
import (
"io"
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
"goadb/internal/errors"
"goadb/wire"
)
// syncFileReader wraps a SyncConn that has requested to receive a file.

View file

@ -6,8 +6,9 @@ import (
"strings"
"testing"
"goadb/wire"
"github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/wire"
)
func TestReadNextChunk(t *testing.T) {

View file

@ -6,8 +6,8 @@ import (
"os"
"time"
"github.com/zach-klippenstein/goadb/internal/errors"
"github.com/zach-klippenstein/goadb/wire"
"goadb/internal/errors"
"goadb/wire"
)
// syncFileWriter wraps a SyncConn that has requested to send a file.

View file

@ -8,8 +8,9 @@ import (
"encoding/binary"
"strings"
"goadb/wire"
"github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/wire"
)
func TestFileWriterWriteSingleChunk(t *testing.T) {
@ -48,7 +49,7 @@ func TestFileWriterWriteLargeChunk(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, wire.SyncMaxChunkSize+1, n)
assert.Equal(t, 8 + 8 + wire.SyncMaxChunkSize+1, buf.Len())
assert.Equal(t, 8+8+wire.SyncMaxChunkSize+1, buf.Len())
// First header.
chunk := buf.Bytes()[:8+wire.SyncMaxChunkSize]
@ -58,7 +59,7 @@ func TestFileWriterWriteLargeChunk(t *testing.T) {
assert.Equal(t, data[:wire.SyncMaxChunkSize], chunk[8:])
// Second header.
chunk = buf.Bytes()[wire.SyncMaxChunkSize+8:wire.SyncMaxChunkSize+8+1]
chunk = buf.Bytes()[wire.SyncMaxChunkSize+8 : wire.SyncMaxChunkSize+8+1]
expectedHeader = []byte("DATA\000\000\000\000")
binary.LittleEndian.PutUint32(expectedHeader[4:], 1)
assert.Equal(t, expectedHeader, chunk[:8])

View file

@ -6,7 +6,7 @@ import (
"regexp"
"strings"
"github.com/zach-klippenstein/goadb/internal/errors"
"goadb/internal/errors"
)
var (

View file

@ -2,14 +2,14 @@ package main
import (
"fmt"
"goadb/adb"
"io"
"os"
"path/filepath"
"syscall"
"time"
"github.com/cheggaaa/pb"
"github.com/zach-klippenstein/goadb"
"github.com/cheggaaa/pb/v3"
"gopkg.in/alecthomas/kingpin.v2"
)
@ -99,7 +99,6 @@ func parseDevice() adb.DeviceDescriptor {
}
func listDevices(long bool) int {
//client := adb.New(server)
devices, err := client.ListDevices()
if err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
@ -251,24 +250,21 @@ func push(showProgress bool, localPath, remotePath string, device adb.DeviceDesc
// After copying, final stats about the transfer speed and size are shown.
// Progress and stats are printed to stderr.
func copyWithProgressAndStats(dst io.Writer, src io.Reader, size int, showProgress bool) error {
var progress *pb.ProgressBar
var bar *pb.ProgressBar
if showProgress && size > 0 {
progress = pb.New(size)
bar = pb.New(size)
// Write to stderr in case dst is stdout.
progress.Output = os.Stderr
progress.ShowSpeed = true
progress.ShowPercent = true
progress.ShowTimeLeft = true
progress.SetUnits(pb.U_BYTES)
progress.Start()
dst = io.MultiWriter(dst, progress)
bar.SetWriter(os.Stderr)
bar.Set(pb.Bytes, true)
bar.Start()
dst = bar.NewProxyWriter(dst)
}
startTime := time.Now()
copied, err := io.Copy(dst, src)
if progress != nil {
progress.Finish()
if bar != nil {
bar.Finish()
}
if pathErr, ok := err.(*os.PathError); ok {

View file

@ -4,12 +4,12 @@ package main
import (
"flag"
"fmt"
"goadb/adb"
"io/ioutil"
"log"
"time"
adb "github.com/zach-klippenstein/goadb"
"github.com/zach-klippenstein/goadb/internal/errors"
"goadb/internal/errors"
)
var (

View file

@ -5,13 +5,13 @@ import (
"bufio"
"flag"
"fmt"
"goadb/adb"
"io"
"log"
"os"
"strings"
"github.com/zach-klippenstein/goadb"
"github.com/zach-klippenstein/goadb/wire"
"goadb/wire"
)
var port = flag.Int("p", adb.AdbPort, "`port` the adb server is listening on")

12
go.mod Normal file
View file

@ -0,0 +1,12 @@
module goadb
go 1.14
require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/cheggaaa/pb/v3 v3.0.4
github.com/stretchr/testify v1.6.1
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)

37
go.sum Normal file
View file

@ -0,0 +1,37 @@
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/cheggaaa/pb/v3 v3.0.4 h1:QZEPYOj2ix6d5oEg63fbHmpolrnNiwjUsk+h74Yt4bM=
github.com/cheggaaa/pb/v3 v3.0.4/go.mod h1:7rgWxLrAUcFMkvJuv09+DYi7mMUYi8nO9iOWcvGJPfw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View file

@ -1,6 +1,6 @@
package wire
import "github.com/zach-klippenstein/goadb/internal/errors"
import "goadb/internal/errors"
const (
// The official implementation of adb imposes an undocumented 255-byte limit

View file

@ -6,7 +6,7 @@ import (
"io/ioutil"
"strconv"
"github.com/zach-klippenstein/goadb/internal/errors"
"goadb/internal/errors"
)
// TODO(zach): All EOF errors returned from networoking calls should use ConnectionResetError.

View file

@ -7,8 +7,9 @@ import (
"io/ioutil"
"testing"
"goadb/internal/errors"
"github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/internal/errors"
)
func TestReadStatusOkay(t *testing.T) {

View file

@ -4,7 +4,7 @@ import (
"fmt"
"io"
"github.com/zach-klippenstein/goadb/internal/errors"
"goadb/internal/errors"
)
// Sender sends messages to the server.

View file

@ -1,6 +1,6 @@
package wire
import "github.com/zach-klippenstein/goadb/internal/errors"
import "goadb/internal/errors"
const (
// Chunks cannot be longer than 64k.

View file

@ -6,7 +6,7 @@ import (
"os"
"time"
"github.com/zach-klippenstein/goadb/internal/errors"
"goadb/internal/errors"
)
type SyncScanner interface {

View file

@ -6,7 +6,7 @@ import (
"os"
"time"
"github.com/zach-klippenstein/goadb/internal/errors"
"goadb/internal/errors"
)
type SyncSender interface {

View file

@ -7,8 +7,9 @@ import (
"testing"
"time"
"goadb/internal/errors"
"github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/internal/errors"
)
var (

View file

@ -6,7 +6,7 @@ import (
"regexp"
"sync"
"github.com/zach-klippenstein/goadb/internal/errors"
"goadb/internal/errors"
)
// ErrorResponseDetails is an error message returned by the server for a particular request.

View file

@ -3,8 +3,9 @@ package wire
import (
"testing"
"goadb/internal/errors"
"github.com/stretchr/testify/assert"
"github.com/zach-klippenstein/goadb/internal/errors"
)
func TestAdbServerError_NoRequest(t *testing.T) {