From fec823e0a7aeca3d0ec6f5a1da6f85833f8bf654 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 7 Aug 2013 22:17:15 +0800 Subject: [PATCH] New version. --- .gitignore | 25 -- .travis.yml | 13 - LICENSE | 45 --- README.md | 81 ---- README_ZH.md | 36 -- cmd/build.go | 79 ---- cmd/check.go | 177 --------- cmd/install.go | 347 ----------------- cmd/remove.go | 188 --------- cmd/search.go | 115 ------ cmd/struct.go | 114 ------ conf/gopm.toml | 19 - conf/sources.txt | 0 doc/bitbucket.go | 193 ---------- doc/error.go | 36 -- doc/github.go | 197 ---------- doc/google.go | 236 ------------ doc/http.go | 143 ------- doc/launchpad.go | 143 ------- doc/struct.go | 43 --- doc/vcs.go | 238 ------------ doc/walker.go | 138 ------- docs/Quick_Start.md | 135 ------- docs/Quick_Start_ZH.md | 0 gopm.go | 361 ------------------ gopm.json | 16 - i18n/en-US/prompt.txt | 36 -- i18n/en-US/usage.tpl | 18 - i18n/en-US/usage_build.txt | 19 - i18n/en-US/usage_check.txt | 10 - i18n/en-US/usage_install.txt | 29 -- i18n/en-US/usage_remove.txt | 18 - i18n/en-US/usage_search.txt | 7 - i18n/zh-CN/prompt.txt | 36 -- i18n/zh-CN/usage.tpl | 18 - i18n/zh-CN/usage_build.txt | 19 - i18n/zh-CN/usage_check.txt | 9 - i18n/zh-CN/usage_install.txt | 27 -- i18n/zh-CN/usage_remove.txt | 18 - i18n/zh-CN/usage_search.txt | 7 - repo/bundles/install_test.json | 22 -- repo/bundles/test_bundle.json | 58 --- utils/utils.go | 679 --------------------------------- utils/utils_test.go | 77 ---- 44 files changed, 4225 deletions(-) delete mode 100644 .gitignore delete mode 100644 .travis.yml delete mode 100644 LICENSE delete mode 100644 README.md delete mode 100644 README_ZH.md delete mode 100644 cmd/build.go delete mode 100644 cmd/check.go delete mode 100644 cmd/install.go delete mode 100644 cmd/remove.go delete mode 100644 cmd/search.go delete mode 100644 cmd/struct.go delete mode 100644 conf/gopm.toml delete mode 100644 conf/sources.txt delete mode 100644 doc/bitbucket.go delete mode 100644 doc/error.go delete mode 100644 doc/github.go delete mode 100644 doc/google.go delete mode 100644 doc/http.go delete mode 100644 doc/launchpad.go delete mode 100644 doc/struct.go delete mode 100644 doc/vcs.go delete mode 100644 doc/walker.go delete mode 100644 docs/Quick_Start.md delete mode 100644 docs/Quick_Start_ZH.md delete mode 100644 gopm.go delete mode 100644 gopm.json delete mode 100644 i18n/en-US/prompt.txt delete mode 100644 i18n/en-US/usage.tpl delete mode 100644 i18n/en-US/usage_build.txt delete mode 100644 i18n/en-US/usage_check.txt delete mode 100644 i18n/en-US/usage_install.txt delete mode 100644 i18n/en-US/usage_remove.txt delete mode 100644 i18n/en-US/usage_search.txt delete mode 100644 i18n/zh-CN/prompt.txt delete mode 100644 i18n/zh-CN/usage.tpl delete mode 100644 i18n/zh-CN/usage_build.txt delete mode 100644 i18n/zh-CN/usage_check.txt delete mode 100644 i18n/zh-CN/usage_install.txt delete mode 100644 i18n/zh-CN/usage_remove.txt delete mode 100644 i18n/zh-CN/usage_search.txt delete mode 100644 repo/bundles/install_test.json delete mode 100644 repo/bundles/test_bundle.json delete mode 100644 utils/utils.go delete mode 100644 utils/utils_test.go diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 8f42af935..000000000 --- a/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe - -gopm -data/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 254edb187..000000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: go - -notificaitons: - email: - recipients: gpmgo.com@gmail.com - on_success: change - on_failure: always - -before_script: -- go get github.com/BurntSushi/toml - -script: - - go build -v diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 87feceb7f..000000000 --- a/LICENSE +++ /dev/null @@ -1,45 +0,0 @@ -Copyright (c) 2013 GPMGo Members. All rights reserved. - -MIT +no-false-attribs License - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -Distributions of all or part of the Software intended to be used -by the recipients as they would use the unmodified Software, -containing modifications that substantially alter, remove, or -disable functionality of the Software, outside of the documented -configuration mechanisms provided by the Software, shall be -modified such that the Original Author's bug reporting email -addresses and urls are either replaced with the contact information -of the parties responsible for the changes, or removed entirely. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - - -Except where noted, this license applies to any and all software -programs and associated documentation files created by the -Original Author, when distributed with the Software. - -Packages published in the gpm registry (other than the Software and -its included dependencies) are not part of gpm itself, are the sole -property of their respective maintainers, and are not covered by -this license. - -"gpm Logo" created by "Earl of Hell" and used with permission. \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 9ec503acb..000000000 --- a/README.md +++ /dev/null @@ -1,81 +0,0 @@ -gopm - Go Package Manager -=== - -![GPMGo_Logo](https://raw.github.com/GPMGo/gpm-site/master/static/img/gpmgo2.png?raw=true) - -gopm(Go Package Manager) is a Go package manage tool for search, install, update, share and backup packages in Go. - -[![Build Status](https://travis-ci.org/GPMGo/gopm.png?branch=master)](https://travis-ci.org/GPMGo/gopm) [![Build Status](https://drone.io/github.com/GPMGo/gpm/status.png)](https://drone.io/github.com/GPMGo/gpm/latest) [![Coverage Status](https://coveralls.io/repos/GPMGo/gpm/badge.png)](https://coveralls.io/r/GPMGo/gpm) - -(Travis CI hasn't support Go 1.1 yet) - -This application still in experiment, any change could happen, but it doesn't affect download and install packages. - -## Main features - -- Download packages from popular project hosting with/without version control tools. -- Remove packages from local file system. -- Check package dependencies and download missing ones. -- More specific examples, see [Quick Start](docs/Quick_Start.md). - -## Main commands - -- `build` compiles and installs packages and dependencies: basically, it calls `go install` and moves executable to current path from `GOPATH` if any, the executable name is the folder name which is default by `go install`. -- `search` searchs packages in [Go Walker](http://gowalker.org) database by keyword. -- `install` downloads and installs packages and dependencies: you can download packages without version control tools like git, hg, svn, etc. It downloads and installs all packages including all dependencies automatically(except when you use bundle or snapshot). For now, this command supports `code.google.com`, `github.com`, `launchpad.net`, `bitbucket.org`. -- `remove` removes packages and dependencies: it removes all packages including all dependencies(except when you use bundle or snapshot). -- `check` checks dependencies of packages, and install all missing as a choose. - -## Known issues - -- When you use commands like `gopm install bitbucket.org/zombiezen/gopdf` where is project root path but the directory doesn't contain any source files, you will get error in the installation step, you have to use `gopm install bitbucket.org/zombiezen/gopdf/pdf` in order to go through all steps correctly. -- Cannot remove `.git` with error `access is denied`. - -## Todo - -### v0.3.* - -- Command `check` add feature to update gopm.json. -- Command `install` generates dependencies configuration file. -- Command `install` save tarball add support for packages in code.google.com, bitbucket.org, launchpad.net, git.oschina.net, gitcafe.com, *.codeplex.com. -- Command `build` use dependencies configuration file to build with specific versions of dependencies. -- Command `clean` is for cleaning empty directories and backup. -- Add gpm working principle design. -- Complete documentation. - -### Future - -- Command `install` and `remove` give number to let user choose operate one package when using snapshot. -- Figure out how to use tool chian directly in order to compile only with `.a` files. -- Command `search` compares version. -- Command `home` and `doc`. -- Command `remove` add flag `-d` for removing dependencies at the same time. -- Command `remove` add feature check for dependencies, make sure other packages don't import this one, and give choose for users. -- Command `update` is for checking updates. -- Command `sync` is for sync packages in two computers, support client and server mode through ssh. -- Command `init` is for auto-configuring Go develop environment. -- Command `install` and `remove` and `update` backup data(up to 50 records) before executing. -- Command `rollback` is for rolling back to certain operation. -- Add feature "struct generator". -- Command `install` add flag `-all` for re-installing everything in GOPATH, usually use this after upgraded Go version. -- Command `daemon` is for auto-compile web applications when debug it locally. -- Collect download and installation results and report to users in the end. -- Add user system to create, edit, upload, and download bundles or snapshots through gpm client program. -- Develop user source API server template application to support user sources in bundles. -- Add support for downloading tarballs from user sources. -- After downloaded all packages in bundles or snapshots, need to check if all dependencies have been downloaded as well. -- Download package from code.google.com only support hg as version control system, probably support git and svn. -- Command `install` add support for downloading code from git.oschina.net, gitcafe.com, *.codeplex.com. -- Command `install` add support for downloading by tag and branch for packages in git.oschina.net, gitcafe.com. -- Command `install` and `remove` add bundle parse code for getting data from server. -- Command `install` and `remove` add snapshot parse code for downloading or removing snapshot. -- Add built-in application version in order to backup data when users update. - -## Credits - -- Source files that contain code that is from [gopkgdoc](https://github.com/garyburd/gopkgdoc) is honored in specific. -- Idea that support packages build revision is inspired by [gopack](https://github.com/d2fn/gopack). - -## License - -[MIT-STYLE](LICENSE). diff --git a/README_ZH.md b/README_ZH.md deleted file mode 100644 index 09b111013..000000000 --- a/README_ZH.md +++ /dev/null @@ -1,36 +0,0 @@ -gopm - Go 包管理工具 -=== - -![GPMGo_Logo](https://raw.github.com/GPMGo/gpm-site/master/static/img/gpmgo2.png?raw=true) - -gopm(Go 包管理工具) 是一款涵盖搜索、安装、更新、分享以及备份功能 Go 包的管理工具。 - -[![Build Status](https://travis-ci.org/GPMGo/gpm.png)](https://travis-ci.org/GPMGo/gpm) [![Build Status](https://drone.io/github.com/GPMGo/gpm/status.png)](https://drone.io/github.com/GPMGo/gpm/latest) [![Coverage Status](https://coveralls.io/repos/GPMGo/gpm/badge.png)](https://coveralls.io/r/GPMGo/gpm) - -(Travis CI 暂未支持 Go 1.1) - -该应用目前扔处于实验阶段,任何改变都可能发生,但这不会影响到您下载和安装 Go 包。 - -## 主要功能 - -- 无需安装各类复杂的版本控制工具就可以从源代码托管平台下载并安装 Go 包。 -- 从本地文件系统中删除 Go 包。 -- 检查并下载缺失的依赖包。 -- 更多示例,参见 [快速入门](docs/Quick_Start_ZH.md) - -## 主要命令 - -- `build` 编译并安装 Go 包以及其依赖包:该命令从底层调用 `go install` 命令,如果为 main 包,则会将可执行文件从 `GOPATH` 中移至当前目录,可执行文件的名称是由 `go install` 默认指定的当前文件夹名称。 -- `search` 通过关键字在 [Go Walker](http://gowalker.org) 数据库中查找相关包。 -- `install` 下载并安装 Go 包以及其依赖包:您无需安装像 git、hg 或 svn 这类版本控制工具就可以下载您指定的包。该命令也会自动下载相关的依赖包(当您使用集合或快照下载时,不会自动下载依赖包)。目前,该命令支持托管在 `code.google.com`、`github.com`、`launchpad.net` 和 `bitbucket.org` 上的开源项目。 -- `remove` 删除 Go 包及其依赖包:该命令可删除 Go 包及其依赖包(当您使用集合或快照删除时,无法自动删除依赖包)。 -- `check` 检查当前包的依赖包是否全部安装,如果发现未安装的依赖包会提示您是否选择安装。 - -## 已知问题 - -- 当您使用命令例如 `gopm install bitbucket.org/zombiezen/gopdf` 时,你会在安装步骤时得到错误,虽然这是项目的根目录,但是并没有包含任何 Go 源代码,因此您必须使用 `gopm install bitbucket.org/zombiezen/gopdf/pdf` 才能正确完成安装。 -- 删除目录 `.git` 会因为权限不足而失败。 - -## 授权许可 - -[MIT-STYLE](LICENSE) \ No newline at end of file diff --git a/cmd/build.go b/cmd/build.go deleted file mode 100644 index 6ca16867e..000000000 --- a/cmd/build.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package cmd - -import ( - "fmt" - "os" - - "github.com/GPMGo/gopm/utils" -) - -var CmdBuild = &Command{ - UsageLine: "build [build flags] [packages]", -} - -func init() { - CmdBuild.Run = runBuild - CmdBuild.Flags = map[string]bool{ - "-v": false, - "-r": false, - } -} - -// printBuildPrompt prints prompt information to users to -// let them know what's going on. -func printBuildPrompt(flag string) { - switch flag { - - } -} - -func runBuild(cmd *Command, args []string) { - // Check flags. - num := checkFlags(cmd.Flags, Config.AutoEnable.Build, args, printBuildPrompt) - if num == -1 { - return - } - args = args[num:] - - var cmdArgs []string - cmdArgs = append(cmdArgs, "install") - if CmdBuild.Flags["-v"] { - cmdArgs = append(cmdArgs, "-v") - } - - executeCommand("go", cmdArgs) - - // Find executable in GOPATH and copy to current directory. - wd, _ := os.Getwd() - proName := utils.GetExecuteName(wd) - paths := utils.GetGOPATH() - - for _, v := range paths { - if utils.IsExist(v + "/bin/" + proName) { - if utils.IsExist(wd + "/" + proName) { - err := os.Remove(wd + "/" + proName) - if err != nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] %s\n", PromptMsg["RemoveFile"]), err)) - return - } - } - err := os.Rename(v+"/bin/"+proName, wd+"/"+proName) - if err == nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("$ %s\n", PromptMsg["MovedFile"]), v, wd)) - // Check if need to run program. - if CmdBuild.Flags["-r"] { - cmdArgs = make([]string, 0) - executeCommand(proName, cmdArgs) - } - return - } - - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["MoveFile"]), v, wd) - break - } - } -} diff --git a/cmd/check.go b/cmd/check.go deleted file mode 100644 index cd6405e52..000000000 --- a/cmd/check.go +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package cmd - -import ( - "encoding/json" - "fmt" - "os" - "strings" - - "github.com/GPMGo/gopm/doc" - "github.com/GPMGo/gopm/utils" - "github.com/GPMGo/node" -) - -var CmdCheck = &Command{ - UsageLine: "check [check flags] [packages]", -} - -func init() { - CmdCheck.Run = runCheck - CmdCheck.Flags = map[string]bool{ - "-e": false, - } -} - -// printCheckPrompt prints prompt information to users to -// let them know what's going on. -func printCheckPrompt(flag string) { - switch flag { - case "-e": - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["CheckExDeps"])) - } -} - -func runCheck(cmd *Command, args []string) { - // Check flags. - num := checkFlags(cmd.Flags, Config.AutoEnable.Check, args, printCheckPrompt) - if num == -1 { - return - } - args = args[num:] - - wd, _ := os.Getwd() - // Guess import path. - gopath := utils.GetBestMatchGOPATH(wd) + "/src/" - if len(wd) <= len(gopath) { - fmt.Printf(fmt.Sprintf("runCheck -> %s\n", PromptMsg["InvalidPath"])) - return - } - - importPath := wd[len(gopath):] - imports, err := checkImportsByRoot(wd+"/", importPath) - if err != nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("runCheck -> %s\n", PromptMsg["CheckImports"]), err)) - return - } - - if len(imports) == 0 { - return - } - - pkgConf := new(gopmConfig) - importsCache := make(map[string]bool) - uninstallList := make([]string, 0) - isInstalled := false - // Check if dependencies have been installed. - - for _, v := range imports { - // Make sure it doesn't belong to same project. - if utils.GetProjectPath(v) != utils.GetProjectPath(importPath) { - if !importsCache[v] { - importsCache[v] = true - pkgConf.Deps = append(pkgConf.Deps, &node.Node{ - ImportPath: v, - }) - - if _, ok := utils.CheckIsExistInGOPATH(importPath); ok { - isInstalled = true - } - - if !isInstalled { - uninstallList = append(uninstallList, v) - } - } - } - isInstalled = false - } - - // Check if need to install packages. - if len(uninstallList) > 0 { - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["MissingImports"])) - for _, v := range uninstallList { - fmt.Printf("%s\n", v) - } - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["ContinueDownload"])) - var option string - fmt.Fscan(os.Stdin, &option) - if strings.ToLower(option) != "y" { - os.Exit(0) - } - - installGOPATH = utils.GetBestMatchGOPATH(AppPath) - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("%s\n", PromptMsg["DownloadPath"]), installGOPATH)) - // Generate temporary nodes. - nodes := make([]*node.Node, len(uninstallList)) - for i := range nodes { - nodes[i] = new(node.Node) - nodes[i].ImportPath = uninstallList[i] - } - // Download packages. - downloadPackages(nodes) - - removePackageFiles("", uninstallList) - - // Install packages all together. - var cmdArgs []string - cmdArgs = append(cmdArgs, "install") - cmdArgs = append(cmdArgs, "") - - for _, k := range uninstallList { - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["InstallStatus"]), k) - cmdArgs[1] = k - executeCommand("go", cmdArgs) - } - } - - // Generate configure file. - if !utils.IsExist("gopm.json") { - fw, err := os.Create("gopm.json") - if err != nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] runCheck -> %s\n", PromptMsg["OpenFile"]), err)) - return - } - defer fw.Close() - - fbytes, err := json.MarshalIndent(&pkgConf, "", "\t") - if err != nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] runCheck -> %s\n", PromptMsg["ParseJSON"]), err)) - return - } - fw.Write(fbytes) - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("$ %s\n", PromptMsg["GenerateConfig"]), importPath)) - } -} - -// checkImportsByRoot checks imports of packages from root path, -// and recursion checks all sub-directories. -func checkImportsByRoot(rootPath, importPath string) (imports []string, err error) { - // Check imports of root path. - importPkgs, err := doc.CheckImports(rootPath, importPath) - if err != nil { - return nil, err - } - imports = append(imports, importPkgs...) - - // Check sub-directories. - dirs, err := utils.GetDirsInfo(rootPath) - if err != nil { - return nil, err - } - - for _, d := range dirs { - if d.IsDir() && - !(!CmdCheck.Flags["-e"] && strings.Contains(d.Name(), "example")) { - importPkgs, err := checkImportsByRoot(rootPath+d.Name()+"/", importPath) - if err != nil { - return nil, err - } - imports = append(imports, importPkgs...) - } - } - - return imports, err -} diff --git a/cmd/install.go b/cmd/install.go deleted file mode 100644 index 939f20aff..000000000 --- a/cmd/install.go +++ /dev/null @@ -1,347 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package cmd - -import ( - "encoding/json" - "errors" - "fmt" - "net/http" - "os" - "os/exec" - "regexp" - "strconv" - "strings" - - "github.com/GPMGo/gopm/doc" - "github.com/GPMGo/gopm/utils" - "github.com/GPMGo/node" -) - -var ( - isHasGit, isHasHg bool - downloadCache map[string]bool // Saves packages that have been downloaded. - installGOPATH string // The GOPATH that packages are downloaded to. -) - -var CmdInstall = &Command{ - UsageLine: "install [install flags] ", -} - -func init() { - downloadCache = make(map[string]bool) - CmdInstall.Run = runInstall - CmdInstall.Flags = map[string]bool{ - "-d": false, - "-u": false, - "-e": false, - "-b": false, - "-s": false, - } -} - -// printInstallPrompt prints prompt information to users to -// let them know what's going on. -func printInstallPrompt(flag string) { - switch flag { - case "-d": - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["DownloadOnly"])) - case "-u": - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["ForceUpdate"])) - case "-e": - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["DownloadExDeps"])) - } -} - -// checkFlags checks if the flag exists with correct format. -func checkFlags(flags map[string]bool, enable []string, args []string, print func(string)) int { - // Check auto-enable. - for _, v := range enable { - flags["-"+v] = true - print("-" + v) - } - - num := 0 // Number of valid flags, use to cut out. - for i, f := range args { - // Check flag prefix '-'. - if !strings.HasPrefix(f, "-") { - // Not a flag, finish check process. - break - } - - // Check if it a valid flag. - if v, ok := flags[f]; ok { - flags[f] = !v - if !v { - print(f) - } else { - fmt.Println("DISABLE: " + f) - } - } else { - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["UnknownFlag"]), f) - return -1 - } - num = i + 1 - } - - return num -} - -// checkVCSTool checks if users have installed version control tools. -func checkVCSTool() { - // git. - if _, err := exec.LookPath("git"); err == nil { - isHasGit = true - } - // hg. - if _, err := exec.LookPath("hg"); err == nil { - isHasHg = true - } - // svn. -} - -func runInstall(cmd *Command, args []string) { - // Check flags. - num := checkFlags(cmd.Flags, Config.AutoEnable.Install, args, printInstallPrompt) - if num == -1 { - return - } - args = args[num:] - - // Check length of arguments. - if len(args) < 1 { - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["NoPackage"])) - return - } - - // Check version control tools. - // checkVCSTool() // Since we don't user version control, we don't need to check this anymore. - - installGOPATH = utils.GetBestMatchGOPATH(AppPath) - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("%s\n", PromptMsg["DownloadPath"]), installGOPATH)) - - var nodes []*node.Node - // Check if it is a bundle or snapshot. - switch { - case CmdInstall.Flags["-b"]: - bundle := args[0] - // Check local bundles. - nodes = checkLocalBundles(bundle) - if len(nodes) > 0 { - // Check with users if continue. - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("%s\n", PromptMsg["BundleInfo"]), bundle)) - for i, n := range nodes { - fmt.Printf("%d.[%s] -> %s: %s.\n", i+1, n.ImportPath, n.Type, n.Value) - } - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["ContinueDownload"])) - var option string - fmt.Fscan(os.Stdin, &option) - // Chekc if it is a index. - num, err := strconv.Atoi(option) - if err == nil && num > 0 && num <= len(nodes) { - nodes = nodes[num-1 : num] - break - } - - if strings.ToLower(option) != "y" { - os.Exit(0) - return - } - } else { - // Check from server. - // TODO: api.GetBundleInfo() - fmt.Println("Unable to find bundle, and we cannot check with server right now.") - } - case CmdInstall.Flags["-s"]: - fmt.Println("gopm has not supported snapshot yet.") - // TODO: api.GetSnapshotInfo() - default: - // Generate temporary nodes. - nodes = make([]*node.Node, len(args)) - for i := range nodes { - nodes[i] = new(node.Node) - nodes[i].ImportPath = args[i] - } - } - - // Download packages. - downloadPackages(nodes) - - // Check if need to install packages. - if !CmdInstall.Flags["-d"] { - // Remove old files. - uninstallList := make([]string, 0, len(downloadCache)) - for k := range downloadCache { - uninstallList = append(uninstallList, k) - } - removePackageFiles("", uninstallList) - - // Install packages all together. - var cmdArgs []string - cmdArgs = append(cmdArgs, "install") - cmdArgs = append(cmdArgs, "") - - for k := range downloadCache { - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["InstallStatus"]), k) - cmdArgs[1] = k - executeCommand("go", cmdArgs) - } - - // Save local nodes to file. - fw, err := os.Create(AppPath + "data/nodes.json") - if err != nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] runInstall -> %s\n", PromptMsg["OpenFile"]), err)) - return - } - defer fw.Close() - fbytes, err := json.MarshalIndent(&LocalNodes, "", "\t") - if err != nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] runInstall -> %s\n", PromptMsg["ParseJSON"]), err)) - return - } - fw.Write(fbytes) - } -} - -// chekcDeps checks dependencies of nodes. -func chekcDeps(nodes []*node.Node) (depnodes []*node.Node) { - for _, n := range nodes { - // Make sure it will not download all dependencies automatically. - if len(n.Value) == 0 { - n.Value = "B" - } - depnodes = append(depnodes, n) - depnodes = append(depnodes, chekcDeps(n.Deps)...) - } - return depnodes -} - -// checkLocalBundles checks if the bundle is in local file system. -func checkLocalBundles(bundle string) (nodes []*node.Node) { - for _, b := range LocalBundles { - if bundle == b.Name { - nodes = append(nodes, chekcDeps(b.Nodes)...) - return nodes - } - } - return nil -} - -// downloadPackages downloads packages with certain commit, -// if the commit is empty string, then it downloads all dependencies, -// otherwise, it only downloada package with specific commit only. -func downloadPackages(nodes []*node.Node) { - // Check all packages, they may be bundles, snapshots or raw packages path. - for _, n := range nodes { - // Check if it is a valid remote path. - if utils.IsValidRemotePath(n.ImportPath) { - if !CmdInstall.Flags["-u"] { - // Check if package has been downloaded. - if _, ok := utils.CheckIsExistInGOPATH(n.ImportPath); ok { - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["SkipInstalled"]), n.ImportPath) - continue - } - } - - if !downloadCache[n.ImportPath] { - // Download package. - nod, imports := downloadPackage(n) - if len(imports) > 0 { - // Need to download dependencies. - // Generate temporary nodes. - nodes := make([]*node.Node, len(imports)) - for i := range nodes { - nodes[i] = new(node.Node) - nodes[i].ImportPath = imports[i] - } - downloadPackages(nodes) - } - - // Only save package information with specific commit. - if nod != nil { - // Save record in local nodes. - saveNode(nod) - } - } else { - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["SkipDownloaded"]), n.ImportPath) - } - } else { - // Invalid import path. - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["SkipInvalidPath"]), n.ImportPath) - } - } -} - -// saveNode saves node into local nodes. -func saveNode(n *node.Node) { - // Node dependencies list. - n.Deps = nil - - // Check if this node exists. - for i, v := range LocalNodes { - if n.ImportPath == v.ImportPath { - LocalNodes[i] = n - return - } - } - - // Add new node. - LocalNodes = append(LocalNodes, n) -} - -// downloadPackage downloads package either use version control tools or not. -func downloadPackage(nod *node.Node) (*node.Node, []string) { - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["DownloadStatus"]), nod.ImportPath) - // Mark as donwloaded. - downloadCache[nod.ImportPath] = true - - imports, err := pureDownload(nod) - - if err != nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] %s\n", PromptMsg["DownloadError"]), nod.ImportPath, err)) - return nil, nil - } - return nod, imports -} - -// service represents a source code control service. -type service struct { - pattern *regexp.Regexp - prefix string - get func(*http.Client, map[string]string, string, *node.Node, map[string]bool) ([]string, error) -} - -// services is the list of source code control services handled by gopkgdoc. -var services = []*service{ - {doc.GithubPattern, "github.com/", doc.GetGithubDoc}, - {doc.GooglePattern, "code.google.com/", doc.GetGoogleDoc}, - {doc.BitbucketPattern, "bitbucket.org/", doc.GetBitbucketDoc}, - {doc.LaunchpadPattern, "launchpad.net/", doc.GetLaunchpadDoc}, -} - -// pureDownload downloads package without version control. -func pureDownload(nod *node.Node) ([]string, error) { - for _, s := range services { - if s.get == nil || !strings.HasPrefix(nod.ImportPath, s.prefix) { - continue - } - m := s.pattern.FindStringSubmatch(nod.ImportPath) - if m == nil { - if s.prefix != "" { - return nil, - doc.NotFoundError{fmt.Sprintf("%s", PromptMsg["NotFoundError"])} - } - continue - } - match := map[string]string{"importPath": nod.ImportPath} - for i, n := range s.pattern.SubexpNames() { - if n != "" { - match[n] = m[i] - } - } - return s.get(doc.HttpClient, match, installGOPATH, nod, CmdInstall.Flags) - } - return nil, errors.New(fmt.Sprintf("%s", PromptMsg["NotFoundError"])) -} diff --git a/cmd/remove.go b/cmd/remove.go deleted file mode 100644 index fe06d4392..000000000 --- a/cmd/remove.go +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package cmd - -import ( - "encoding/json" - "fmt" - "os" - "runtime" - "strconv" - "strings" - - "github.com/GPMGo/gopm/utils" - "github.com/GPMGo/node" -) - -var ( - removeCache map[string]bool // Saves packages that have been removed. -) - -var CmdRemove = &Command{ - UsageLine: "remove [remove flags] ", -} - -func init() { - removeCache = make(map[string]bool) - CmdRemove.Run = runRemove -} - -func runRemove(cmd *Command, args []string) { - // Check length of arguments. - if len(args) < 1 { - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["NoPackage"])) - return - } - - var nodes []*node.Node - // Check if it is a bundle or snapshot. - switch { - case CmdRemove.Flags["-b"]: - bundle := args[0] - // Check local bundles. - nodes = checkLocalBundles(bundle) - if len(nodes) > 0 { - // Check with users if continue. - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("%s\n", PromptMsg["BundleInfo"]), bundle)) - for _, n := range nodes { - fmt.Printf("[%s] -> %s: %s.\n", n.ImportPath, n.Type, n.Value) - } - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["ContinueRemove"])) - var option string - fmt.Fscan(os.Stdin, &option) - // Chekc if it is a index. - num, err := strconv.Atoi(option) - if err == nil && num > 0 && num <= len(nodes) { - nodes = nodes[num-1 : num] - break - } - - if strings.ToLower(option) != "y" { - os.Exit(0) - return - } - } else { - // Check from server. - // TODO: api.GetBundleInfo() - fmt.Println("Unable to find bundle, and we cannot check with server right now.") - } - case CmdRemove.Flags["-s"]: - fmt.Println("gopm has not supported snapshot yet.") - // TODO: api.GetSnapshotInfo() - default: - // Generate temporary nodes. - nodes = make([]*node.Node, len(args)) - for i := range nodes { - nodes[i] = new(node.Node) - nodes[i].ImportPath = args[i] - } - } - - // Removes packages. - removePackages(nodes) - - // Save local nodes to file. - fw, err := os.Create(AppPath + "data/nodes.json") - if err != nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] runRemove -> %s\n", PromptMsg["OpenFile"]), err)) - return - } - defer fw.Close() - fbytes, err := json.MarshalIndent(&LocalNodes, "", "\t") - if err != nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] runRemove -> %s\n", PromptMsg["ParseJSON"]), err)) - return - } - fw.Write(fbytes) -} - -// removePackages removes packages from local file system. -func removePackages(nodes []*node.Node) { - // Check all packages, they may be bundles, snapshots or raw packages path. - for _, n := range nodes { - // Check if it is a bundle or snapshot. - if utils.IsValidRemotePath(n.ImportPath) { - if !removeCache[n.ImportPath] { - // Remove package. - nod, imports := removePackage(n) - if len(imports) > 0 { - fmt.Println("Check denpendencies for removing package has not been supported.") - } - - // Remove record in local nodes. - if nod != nil { - removeNode(nod) - } - } - } else { - // Invalid import path. - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["SkipInvalidPath"]), n.ImportPath) - } - } -} - -// removeNode removes node from local nodes. -func removeNode(n *node.Node) { - // Check if this node exists. - for i, v := range LocalNodes { - if n.ImportPath == v.ImportPath { - LocalNodes = append(LocalNodes[:i], LocalNodes[i+1:]...) - return - } - } -} - -// removePackage removes package from local file system. -func removePackage(nod *node.Node) (*node.Node, []string) { - // Find package in GOPATH. - paths := utils.GetGOPATH() - for _, p := range paths { - absPath := p + "/src/" + utils.GetProjectPath(nod.ImportPath) + "/" - if utils.IsExist(absPath) { - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["RemovePackage"]), nod.ImportPath) - // Remove files. - os.RemoveAll(absPath) - // Remove file in GOPATH/bin - proName := utils.GetExecuteName(nod.ImportPath) - paths := utils.GetGOPATH() - var gopath string - - for _, v := range paths { - if utils.IsExist(v + "/bin/" + proName) { - gopath = v // Don't need to find again. - os.Remove(v + "/bin/" + proName) - } - } - - pkgList := []string{nod.ImportPath} - removePackageFiles(gopath, pkgList) - - return nod, nil - } - } - - // Cannot find package. - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["PackageNotFound"]), nod.ImportPath) - return nil, nil -} - -// removePackageFiles removes package files in $GOPATH/pkg. -func removePackageFiles(gopath string, pkgList []string) { - var paths []string - // Check if need to find GOPATH. - if len(gopath) == 0 { - paths = utils.GetGOPATH() - } else { - paths = append(paths, gopath) - } - - pkgPath := "/pkg/" + runtime.GOOS + "_" + runtime.GOARCH + "/" - for _, p := range pkgList { - for _, g := range paths { - os.RemoveAll(g + pkgPath + p + "/") - os.Remove(g + pkgPath + p + ".a") - } - } -} diff --git a/cmd/search.go b/cmd/search.go deleted file mode 100644 index 8b840e557..000000000 --- a/cmd/search.go +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package cmd - -import ( - "bytes" - "fmt" - "runtime" - "strings" - - "github.com/GPMGo/gopm/doc" - "github.com/GPMGo/gopm/utils" -) - -var CmdSearch = &Command{ - UsageLine: "search [search flags] ", -} - -func init() { - CmdSearch.Run = runSearch -} - -// printSearchPrompt prints prompt information to users to -// let them know what's going on. -func printSearchPrompt(flag string) { - switch flag { - - } -} - -func runSearch(cmd *Command, args []string) { - // Check flags. - num := checkFlags(cmd.Flags, Config.AutoEnable.Search, args, printSearchPrompt) - if num == -1 { - return - } - args = args[num:] - - // Check length of arguments. - if len(args) < 1 { - fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["NoKeyword"])) - return - } - - // Search from server, and list results. - results, err := doc.HttpGetBytes(doc.HttpClient, "http://gowalker.org/search?raw=true&q="+args[0], nil) - if err != nil { - utils.ColorPrint(fmt.Sprintf("[ERROR] runSearch -> [ %s ]\n", err)) - return - } - - pkgsCache := make(map[string]string) - paths := utils.GetGOPATH() - pkgs := strings.Split(string(results), "|||") - for _, p := range pkgs { - i := strings.Index(p, "$") - if i > -1 { - // Do not display standard library. - if !utils.IsGoRepoPath(p[:i]) { - pkgsCache[utils.GetProjectPath(p[:i])] = p[i+1:] - } - } - } - - if len(pkgsCache) == 0 { - fmt.Printf("No result is available for keyword: %s.\n", args[0]) - return - } - - isWindws := runtime.GOOS == "windows" - var buf bytes.Buffer - // Print split line for more clear look. - splitLine := fmt.Sprintf("<-----------------------------%s--------------------------->\n", PromptMsg["SearchResult"]) - if !isWindws { - splitLine = strings.Replace(splitLine, "<", fmt.Sprintf(utils.PureStartColor, utils.Magenta)+"<", 1) - splitLine = strings.Replace(splitLine, ">", ">"+utils.EndColor, 1) - } - buf.WriteString(splitLine) - - for k, v := range pkgsCache { - // Package import path. - buf.WriteString("-> " + k) - // Check if has been installed. - for _, path := range paths { - if utils.CheckIsExistWithVCS(path + "/src/" + k + "/") { - installStr := " [Installed]" - if !isWindws { - installStr = strings.Replace(installStr, "[", - fmt.Sprintf("[\033[%dm", utils.Green), 1) - installStr = strings.Replace(installStr, "]", - utils.EndColor+"]", 1) - } - buf.WriteString(installStr) - break - } - } - buf.WriteString("\n") - - if len(v) > 0 { - buf.WriteString(" " + v + "\n") // Synopsis。 - } - } - - resultStr := buf.String() - - if !isWindws { - // Set color highlight. - resultStr = strings.Replace(resultStr, args[0], - fmt.Sprintf(utils.PureStartColor, utils.Yellow)+args[0]+utils.EndColor, -1) - } - - fmt.Print(resultStr) -} diff --git a/cmd/struct.go b/cmd/struct.go deleted file mode 100644 index 909639aaa..000000000 --- a/cmd/struct.go +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package cmd - -import ( - "fmt" - "io" - "os" - "os/exec" - "strings" - - "github.com/GPMGo/gopm/doc" - "github.com/GPMGo/node" -) - -var ( - Config tomlConfig - AppPath string // Application path. -) - -var ( - LocalNodes []*node.Node - LocalBundles []*doc.Bundle -) - -// gopmConfig represents the package config file in correspoding directory. -type gopmConfig struct { - Deps []*node.Node -} - -type tomlConfig struct { - Title, Version string - Lang string `toml:"user_language"` - AutoBackup bool `toml:"auto_backup"` - Account account - AutoEnable flagEnable `toml:"auto_enable"` -} - -type flagEnable struct { - Build, Install, Search, Check []string -} - -type account struct { - Username, Password string - Github_Access_Token string `toml:"github_access_token"` -} - -// Use for i18n, key is prompt code, value is corresponding message. -var PromptMsg map[string]string - -// A Command is an implementation of a go command -// like go build or go fix. -type Command struct { - // Run runs the command. - // The args are the arguments after the command name. - Run func(cmd *Command, args []string) - - // UsageLine is the one-line usage message. - // The first word in the line is taken to be the command name. - UsageLine string - - // Short is the short description shown in the 'go help' output. - Short string - - // Long is the long message shown in the 'go help ' output. - Long string - - // Flag is a set of flags specific to this command. - Flags map[string]bool -} - -// Name returns the command's name: the first word in the usage line. -func (c *Command) Name() string { - name := c.UsageLine - i := strings.Index(name, " ") - if i >= 0 { - name = name[:i] - } - return name -} - -func (c *Command) Usage() { - fmt.Fprintf(os.Stderr, "usage: %s\n\n", c.UsageLine) - fmt.Fprintf(os.Stderr, "%s\n", strings.TrimSpace(c.Long)) - os.Exit(2) -} - -// Runnable reports whether the command can be run; otherwise -// it is a documentation pseudo-command such as importpath. -func (c *Command) Runnable() bool { - return c.Run != nil -} - -// executeCommand executes commands in command line. -func executeCommand(cmd string, args []string) { - cmdExec := exec.Command(cmd, args...) - stdout, err := cmdExec.StdoutPipe() - if err != nil { - fmt.Println(err) - } - stderr, err := cmdExec.StderrPipe() - if err != nil { - fmt.Println(err) - } - err = cmdExec.Start() - if err != nil { - fmt.Println(err) - } - go io.Copy(os.Stdout, stdout) - go io.Copy(os.Stderr, stderr) - cmdExec.Wait() -} diff --git a/conf/gopm.toml b/conf/gopm.toml deleted file mode 100644 index e2b5e27fc..000000000 --- a/conf/gopm.toml +++ /dev/null @@ -1,19 +0,0 @@ -# This is a configuration file for gpm with toml format. - -title = "gpm(Go Package Manager)" -version = "v0.2.6 Build 0527" -user_language = "en-US" -#user_language = "zh-CN" -auto_backup = true - -[account] -username = "" -password = "" -github_access_token = "" - -[auto_enable] -build = [] -install = [] -search = [] -remove = [] -check = [] \ No newline at end of file diff --git a/conf/sources.txt b/conf/sources.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/doc/bitbucket.go b/doc/bitbucket.go deleted file mode 100644 index 1da2376da..000000000 --- a/doc/bitbucket.go +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package doc - -import ( - "archive/tar" - "bytes" - "compress/gzip" - "errors" - "io" - "net/http" - "os" - "path" - "regexp" - "strings" - - "github.com/GPMGo/gopm/utils" - "github.com/GPMGo/node" -) - -var ( - BitbucketPattern = regexp.MustCompile(`^bitbucket\.org/(?P[a-z0-9A-Z_.\-]+)/(?P[a-z0-9A-Z_.\-]+)(?P/[a-z0-9A-Z_.\-/]*)?$`) - bitbucketEtagRe = regexp.MustCompile(`^(hg|git)-`) -) - -// GetBitbucketDoc downloads tarball from bitbucket.org. -func GetBitbucketDoc(client *http.Client, match map[string]string, installGOPATH string, nod *node.Node, cmdFlags map[string]bool) ([]string, error) { - // Check version control. - if m := bitbucketEtagRe.FindStringSubmatch(nod.Value); m != nil { - match["vcs"] = m[1] - } else { - var repo struct { - Scm string - } - if err := httpGetJSON(client, expand("https://api.bitbucket.org/1.0/repositories/{owner}/{repo}", match), &repo); err != nil { - return nil, err - } - match["vcs"] = repo.Scm - } - - // bundle and snapshot will have commit 'B' and 'S', - // but does not need to download dependencies. - isCheckImport := len(nod.Value) == 0 - - switch { - case isCheckImport || len(nod.Value) == 1: - // Get up-to-date version. - tags := make(map[string]string) - for _, nodeType := range []string{"branches", "tags"} { - var nodes map[string]struct { - Node string - } - if err := httpGetJSON(client, expand("https://api.bitbucket.org/1.0/repositories/{owner}/{repo}/{0}", match, nodeType), &nodes); err != nil { - return nil, err - } - for t, n := range nodes { - tags[t] = n.Node - } - } - - // Check revision tag. - var err error - match["tag"], match["commit"], err = bestTag(tags, defaultTags[match["vcs"]]) - if err != nil { - return nil, err - } - - nod.Type = "commit" - nod.Value = match["commit"] - case !isCheckImport: // Bundle or snapshot. - // Check downlaod type. - switch nod.Type { - case "tag", "commit", "branch": - match["commit"] = nod.Value - default: - return nil, errors.New("Unknown node type: " + nod.Type) - } - } - - // We use .tar.gz here. - // zip : https://bitbucket.org/{owner}/{repo}/get/{commit}.zip - // tarball : https://bitbucket.org/{owner}/{repo}/get/{commit}.tar.gz - - // Downlaod archive. - p, err := HttpGetBytes(client, expand("https://bitbucket.org/{owner}/{repo}/get/{commit}.tar.gz", match), nil) - if err != nil { - return nil, err - } - - projectPath := expand("bitbucket.org/{owner}/{repo}", match) - installPath := installGOPATH + "/src/" + projectPath - nod.ImportPath = projectPath - - // Remove old files. - os.RemoveAll(installPath + "/") - // Create destination directory. - os.MkdirAll(installPath+"/", os.ModePerm) - - gzr, err := gzip.NewReader(bytes.NewReader(p)) - if err != nil { - return nil, err - } - defer gzr.Close() - - tr := tar.NewReader(gzr) - - isCodeOnly := cmdFlags["-c"] - var autoPath string // Auto path is the root path that generated by bitbucket.org. - // Get source file data. - dirs := make([]string, 0, 5) - for { - h, err := tr.Next() - if err == io.EOF { - break - } else if err != nil { - return nil, err - } - - fn := h.FileInfo().Name() - - // In case that we find directory, usually we should not. - if strings.HasSuffix(fn, "/") { - continue - } - - // Check root path. - if len(autoPath) == 0 { - autoPath = fn[:strings.Index(fn, "/")] - } - absPath := strings.Replace(fn, autoPath, installPath, 1) - - // Create diretory before create file. - dir := path.Dir(absPath) - if !checkDir(dir, dirs) && !(!cmdFlags["-e"] && strings.Contains(absPath, "example")) { - dirs = append(dirs, dir) - os.MkdirAll(dir+"/", os.ModePerm) - } - - if isCodeOnly && !utils.IsDocFile(path.Base(absPath)) { - continue - } else if strings.HasPrefix(fn, ".") { - continue - } - - // Get data from archive. - fbytes := make([]byte, h.Size) - if _, err := io.ReadFull(tr, fbytes); err != nil { - return nil, err - } - - // Write data to file - fw, err := os.Create(absPath) - if err != nil { - return nil, err - } - - _, err = fw.Write(fbytes) - fw.Close() - if err != nil { - return nil, err - } - - // Set modify time. - os.Chtimes(absPath, h.AccessTime, h.ModTime) - } - - var imports []string - - // Check if need to check imports. - if isCheckImport { - for _, d := range dirs { - importPkgs, err := CheckImports(d+"/", match["importPath"]) - if err != nil { - return nil, err - } - imports = append(imports, importPkgs...) - } - } - - return imports, err -} - -// checkDir checks if current directory has been saved. -func checkDir(dir string, dirs []string) bool { - for _, d := range dirs { - if dir == d { - return true - } - } - return false -} diff --git a/doc/error.go b/doc/error.go deleted file mode 100644 index dc12c93f1..000000000 --- a/doc/error.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package doc - -import ( - "errors" -) - -var ( - errNotModified = errors.New("package not modified") - errUpdateTimeout = errors.New("update timeout") -) - -type NotFoundError struct { - Message string -} - -func (e NotFoundError) Error() string { - return e.Message -} - -func isNotFound(err error) bool { - _, ok := err.(NotFoundError) - return ok -} - -type RemoteError struct { - Host string - err error -} - -func (e *RemoteError) Error() string { - return e.err.Error() -} diff --git a/doc/github.go b/doc/github.go deleted file mode 100644 index 27cc4452d..000000000 --- a/doc/github.go +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package doc - -import ( - "archive/zip" - "bytes" - "errors" - "io" - "net/http" - "os" - "path" - "regexp" - "strings" - - "github.com/GPMGo/gopm/utils" - "github.com/GPMGo/node" -) - -var ( - githubRawHeader = http.Header{"Accept": {"application/vnd.github-blob.raw"}} - GithubPattern = regexp.MustCompile(`^github\.com/(?P[a-z0-9A-Z_.\-]+)/(?P[a-z0-9A-Z_.\-]+)(?P/[a-z0-9A-Z_.\-/]*)?$`) - githubCred string -) - -/*func SetGithubCredentials(id, secret string) { - //githubCred = "client_id=" + id + "&client_secret=" + secret -}*/ - -func SetGithubCredentials(token string) { - if len(token) > 0 { - githubCred = "access_token=" + token - } -} - -// GetGithubDoc downloads tarball from github.com. -func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH string, nod *node.Node, cmdFlags map[string]bool) ([]string, error) { - match["cred"] = githubCred - - // JSON struct for github.com. - var refs []*struct { - Ref string - Url string - Object struct { - Sha string - Type string - Url string - } - } - - // bundle and snapshot will have commit 'B' and 'S', - // but does not need to download dependencies. - isCheckImport := len(nod.Value) == 0 - - switch { - case isCheckImport || len(nod.Value) == 1: - // Get up-to-date version. - err := httpGetJSON(client, expand("https://api.github.com/repos/{owner}/{repo}/git/refs?{cred}", match), &refs) - if err != nil { - return nil, err - } - - tags := make(map[string]string) - for _, ref := range refs { - switch { - case strings.HasPrefix(ref.Ref, "refs/heads/"): - tags[ref.Ref[len("refs/heads/"):]] = ref.Object.Sha - case strings.HasPrefix(ref.Ref, "refs/tags/"): - tags[ref.Ref[len("refs/tags/"):]] = ref.Object.Sha - } - } - - // Check revision tag. - match["tag"], match["sha"], err = bestTag(tags, "master") - if err != nil { - return nil, err - } - - nod.Type = "commit" - nod.Value = match["sha"] - case !isCheckImport: // Bundle or snapshot. - // Check downlaod type. - switch nod.Type { - case "tag", "commit", "branch": - match["sha"] = nod.Value - default: - return nil, errors.New("Unknown node type: " + nod.Type) - } - } - - // We use .zip here. - // zip : https://github.com/{owner}/{repo}/archive/{sha}.zip - // tarball : https://github.com/{owner}/{repo}/tarball/{sha} - - // Downlaod archive. - p, err := HttpGetBytes(client, expand("https://github.com/{owner}/{repo}/archive/{sha}.zip", match), nil) - if err != nil { - return nil, err - } - - shaName := expand("{repo}-{sha}", match) - if nod.Type == "tag" { - shaName = strings.Replace(shaName, "-v", "-", 1) - } - - projectPath := expand("github.com/{owner}/{repo}", match) - installPath := installGOPATH + "/src/" + projectPath - nod.ImportPath = projectPath - - // Remove old files. - os.RemoveAll(installPath + "/") - // Create destination directory. - os.MkdirAll(installPath+"/", os.ModePerm) - - r, err := zip.NewReader(bytes.NewReader(p), int64(len(p))) - if err != nil { - return nil, err - } - - isCodeOnly := cmdFlags["-c"] - dirs := make([]string, 0, 5) - // Need to add root path because we cannot get from tarball. - dirs = append(dirs, installPath+"/") - for _, f := range r.File { - absPath := strings.Replace(f.FileInfo().Name(), shaName, installPath, 1) - // Create diretory before create file. - os.MkdirAll(path.Dir(absPath)+"/", os.ModePerm) - - compareDir: - switch { - case strings.HasSuffix(absPath, "/"): // Directory. - // Check if current directory is example. - if !(!cmdFlags["-e"] && strings.Contains(absPath, "example")) { - for _, d := range dirs { - if d == absPath { - break compareDir - } - } - dirs = append(dirs, absPath) - } - case isCodeOnly && !utils.IsDocFile(path.Base(absPath)): - continue - case !strings.HasPrefix(f.FileInfo().Name(), "."): - // Get file from archive. - rc, err := f.Open() - if err != nil { - return nil, err - } - - // Write data to file - fw, _ := os.Create(absPath) - if err != nil { - return nil, err - } - - _, err = io.Copy(fw, rc) - // Close files. - rc.Close() - fw.Close() - if err != nil { - return nil, err - } - - // Set modify time. - os.Chtimes(absPath, f.ModTime(), f.ModTime()) - } - } - - var imports []string - - // Check if need to check imports. - if isCheckImport { - for _, d := range dirs { - importPkgs, err := CheckImports(d, match["importPath"]) - if err != nil { - return nil, err - } - imports = append(imports, importPkgs...) - } - } - - /*fpath := appPath + "repo/tarballs/" + node.ImportPath + "-" + node.Value + ".zip" - // Save tarball. - if autoBackup && !utils.IsExist(fpath) { - os.MkdirAll(path.Dir(fpath)+"/", os.ModePerm) - f, err := os.Create(fpath) - if err != nil { - return nil, err - } - defer f.Close() - _, err = f.Write(p) - }*/ - - return imports, err -} diff --git a/doc/google.go b/doc/google.go deleted file mode 100644 index 9282f05aa..000000000 --- a/doc/google.go +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package doc - -import ( - "errors" - "net/http" - "os" - "path" - "regexp" - "strings" - - "github.com/GPMGo/gopm/utils" - "github.com/GPMGo/node" -) - -var ( - googleRepoRe = regexp.MustCompile(`id="checkoutcmd">(hg|git|svn)`) - googleRevisionRe = regexp.MustCompile(`

(?:[^ ]+ - )?Revision *([^:]+):`) - googleEtagRe = regexp.MustCompile(`^(hg|git|svn)-`) - googleFileRe = regexp.MustCompile(`
  • [a-z0-9\-]+)(:?\.(?P[a-z0-9\-]+))?(?P/[a-z0-9A-Z_.\-/]+)?$`) -) - -func setupGoogleMatch(match map[string]string) { - if s := match["subrepo"]; s != "" { - match["dot"] = "." - match["query"] = "?repo=" + s - } else { - match["dot"] = "" - match["query"] = "" - } -} - -func getGoogleVCS(client *http.Client, match map[string]string) error { - // Scrape the HTML project page to find the VCS. - p, err := HttpGetBytes(client, expand("http://code.google.com/p/{repo}/source/checkout", match), nil) - if err != nil { - return err - } - m := googleRepoRe.FindSubmatch(p) - if m == nil { - return NotFoundError{"Could not VCS on Google Code project page."} - } - - match["vcs"] = string(m[1]) - return nil -} - -// GetGoogleDoc downloads raw files from code.google.com. -func GetGoogleDoc(client *http.Client, match map[string]string, installGOPATH string, nod *node.Node, cmdFlags map[string]bool) ([]string, error) { - setupGoogleMatch(match) - // Check version control. - if m := googleEtagRe.FindStringSubmatch(nod.Value); m != nil { - match["vcs"] = m[1] - } else if err := getGoogleVCS(client, match); err != nil { - return nil, err - } - - // bundle and snapshot will have commit 'B' and 'S', - // but does not need to download dependencies. - isCheckImport := len(nod.Value) == 0 - if len(nod.Value) == 1 { - nod.Value = "" - } - - rootPath := expand("http://{subrepo}{dot}{repo}.googlecode.com/{vcs}{dir}/", match) - - // Scrape the repo browser to find the project revision and individual Go files. - p, err := HttpGetBytes(client, rootPath+"?r="+nod.Value, nil) - if err != nil { - return nil, err - } - - // Check revision tag. - if m := googleRevisionRe.FindSubmatch(p); m == nil { - return nil, - errors.New("doc.GetGoogleDoc(): Could not find revision for " + match["importPath"]) - } else { - nod.Type = "commit" - nod.Value = string(m[1]) - } - - projectPath := expand("code.google.com/p/{repo}{dot}{subrepo}{dir}", match) - installPath := installGOPATH + "/src/" + projectPath - nod.ImportPath = projectPath - - // Remove old files. - os.RemoveAll(installPath + "/") - // Create destination directory. - os.MkdirAll(installPath+"/", os.ModePerm) - - isCodeOnly := cmdFlags["-c"] - // Get source files in root path. - files := make([]*source, 0, 5) - for _, m := range googleFileRe.FindAllSubmatch(p, -1) { - fname := strings.Split(string(m[1]), "?")[0] - if isCodeOnly && !utils.IsDocFile(fname) { - continue - } else if strings.HasPrefix(fname, ".") { - continue - } - - files = append(files, &source{ - name: fname, - rawURL: expand("http://{subrepo}{dot}{repo}.googlecode.com/{vcs}{dir}/{0}", match, fname) + "?r=" + nod.Value, - }) - } - - // Fetch files from VCS. - if err := fetchFiles(client, files, nil); err != nil { - return nil, err - } - - // Save files. - for _, f := range files { - absPath := installPath + "/" - - // Create diretory before create file. - os.MkdirAll(path.Dir(absPath), os.ModePerm) - - // Write data to file - fw, err := os.Create(absPath + f.name) - if err != nil { - return nil, err - } - - _, err = fw.Write(f.data) - fw.Close() - if err != nil { - return nil, err - } - } - - dirs := make([]string, 0, 3) - // Get subdirectories. - for _, m := range googleDirRe.FindAllSubmatch(p, -1) { - dirName := strings.Split(string(m[1]), "?")[0] - if strings.HasSuffix(dirName, "/") { - dirs = append(dirs, dirName) - } - } - - err = downloadFiles(client, match, rootPath, installPath+"/", nod.Value, dirs) - if err != nil { - return nil, err - } - - var imports []string - - // Check if need to check imports. - if isCheckImport { - dirs, err := utils.GetDirsInfo(installPath + "/") - if err != nil { - return nil, err - } - - for _, d := range dirs { - if d.IsDir() && !(!cmdFlags["-e"] && strings.Contains(d.Name(), "example")) { - absPath := installPath + "/" + d.Name() + "/" - importPkgs, err := CheckImports(absPath, match["importPath"]) - if err != nil { - return nil, err - } - imports = append(imports, importPkgs...) - } - } - } - - return imports, err -} - -func downloadFiles(client *http.Client, match map[string]string, rootPath, installPath, commit string, dirs []string) error { - for _, d := range dirs { - p, err := HttpGetBytes(client, rootPath+d+"?r="+commit, nil) - if err != nil { - return err - } - - // Create destination directory. - os.MkdirAll(installPath+d, os.ModePerm) - - // Get source files in current path. - files := make([]*source, 0, 5) - for _, m := range googleFileRe.FindAllSubmatch(p, -1) { - fname := strings.Split(string(m[1]), "?")[0] - files = append(files, &source{ - name: fname, - rawURL: expand("http://{subrepo}{dot}{repo}.googlecode.com/{vcs}{dir}/", match) + d + fname + "?r=" + commit, - }) - } - - // Fetch files from VCS. - if err := fetchFiles(client, files, nil); err != nil { - return err - } - - // Save files. - for _, f := range files { - absPath := installPath + d - - // Create diretory before create file. - os.MkdirAll(path.Dir(absPath), os.ModePerm) - - // Write data to file - fw, err := os.Create(absPath + f.name) - if err != nil { - return err - } - - _, err = fw.Write(f.data) - fw.Close() - if err != nil { - return err - } - } - - subdirs := make([]string, 0, 3) - // Get subdirectories. - for _, m := range googleDirRe.FindAllSubmatch(p, -1) { - dirName := strings.Split(string(m[1]), "?")[0] - if strings.HasSuffix(dirName, "/") { - subdirs = append(subdirs, d+dirName) - } - } - - err = downloadFiles(client, match, rootPath, installPath, commit, subdirs) - if err != nil { - return err - } - } - return nil -} diff --git a/doc/http.go b/doc/http.go deleted file mode 100644 index 34e6b3e3f..000000000 --- a/doc/http.go +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package doc - -import ( - "encoding/json" - "flag" - "fmt" - "io" - "io/ioutil" - "net" - "net/http" - "time" -) - -var userAgent = "go application" - -var ( - dialTimeout = flag.Duration("dial_timeout", 10*time.Second, "Timeout for dialing an HTTP connection.") - readTimeout = flag.Duration("read_timeout", 10*time.Second, "Timeoout for reading an HTTP response.") - writeTimeout = flag.Duration("write_timeout", 5*time.Second, "Timeout writing an HTTP request.") -) - -type timeoutConn struct { - net.Conn -} - -func (c *timeoutConn) Read(p []byte) (int, error) { - return c.Conn.Read(p) -} - -func (c *timeoutConn) Write(p []byte) (int, error) { - // Reset timeouts when writing a request. - c.Conn.SetWriteDeadline(time.Now().Add(*readTimeout)) - c.Conn.SetWriteDeadline(time.Now().Add(*writeTimeout)) - return c.Conn.Write(p) -} -func timeoutDial(network, addr string) (net.Conn, error) { - c, err := net.DialTimeout(network, addr, *dialTimeout) - if err != nil { - return nil, err - } - return &timeoutConn{Conn: c}, nil -} - -var ( - httpTransport = &http.Transport{Dial: timeoutDial} - HttpClient = &http.Client{Transport: httpTransport} -) - -// HttpGetBytes returns page data in []byte. -func HttpGetBytes(client *http.Client, url string, header http.Header) ([]byte, error) { - rc, err := httpGet(client, url, header) - if err != nil { - return nil, err - } - p, err := ioutil.ReadAll(rc) - rc.Close() - return p, err -} - -// httpGet gets the specified resource. ErrNotFound is returned if the -// server responds with status 404. -func httpGet(client *http.Client, url string, header http.Header) (io.ReadCloser, error) { - req, err := http.NewRequest("GET", url, nil) - if err != nil { - return nil, err - } - req.Header.Set("User-Agent", userAgent) - for k, vs := range header { - req.Header[k] = vs - } - resp, err := client.Do(req) - if err != nil { - return nil, &RemoteError{req.URL.Host, err} - } - - if resp.StatusCode == 200 { - return resp.Body, nil - } - resp.Body.Close() - if resp.StatusCode == 404 { // 403 can be rate limit error. || resp.StatusCode == 403 { - err = NotFoundError{"Resource not found: " + url} - } else { - err = &RemoteError{req.URL.Host, fmt.Errorf("get %s -> %d", url, resp.StatusCode)} - } - return nil, err -} - -// fetchFiles fetches the source files specified by the rawURL field in parallel. -func fetchFiles(client *http.Client, files []*source, header http.Header) error { - ch := make(chan error, len(files)) - for i := range files { - go func(i int) { - req, err := http.NewRequest("GET", files[i].rawURL, nil) - if err != nil { - ch <- err - return - } - req.Header.Set("User-Agent", userAgent) - for k, vs := range header { - req.Header[k] = vs - } - resp, err := client.Do(req) - if err != nil { - ch <- &RemoteError{req.URL.Host, err} - return - } - defer resp.Body.Close() - if resp.StatusCode != 200 { - ch <- &RemoteError{req.URL.Host, fmt.Errorf("get %s -> %d", req.URL, resp.StatusCode)} - return - } - files[i].data, err = ioutil.ReadAll(resp.Body) - if err != nil { - ch <- &RemoteError{req.URL.Host, err} - return - } - ch <- nil - }(i) - } - for _ = range files { - if err := <-ch; err != nil { - return err - } - } - return nil -} - -func httpGetJSON(client *http.Client, url string, v interface{}) error { - rc, err := httpGet(client, url, nil) - if err != nil { - return err - } - defer rc.Close() - err = json.NewDecoder(rc).Decode(v) - if _, ok := err.(*json.SyntaxError); ok { - err = NotFoundError{"JSON syntax error at " + url} - } - return err -} diff --git a/doc/launchpad.go b/doc/launchpad.go deleted file mode 100644 index 849883079..000000000 --- a/doc/launchpad.go +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package doc - -import ( - "archive/tar" - "bytes" - "compress/gzip" - "io" - "net/http" - "os" - "path" - "regexp" - "strings" - - "github.com/GPMGo/gopm/utils" - "github.com/GPMGo/node" -) - -var LaunchpadPattern = regexp.MustCompile(`^launchpad\.net/(?P(?P[a-z0-9A-Z_.\-]+)(?P/[a-z0-9A-Z_.\-]+)?|~[a-z0-9A-Z_.\-]+/(\+junk|[a-z0-9A-Z_.\-]+)/[a-z0-9A-Z_.\-]+)(?P/[a-z0-9A-Z_.\-/]+)*$`) - -// GetLaunchpadDoc downloads tarball from launchpad.net. -func GetLaunchpadDoc(client *http.Client, match map[string]string, installGOPATH string, nod *node.Node, cmdFlags map[string]bool) ([]string, error) { - - if match["project"] != "" && match["series"] != "" { - rc, err := httpGet(client, expand("https://code.launchpad.net/{project}{series}/.bzr/branch-format", match), nil) - switch { - case err == nil: - rc.Close() - // The structure of the import path is launchpad.net/{root}/{dir}. - case isNotFound(err): - // The structure of the import path is is launchpad.net/{project}/{dir}. - match["repo"] = match["project"] - match["dir"] = expand("{series}{dir}", match) - default: - return nil, err - } - } - - // bundle and snapshot will have commit 'B' and 'S', - // but does not need to download dependencies. - isCheckImport := len(nod.Value) == 0 - - var downloadPath string - // Check if download with specific revision. - if isCheckImport || len(nod.Value) == 1 { - downloadPath = expand("https://bazaar.launchpad.net/+branch/{repo}/tarball", match) - nod.Type = "commit" - } else { - downloadPath = expand("https://bazaar.launchpad.net/+branch/{repo}/tarball/"+nod.Value, match) - } - - // Scrape the repo browser to find the project revision and individual Go files. - p, err := HttpGetBytes(client, downloadPath, nil) - if err != nil { - return nil, err - } - - projectPath := expand("launchpad.net/{repo}", match) - installPath := installGOPATH + "/src/" + projectPath - nod.ImportPath = projectPath - - // Remove old files. - os.RemoveAll(installPath + "/") - // Create destination directory. - os.MkdirAll(installPath+"/", os.ModePerm) - - gzr, err := gzip.NewReader(bytes.NewReader(p)) - if err != nil { - return nil, err - } - defer gzr.Close() - - tr := tar.NewReader(gzr) - - isCodeOnly := cmdFlags["-c"] - var autoPath string // Auto path is the root path that generated by bitbucket.org. - // Get source file data. - dirs := make([]string, 0, 5) - for { - h, err := tr.Next() - if err == io.EOF { - break - } else if err != nil { - return nil, err - } - - fn := h.FileInfo().Name() - // Check root path. - if len(autoPath) == 0 { - autoPath = fn[:strings.Index(fn, match["repo"])+len(match["repo"])] - } - absPath := strings.Replace(fn, autoPath, installPath, 1) - - switch { - case h.FileInfo().IsDir(): // Directory. - // Check if current directory is example. - if !(!cmdFlags["-e"] && strings.Contains(absPath, "example")) { - dirs = append(dirs, absPath) - } - case isCodeOnly && !utils.IsDocFile(path.Base(absPath)): - continue - case !strings.HasPrefix(fn, "."): - // Create diretory before create file. - os.MkdirAll(path.Dir(absPath)+"/", os.ModePerm) - - // Get data from archive. - fbytes := make([]byte, h.Size) - if _, err := io.ReadFull(tr, fbytes); err != nil { - return nil, err - } - - // Write data to file - fw, err := os.Create(absPath) - if err != nil { - return nil, err - } - - _, err = fw.Write(fbytes) - fw.Close() - if err != nil { - return nil, err - } - } - } - - var imports []string - - // Check if need to check imports. - if isCheckImport { - for _, d := range dirs { - importPkgs, err := CheckImports(d+"/", match["importPath"]) - if err != nil { - return nil, err - } - imports = append(imports, importPkgs...) - } - } - - return imports, err -} diff --git a/doc/struct.go b/doc/struct.go deleted file mode 100644 index 89eaebd1a..000000000 --- a/doc/struct.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package doc - -import ( - "go/token" - "os" - "time" - "github.com/GPMGo/node" -) - -// Bundle represents a bundle. -type Bundle struct { - Id int64 - UserId int64 `json:"user_id"` - Name string `json:"bundle_name"` - Timestamp int64 - Comment string - Nodes []*node.Node -} - -// source is source code file. -type source struct { - rawURL string - name string - data []byte -} - -func (s *source) Name() string { return s.name } -func (s *source) Size() int64 { return int64(len(s.data)) } -func (s *source) Mode() os.FileMode { return 0 } -func (s *source) ModTime() time.Time { return time.Time{} } -func (s *source) IsDir() bool { return false } -func (s *source) Sys() interface{} { return nil } - -// walker holds the state used when building the documentation. -type walker struct { - ImportPath string - srcs map[string]*source // Source files. - fset *token.FileSet -} diff --git a/doc/vcs.go b/doc/vcs.go deleted file mode 100644 index 8a1628249..000000000 --- a/doc/vcs.go +++ /dev/null @@ -1,238 +0,0 @@ -// Copyright 2012 Gary Burd -// -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package doc - -import ( - "bytes" - "io/ioutil" - "log" - "os" - "os/exec" - "path" - "regexp" - "strconv" - "strings" -) - -var ( - appPath string - autoBackup bool -) - -func SetAppConfig(path string, backup bool) { - appPath = path - autoBackup = backup -} - -// TODO: specify with command line flag -const repoRoot = "/tmp/gddo" - -var urlTemplates = []struct { - re *regexp.Regexp - template string - lineFmt string -}{ - { - regexp.MustCompile(`^git\.gitorious\.org/(?P[^/]+/[^/]+)$`), - "https://gitorious.org/{repo}/blobs/{tag}/{dir}{0}", - "#line%d", - }, - { - regexp.MustCompile(`^camlistore\.org/r/p/(?P[^/]+)$`), - "http://camlistore.org/code/?p={repo}.git;hb={tag};f={dir}{0}", - "#l%d", - }, -} - -// lookupURLTemplate finds an expand() template, match map and line number -// format for well known repositories. -func lookupURLTemplate(repo, dir, tag string) (string, map[string]string, string) { - if strings.HasPrefix(dir, "/") { - dir = dir[1:] + "/" - } - for _, t := range urlTemplates { - if m := t.re.FindStringSubmatch(repo); m != nil { - match := map[string]string{ - "dir": dir, - "tag": tag, - } - for i, name := range t.re.SubexpNames() { - if name != "" { - match[name] = m[i] - } - } - return t.template, match, t.lineFmt - } - } - return "", nil, "" -} - -type vcsCmd struct { - schemes []string - download func([]string, string, string) (string, string, error) -} - -var vcsCmds = map[string]*vcsCmd{ - "git": &vcsCmd{ - schemes: []string{"http", "https", "git"}, - download: downloadGit, - }, -} - -var lsremoteRe = regexp.MustCompile(`(?m)^([0-9a-f]{40})\s+refs/(?:tags|heads)/(.+)$`) - -func downloadGit(schemes []string, repo, savedEtag string) (string, string, error) { - var p []byte - var scheme string - for i := range schemes { - cmd := exec.Command("git", "ls-remote", "--heads", "--tags", schemes[i]+"://"+repo+".git") - log.Println(strings.Join(cmd.Args, " ")) - var err error - p, err = cmd.Output() - if err == nil { - scheme = schemes[i] - break - } - } - - if scheme == "" { - return "", "", NotFoundError{"VCS not found"} - } - - tags := make(map[string]string) - for _, m := range lsremoteRe.FindAllSubmatch(p, -1) { - tags[string(m[2])] = string(m[1]) - } - - tag, commit, err := bestTag(tags, "master") - if err != nil { - return "", "", err - } - - etag := scheme + "-" + commit - - if etag == savedEtag { - return "", "", errNotModified - } - - dir := path.Join(repoRoot, repo+".git") - p, err = ioutil.ReadFile(path.Join(dir, ".git/HEAD")) - switch { - case err != nil: - if err := os.MkdirAll(dir, 0777); err != nil { - return "", "", err - } - cmd := exec.Command("git", "clone", scheme+"://"+repo, dir) - log.Println(strings.Join(cmd.Args, " ")) - if err := cmd.Run(); err != nil { - return "", "", err - } - case string(bytes.TrimRight(p, "\n")) == commit: - return tag, etag, nil - default: - cmd := exec.Command("git", "fetch") - log.Println(strings.Join(cmd.Args, " ")) - cmd.Dir = dir - if err := cmd.Run(); err != nil { - return "", "", err - } - } - - cmd := exec.Command("git", "checkout", "--detach", "--force", commit) - cmd.Dir = dir - if err := cmd.Run(); err != nil { - return "", "", err - } - - return tag, etag, nil -} - -var defaultTags = map[string]string{"git": "master", "hg": "default"} - -func bestTag(tags map[string]string, defaultTag string) (string, string, error) { - if commit, ok := tags["go1"]; ok { - return "go1", commit, nil - } - if commit, ok := tags[defaultTag]; ok { - return defaultTag, commit, nil - } - return "", "", NotFoundError{"Tag or branch not found."} -} - -// expand replaces {k} in template with match[k] or subs[atoi(k)] if k is not in match. -func expand(template string, match map[string]string, subs ...string) string { - var p []byte - var i int - for { - i = strings.Index(template, "{") - if i < 0 { - break - } - p = append(p, template[:i]...) - template = template[i+1:] - i = strings.Index(template, "}") - if s, ok := match[template[:i]]; ok { - p = append(p, s...) - } else { - j, _ := strconv.Atoi(template[:i]) - p = append(p, subs[j]...) - } - template = template[i+1:] - } - p = append(p, template...) - return string(p) -} - -// checkImports checks package denpendencies. -func CheckImports(absPath, importPath string) (importPkgs []string, err error) { - dir, err := os.Open(absPath) - if err != nil { - return nil, err - } - defer dir.Close() - - // Get file info slice. - fis, err := dir.Readdir(0) - if err != nil { - return nil, err - } - - files := make([]*source, 0, 10) - for _, fi := range fis { - // Only handle files. - if strings.HasSuffix(fi.Name(), ".go") { - f, err := os.Open(absPath + fi.Name()) - if err != nil { - return nil, err - } - - fbytes := make([]byte, fi.Size()) - _, err = f.Read(fbytes) - f.Close() - - if err != nil { - return nil, err - } - - files = append(files, &source{ - name: fi.Name(), - data: fbytes, - }) - } - } - - // Check if has Go source files. - if len(files) > 0 { - w := &walker{ImportPath: importPath} - importPkgs, err = w.build(files) - if err != nil { - return nil, err - } - } - - return importPkgs, err -} diff --git a/doc/walker.go b/doc/walker.go deleted file mode 100644 index 6c305dde8..000000000 --- a/doc/walker.go +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright 2012 Gary Burd -// -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package doc - -import ( - "bytes" - "errors" - "go/ast" - "go/build" - "go/parser" - "go/token" - "io" - "io/ioutil" - "os" - "path" - "runtime" - "strings" - - "github.com/GPMGo/gopm/utils" -) - -type sliceWriter struct{ p *[]byte } - -func (w sliceWriter) Write(p []byte) (int, error) { - *w.p = append(*w.p, p...) - return len(p), nil -} - -func (w *walker) readDir(dir string) ([]os.FileInfo, error) { - if dir != w.ImportPath { - panic("unexpected") - } - fis := make([]os.FileInfo, 0, len(w.srcs)) - for _, src := range w.srcs { - fis = append(fis, src) - } - return fis, nil -} - -func (w *walker) openFile(path string) (io.ReadCloser, error) { - if strings.HasPrefix(path, w.ImportPath+"/") { - if src, ok := w.srcs[path[len(w.ImportPath)+1:]]; ok { - return ioutil.NopCloser(bytes.NewReader(src.data)), nil - } - } - panic("unexpected") -} - -func simpleImporter(imports map[string]*ast.Object, path string) (*ast.Object, error) { - pkg := imports[path] - if pkg == nil { - // Guess the package name without importing it. Start with the last - // element of the path. - name := path[strings.LastIndex(path, "/")+1:] - - // Trim commonly used prefixes and suffixes containing illegal name - // runes. - name = strings.TrimSuffix(name, ".go") - name = strings.TrimSuffix(name, "-go") - name = strings.TrimPrefix(name, "go.") - name = strings.TrimPrefix(name, "go-") - name = strings.TrimPrefix(name, "biogo.") - - // It's also common for the last element of the path to contain an - // extra "go" prefix, but not always. TODO: examine unresolved ids to - // detect when trimming the "go" prefix is appropriate. - - pkg = ast.NewObj(ast.Pkg, name) - pkg.Data = ast.NewScope(nil) - imports[path] = pkg - } - return pkg, nil -} - -// build gets imports from source files. -func (w *walker) build(srcs []*source) ([]string, error) { - // Add source files to walker, I skipped references here. - w.srcs = make(map[string]*source) - for _, src := range srcs { - w.srcs[src.name] = src - } - - w.fset = token.NewFileSet() - - // Find the package and associated files. - ctxt := build.Context{ - GOOS: runtime.GOOS, - GOARCH: runtime.GOARCH, - CgoEnabled: true, - JoinPath: path.Join, - IsAbsPath: path.IsAbs, - SplitPathList: func(list string) []string { return strings.Split(list, ":") }, - IsDir: func(path string) bool { panic("unexpected") }, - HasSubdir: func(root, dir string) (rel string, ok bool) { panic("unexpected") }, - ReadDir: func(dir string) (fi []os.FileInfo, err error) { return w.readDir(dir) }, - OpenFile: func(path string) (r io.ReadCloser, err error) { return w.openFile(path) }, - Compiler: "gc", - } - - bpkg, err := ctxt.ImportDir(w.ImportPath, 0) - // Continue if there are no Go source files; we still want the directory info. - _, nogo := err.(*build.NoGoError) - if err != nil { - if nogo { - err = nil - } else { - return nil, errors.New("doc.walker.build(): " + err.Error()) - } - } - - // Parse the Go files - - files := make(map[string]*ast.File) - for _, name := range append(bpkg.GoFiles, bpkg.CgoFiles...) { - file, err := parser.ParseFile(w.fset, name, w.srcs[name].data, parser.ParseComments) - if err != nil { - //beego.Error("doc.walker.build():", err) - continue - } - files[name] = file - } - - w.ImportPath = strings.Replace(w.ImportPath, "\\", "/", -1) - var imports []string - for _, v := range bpkg.Imports { - // Skip strandard library. - if !utils.IsGoRepoPath(v) && - (utils.GetProjectPath(v) != utils.GetProjectPath(w.ImportPath)) { - imports = append(imports, v) - } - } - - return imports, err -} diff --git a/docs/Quick_Start.md b/docs/Quick_Start.md deleted file mode 100644 index 17764d9ec..000000000 --- a/docs/Quick_Start.md +++ /dev/null @@ -1,135 +0,0 @@ -# Quick Start - -Full documentation please visit [GPMGo Documentation]()(Haven't done yet!). - -## Index - -- [When and why](#when-and-why) -- [Installation](#installation) -- [ **Install** package, or packages](#install-package-or-packages) -- [ **Build** and run it](#build-and-run-it) -- [ **Remove** package, or packages](#remove-package-or-packages) -- [ Use **check** to check dependencies](#use-check-to-check-dependencies) -- [ **Search** and find more](#search-and-find-more) - -## When and why - -### Lightweight version control - -Unlike large version control system like git, hg, or svn, you don't have to install any version control tool for using gpm; you are still able to download and install packages that you prefer to. - -### Not only project, but dependencies! - -With gpm, it's much easier to control dependencies version of your packages specifically. All you need to do is that indicate version either by tag, branch or commit of your dependencies, and leave rest of work to gpm! - -### Killer feature over `go get`? - -- `go get` gives great advantages of package installation in Go, but the only thing it's missing is version control of dependencies. -- Every time you use `go get`, you may download unstable version of your package dependencies, and you may waste your time to find last version in almost unreadable commit history. -- Not only main package, dependencies also have their dependencies, in a big project, small things like this should not waste your attention for building awesome applications. - -### How's configuration file looks like? - -In gpm, we call `bundle` for this kind of files, here is an example of a [bundle](https://github.com/GPMGo/gpm/blob/master/repo/bundles/test_bundle.json), don't get it? It's fine, we'll talk about it more just one second. - -## Installation - -You can install gpm either from source or download binary. - -### Install from source - -- gopm is a `go get` able project: execute command `go get github.com/GPMGo/gopm` to download and install. -- Run test: switch work directory to gopm project, and execute command `go test` to build and test commands automatically(for now, tested commands are `gopm install`, `gopm remove`). -- Add gopm project path to your environment variable `PATH` in order to execute it in other directories. - -**Attention** If you install from source, you can actually put binary in any path that has already existed in $PATH, so you don't need to add a new path to $PATH again. - -### Download binary - -At this time, we recommend you install from source. - -Because we don't have all kinds of operating systems, we need your help to complete following download list!(I'm just too lazy to cross compiling -_-|||) - -- darwin-386: -- darwin-amd64: -- freebsd-386: -- freebsd-amd64: -- linux-386: -- linux-amd64: -- windows_386: -- windows_amd64: - -**Attention** Because we use API to get information of packages that are hosted on github.com, but it limits 60 requests per hour, so you may get errors if you download too much(more than 50 packages per hour). We do not provider access token for security reason, but we do have configure option `github_access_token` in configuration file `conf/gopm.toml`, so you can go to [here](https://github.com/settings/applications) and create your personal access token(up to 5000 request per hour), and set it in `gopm.toml`. - -## Install package, or packages - -Command `install` downloads and installs packages along with all dependencies(except when you use bundle or snapshot). - -Suppose you want to install package `github.com/GPMGoTest/install_test`, here two ways to do it: - -### Install like `go get` - -- Execute command `gpm install github.com/GPMGoTest/install_test`, and you do not need to install version control tool. In case you want to, `gpm install -v github.com/GPMGoTest/install_test` calls `go get` in underlying. - -### Install through bundle - -- It's still not cool enough to download and install packages with import path, let's try execute command `gopm install test.b`, see what happens? -- Where is the `test.b` comes from? We actually created a bundle for you in directory `repo/bundles/`, and all bundles should be put there. -- This is how bundle works, you can open it and see what's inside, it includes import path, type, value and dependencies. -- The `test.b` means the bundle whose name is `test`, if you want to use bundle, you have to add suffix `.b`. You may notice that our file name is `install_test.json`, why is `test`? Because we use `bundle_name` inside file, file name doesn't mean anything unless you leave `bundle_name` blank, then the file name becomes bundle name automatically, but be sure that all bundle file name should use JSON and suffix `.json`. -- For `code.google.com`, `launchpad.net`, type is **ALWAYS** `commit`, and you can leave value blank which means up-to-date, or give it a certain value and you will download the same version of the package no matter how many times. -- For `github.com`, `bitbucket.org`, type can be either `commit`, `branch` or `tag`, and give it corresponding value. -- Now, you should have two packages which are `github.com/GPMGoTest/install_test` and `github.com/GPMGoTest/install_test2` in your computer. - -### Share? - -Copy and paste your bundle files to anyone else, nothing much! - -## Build and run it - -Command `build` compiles and installs packages along with all dependencies. - -Let's switch work directory to package `github.com/GPMGoTest/install_test`. - -- Execute command `gopm build -r`. -- After built, you should see string `Welcome to use gopm(Go Package Manager)!` was printed on the screen. -- Then, gpm calls `go install` in underlying, so you should have binary `$GOPATH/bin/install_test`, then gpm moves it to current directory. -- Flag `-r` means run after built, so you saw the string was printed. - -### Why we do this? - -In some cases like building web applications, we use relative path to access static files, and `go build` compiles packages without saving, so it's a shortcut for `go install` + `go build` + `go run`, and you don't need to compile packages again for those have not changed. - -## Remove package, or packages - -Command `remove` removes packages from your local file system. - -Suppose you want to remove package `github.com/GPMGoTest/install_test2/subpkg`. - -- Execute command `gopm remove github.com/GPMGoTest/install_test2/subpkg`, gopm finds this project in all paths in your GOPATH environment. -- You may notice this is not project path, it's OK because gpm knows it, and deletes directory `$GOPATH/src/github.com/GPMGoTest/install_test2/`, this command delete files in `$GOPATH/bin` and `$GOPATH/pkg` as well. -- You can also use `gopm remove test.b` to remove all packages are included in bundle, but we don't need here because we have one more cool stuff to try. - -## Use check to check dependencies - -Command `check` checks package dependencies and installs missing ones. - -Suppose you want to check package `github.com/GPMGoTest/install_test`. - -- Switch work directory to package path. -- Execute command `gopm check`. -- That's it! - -## Search and find more - -Command `search` is for searching packages in [Go Walker](http://gowalker.org) database. - -- Execute command `gopm search mysql`. -- Try it by yourself. - -## Go further - -- Online full documentation is still working, I'm sorry about that. -- Give us your feedback, these things matters. -- Join us and get better together. -- Contact: [gpmgo.com@gmail.com](mailto:gpmgo.com@gmail.com). \ No newline at end of file diff --git a/docs/Quick_Start_ZH.md b/docs/Quick_Start_ZH.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/gopm.go b/gopm.go deleted file mode 100644 index 81f7eccf3..000000000 --- a/gopm.go +++ /dev/null @@ -1,361 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -// gpm(Go Package Manager) is a Go package manage tool for search, install, update and share packages in Go. - -package main - -import ( - "encoding/json" - "fmt" - "io" - "os" - "os/exec" - "path" - "path/filepath" - "runtime" - "strings" - "sync" - "text/template" - "unicode" - "unicode/utf8" - - "github.com/BurntSushi/toml" - "github.com/GPMGo/gopm/cmd" - "github.com/GPMGo/gopm/doc" - "github.com/GPMGo/gopm/utils" -) - -// Commands lists the available commands and help topics. -// The order here is the order in which they are printed by 'gpm help'. -var commands = []*cmd.Command{ - cmd.CmdBuild, - cmd.CmdSearch, - cmd.CmdInstall, - cmd.CmdRemove, - cmd.CmdCheck, -} - -// getAppPath returns application execute path for current process. -func getAppPath() bool { - // Look up executable in PATH variable. - cmd.AppPath, _ = exec.LookPath(path.Base(os.Args[0])) - // Check if run under $GOPATH/bin - if !utils.IsExist(cmd.AppPath + "conf/") { - paths := utils.GetGOPATH() - for _, p := range paths { - if utils.IsExist(p + "/src/github.com/GPMGo/gopm/") { - cmd.AppPath = p + "/src/github.com/GPMGo/gopm/" - break - } - } - } - - if len(cmd.AppPath) == 0 { - utils.ColorPrint("[ERROR] getAppPath ->[ Unable to indicate current execute path. ]\n") - return false - } - - cmd.AppPath = filepath.Dir(cmd.AppPath) + "/" - if runtime.GOOS == "windows" { - // Replace all '\' to '/'. - cmd.AppPath = strings.Replace(cmd.AppPath, "\\", "/", -1) - } - - doc.SetAppConfig(cmd.AppPath, cmd.Config.AutoBackup) - return true -} - -// loadPromptMsg loads prompt messages according to user language. -func loadPromptMsg(lang string) bool { - cmd.PromptMsg = make(map[string]string) - - // Load prompt messages. - f, err := os.Open(cmd.AppPath + "i18n/" + lang + "/prompt.txt") - if err != nil { - utils.ColorPrint(fmt.Sprintf("[ERROR] loadUsage -> Fail to load prompt messages[ %s ]\n", err)) - return false - } - defer f.Close() - - // Read prompt messages. - fi, _ := f.Stat() - promptBytes := make([]byte, fi.Size()) - f.Read(promptBytes) - promptStrs := strings.Split(string(promptBytes), "\n") - for _, p := range promptStrs { - i := strings.Index(p, "=") - if i > -1 { - cmd.PromptMsg[p[:i]] = p[i+1:] - } - } - return true -} - -// loadUsage loads usage according to user language. -func loadUsage(lang string) bool { - if !loadPromptMsg(lang) { - return false - } - - // Load main usage. - f, err := os.Open(cmd.AppPath + "i18n/" + lang + "/usage.tpl") - if err != nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] loadUsage -> %s\n", cmd.PromptMsg["LoadCommandUsage"]), "main", err)) - return false - } - defer f.Close() - - // Read main usages. - fi, _ := f.Stat() - usageBytes := make([]byte, fi.Size()) - f.Read(usageBytes) - usageTemplate = string(usageBytes) - - // Load command usage. - for _, command := range commands { - f, err := os.Open(cmd.AppPath + "i18n/" + lang + "/usage_" + command.Name() + ".txt") - if err != nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] loadUsage -> %s\n", cmd.PromptMsg["LoadCommandUsage"]), command.Name(), err)) - return false - } - defer f.Close() - - // Read usage. - fi, _ := f.Stat() - usageBytes := make([]byte, fi.Size()) - f.Read(usageBytes) - usages := strings.Split(string(usageBytes), "|||") - if len(usages) < 2 { - utils.ColorPrint(fmt.Sprintf( - fmt.Sprintf("[ERROR] loadUsage -> %s\n", cmd.PromptMsg["ReadCoammndUsage"]), command.Name())) - return false - } - command.Short = usages[0] - command.Long = usages[1] - } - - return true -} - -// loadLocalNodes loads nodes information from local file system. -func loadLocalNodes() bool { - if !utils.IsExist(cmd.AppPath + "data/nodes.json") { - os.MkdirAll(cmd.AppPath+"data/", os.ModePerm) - } else { - fr, err := os.Open(cmd.AppPath + "data/nodes.json") - if err != nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] loadLocalNodes -> %s\n", cmd.PromptMsg["LoadLocalData"]), err)) - return false - } - defer fr.Close() - - err = json.NewDecoder(fr).Decode(&cmd.LocalNodes) - if err != nil && err != io.EOF { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] loadLocalNodes -> %s\n", cmd.PromptMsg["ParseJSON"]), err)) - return false - } - } - return true -} - -// loadLocalBundles loads bundles from local file system. -func loadLocalBundles() bool { - // Find all bundles. - dir, err := os.Open(cmd.AppPath + "repo/bundles/") - if err != nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] loadLocalBundles -> %s\n", cmd.PromptMsg["OpenFile"]), err)) - return false - } - defer dir.Close() - - fis, err := dir.Readdir(0) - if err != nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] loadLocalBundles -> %s\n", cmd.PromptMsg["OpenFile"]), err)) - return false - } - - for _, fi := range fis { - // In case this folder contains unexpected directories. - if !fi.IsDir() && strings.HasSuffix(fi.Name(), ".json") { - fr, err := os.Open(cmd.AppPath + "repo/bundles/" + fi.Name()) - if err != nil { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] loadLocalBundles -> %s\n", cmd.PromptMsg["OpenFile"]), err)) - return false - } - - bundle := new(doc.Bundle) - err = json.NewDecoder(fr).Decode(bundle) - fr.Close() - if err != nil && err != io.EOF { - utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] loadLocalBundles -> %s\n", cmd.PromptMsg["ParseJSON"]), err)) - return false - } - - // Make sure bundle name is not empty. - if len(bundle.Name) == 0 { - bundle.Name = fi.Name()[:strings.Index(fi.Name(), ".")] - } - - cmd.LocalBundles = append(cmd.LocalBundles, bundle) - } - } - return true -} - -// We don't use init() to initialize -// bacause we need to get execute path in runtime. -func initialize() bool { - // Try to have highest performance. - runtime.GOMAXPROCS(runtime.NumCPU()) - - // Get application execute path. - if !getAppPath() { - return false - } - - // Load configuration. - if _, err := toml.DecodeFile(cmd.AppPath+"conf/gopm.toml", &cmd.Config); err != nil { - fmt.Printf("initialize -> Fail to load configuration[ %s ]\n", err) - return false - } - - // Set github.com access token. - doc.SetGithubCredentials(cmd.Config.Account.Github_Access_Token) - - // Load usages by language. - if !loadUsage(cmd.Config.Lang) { - return false - } - - // Create bundle and snapshot directories. - os.MkdirAll(cmd.AppPath+"repo/bundles/", os.ModePerm) - os.MkdirAll(cmd.AppPath+"repo/snapshots/", os.ModePerm) - // Create local tarball directories. - os.MkdirAll(cmd.AppPath+"repo/tarballs/", os.ModePerm) - - // Initialize local data. - if !loadLocalNodes() || !loadLocalBundles() { - return false - } - - return true -} - -func main() { - // Initialization. - if !initialize() { - return - } - - // Check length of arguments. - args := os.Args[1:] - if len(args) < 1 { - usage() - return - } - - // Show help documentation. - if args[0] == "help" { - help(args[1:]) - return - } - - // Check commands and run. - for _, comm := range commands { - if comm.Name() == args[0] && comm.Run != nil { - comm.Run(comm, args[1:]) - exit() - return - } - } - - // Uknown commands. - fmt.Fprintf(os.Stderr, fmt.Sprintf("%s\n", cmd.PromptMsg["UnknownCommand"]), args[0]) - setExitStatus(2) - exit() -} - -var exitStatus = 0 -var exitMu sync.Mutex - -func setExitStatus(n int) { - exitMu.Lock() - if exitStatus < n { - exitStatus = n - } - exitMu.Unlock() -} - -var usageTemplate string -var helpTemplate = `{{if .Runnable}}usage: gopm {{.UsageLine}} - -{{end}}{{.Long | trim}} -` - -// tmpl executes the given template text on data, writing the result to w. -func tmpl(w io.Writer, text string, data interface{}) { - t := template.New("top") - t.Funcs(template.FuncMap{"trim": strings.TrimSpace, "capitalize": capitalize}) - template.Must(t.Parse(text)) - if err := t.Execute(w, data); err != nil { - panic(err) - } -} - -func capitalize(s string) string { - if s == "" { - return s - } - r, n := utf8.DecodeRuneInString(s) - return string(unicode.ToTitle(r)) + s[n:] -} - -func printUsage(w io.Writer) { - tmpl(w, usageTemplate, commands) -} - -func usage() { - printUsage(os.Stderr) - os.Exit(2) -} - -// help implements the 'help' command. -func help(args []string) { - if len(args) == 0 { - printUsage(os.Stdout) - // not exit 2: succeeded at 'gpm help'. - return - } - if len(args) != 1 { - fmt.Fprintf(os.Stderr, "usage: gopm help command\n\nToo many arguments given.\n") - os.Exit(2) // failed at 'gpm help' - } - - arg := args[0] - - for _, comm := range commands { - if comm.Name() == arg { - tmpl(os.Stdout, helpTemplate, comm) - // not exit 2: succeeded at 'go help cmd'. - return - } - } - - fmt.Fprintf(os.Stderr, "Unknown help topic %#q. Run 'gopm help'.\n", arg) - os.Exit(2) // failed at 'go help cmd' -} - -var atexitFuncs []func() - -func atexit(f func()) { - atexitFuncs = append(atexitFuncs, f) -} - -func exit() { - for _, f := range atexitFuncs { - f() - } - os.Exit(exitStatus) -} diff --git a/gopm.json b/gopm.json deleted file mode 100644 index d9592c63d..000000000 --- a/gopm.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "Deps": [ - { - "import_path": "github.com/BurntSushi/toml", - "type": "", - "value": "", - "deps": null - }, - { - "import_path": "github.com/GPMGo/node", - "type": "", - "value": "", - "deps": null - } - ] -} \ No newline at end of file diff --git a/i18n/en-US/prompt.txt b/i18n/en-US/prompt.txt deleted file mode 100644 index 5543be5bf..000000000 --- a/i18n/en-US/prompt.txt +++ /dev/null @@ -1,36 +0,0 @@ -LoadCommandUsage=Fail to load command(%s) usage[ %s ] -ReadCoammndUsage=Unacceptable command(%s) usage file. -LoadLocalData=Fail to load local data[ %s ] -ParseJSON=Fail to parse JSON[ %s ] -OpenFile=Fail to open file[ %s ] -RemoveFile=Fail to remove file[ %s ] -UnknownCommand=gopm: Unknown command %q. Run 'gopm help' for usage. -MoveFile=Fail to move file from $GOPATH(%s) to current directory(%s). -UnknownFlag=Unknown flag: %s. -DownloadError=Fail to download package(%s)[ %s ] -NotFoundError=Import path prefix matches known service, but regexp does not. -ErrNoMatch=Unsupported project hosting. -PackageNotFound=Cannot find package: %s. -CheckImports=Fail to check dependencies[ %s ] - -MovedFile=Moved file from $GOPATH(%s) to current directory(%s). -DownloadOnly=You enabled download without installing. -ForceUpdate=You enabled force update. -DownloadExDeps=You enabled download dependencies in example. -NoPackage=Please list at least one package/bundle/snapshot. -DownloadPath=Packages will be downloaded to GOPATH(%s). -InstallStatus=Installing package: %s. -BundleInfo=Bundle(%s) contains following nodes: -ContinueDownload=Continue to download?(Y/n or index). -SkipInstalled=Skipped installed pakcage: %s. -SkipDownloaded=Skipped downloaded package: %s. -SkipInvalidPath=Skipped invalid import path: %s. -DownloadStatus=Downloading package: %s. -RemovePackage=Removing package: %s. -NoKeyword=Cannot search without a keyword. -ContinueRemove=Continue to remove?(Y/n). -InvalidPath=Cannot find package in current path. -MissingImports=Following packages are missing: -GenerateConfig=Auto-generated configuration file for package: %s. -CheckExDeps=You enabled check dependencies in example. -SearchResult=search results \ No newline at end of file diff --git a/i18n/en-US/usage.tpl b/i18n/en-US/usage.tpl deleted file mode 100644 index e34116a55..000000000 --- a/i18n/en-US/usage.tpl +++ /dev/null @@ -1,18 +0,0 @@ -gopm(Go Package Manager) is a Go package manage tool for search, install, update, share packages. - -Usage: - - gopm command [arguments] - -The commands are: -{{range .}}{{if .Runnable}} - {{.Name | printf "%-11s"}} {{.Short}}{{end}}{{end}} - -Use "gopm help [command]" for more information about a command. - -Additional help topics: -{{range .}}{{if not .Runnable}} - {{.Name | printf "%-11s"}} {{.Short}}{{end}}{{end}} - -Use "gopm help [topic]" for more information about that topic. - diff --git a/i18n/en-US/usage_build.txt b/i18n/en-US/usage_build.txt deleted file mode 100644 index 8d4b27526..000000000 --- a/i18n/en-US/usage_build.txt +++ /dev/null @@ -1,19 +0,0 @@ -compile and install packages and dependencies||| -Build compiles and installs the packages named by the import paths, -along with their dependencies. - -If the package is main, the output file -name is the base name of the containing directory. - -The build flags are shared by the build and test commands: - - -v - print the names of packages as they are compiled. - -r - run program after built. - -The list flags accept a space-separated list of strings. - -For more about specifying packages, see 'go help packages'. - -See also: gopm install. diff --git a/i18n/en-US/usage_check.txt b/i18n/en-US/usage_check.txt deleted file mode 100644 index c6b45bb19..000000000 --- a/i18n/en-US/usage_check.txt +++ /dev/null @@ -1,10 +0,0 @@ -check packages dependencies||| -Check checks packages dependencies if have been installed -and generate configure file. - -The check flags are: - - -e - check dependencies for examples. - -The list flags accept a space-separated list of strings. \ No newline at end of file diff --git a/i18n/en-US/usage_install.txt b/i18n/en-US/usage_install.txt deleted file mode 100644 index 384ca9eb7..000000000 --- a/i18n/en-US/usage_install.txt +++ /dev/null @@ -1,29 +0,0 @@ -download and install packages and dependencies||| -Install downloads and installs the packages named by the import paths, -along with their dependencies. - -This command works even you haven't installed any version control tool -such as git, hg, etc. - -The install flags are: - - -v - download packages with version control. - -d - download without installing packages. - -u - force to update pakcages. - -e - download dependencies for examples. - -b - download and install bundle. - -s - download and install snapshot. - -The list flags accept a space-separated list of strings. - -For more about specifying packages, see 'go help packages'. -For more about bundle, see 'gopm help bundle'. -For more about snapshot, see 'gopm help snapshot'. - -See also: gopm remove. diff --git a/i18n/en-US/usage_remove.txt b/i18n/en-US/usage_remove.txt deleted file mode 100644 index 740de80c8..000000000 --- a/i18n/en-US/usage_remove.txt +++ /dev/null @@ -1,18 +0,0 @@ -remove packages and dependencies||| -Remove removes the packages named by the import paths, -along with their dependencies. - -The remove flags are: - - -b - remove bundle. - -s - remove snapshot. - -The list flags accept a space-separated list of strings. - -For more about specifying packages, see 'go help packages'. -For more about bundle, see 'gopm help bundle'. -For more about snapshot, see 'gopm help snapshot'. - -See also: gopm install. diff --git a/i18n/en-US/usage_search.txt b/i18n/en-US/usage_search.txt deleted file mode 100644 index 7f9076eca..000000000 --- a/i18n/en-US/usage_search.txt +++ /dev/null @@ -1,7 +0,0 @@ -search packages||| -Search searchs packages by keyword. - -The search flags are: - - -The list flags accept a space-separated list of strings. diff --git a/i18n/zh-CN/prompt.txt b/i18n/zh-CN/prompt.txt deleted file mode 100644 index f4b88adb3..000000000 --- a/i18n/zh-CN/prompt.txt +++ /dev/null @@ -1,36 +0,0 @@ -LoadCommandUsage=加载命令 (%s) 说明失败 [ %s ] -ReadCoammndUsage=不可用的 (%s) 说明文件. -LoadLocalData=无法加载本地数据 [ %s ] -ParseJSON=JSON 解析失败 [ %s ] -OpenFile=文件打开失败 [ %s ] -RemoveFile=移除文件失败 [ %s ] -UnknownCommand=gopm: 未知命令 %q. 运行 'gopm help' 获取帮助. -MoveFile=从 $GOPATH(%s) 拷贝文件到当前目录 (%s) 失败. -UnknownFlag=未知参数: %s. -DownloadError=下载包 (%s) 失败 [ %s ] -NotFoundError=合法的源代码托管平台,但正则匹配失败. -ErrNoMatch=不被支持的源代码托管平台. -PackageNotFound=无法找到包: %s. -CheckImports=一百遍检查失败 [ %s ] - -MovedFile=成功将文件从 $GOPATH(%s) 移动至当前目录 (%s). -DownloadOnly=已激活无安装模式. -ForceUpdate=已激活强制更新. -DownloadExDeps=已激活下载示例代码依赖. -NoPackage=请列出至少一个包、集合或快照. -DownloadPath=所有包将会被下载至 GOPATH(%s). -InstallStatus=正在安装包: %s. -BundleInfo=集合 (%s) 包含以下结点: -ContinueDownload=是否继续下载?(Y/n 或索引). -SkipInstalled=忽略已安装包: %s. -SkipDownloaded=忽略已下载包: %s. -SkipInvalidPath=忽略无效的导入路径: %s. -DownloadStatus=正在下载包: %s. -RemovePackage=正在删除包: %s. -NoKeyword=没有关键字,无法搜索. -ContinueRemove=是否继续删除?(Y/n). -InvalidPath=无法在当前目录中找到包. -MissingImports=下列依赖包未找到: -GenerateConfig=已自动生成包配置文件: %s. -CheckExDeps=已激活示例代码依赖检查. -SearchResult=搜索结果 \ No newline at end of file diff --git a/i18n/zh-CN/usage.tpl b/i18n/zh-CN/usage.tpl deleted file mode 100644 index e3a71cb94..000000000 --- a/i18n/zh-CN/usage.tpl +++ /dev/null @@ -1,18 +0,0 @@ -gopm(Go 包管理工具) 是一款涵盖搜索、安装、更新、分享功能 Go 包的管理工具。 - -用法: - - gopm 命令 [参数] - -命令列表: -{{range .}}{{if .Runnable}} - {{.Name | printf "%-11s"}} {{.Short}}{{end}}{{end}} - -使用 "gopm help [命令]" 来获取相关命令的更多信息. - -其它帮助主题: -{{range .}}{{if not .Runnable}} - {{.Name | printf "%-11s"}} {{.Short}}{{end}}{{end}} - -使用 "gopm help [主题]" 来获取相关主题的更多信息. - diff --git a/i18n/zh-CN/usage_build.txt b/i18n/zh-CN/usage_build.txt deleted file mode 100644 index 475036805..000000000 --- a/i18n/zh-CN/usage_build.txt +++ /dev/null @@ -1,19 +0,0 @@ -编译安装 Go 包及其依赖包||| -Build 命令编译并安装 Go 包以及其依赖包. - -如果被安装的包为 main 包,则可执行文件的名称是根据包含该包的 -文件夹目录的名称决定的. - -下列参数可用于 build 和 test 命令: - - -v - 打印被编译包的名称列表. - -r - 完成构建后运行程序. - -多个参数通过空格来间隔. - -获取更多有关包的信息,参见 'go help packages'. - -相关主题: gopm install. - diff --git a/i18n/zh-CN/usage_check.txt b/i18n/zh-CN/usage_check.txt deleted file mode 100644 index 52e267b30..000000000 --- a/i18n/zh-CN/usage_check.txt +++ /dev/null @@ -1,9 +0,0 @@ -检查安装依赖包||| -Check 命令用于检查并安装缺失的依赖包,并生成依赖配置文件. - -下列参数可用于 check 命令: - - -e - 检查示例代码的依赖包. - -多个参数通过空格来间隔. diff --git a/i18n/zh-CN/usage_install.txt b/i18n/zh-CN/usage_install.txt deleted file mode 100644 index 786b73237..000000000 --- a/i18n/zh-CN/usage_install.txt +++ /dev/null @@ -1,27 +0,0 @@ -下载并安装 Go 包及其依赖包||| -Install 命令下载并安装 Go 包及其依赖包. - -即使您没有安装像 git、hg 这类版本控制工具,该命令依旧有效. - -下列参数可用于 install 命令: - - -v - 使用版本控制工具下载. - -d - 下载但不安装包. - -u - 强制更新包. - -e - 下载示例代码中的依赖包. - -b - 下载并安装集合. - -s - 下载并安装快照. - -多个参数通过空格来间隔. - -获取更多有关包的信息,参见 'go help packages'. -获取更多有关集合的信息,参见 'gopm help bundle'. -获取更多有关快照的信息,参见 'gopm help snapshot'. - -相关主题: gopm build. diff --git a/i18n/zh-CN/usage_remove.txt b/i18n/zh-CN/usage_remove.txt deleted file mode 100644 index c75e9c69a..000000000 --- a/i18n/zh-CN/usage_remove.txt +++ /dev/null @@ -1,18 +0,0 @@ -删除 Go 包及其依赖包||| -Remove 命令删除 Go 包及其依赖包. - -下列参数可用于 remove 命令: - - -多个参数通过空格来间隔. - - -b - 删除集合. - -s - 删除快照. - -获取更多有关包的信息,参见 'go help packages'. -获取更多有关集合的信息,参见 'gopm help bundle'. -获取更多有关快照的信息,参见 'gopm help snapshot'. - -相关主题: gopm install. \ No newline at end of file diff --git a/i18n/zh-CN/usage_search.txt b/i18n/zh-CN/usage_search.txt deleted file mode 100644 index 9a35ac1f2..000000000 --- a/i18n/zh-CN/usage_search.txt +++ /dev/null @@ -1,7 +0,0 @@ -搜索 Go 包||| -Search 命令通过关键字搜索 Go 包. - -下列参数可用于 search 命令: - - -多个参数通过空格来间隔. diff --git a/repo/bundles/install_test.json b/repo/bundles/install_test.json deleted file mode 100644 index 50fb082ae..000000000 --- a/repo/bundles/install_test.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "id": 0, - "user_id": 0, - "bundle_name": "test", - "comment": "just a test", - "timestamp": 0, - "nodes": [ - { - "import_path": "github.com/GPMGoTest/install_test", - "type": "branch", - "value": "master", - "deps": [ - { - "import_path": "github.com/GPMGoTest/install_test2", - "type": "branch", - "value": "master", - "deps": null - } - ] - } - ] -} \ No newline at end of file diff --git a/repo/bundles/test_bundle.json b/repo/bundles/test_bundle.json deleted file mode 100644 index e8bbceb01..000000000 --- a/repo/bundles/test_bundle.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "id": 0, - "user_id": 0, - "bundle_name": "bundle_test", - "comment": "just a test", - "timestamp": 0, - "nodes": [ - { - "import_path": "github.com/astaxie/beego", - "type": "tag", - "value": "v0.6.0", - "deps":[ - { - "import_path": "github.com/russross/blackfriday", - "type": "commit", - "value": "", - "deps": null - }, - { - "import_path": "code.google.com/p/vitess/go/memcache", - "type": "commit", - "value": "", - "deps": null - }, - { - "import_path": "github.com/garyburd/redigo/redis", - "type": "commit", - "value": "aa31b4b202d4ea44ca45b3c93d71575c02ba35dc", - "deps": null - }, - { - "import_path": "github.com/go-sql-driver/mysql", - "type": "tag", - "value": "v1.0", - "deps": null - } - ] - }, - { - "import_path": "github.com/coocood/qbs", - "type": "commit", - "value": "afbf6b7370d76dc479f8d3f9ce9e802ce2c34cf2", - "deps": null - }, - { - "import_path": "bitbucket.org/zombiezen/gopdf/pdf", - "type": "branch", - "value": "default", - "deps": null - }, - { - "import_path": "launchpad.net/goamz/aws", - "type": "commit", - "value": "", - "deps": null - } - ] -} \ No newline at end of file diff --git a/utils/utils.go b/utils/utils.go deleted file mode 100644 index 2627a7de3..000000000 --- a/utils/utils.go +++ /dev/null @@ -1,679 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package utils - -import ( - "fmt" - "os" - "path" - "regexp" - "runtime" - "strings" -) - -const ( - PureStartColor = "\033[%dm" - Gray = uint8(90) - Red = uint8(91) - Green = uint8(92) - Yellow = uint8(93) - Blue = uint8(94) - Magenta = uint8(95) - //NRed = uint8(31) // Normal - EndColor = "\033[0m" -) - -// ColorPrint prints colorful log print, doesn't work in windows. -// content in () with yellow, content in [] with read. -func ColorPrint(log string) { - // Make sure it's not windows. - if runtime.GOOS != "windows" { - log = strings.Replace(log, "[", fmt.Sprintf("[\033[%dm", Red), -1) - log = strings.Replace(log, "]", EndColor+"]", -1) - log = strings.Replace(log, "(", fmt.Sprintf("(\033[%dm", Yellow), -1) - log = strings.Replace(log, ")", EndColor+")", -1) - log = strings.Replace(log, "<", fmt.Sprintf("[\033[%dm", Green), -1) - log = strings.Replace(log, ">$", EndColor+"]", -1) - } - fmt.Print(log) -} - -// IsExist returns if a file or directory exists -func IsExist(path string) bool { - _, err := os.Stat(path) - return err == nil || os.IsExist(err) -} - -// CheckIsExistWithVCS returns false if directory only has VCS folder, -// or doesn't exist. -func CheckIsExistWithVCS(path string) bool { - // Check if directory exist. - if !IsExist(path) { - return false - } - - // Check if only has VCS folder. - dirs, err := GetDirsInfo(path) - if err != nil { - ColorPrint(fmt.Sprintf("[ERROR] CheckIsExistWithVCS -> [ %s ]", err)) - return false - } - - if len(dirs) > 1 { - return true - } else if len(dirs) == 0 { - return false - } - - switch dirs[0].Name() { - case ".git", ".hg", ".svn": - return false - } - - return true -} - -// CheckIsExistInGOPATH checks if given package import path exists in any path in GOPATH/src, -// and returns corresponding GOPATH. -func CheckIsExistInGOPATH(importPath string) (string, bool) { - paths := GetGOPATH() - for _, p := range paths { - if CheckIsExistWithVCS(p + "/src/" + importPath + "/") { - return p, true - } - } - return "", false -} - -// GetGOPATH returns all paths in GOPATH variable. -func GetGOPATH() []string { - gopath := os.Getenv("GOPATH") - var paths []string - if runtime.GOOS == "windows" { - gopath = strings.Replace(gopath, "\\", "/", -1) - paths = strings.Split(gopath, ";") - } else { - paths = strings.Split(gopath, ":") - } - return paths -} - -// GetGOPATH returns best matched GOPATH. -func GetBestMatchGOPATH(appPath string) string { - paths := GetGOPATH() - for _, p := range paths { - if strings.HasPrefix(p, appPath) { - return strings.Replace(p, "\\", "/", -1) - } - } - return paths[0] -} - -// GetProjectPath returns project path of import path. -func GetProjectPath(importPath string) (projectPath string) { - projectPath = importPath - - // Check project hosting. - switch { - case strings.HasPrefix(importPath, "github.com"): - projectPath = joinPath(importPath, 3) - case strings.HasPrefix(importPath, "code.google.com"): - projectPath = joinPath(importPath, 3) - case strings.HasPrefix(importPath, "bitbucket.org"): - projectPath = joinPath(importPath, 3) - case strings.HasPrefix(importPath, "launchpad.net"): - projectPath = joinPath(importPath, 2) - } - - return projectPath -} - -func joinPath(importPath string, num int) string { - subdirs := strings.Split(importPath, "/") - if len(subdirs) > num { - return strings.Join(subdirs[:num], "/") - } - return importPath -} - -// GetExecuteName returns work directory and possible execute name according work directory. -func GetExecuteName(wd string) string { - wd = strings.Replace(wd, "\\", "/", -1) - execName := path.Base(wd) - if runtime.GOOS == "windows" { - execName += ".exe" - } - return execName -} - -var ( - readmePat = regexp.MustCompile(`^[Rr][Ee][Aa][Dd][Mm][Ee](?:$|\.)`) - licensePat = regexp.MustCompile(`^[Ll][Ii][Cc][En][Nn][Ss][Ee]`) -) - -func IsDocFile(n string) bool { - if (strings.HasSuffix(n, ".go") || strings.HasSuffix(n, ".h") || strings.HasSuffix(n, ".c")) && - n[0] != '_' && n[0] != '.' { - return true - } - - return readmePat.MatchString(n) || licensePat.MatchString(n) -} - -// GetDirsInfo returns os.FileInfo of all sub-directories in root path. -func GetDirsInfo(rootPath string) ([]os.FileInfo, error) { - rootDir, err := os.Open(rootPath) - if err != nil { - return nil, err - } - defer rootDir.Close() - - dirs, err := rootDir.Readdir(0) - if err != nil { - return nil, err - } - - return dirs, err -} - -var validTLD = map[string]bool{ - // curl http://data.iana.org/TLD/tlds-alpha-by-domain.txt | sed -e '/#/ d' -e 's/.*/"&": true,/' | tr [:upper:] [:lower:] - ".ac": true, - ".ad": true, - ".ae": true, - ".aero": true, - ".af": true, - ".ag": true, - ".ai": true, - ".al": true, - ".am": true, - ".an": true, - ".ao": true, - ".aq": true, - ".ar": true, - ".arpa": true, - ".as": true, - ".asia": true, - ".at": true, - ".au": true, - ".aw": true, - ".ax": true, - ".az": true, - ".ba": true, - ".bb": true, - ".bd": true, - ".be": true, - ".bf": true, - ".bg": true, - ".bh": true, - ".bi": true, - ".biz": true, - ".bj": true, - ".bm": true, - ".bn": true, - ".bo": true, - ".br": true, - ".bs": true, - ".bt": true, - ".bv": true, - ".bw": true, - ".by": true, - ".bz": true, - ".ca": true, - ".cat": true, - ".cc": true, - ".cd": true, - ".cf": true, - ".cg": true, - ".ch": true, - ".ci": true, - ".ck": true, - ".cl": true, - ".cm": true, - ".cn": true, - ".co": true, - ".com": true, - ".coop": true, - ".cr": true, - ".cu": true, - ".cv": true, - ".cw": true, - ".cx": true, - ".cy": true, - ".cz": true, - ".de": true, - ".dj": true, - ".dk": true, - ".dm": true, - ".do": true, - ".dz": true, - ".ec": true, - ".edu": true, - ".ee": true, - ".eg": true, - ".er": true, - ".es": true, - ".et": true, - ".eu": true, - ".fi": true, - ".fj": true, - ".fk": true, - ".fm": true, - ".fo": true, - ".fr": true, - ".ga": true, - ".gb": true, - ".gd": true, - ".ge": true, - ".gf": true, - ".gg": true, - ".gh": true, - ".gi": true, - ".gl": true, - ".gm": true, - ".gn": true, - ".gov": true, - ".gp": true, - ".gq": true, - ".gr": true, - ".gs": true, - ".gt": true, - ".gu": true, - ".gw": true, - ".gy": true, - ".hk": true, - ".hm": true, - ".hn": true, - ".hr": true, - ".ht": true, - ".hu": true, - ".id": true, - ".ie": true, - ".il": true, - ".im": true, - ".in": true, - ".info": true, - ".int": true, - ".io": true, - ".iq": true, - ".ir": true, - ".is": true, - ".it": true, - ".je": true, - ".jm": true, - ".jo": true, - ".jobs": true, - ".jp": true, - ".ke": true, - ".kg": true, - ".kh": true, - ".ki": true, - ".km": true, - ".kn": true, - ".kp": true, - ".kr": true, - ".kw": true, - ".ky": true, - ".kz": true, - ".la": true, - ".lb": true, - ".lc": true, - ".li": true, - ".lk": true, - ".lr": true, - ".ls": true, - ".lt": true, - ".lu": true, - ".lv": true, - ".ly": true, - ".ma": true, - ".mc": true, - ".md": true, - ".me": true, - ".mg": true, - ".mh": true, - ".mil": true, - ".mk": true, - ".ml": true, - ".mm": true, - ".mn": true, - ".mo": true, - ".mobi": true, - ".mp": true, - ".mq": true, - ".mr": true, - ".ms": true, - ".mt": true, - ".mu": true, - ".museum": true, - ".mv": true, - ".mw": true, - ".mx": true, - ".my": true, - ".mz": true, - ".na": true, - ".name": true, - ".nc": true, - ".ne": true, - ".net": true, - ".nf": true, - ".ng": true, - ".ni": true, - ".nl": true, - ".no": true, - ".np": true, - ".nr": true, - ".nu": true, - ".nz": true, - ".om": true, - ".org": true, - ".pa": true, - ".pe": true, - ".pf": true, - ".pg": true, - ".ph": true, - ".pk": true, - ".pl": true, - ".pm": true, - ".pn": true, - ".post": true, - ".pr": true, - ".pro": true, - ".ps": true, - ".pt": true, - ".pw": true, - ".py": true, - ".qa": true, - ".re": true, - ".ro": true, - ".rs": true, - ".ru": true, - ".rw": true, - ".sa": true, - ".sb": true, - ".sc": true, - ".sd": true, - ".se": true, - ".sg": true, - ".sh": true, - ".si": true, - ".sj": true, - ".sk": true, - ".sl": true, - ".sm": true, - ".sn": true, - ".so": true, - ".sr": true, - ".st": true, - ".su": true, - ".sv": true, - ".sx": true, - ".sy": true, - ".sz": true, - ".tc": true, - ".td": true, - ".tel": true, - ".tf": true, - ".tg": true, - ".th": true, - ".tj": true, - ".tk": true, - ".tl": true, - ".tm": true, - ".tn": true, - ".to": true, - ".tp": true, - ".tr": true, - ".travel": true, - ".tt": true, - ".tv": true, - ".tw": true, - ".tz": true, - ".ua": true, - ".ug": true, - ".uk": true, - ".us": true, - ".uy": true, - ".uz": true, - ".va": true, - ".vc": true, - ".ve": true, - ".vg": true, - ".vi": true, - ".vn": true, - ".vu": true, - ".wf": true, - ".ws": true, - ".xn--0zwm56d": true, - ".xn--11b5bs3a9aj6g": true, - ".xn--3e0b707e": true, - ".xn--45brj9c": true, - ".xn--80akhbyknj4f": true, - ".xn--80ao21a": true, - ".xn--90a3ac": true, - ".xn--9t4b11yi5a": true, - ".xn--clchc0ea0b2g2a9gcd": true, - ".xn--deba0ad": true, - ".xn--fiqs8s": true, - ".xn--fiqz9s": true, - ".xn--fpcrj9c3d": true, - ".xn--fzc2c9e2c": true, - ".xn--g6w251d": true, - ".xn--gecrj9c": true, - ".xn--h2brj9c": true, - ".xn--hgbk6aj7f53bba": true, - ".xn--hlcj6aya9esc7a": true, - ".xn--j6w193g": true, - ".xn--jxalpdlp": true, - ".xn--kgbechtv": true, - ".xn--kprw13d": true, - ".xn--kpry57d": true, - ".xn--lgbbat1ad8j": true, - ".xn--mgb9awbf": true, - ".xn--mgbaam7a8h": true, - ".xn--mgbayh7gpa": true, - ".xn--mgbbh1a71e": true, - ".xn--mgbc0a9azcg": true, - ".xn--mgberp4a5d4ar": true, - ".xn--mgbx4cd0ab": true, - ".xn--o3cw4h": true, - ".xn--ogbpf8fl": true, - ".xn--p1ai": true, - ".xn--pgbs0dh": true, - ".xn--s9brj9c": true, - ".xn--wgbh1c": true, - ".xn--wgbl6a": true, - ".xn--xkc2al3hye2a": true, - ".xn--xkc2dl3a5ee0h": true, - ".xn--yfro4i67o": true, - ".xn--ygbi2ammx": true, - ".xn--zckzah": true, - ".xxx": true, - ".ye": true, - ".yt": true, - ".za": true, - ".zm": true, - ".zw": true, -} - -var ( - validHost = regexp.MustCompile(`^[-a-z0-9]+(?:\.[-a-z0-9]+)+$`) - validPathElement = regexp.MustCompile(`^[-A-Za-z0-9~+][-A-Za-z0-9_.]*$`) -) - -// IsValidRemotePath returns true if importPath is structurally valid for "go get". -func IsValidRemotePath(importPath string) bool { - - parts := strings.Split(importPath, "/") - - if len(parts) <= 1 { - // Import path must contain at least one "/". - return false - } - - if !validTLD[path.Ext(parts[0])] { - return false - } - - if !validHost.MatchString(parts[0]) { - return false - } - for _, part := range parts[1:] { - if !validPathElement.MatchString(part) || part == "testdata" { - return false - } - } - - return true -} - -var standardPath = map[string]bool{ - "builtin": true, - - // go list -f '"{{.ImportPath}}": true,' std | grep -v 'cmd/|exp/' - "cmd/api": true, - "cmd/cgo": true, - "cmd/fix": true, - "cmd/go": true, - "cmd/godoc": true, - "cmd/gofmt": true, - "cmd/vet": true, - "cmd/yacc": true, - "archive/tar": true, - "archive/zip": true, - "bufio": true, - "bytes": true, - "compress/bzip2": true, - "compress/flate": true, - "compress/gzip": true, - "compress/lzw": true, - "compress/zlib": true, - "container/heap": true, - "container/list": true, - "container/ring": true, - "crypto": true, - "crypto/aes": true, - "crypto/cipher": true, - "crypto/des": true, - "crypto/dsa": true, - "crypto/ecdsa": true, - "crypto/elliptic": true, - "crypto/hmac": true, - "crypto/md5": true, - "crypto/rand": true, - "crypto/rc4": true, - "crypto/rsa": true, - "crypto/sha1": true, - "crypto/sha256": true, - "crypto/sha512": true, - "crypto/subtle": true, - "crypto/tls": true, - "crypto/x509": true, - "crypto/x509/pkix": true, - "database/sql": true, - "database/sql/driver": true, - "debug/dwarf": true, - "debug/elf": true, - "debug/gosym": true, - "debug/macho": true, - "debug/pe": true, - "encoding/ascii85": true, - "encoding/asn1": true, - "encoding/base32": true, - "encoding/base64": true, - "encoding/binary": true, - "encoding/csv": true, - "encoding/gob": true, - "encoding/hex": true, - "encoding/json": true, - "encoding/pem": true, - "encoding/xml": true, - "errors": true, - "expvar": true, - "flag": true, - "fmt": true, - "go/ast": true, - "go/build": true, - "go/doc": true, - "go/format": true, - "go/parser": true, - "go/printer": true, - "go/scanner": true, - "go/token": true, - "hash": true, - "hash/adler32": true, - "hash/crc32": true, - "hash/crc64": true, - "hash/fnv": true, - "html": true, - "html/template": true, - "image": true, - "image/color": true, - "image/draw": true, - "image/gif": true, - "image/jpeg": true, - "image/png": true, - "index/suffixarray": true, - "io": true, - "io/ioutil": true, - "log": true, - "log/syslog": true, - "math": true, - "math/big": true, - "math/cmplx": true, - "math/rand": true, - "mime": true, - "mime/multipart": true, - "net": true, - "net/http": true, - "net/http/cgi": true, - "net/http/cookiejar": true, - "net/http/fcgi": true, - "net/http/httptest": true, - "net/http/httputil": true, - "net/http/pprof": true, - "net/mail": true, - "net/rpc": true, - "net/rpc/jsonrpc": true, - "net/smtp": true, - "net/textproto": true, - "net/url": true, - "os": true, - "os/exec": true, - "os/signal": true, - "os/user": true, - "path": true, - "path/filepath": true, - "reflect": true, - "regexp": true, - "regexp/syntax": true, - "runtime": true, - "runtime/cgo": true, - "runtime/debug": true, - "runtime/pprof": true, - "sort": true, - "strconv": true, - "strings": true, - "sync": true, - "sync/atomic": true, - "syscall": true, - "testing": true, - "testing/iotest": true, - "testing/quick": true, - "text/scanner": true, - "text/tabwriter": true, - "text/template": true, - "text/template/parse": true, - "time": true, - "unicode": true, - "unicode/utf16": true, - "unicode/utf8": true, - "unsafe": true, -} - -// IsGoRepoPath returns true if package is from standard library. -func IsGoRepoPath(importPath string) bool { - return standardPath[importPath] -} diff --git a/utils/utils_test.go b/utils/utils_test.go deleted file mode 100644 index bd53ad634..000000000 --- a/utils/utils_test.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2013 GPMGo Members. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package utils - -import ( - "runtime" - "testing" -) - -var remotePaths = []string{ - "github.com/coocood/qbs", - "code.google.com/p/draw2d", - "launchpad.net/goamz", - "bitbucket.org/gotamer/conv", -} - -func TestIsValidRemotePath(t *testing.T) { - for _, p := range remotePaths { - if !IsValidRemotePath(p) { - t.Errorf("Invalid remote path: %s", p) - } - } -} - -var importPaths = []string{ - "github.com/coocood/qbs/test", - "code.google.com/p/draw2d/test", - "launchpad.net/goamz/test", - "bitbucket.org/gotamer/conv/test", -} - -func TestGetProjectPath(t *testing.T) { - // Should return same path. - for _, p := range remotePaths { - if p != GetProjectPath(p) { - t.Errorf("Fail to get projet path: %s", p) - } - } - - // Should return same path for remote paths. - for i, p := range remotePaths { - if remotePaths[i] != GetProjectPath(p) { - t.Errorf("Fail to verify projet path: %s", p) - } - } -} - -func TestGetExecuteName(t *testing.T) { - // Non-windows. - if runtime.GOOS != "windows" && GetExecuteName("gtihub.com/astaxie/beego") != "beego" { - t.Errorf("Fail to verify execute name in non-windows.") - } - - // Windows. - if runtime.GOOS == "windows" && GetExecuteName("gtihub.com/astaxie/beego") != "beego.exe" { - t.Errorf("Fail to verify execute name in windows.") - } -} - -var docFiles = []string{ - "Readme", - "readme.md", - "README", - "README.MD", - "main.go", - "LICENse", -} - -func TestIsDocFile(t *testing.T) { - for _, v := range docFiles { - if !IsDocFile(v) { - t.Errorf("Fail to verify doc file: %s", v) - } - } -}