Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
// The MIT License (MIT)
//
// Copyright (c) 2020 Temporal Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
The MIT License

Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
67 changes: 48 additions & 19 deletions cmd/copyright/licensegen.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// The MIT License (MIT)
// The MIT License
//
// Copyright (c) 2020 Temporal Technologies, Inc.
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2017 Uber Technologies, Inc.
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -25,9 +25,9 @@
package main

import (
"bufio"
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
Expand All @@ -53,19 +53,19 @@ type (
const licenseFileName = "LICENSE"

// unique prefix that identifies a license header
const licenseHeaderPrefix = "// The MIT License (MIT)"
const licenseHeaderPrefix = "// The MIT License"

var (
// directories to be excluded
dirBlacklist = []string{}
dirBlacklist = []string{".gen/", ".git/", ".vscode/", ".idea/"}
// default perms for the newly created files
defaultFilePerms = os.FileMode(0644)
)

// command line utility that adds license header
// to the source files. Usage as follows:
//
// ./cmd/copyright/licensegen.go
// ./cmd/tools/copyright/licensegen.go
func main() {

var cfg config
Expand Down Expand Up @@ -93,7 +93,10 @@ func (task *addLicenseHeaderTask) run() error {
return fmt.Errorf("error reading license file, errr=%v", err.Error())
}

task.license = string(data)
task.license, err = commentOutLines(string(data))
if err != nil {
return fmt.Errorf("copyright header failed to comment out lines, err=%v", err.Error())
}

err = filepath.Walk(task.config.rootDir, task.handleFile)
if err != nil {
Expand All @@ -103,7 +106,6 @@ func (task *addLicenseHeaderTask) run() error {
}

func (task *addLicenseHeaderTask) handleFile(path string, fileInfo os.FileInfo, err error) error {

if err != nil {
return err
}
Expand All @@ -120,28 +122,37 @@ func (task *addLicenseHeaderTask) handleFile(path string, fileInfo os.FileInfo,
return nil
}

// Used as part of the cli to write licence headers on files, does not use user supplied input so marked as nosec
// #nosec
f, err := os.Open(path)
if err != nil {
return err
}

buf := make([]byte, len(licenseHeaderPrefix))
_, err = io.ReadFull(f, buf)
_ = f.Close()

if err != nil && !isEOF(err) {
scanner := bufio.NewScanner(f)
readLineSucc := scanner.Scan()
if !readLineSucc {
return fmt.Errorf("fail to read first line of file %v", path)
}
firstLine := strings.TrimSpace(scanner.Text())
if err := scanner.Err(); err != nil {
return err
}
f.Close()

if string(buf) == licenseHeaderPrefix {
if strings.Contains(firstLine, licenseHeaderPrefix) {
return nil // file already has the copyright header
}

// at this point, src file is missing the header
if task.config.verifyOnly {
return fmt.Errorf("%v missing license header", path)
if !isFileAutogenerated(path) {
return fmt.Errorf("%v missing license header", path)
}
}

// Used as part of the cli to write licence headers on files, does not use user supplied input so marked as nosec
// #nosec
data, err := ioutil.ReadFile(path)
if err != nil {
return err
Expand All @@ -150,6 +161,10 @@ func (task *addLicenseHeaderTask) handleFile(path string, fileInfo os.FileInfo,
return ioutil.WriteFile(path, []byte(task.license+string(data)), defaultFilePerms)
}

func isFileAutogenerated(path string) bool {
return false
}

func mustProcessPath(path string) bool {
for _, d := range dirBlacklist {
if strings.HasPrefix(path, d) {
Expand All @@ -159,7 +174,21 @@ func mustProcessPath(path string) bool {
return true
}

// returns true if the error type is an EOF
func isEOF(err error) bool {
return err == io.EOF || err == io.ErrUnexpectedEOF
func commentOutLines(str string) (string, error) {
var lines []string
scanner := bufio.NewScanner(strings.NewReader(str))
for scanner.Scan() {
line := scanner.Text()
if line == "" {
lines = append(lines, "//\n")
} else {
lines = append(lines, fmt.Sprintf("// %s\n", line))
}
}
lines = append(lines, "\n")

if err := scanner.Err(); err != nil {
return "", err
}
return strings.Join(lines, ""), nil
}
12 changes: 6 additions & 6 deletions common/enum.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions common/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions decision/enum.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions decision/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions errordetails/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions event/enum.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading