Esempio n. 1
0
// NormalizeData sorts data and performs other postprocessing.
func NormalizeData(currentRepoURI, unitType, dir string, o *graph.Output) error {
	for _, ref := range o.Refs {
		if ref.DefRepo == currentRepoURI {
			ref.DefRepo = ""
		}
		if ref.DefRepo != "" {
			ref.DefRepo = graph.MakeURI(string(ref.DefRepo))
		}
		if ref.Repo == currentRepoURI {
			ref.Repo = ""
		}
		if ref.Repo != "" {
			ref.Repo = graph.MakeURI(string(ref.Repo))
		}
	}

	if unitType != "GoPackage" && unitType != "Dockerfile" && !strings.HasPrefix(unitType, "Java") {
		ensureOffsetsAreByteOffsets(dir, o)
	}

	if err := ValidateRefs(o.Refs); err != nil {
		return err
	}
	if err := ValidateDefs(o.Defs); err != nil {
		return err
	}
	if err := ValidateDocs(o.Docs); err != nil {
		return err
	}

	sortedOutput(o)
	return nil
}
Esempio n. 2
0
// ResolutionsToResolvedDeps converts a []*Resolution for a source unit to a
// []*ResolvedDep (which is a data structure that includes the source unit
// type/name/etc., so elements are meaningful even if the associated source unit
// struct is not available).
//
// Resolutions with Errors are omitted from the returned slice and no such
// errors are returned.
func ResolutionsToResolvedDeps(ress []*Resolution, unit *unit.SourceUnit, fromRepo string, fromCommitID string) ([]*ResolvedDep, error) {
	or := func(a, b string) string {
		if a != "" {
			return a
		}
		return b
	}
	var resolved []*ResolvedDep
	for _, res := range ress {
		if res.Error != "" {
			continue
		}

		if rt := res.Target; rt != nil {
			var uri string
			if rt.ToRepoCloneURL != "" {
				uri = graph.MakeURI(rt.ToRepoCloneURL)
			} else {
				uri = fromRepo
			}

			rd := &ResolvedDep{
				FromRepo:        fromRepo,
				FromCommitID:    fromCommitID,
				FromUnit:        unit.Name,
				FromUnitType:    unit.Type,
				ToRepo:          uri,
				ToUnit:          or(rt.ToUnit, unit.Name),
				ToUnitType:      or(rt.ToUnitType, unit.Type),
				ToVersionString: rt.ToVersionString,
				ToRevSpec:       rt.ToRevSpec,
			}
			resolved = append(resolved, rd)
		}
	}
	sort.Sort(resolvedDeps(resolved))
	return resolved, nil
}