up
This commit is contained in:
40
main.go
40
main.go
@@ -37,9 +37,11 @@ Flags:
|
|||||||
`
|
`
|
||||||
|
|
||||||
var (
|
var (
|
||||||
skipExtensionFlags stringSlice
|
skipExtensionFlags stringSlice
|
||||||
ignorePatterns stringSlice
|
ignorePatterns stringSlice
|
||||||
spdx spdxFlag
|
filesFlags stringSlice
|
||||||
|
spdx spdxFlag
|
||||||
|
fileList []string
|
||||||
|
|
||||||
holder = flag.String("c", "Avroid, Ltd.", "copyright holder")
|
holder = flag.String("c", "Avroid, Ltd.", "copyright holder")
|
||||||
license = flag.String("l", "commercial", "license type: commercial, apache, bsd, mit, mpl")
|
license = flag.String("l", "commercial", "license type: commercial, apache, bsd, mit, mpl")
|
||||||
@@ -56,6 +58,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
flag.Var(&skipExtensionFlags, "skip", "[deprecated: see -ignore] file extensions to skip, for example: -skip rb -skip go")
|
flag.Var(&skipExtensionFlags, "skip", "[deprecated: see -ignore] file extensions to skip, for example: -skip rb -skip go")
|
||||||
flag.Var(&ignorePatterns, "ignore", "file patterns to ignore, for example: -ignore **/*.go -ignore vendor/**")
|
flag.Var(&ignorePatterns, "ignore", "file patterns to ignore, for example: -ignore **/*.go -ignore vendor/**")
|
||||||
|
flag.Var(&listFiles, "files", "list of files to include, for example: -files 'src/main.c src/header.h'")
|
||||||
flag.Var(&spdx, "s", "Include SPDX identifier in license header. Set -s=only to only include SPDX identifier.")
|
flag.Var(&spdx, "s", "Include SPDX identifier in license header. Set -s=only to only include SPDX identifier.")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +115,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert string of files to list of files
|
||||||
|
for _, l := range listFiles {
|
||||||
|
files := strings.Fields(l)
|
||||||
|
for _, file := range files {
|
||||||
|
fileList := append(fileList, file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// map legacy license values
|
// map legacy license values
|
||||||
if t, ok := legacyLicenseTypes[*license]; ok {
|
if t, ok := legacyLicenseTypes[*license]; ok {
|
||||||
*license = t
|
*license = t
|
||||||
@@ -160,6 +171,10 @@ func main() {
|
|||||||
fmt.Printf("%s\n", f.path)
|
fmt.Printf("%s\n", f.path)
|
||||||
return errors.New("missing license header")
|
return errors.New("missing license header")
|
||||||
}
|
}
|
||||||
|
if !hasCorrectAvroidLicense(f.path) {
|
||||||
|
fmt.Printf("%s\n", f.path)
|
||||||
|
return errors.New("incorrect year in license header")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
modified, err := addLicense(f.path, f.mode, t, data)
|
modified, err := addLicense(f.path, f.mode, t, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -209,6 +224,9 @@ func walk(ch chan<- *file, start string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if fileList !fileMatches(path, fileList) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
ch <- &file{path, fi.Mode()}
|
ch <- &file{path, fi.Mode()}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -365,11 +383,23 @@ func isGenerated(b []byte) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func hasLicense(b []byte) bool {
|
func hasLicense(b []byte) bool {
|
||||||
n := 1000
|
n := 500
|
||||||
if len(b) < 1000 {
|
if len(b) < 500 {
|
||||||
n = len(b)
|
n = len(b)
|
||||||
}
|
}
|
||||||
return bytes.Contains(bytes.ToLower(b[:n]), []byte("copyright")) ||
|
return bytes.Contains(bytes.ToLower(b[:n]), []byte("copyright")) ||
|
||||||
bytes.Contains(bytes.ToLower(b[:n]), []byte("mozilla public")) ||
|
bytes.Contains(bytes.ToLower(b[:n]), []byte("mozilla public")) ||
|
||||||
bytes.Contains(bytes.ToLower(b[:n]), []byte("spdx-license-identifier"))
|
bytes.Contains(bytes.ToLower(b[:n]), []byte("spdx-license-identifier"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasCorrectAvroidLicense(b []byte) bool {
|
||||||
|
n := 500
|
||||||
|
if len(b) < 500 {
|
||||||
|
n = len(b)
|
||||||
|
}
|
||||||
|
if bytes.Contains([]byte("AVROID, Ltd. written permission")) {
|
||||||
|
return bytes.Contains([]byte(fmt.Sprintf("Copyright (c) AVROID, Ltd., %s", data.Year))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user