├── README.md └── main.go /README.md: -------------------------------------------------------------------------------- 1 | # check-code-google-com 2 | 3 | Check your package is depend on code.google.com 4 | 5 | March 12, 2015, Google decide to close Google Code. 6 | 7 | http://google-opensource.blogspot.com/2015/03/farewell-to-google-code.html 8 | 9 | I am grateful to Google Code. When there was not GitHub, I put my codes on 10 | Google Code. It was very stable. I had never see the server is down. 11 | Unfortunately, Google Code will close. However we, gopher has many codes that 12 | contains packages which is on code.google.com. We must finish transition to 13 | find alternative packages until the Google Code will close. 14 | 15 | ## Usage 16 | 17 | ``` 18 | $ check-code-google-com [package] 19 | ``` 20 | 21 | For example: 22 | 23 | ![Bad](http://go-gyazo.appspot.com/d7648e8179e45bf8.png) 24 | 25 | ![Good](http://go-gyazo.appspot.com/7f26fede3724d46a.png) 26 | 27 | Then, which packages are depend on `code.google.com`? So use `-v` 28 | 29 | ![-v](http://go-gyazo.appspot.com/70269f8014c1ca78.png) 30 | 31 | ## Installation 32 | 33 | ``` 34 | $ go get github.com/mattn/check-code-google-com 35 | ``` 36 | 37 | ## License 38 | 39 | MIT 40 | 41 | ## Author 42 | 43 | Yasuhiro Matsumoto (a.k.a mattn) 44 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "flag" 6 | "fmt" 7 | "github.com/daviddengcn/go-colortext" 8 | "os" 9 | "os/exec" 10 | "strings" 11 | ) 12 | 13 | var verbose = flag.Bool("v", false, "vebose") 14 | 15 | func main() { 16 | flag.Usage = func() { 17 | fmt.Fprintf(os.Stderr, "usage of %s: [package]\n", os.Args[0]) 18 | } 19 | flag.Parse() 20 | 21 | if flag.NArg() != 1 { 22 | flag.Usage() 23 | os.Exit(1) 24 | } 25 | name := flag.Arg(0) 26 | 27 | walk := map[string]bool{} 28 | walk[name] = false 29 | 30 | code_google_com := map[string]bool{} 31 | found := false 32 | 33 | b, err := exec.Command("go", "list", "std").CombinedOutput() 34 | if err != nil { 35 | fmt.Fprintln(os.Stderr, err) 36 | os.Exit(1) 37 | } 38 | for _, v := range strings.Split(string(b), "\n") { 39 | walk[v] = true 40 | } 41 | 42 | for { 43 | updated := false 44 | for k, v := range walk { 45 | if v { 46 | continue 47 | } 48 | if *verbose { 49 | ct.ChangeColor(ct.Yellow, false, ct.None, true) 50 | fmt.Println("checking:", k) 51 | ct.ResetColor() 52 | } 53 | b, err := exec.Command("go", "list", "-json", k).CombinedOutput() 54 | if err != nil { 55 | if len(b) > 0 { 56 | fmt.Fprintln(os.Stderr, string(b)) 57 | } else { 58 | fmt.Fprintln(os.Stderr, err) 59 | } 60 | if k == name { 61 | os.Exit(1) 62 | } 63 | walk[k] = true 64 | continue 65 | } 66 | var imports struct { 67 | Imports []string 68 | } 69 | err = json.Unmarshal(b, &imports) 70 | if err != nil { 71 | fmt.Fprintln(os.Stderr, err) 72 | walk[k] = true 73 | continue 74 | } 75 | for _, imp := range imports.Imports { 76 | if _, ok := walk[imp]; !ok { 77 | walk[imp] = false 78 | if strings.HasPrefix(imp, "code.google.com/") { 79 | code_google_com[imp] = true 80 | found = true 81 | if *verbose { 82 | ct.ChangeColor(ct.Magenta, false, ct.None, true) 83 | fmt.Println(" " + imp) 84 | ct.ResetColor() 85 | } 86 | } 87 | } 88 | } 89 | walk[k] = true 90 | updated = true 91 | } 92 | if !updated { 93 | break 94 | } 95 | } 96 | 97 | if found { 98 | ct.ChangeColor(ct.White, false, ct.Red, true) 99 | fmt.Printf("%s depends on below's packages on code.google.com:", name) 100 | ct.ResetColor() 101 | fmt.Println() 102 | for k := range code_google_com { 103 | fmt.Println(k) 104 | } 105 | } else { 106 | ct.ChangeColor(ct.Black, false, ct.Green, true) 107 | fmt.Printf("%s is independent of packages on code.google.com", name) 108 | ct.ResetColor() 109 | fmt.Println() 110 | } 111 | } 112 | --------------------------------------------------------------------------------