@@ -23,6 +23,7 @@ import (
23
23
"github.com/golang/dep"
24
24
"github.com/golang/dep/gps"
25
25
"github.com/golang/dep/gps/paths"
26
+ "github.com/golang/dep/gps/pkgtree"
26
27
"github.com/pkg/errors"
27
28
)
28
29
@@ -747,6 +748,10 @@ type projectConstraint struct {
747
748
Constraint gps.Constraint
748
749
}
749
750
751
+ func (pc projectConstraint ) String () string {
752
+ return fmt .Sprintf ("%s(%s)" , pc .Constraint .String (), string (pc .Project ))
753
+ }
754
+
750
755
// constraintsCollection is a map of ProjectRoot(dependency) and a collection of
751
756
// projectConstraint for the dependencies. This can be used to find constraints
752
757
// on a dependency and the projects that apply those constraints.
@@ -881,6 +886,7 @@ func (pv pubVersions) TabString() string {
881
886
return buf .String ()
882
887
}
883
888
889
+ // projectImporters stores a map of project names that import a specific project.
884
890
type projectImporters map [string ]bool
885
891
886
892
func (pi projectImporters ) String () string {
@@ -896,6 +902,7 @@ func (pi projectImporters) String() string {
896
902
return strings .Join (projects , ", " )
897
903
}
898
904
905
+ // packageImporters stores a map of package and projects that import them.
899
906
type packageImporters map [string ][]string
900
907
901
908
func (pi packageImporters ) TabString () string {
@@ -940,10 +947,37 @@ func (pi packageImporters) TabString() string {
940
947
return buf .String ()
941
948
}
942
949
950
+ // projectConstraints is a slice of projectConstraint
951
+ type projectConstraints []projectConstraint
952
+
953
+ func (pcs projectConstraints ) TabString () string {
954
+ var buf bytes.Buffer
955
+ w := bufio .NewWriter (& buf )
956
+
957
+ // Sort for consistent result.
958
+ sort .Sort (byProject (pcs ))
959
+
960
+ // Count lines and add newlines("\n") and tabs("\t"), compatible with
961
+ // tabwriter.
962
+ // ^0.5.0(btb.com/x/y)\n \t^1.0.0(gh.com/f/b)\t \t^1.5.0(gh.com/a/c)
963
+ count := 0
964
+ for _ , c := range pcs {
965
+ count ++
966
+ if count > 1 {
967
+ fmt .Fprintf (w , "\n \t " )
968
+ }
969
+
970
+ fmt .Fprintf (w , "%s" , c )
971
+ }
972
+ w .Flush ()
973
+
974
+ return buf .String ()
975
+ }
976
+
943
977
type projectStatus struct {
944
978
Project string
945
979
Version string
946
- Constraints [] string
980
+ Constraints projectConstraints
947
981
Source string
948
982
AltSource string
949
983
PubVersions pubVersions
@@ -987,7 +1021,7 @@ func (ps projectStatus) String() string {
987
1021
"PACKAGE IMPORTERS:\t %s\n " +
988
1022
"UPSTREAM EXISTS:\t %s\n " +
989
1023
"UPSTREAM VERSION EXISTS:\t %s" ,
990
- ps .Project , ps .Version , ps .Constraints , ps .Source , ps .AltSource ,
1024
+ ps .Project , ps .Version , ps .Constraints . TabString () , ps .Source , ps .AltSource ,
991
1025
ps .PubVersions .TabString (), ps .Revision , ps .LatestAllowed , ps .SourceType ,
992
1026
strings .Join (ps .Packages , ", " ), ps .ProjectImporters ,
993
1027
ps .PackageImporters .TabString (), upstreamExists , upstreamVersionExists ,
@@ -1019,13 +1053,19 @@ func runProjectStatus(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.Source
1019
1053
prs = append (prs , pr )
1020
1054
}
1021
1055
1022
- // This ptree would not be required with the new collectConstraints() implementation.
1023
- ptree , err := p .ParseRootPackageTree ()
1024
- if err != nil {
1025
- return err
1026
- }
1027
1056
// Collect all the constraints.
1028
- cc := collectConstraints (ptree , p , sm )
1057
+ cc , ccerrs := collectConstraints (ctx , p , sm )
1058
+ // If found any errors, print to stderr.
1059
+ if len (ccerrs ) > 0 {
1060
+ if ctx .Verbose {
1061
+ for _ , e := range ccerrs {
1062
+ ctx .Err .Println (e )
1063
+ }
1064
+ } else {
1065
+ ctx .Out .Println ("Got errors while collecting constraints. Rerun with `-v` flag to see details." )
1066
+ }
1067
+ return errors .New ("errors while collecting constraints" )
1068
+ }
1029
1069
1030
1070
// Collect list of packages in target projects.
1031
1071
pkgs := make (map [gps.ProjectRoot ][]string )
@@ -1173,7 +1213,7 @@ func runProjectStatus(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.Source
1173
1213
// CONSTRAINTS
1174
1214
constraints := cc [string (pr )]
1175
1215
for _ , c := range constraints {
1176
- projStatus .Constraints = append (projStatus .Constraints , c . String () )
1216
+ projStatus .Constraints = append (projStatus .Constraints , c )
1177
1217
}
1178
1218
}
1179
1219
}
0 commit comments