diff --git a/go.mod b/go.mod index 469b46092..fe384b582 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/distribution/reference v0.6.0 github.com/docker/docker v27.3.1+incompatible github.com/docker/go-connections v0.5.0 - github.com/go-imports-organizer/goio v1.3.3 + github.com/go-imports-organizer/goio v1.5.0 github.com/moby/buildkit v0.16.0 github.com/opencontainers/image-spec v1.1.0 github.com/spf13/cobra v1.8.1 @@ -76,7 +76,7 @@ require ( go.opentelemetry.io/otel/metric v1.28.0 // indirect go.opentelemetry.io/otel/trace v1.28.0 // indirect golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect - golang.org/x/mod v0.18.0 // indirect + golang.org/x/mod v0.21.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.29.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f // indirect diff --git a/go.sum b/go.sum index d30217bc1..c6611f99f 100644 --- a/go.sum +++ b/go.sum @@ -73,8 +73,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/go-imports-organizer/goio v1.3.3 h1:JNhCzgh8ti8YvzQ3R6JwAjM+0c3rKrpndcxbJ6OOSmM= -github.com/go-imports-organizer/goio v1.3.3/go.mod h1:CgKd4H6yUHNGhSdxNou67Zi3SIjE7mwDTApEwRnC4jg= +github.com/go-imports-organizer/goio v1.5.0 h1:1dd8nLdvOkx3yRYyZpwEaUsHxz94xiOclelWgckSWM0= +github.com/go-imports-organizer/goio v1.5.0/go.mod h1:dlehECfRN4ahArk7MFpkjpPPWKXILwIQ9ZZT6ScDfQo= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -245,8 +245,8 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= -golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= +golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/vendor/github.com/go-imports-organizer/goio/go.work b/vendor/github.com/go-imports-organizer/goio/go.work deleted file mode 100644 index 52a3b7c09..000000000 --- a/vendor/github.com/go-imports-organizer/goio/go.work +++ /dev/null @@ -1,3 +0,0 @@ -go 1.19 - -use . diff --git a/vendor/github.com/go-imports-organizer/goio/main.go b/vendor/github.com/go-imports-organizer/goio/main.go index 0059729ca..17e20ccfe 100644 --- a/vendor/github.com/go-imports-organizer/goio/main.go +++ b/vendor/github.com/go-imports-organizer/goio/main.go @@ -35,9 +35,11 @@ import ( ) var ( - wg sync.WaitGroup - files = make(chan string) - pathList v1alpha1.PathListFlags + wg sync.WaitGroup + files = make(chan string) + resultsChan = make(chan string) + hasResults = false + pathList v1alpha1.PathListFlags ) func main() { @@ -100,9 +102,21 @@ func main() { // Build the Regular Expressions and DisplayOrder for the group definitions groupRegExpMatchers, displayOrder := groups.Build(conf.Groups, goModuleName) + // Read results from the resultsChan and write them to stdout + go func() { + for { + r := <-resultsChan + if len(r) != 0 { + fmt.Fprintf(os.Stdout, "%s\n", r) + } + } + }() + + // Add one (1) to the WaitGroup so that we can know when the Formatting in completed wg.Add(1) + // Start up the Format worker so that it is ready when we start queuing up files - go imports.Format(&files, &wg, groupRegExpMatchers, displayOrder, listOnly) + go imports.Format(&files, &resultsChan, &hasResults, &wg, groupRegExpMatchers, displayOrder, listOnly) // Set the basePath for use later basePath := goModulePath + "/" @@ -179,6 +193,9 @@ func main() { // Wait for all files to be processed wg.Wait() + // Close the resultsChan as all formatting should be completed + close(resultsChan) + // set MEMPROFILE= to create a .pprof memory profile file if len(os.Getenv("MEMPROFILE")) != 0 { fmt.Fprintf(os.Stdout, "Logging MEMORY profiling information to %s\n", os.Getenv(("MEMPROFILE"))) @@ -194,6 +211,9 @@ func main() { os.Exit(1) } } + if *listOnly && hasResults { + os.Exit(1) + } } func findFile(path, fileName string) (string, bool, error) { diff --git a/vendor/github.com/go-imports-organizer/goio/pkg/imports/imports.go b/vendor/github.com/go-imports-organizer/goio/pkg/imports/imports.go index bb39e6bfe..06cbbf112 100644 --- a/vendor/github.com/go-imports-organizer/goio/pkg/imports/imports.go +++ b/vendor/github.com/go-imports-organizer/goio/pkg/imports/imports.go @@ -137,7 +137,7 @@ func InsertGroups(f *ast.File, importGroups map[string][]ast.ImportSpec, display } // Format processes files as they are added to the queue and organizes the imports -func Format(files *chan string, wg *sync.WaitGroup, groupRegExpMatchers []v1alpha1.RegExpMatcher, displayOrder []string, listOnly *bool) { +func Format(files *chan string, resultsChan *chan string, hasResults *bool, wg *sync.WaitGroup, groupRegExpMatchers []v1alpha1.RegExpMatcher, displayOrder []string, listOnly *bool) { defer wg.Done() for path := range *files { if len(path) == 0 { @@ -195,17 +195,17 @@ func Format(files *chan string, wg *sync.WaitGroup, groupRegExpMatchers []v1alph fmt.Fprintf(os.Stderr, "unable to format source %q, %s", path, err.Error()) } - if *listOnly { - oldFile, err := os.ReadFile(path) - if err != nil { - fmt.Fprintf(os.Stderr, "unable to read file %q: %s", path, err.Error()) - continue - } - if !bytes.Equal(oldFile, out) { - fmt.Fprintf(os.Stdout, "%s is not organized \n", path) - } + oldFile, err := os.ReadFile(path) + if err != nil { + fmt.Fprintf(os.Stderr, "unable to read file %q: %s", path, err.Error()) + continue + } + if !bytes.Equal(oldFile, out) { + *hasResults = true + *resultsChan <- path + } - } else { + if !*listOnly { info, err = os.Stat(path) if err != nil { fmt.Fprintf(os.Stderr, "unable to stat %q: %s", path, err.Error()) @@ -217,6 +217,7 @@ func Format(files *chan string, wg *sync.WaitGroup, groupRegExpMatchers []v1alph } if err = os.WriteFile(path, out, info.Mode()); err != nil { fmt.Fprintf(os.Stderr, "unable to write to path %q, %s", path, err.Error()) + continue } } diff --git a/vendor/golang.org/x/mod/LICENSE b/vendor/golang.org/x/mod/LICENSE index 6a66aea5e..2a7cf70da 100644 --- a/vendor/golang.org/x/mod/LICENSE +++ b/vendor/golang.org/x/mod/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009 The Go Authors. All rights reserved. +Copyright 2009 The Go Authors. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -10,7 +10,7 @@ notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/vendor/golang.org/x/mod/modfile/read.go b/vendor/golang.org/x/mod/modfile/read.go index 220568259..de1b98211 100644 --- a/vendor/golang.org/x/mod/modfile/read.go +++ b/vendor/golang.org/x/mod/modfile/read.go @@ -226,8 +226,9 @@ func (x *FileSyntax) Cleanup() { continue } if ww == 1 && len(stmt.RParen.Comments.Before) == 0 { - // Collapse block into single line. - line := &Line{ + // Collapse block into single line but keep the Line reference used by the + // parsed File structure. + *stmt.Line[0] = Line{ Comments: Comments{ Before: commentsAdd(stmt.Before, stmt.Line[0].Before), Suffix: commentsAdd(stmt.Line[0].Suffix, stmt.Suffix), @@ -235,7 +236,7 @@ func (x *FileSyntax) Cleanup() { }, Token: stringsAdd(stmt.Token, stmt.Line[0].Token), } - x.Stmt[w] = line + x.Stmt[w] = stmt.Line[0] w++ continue } diff --git a/vendor/golang.org/x/mod/modfile/rule.go b/vendor/golang.org/x/mod/modfile/rule.go index 66dcaf980..3e4a1d0ab 100644 --- a/vendor/golang.org/x/mod/modfile/rule.go +++ b/vendor/golang.org/x/mod/modfile/rule.go @@ -43,6 +43,7 @@ type File struct { Exclude []*Exclude Replace []*Replace Retract []*Retract + Tool []*Tool Syntax *FileSyntax } @@ -93,6 +94,12 @@ type Retract struct { Syntax *Line } +// A Tool is a single tool statement. +type Tool struct { + Path string + Syntax *Line +} + // A VersionInterval represents a range of versions with upper and lower bounds. // Intervals are closed: both bounds are included. When Low is equal to High, // the interval may refer to a single version ('v1.2.3') or an interval @@ -297,7 +304,7 @@ func parseToFile(file string, data []byte, fix VersionFixer, strict bool) (parse }) } continue - case "module", "godebug", "require", "exclude", "replace", "retract": + case "module", "godebug", "require", "exclude", "replace", "retract", "tool": for _, l := range x.Line { f.add(&errs, x, l, x.Token[0], l.Token, fix, strict) } @@ -509,6 +516,21 @@ func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, a Syntax: line, } f.Retract = append(f.Retract, retract) + + case "tool": + if len(args) != 1 { + errorf("tool directive expects exactly one argument") + return + } + s, err := parseString(&args[0]) + if err != nil { + errorf("invalid quoted string: %v", err) + return + } + f.Tool = append(f.Tool, &Tool{ + Path: s, + Syntax: line, + }) } } @@ -1567,6 +1589,36 @@ func (f *File) DropRetract(vi VersionInterval) error { return nil } +// AddTool adds a new tool directive with the given path. +// It does nothing if the tool line already exists. +func (f *File) AddTool(path string) error { + for _, t := range f.Tool { + if t.Path == path { + return nil + } + } + + f.Tool = append(f.Tool, &Tool{ + Path: path, + Syntax: f.Syntax.addLine(nil, "tool", path), + }) + + f.SortBlocks() + return nil +} + +// RemoveTool removes a tool directive with the given path. +// It does nothing if no such tool directive exists. +func (f *File) DropTool(path string) error { + for _, t := range f.Tool { + if t.Path == path { + t.Syntax.markRemoved() + *t = Tool{} + } + } + return nil +} + func (f *File) SortBlocks() { f.removeDups() // otherwise sorting is unsafe @@ -1593,9 +1645,9 @@ func (f *File) SortBlocks() { } } -// removeDups removes duplicate exclude and replace directives. +// removeDups removes duplicate exclude, replace and tool directives. // -// Earlier exclude directives take priority. +// Earlier exclude and tool directives take priority. // // Later replace directives take priority. // @@ -1605,10 +1657,10 @@ func (f *File) SortBlocks() { // retract directives are not de-duplicated since comments are // meaningful, and versions may be retracted multiple times. func (f *File) removeDups() { - removeDups(f.Syntax, &f.Exclude, &f.Replace) + removeDups(f.Syntax, &f.Exclude, &f.Replace, &f.Tool) } -func removeDups(syntax *FileSyntax, exclude *[]*Exclude, replace *[]*Replace) { +func removeDups(syntax *FileSyntax, exclude *[]*Exclude, replace *[]*Replace, tool *[]*Tool) { kill := make(map[*Line]bool) // Remove duplicate excludes. @@ -1649,6 +1701,24 @@ func removeDups(syntax *FileSyntax, exclude *[]*Exclude, replace *[]*Replace) { } *replace = repl + if tool != nil { + haveTool := make(map[string]bool) + for _, t := range *tool { + if haveTool[t.Path] { + kill[t.Syntax] = true + continue + } + haveTool[t.Path] = true + } + var newTool []*Tool + for _, t := range *tool { + if !kill[t.Syntax] { + newTool = append(newTool, t) + } + } + *tool = newTool + } + // Duplicate require and retract directives are not removed. // Drop killed statements from the syntax tree. diff --git a/vendor/golang.org/x/mod/modfile/work.go b/vendor/golang.org/x/mod/modfile/work.go index 8f54897cf..5387d0c26 100644 --- a/vendor/golang.org/x/mod/modfile/work.go +++ b/vendor/golang.org/x/mod/modfile/work.go @@ -331,5 +331,5 @@ func (f *WorkFile) SortBlocks() { // retract directives are not de-duplicated since comments are // meaningful, and versions may be retracted multiple times. func (f *WorkFile) removeDups() { - removeDups(f.Syntax, nil, &f.Replace) + removeDups(f.Syntax, nil, &f.Replace, nil) } diff --git a/vendor/golang.org/x/mod/module/module.go b/vendor/golang.org/x/mod/module/module.go index cac1a899e..2a364b229 100644 --- a/vendor/golang.org/x/mod/module/module.go +++ b/vendor/golang.org/x/mod/module/module.go @@ -506,7 +506,6 @@ var badWindowsNames = []string{ "PRN", "AUX", "NUL", - "COM0", "COM1", "COM2", "COM3", @@ -516,7 +515,6 @@ var badWindowsNames = []string{ "COM7", "COM8", "COM9", - "LPT0", "LPT1", "LPT2", "LPT3", diff --git a/vendor/modules.txt b/vendor/modules.txt index 6e657a001..841561d61 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -220,8 +220,8 @@ github.com/docker/go-units # github.com/felixge/httpsnoop v1.0.4 ## explicit; go 1.13 github.com/felixge/httpsnoop -# github.com/go-imports-organizer/goio v1.3.3 -## explicit; go 1.19 +# github.com/go-imports-organizer/goio v1.5.0 +## explicit; go 1.22.0 github.com/go-imports-organizer/goio github.com/go-imports-organizer/goio/pkg/api/v1alpha1 github.com/go-imports-organizer/goio/pkg/config @@ -405,8 +405,8 @@ go.opentelemetry.io/otel/trace/embedded # golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 ## explicit; go 1.20 golang.org/x/exp/maps -# golang.org/x/mod v0.18.0 -## explicit; go 1.18 +# golang.org/x/mod v0.21.0 +## explicit; go 1.22.0 golang.org/x/mod/internal/lazyregexp golang.org/x/mod/modfile golang.org/x/mod/module