up
This commit is contained in:
40
main.go
40
main.go
@@ -37,9 +37,11 @@ Flags:
|
||||
`
|
||||
|
||||
var (
|
||||
skipExtensionFlags stringSlice
|
||||
ignorePatterns stringSlice
|
||||
spdx spdxFlag
|
||||
skipExtensionFlags stringSlice
|
||||
ignorePatterns stringSlice
|
||||
filesFlags stringSlice
|
||||
spdx spdxFlag
|
||||
fileList []string
|
||||
|
||||
holder = flag.String("c", "Avroid, Ltd.", "copyright holder")
|
||||
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(&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.")
|
||||
}
|
||||
|
||||
@@ -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
|
||||
if t, ok := legacyLicenseTypes[*license]; ok {
|
||||
*license = t
|
||||
@@ -160,6 +171,10 @@ func main() {
|
||||
fmt.Printf("%s\n", f.path)
|
||||
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 {
|
||||
modified, err := addLicense(f.path, f.mode, t, data)
|
||||
if err != nil {
|
||||
@@ -209,6 +224,9 @@ func walk(ch chan<- *file, start string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if fileList !fileMatches(path, fileList) {
|
||||
return nil
|
||||
}
|
||||
ch <- &file{path, fi.Mode()}
|
||||
return nil
|
||||
})
|
||||
@@ -365,11 +383,23 @@ func isGenerated(b []byte) bool {
|
||||
}
|
||||
|
||||
func hasLicense(b []byte) bool {
|
||||
n := 1000
|
||||
if len(b) < 1000 {
|
||||
n := 500
|
||||
if len(b) < 500 {
|
||||
n = len(b)
|
||||
}
|
||||
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("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