Copyright 2019 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

package fetch

import (
	

	
	
	
)
moduleUnits returns all of the units in a given module, along with the contents for those units.
func (,  string,
	 []*goPackage,
	 []*internal.Readme,
	 *licenses.Detector) []*internal.Unit {
	 := map[string]*goPackage{}
	for ,  := range  {
		[.path] = 
	}
	 := unitPaths(, )

	 := map[string]*internal.Readme{}
	for ,  := range  {
		if path.Dir(.Filepath) == "." {
			[] = 
		} else if  == stdlib.ModulePath {
			[path.Dir(.Filepath)] = 
		} else {
			[path.Join(, path.Dir(.Filepath))] = 
		}
	}

	var  []*internal.Unit
	for ,  := range  {
		 := internal.Suffix(, )
		if  == stdlib.ModulePath {
			 = 
		}
		,  := .PackageInfo()
		var  []*licenses.Metadata
		for ,  := range  {
			 = append(, .Metadata)
		}
		 := &internal.Unit{
			UnitMeta: internal.UnitMeta{
				ModuleInfo: internal.ModuleInfo{
					ModulePath:        ,
					Version:           ,
					IsRedistributable: .ModuleIsRedistributable(),
				},
				Path:              ,
				IsRedistributable: ,
				Licenses:          ,
			},
		}
		if ,  := [];  {
			.Readme = 
		}
		if ,  := [];  {
			.Name = .name
			.Imports = .imports
			.Documentation = .docs
		}
		 = append(, )
	}
	return 
}
unitPaths returns the paths for all the units in a module.
func ( string,  []*goPackage) []string {
	 := func( string) bool {
		if  == stdlib.ModulePath {
			return  != "."
		}
		return len() > len()
	}

	 := map[string]bool{: true}
	for ,  := range  {
		for  := .path; ();  = path.Dir() {
			[] = true
		}
	}

	var  []string
	for  := range  {
		 = append(, )
	}
	return