Esempio n. 1
0
func (sysOldVendor) Migrate(root string) error {
	ctx, err := context.NewContext(root, "vendor.json", "vendor", false)
	if err != nil {
		return err
	}
	ctx.VendorFilePath = filepath.Join(ctx.RootDir, "vendor", "vendor.json")
	err = ctx.WriteVendorFile()
	if err != nil {
		return err
	}
	return os.Remove(filepath.Join(ctx.RootDir, "vendor.json"))
}
Esempio n. 2
0
func (sysInternal) Migrate(root string) error {
	// Un-rewrite import paths.
	// Copy files from internal to vendor.
	// Update and move vendor file from "internal/vendor.json" to "vendor.json".
	ctx, err := context.NewContext(root, filepath.Join("internal", "vendor.json"), "internal", true)
	if err != nil {
		return err
	}
	list, err := ctx.Status()
	if err != nil {
		return err
	}
	remove := make([]string, 0, len(list))
	for _, item := range list {
		if item.Status != context.StatusVendor {
			continue
		}
		pkg := ctx.Package[item.Local]
		ctx.Operation = append(ctx.Operation, &context.Operation{
			Pkg:  pkg,
			Src:  pkg.Dir,
			Dest: filepath.Join(ctx.RootDir, "vendor", filepath.ToSlash(item.Canonical)),
		})
		remove = append(remove, filepath.Join(ctx.RootGopath, filepath.ToSlash(item.Local)))
		ctx.RewriteRule[item.Local] = item.Canonical
	}
	ctx.VendorFilePath = filepath.Join(ctx.RootDir, "vendor.json")
	for _, vf := range ctx.VendorFile.Package {
		vf.Local = path.Join("vendor", vf.Canonical)
	}
	err = ctx.WriteVendorFile()
	if err != nil {
		return err
	}
	err = ctx.Alter()
	if err != nil {
		return err
	}

	// Remove existing.
	for _, r := range remove {
		err = context.RemovePackage(r, "")
		if err != nil {
			return err
		}
	}
	return os.Remove(filepath.Join(ctx.RootDir, "internal", "vendor.json"))
}
Esempio n. 3
0
func (sysGodep) Migrate(root string) error {
	// Determine if import paths are rewriten.
	// Un-rewrite import paths.
	// Copy files from Godeps/_workspace/src to "vendor".
	// Translate Godeps/Godeps.json to vendor.json.

	vendorFilePath := filepath.Join("Godeps", "_workspace", "src")
	vendorPath := path.Join("Godeps", "_workspace", "src")
	godepFilePath := filepath.Join(root, "Godeps", "Godeps.json")

	ctx, err := context.NewContext(root, "vendor.json", vendorFilePath, true)
	if err != nil {
		return err
	}
	ctx.VendorDiscoverFolder = vendorPath

	list, err := ctx.Status()
	if err != nil {
		return err
	}

	remove := make([]string, 0, len(list))
	for _, item := range list {
		if item.Status != context.StatusVendor {
			continue
		}
		pkg := ctx.Package[item.Local]
		ctx.Operation = append(ctx.Operation, &context.Operation{
			Pkg:  pkg,
			Src:  pkg.Dir,
			Dest: filepath.Join(ctx.RootDir, "vendor", filepath.ToSlash(item.Canonical)),
		})
		remove = append(remove, filepath.Join(ctx.RootGopath, filepath.ToSlash(item.Local)))
		ctx.RewriteRule[item.Local] = item.Canonical
	}
	ctx.VendorFilePath = filepath.Join(ctx.RootDir, "vendor", "vendor.json")

	ctx.VendorDiscoverFolder = "vendor"

	// Translate then remove godeps.json file.
	type Godeps struct {
		ImportPath string
		GoVersion  string   // Abridged output of 'go version'.
		Packages   []string // Arguments to godep save, if any.
		Deps       []struct {
			ImportPath string
			Comment    string // Description of commit, if present.
			Rev        string // VCS-specific commit ID.
		}
	}

	godeps := Godeps{}
	f, err := os.Open(godepFilePath)
	if err != nil {
		return err
	}
	coder := json.NewDecoder(f)
	err = coder.Decode(&godeps)
	f.Close()
	if err != nil {
		return err
	}

	for _, d := range godeps.Deps {
		for _, pkg := range ctx.Package {
			if pkg.Status != context.StatusVendor {
				continue
			}
			if strings.HasPrefix(pkg.Canonical, d.ImportPath) == false {
				continue
			}
			vf := ctx.VendorFilePackagePath(pkg.Canonical)
			if vf == nil {
				ctx.VendorFile.Package = append(ctx.VendorFile.Package, &vendorfile.Package{
					Add:      true,
					Path:     pkg.Canonical,
					Comment:  d.Comment,
					Revision: d.Rev,
				})
			}
		}
	}

	err = ctx.WriteVendorFile()
	if err != nil {
		return err
	}
	err = ctx.Alter()
	if err != nil {
		return err
	}

	// Remove existing.
	for _, r := range remove {
		err = context.RemovePackage(r, "", false)
		if err != nil {
			return err
		}
	}

	return os.RemoveAll(filepath.Join(root, "Godeps"))
}