From bcbbd3117eee395007f44055afbf48c9fc863003 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 21 May 2013 16:35:54 -0400 Subject: [PATCH] command install add feature: auto-install all packages after downloaded --- README.md | 4 ++-- conf/gpm.toml | 2 +- doc/bitbucket.go | 6 ++++-- doc/github.go | 8 ++++++-- doc/google.go | 6 ++++-- doc/launchpad.go | 6 ++++-- doc/vcs.go | 7 +++---- doc/walker.go | 17 ++++------------- install.go | 13 ++++++++++--- 9 files changed, 38 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index a83c421e5..edc8e0183 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ gpm(Go Package Manager) is a Go package manage tool for search, install, update - Command `install` add support for downloading code from git.oschina.net, gitcafe.com, *.codeplex.com; - Add support for downloading tarballs from user sources. -- Command `install` installs all packages after downloaded. - After downloaded all packages in bundles or snapshots, need to check if all dependencies have been downloaded as well. - Develop user source API server template application to support user sources in bundles. - Add bundle and snapshot parser code for downloading by bundle or snapshot id. @@ -21,4 +20,5 @@ gpm(Go Package Manager) is a Go package manage tool for search, install, update - Add feature for downloading through version control tools, and use `checkout` to switch to specific revision; this feature only be enabled when users use bundle or snapshot id. - Add support for downloading by tag for packages in github.com, bitbucket.org. - Get author commit time and save in node. -- Save node information after downloaded, and check for next time, reduce download times. \ No newline at end of file +- Save node information after downloaded, and check for next time, reduce download times. +- Collect download and installation results and report to users in the end. \ No newline at end of file diff --git a/conf/gpm.toml b/conf/gpm.toml index 9e0df3343..6e182fc1b 100644 --- a/conf/gpm.toml +++ b/conf/gpm.toml @@ -1,7 +1,7 @@ # This is a configuration file for gpm with toml format. title = "gpm(Go Package Manager)" -version = "v0.0.4 Build 0520" +version = "v0.0.5 Build 0521" username = "" password = "" user_language = "en-US" \ No newline at end of file diff --git a/doc/bitbucket.go b/doc/bitbucket.go index 5b9c833f5..ed26adcf2 100644 --- a/doc/bitbucket.go +++ b/doc/bitbucket.go @@ -75,7 +75,8 @@ func GetBitbucketDoc(client *http.Client, match map[string]string, installGOPATH return nil, nil, err } - installPath := installGOPATH + "/src/" + match["importPath"] + projectPath := expand("bitbucket.org/{owner}/{repo}", match) + installPath := installGOPATH + "/src/" + projectPath // Remove old files. os.RemoveAll(installPath + "/") @@ -151,10 +152,11 @@ func GetBitbucketDoc(client *http.Client, match map[string]string, installGOPATH // Check if need to check imports. if isCheckImport { for _, d := range dirs { - imports, err = checkImports(d+"/", match["importPath"]) + importPkgs, err := checkImports(d+"/", match["importPath"]) if err != nil { return nil, nil, err } + imports = append(imports, importPkgs...) } } diff --git a/doc/github.go b/doc/github.go index 900980422..a163222b0 100644 --- a/doc/github.go +++ b/doc/github.go @@ -87,7 +87,8 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH, c } shaName := expand("{repo}-{sha}", match) - installPath := installGOPATH + "/src/" + match["importPath"] + projectPath := expand("github.com/{owner}/{repo}", match) + installPath := installGOPATH + "/src/" + projectPath // Remove old files. os.RemoveAll(installPath + "/") @@ -95,6 +96,8 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH, c os.MkdirAll(installPath+"/", os.ModePerm) 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) @@ -142,10 +145,11 @@ func GetGithubDoc(client *http.Client, match map[string]string, installGOPATH, c // Check if need to check imports. if isCheckImport { for _, d := range dirs { - imports, err = checkImports(d, match["importPath"]) + importPkgs, err := checkImports(d, match["importPath"]) if err != nil { return nil, nil, err } + imports = append(imports, importPkgs...) } } diff --git a/doc/google.go b/doc/google.go index bfac52d13..303192d08 100644 --- a/doc/google.go +++ b/doc/google.go @@ -75,7 +75,8 @@ func GetGoogleDoc(client *http.Client, match map[string]string, installGOPATH, c errors.New("doc.GetGoogleDoc(): Could not find revision for " + match["importPath"]) } - installPath := installGOPATH + "/src/" + match["importPath"] + projectPath := expand("code.google.com/p/{repo}{dot}{subrepo}{dir}", match) + installPath := installGOPATH + "/src/" + projectPath // Remove old files. os.RemoveAll(installPath + "/") @@ -154,10 +155,11 @@ func GetGoogleDoc(client *http.Client, match map[string]string, installGOPATH, c for _, d := range dirs { if d.IsDir() && !(!cmdFlags["-e"] && strings.Contains(d.Name(), "example")) { absPath := installPath + "/" + d.Name() + "/" - imports, err = checkImports(absPath, match["importPath"]) + importPkgs, err := checkImports(absPath, match["importPath"]) if err != nil { return nil, nil, err } + imports = append(imports, importPkgs...) } } } diff --git a/doc/launchpad.go b/doc/launchpad.go index 965ce54bd..e49fa728f 100644 --- a/doc/launchpad.go +++ b/doc/launchpad.go @@ -54,7 +54,8 @@ func GetLaunchpadDoc(client *http.Client, match map[string]string, installGOPATH return nil, nil, err } - installPath := installGOPATH + "/src/" + match["importPath"] + projectPath := expand("launchpad.net/{repo}", match) + installPath := installGOPATH + "/src/" + projectPath // Remove old files. os.RemoveAll(installPath + "/") @@ -130,10 +131,11 @@ func GetLaunchpadDoc(client *http.Client, match map[string]string, installGOPATH // Check if need to check imports. if isCheckImport { for _, d := range dirs { - imports, err = checkImports(d+"/", match["importPath"]) + importPkgs, err := checkImports(d+"/", match["importPath"]) if err != nil { return nil, nil, err } + imports = append(imports, importPkgs...) } } diff --git a/doc/vcs.go b/doc/vcs.go index bee39e9ce..452322935 100644 --- a/doc/vcs.go +++ b/doc/vcs.go @@ -178,7 +178,7 @@ func expand(template string, match map[string]string, subs ...string) string { } // checkImports checks package denpendencies. -func checkImports(absPath, importPath string) (imports []string, err error) { +func checkImports(absPath, importPath string) (importPkgs []string, err error) { dir, err := os.Open(absPath) if err != nil { return nil, err @@ -218,12 +218,11 @@ func checkImports(absPath, importPath string) (imports []string, err error) { // Check if has Go source files. if len(files) > 0 { w := &walker{ImportPath: importPath} - importPkgs, err := w.build(files) + importPkgs, err = w.build(files) if err != nil { return nil, err } - imports = append(imports, importPkgs...) } - return imports, nil + return importPkgs, err } diff --git a/doc/walker.go b/doc/walker.go index b56152e7f..be98f7bad 100644 --- a/doc/walker.go +++ b/doc/walker.go @@ -1,17 +1,8 @@ -// Copyright 2011 Gary Burd -// Copyright 2013 Unknown +// Copyright 2012 Gary Burd // -// Licensed under the Apache License, Version 2.0 (the "License"): you may -// not use this file except in compliance with the License. You may obtain -// a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations -// under the License. +// 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 diff --git a/install.go b/install.go index 33f0be988..565608ccc 100644 --- a/install.go +++ b/install.go @@ -115,9 +115,17 @@ func runInstall(cmd *Command, args []string) { commits := make([]string, len(args)) downloadPackages(args, commits) - if !cmdInstall.Flags["d"] && cmdInstall.Flags["-p"] { + if !cmdInstall.Flags["-d"] && cmdInstall.Flags["-p"] { // Install packages all together. - fmt.Printf("Installing package: %s.\n") + var cmdArgs []string + cmdArgs = append(cmdArgs, "install") + cmdArgs = append(cmdArgs, "") + + for k := range downloadCache { + fmt.Printf("Installing package: %s.\n", k) + cmdArgs[1] = k + executeGoCommand(cmdArgs) + } } fmt.Println("Well done.") @@ -189,7 +197,6 @@ func downloadPackage(path, commit string) (pkg *doc.Package, imports []string) { return nil, nil } - //fmt.Println(pkg) return pkg, imports } }