Skip to content

Commit 70f7491

Browse files
authored
Fix LICENSE file to match main repo (#33)
1 parent b82f170 commit 70f7491

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+360
-329
lines changed

LICENSE

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

3+
Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

cmd/copyright/licensegen.go

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// The MIT License (MIT)
1+
// The MIT License
22
//
3-
// Copyright (c) 2020 Temporal Technologies, Inc.
3+
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
44
//
5-
// Copyright (c) 2017 Uber Technologies, Inc.
5+
// Copyright (c) 2020 Uber Technologies, Inc.
66
//
77
// Permission is hereby granted, free of charge, to any person obtaining a copy
88
// of this software and associated documentation files (the "Software"), to deal
@@ -25,9 +25,9 @@
2525
package main
2626

2727
import (
28+
"bufio"
2829
"flag"
2930
"fmt"
30-
"io"
3131
"io/ioutil"
3232
"os"
3333
"path/filepath"
@@ -53,19 +53,19 @@ type (
5353
const licenseFileName = "LICENSE"
5454

5555
// unique prefix that identifies a license header
56-
const licenseHeaderPrefix = "// The MIT License (MIT)"
56+
const licenseHeaderPrefix = "// The MIT License"
5757

5858
var (
5959
// directories to be excluded
60-
dirBlacklist = []string{}
60+
dirBlacklist = []string{".gen/", ".git/", ".vscode/", ".idea/"}
6161
// default perms for the newly created files
6262
defaultFilePerms = os.FileMode(0644)
6363
)
6464

6565
// command line utility that adds license header
6666
// to the source files. Usage as follows:
6767
//
68-
// ./cmd/copyright/licensegen.go
68+
// ./cmd/tools/copyright/licensegen.go
6969
func main() {
7070

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

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

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

105108
func (task *addLicenseHeaderTask) handleFile(path string, fileInfo os.FileInfo, err error) error {
106-
107109
if err != nil {
108110
return err
109111
}
@@ -120,28 +122,37 @@ func (task *addLicenseHeaderTask) handleFile(path string, fileInfo os.FileInfo,
120122
return nil
121123
}
122124

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

128-
buf := make([]byte, len(licenseHeaderPrefix))
129-
_, err = io.ReadFull(f, buf)
130-
_ = f.Close()
131-
132-
if err != nil && !isEOF(err) {
132+
scanner := bufio.NewScanner(f)
133+
readLineSucc := scanner.Scan()
134+
if !readLineSucc {
135+
return fmt.Errorf("fail to read first line of file %v", path)
136+
}
137+
firstLine := strings.TrimSpace(scanner.Text())
138+
if err := scanner.Err(); err != nil {
133139
return err
134140
}
141+
f.Close()
135142

136-
if string(buf) == licenseHeaderPrefix {
143+
if strings.Contains(firstLine, licenseHeaderPrefix) {
137144
return nil // file already has the copyright header
138145
}
139146

140147
// at this point, src file is missing the header
141148
if task.config.verifyOnly {
142-
return fmt.Errorf("%v missing license header", path)
149+
if !isFileAutogenerated(path) {
150+
return fmt.Errorf("%v missing license header", path)
151+
}
143152
}
144153

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

164+
func isFileAutogenerated(path string) bool {
165+
return false
166+
}
167+
153168
func mustProcessPath(path string) bool {
154169
for _, d := range dirBlacklist {
155170
if strings.HasPrefix(path, d) {
@@ -159,7 +174,21 @@ func mustProcessPath(path string) bool {
159174
return true
160175
}
161176

162-
// returns true if the error type is an EOF
163-
func isEOF(err error) bool {
164-
return err == io.EOF || err == io.ErrUnexpectedEOF
177+
func commentOutLines(str string) (string, error) {
178+
var lines []string
179+
scanner := bufio.NewScanner(strings.NewReader(str))
180+
for scanner.Scan() {
181+
line := scanner.Text()
182+
if line == "" {
183+
lines = append(lines, "//\n")
184+
} else {
185+
lines = append(lines, fmt.Sprintf("// %s\n", line))
186+
}
187+
}
188+
lines = append(lines, "\n")
189+
190+
if err := scanner.Err(); err != nil {
191+
return "", err
192+
}
193+
return strings.Join(lines, ""), nil
165194
}

common/enum.pb.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/message.pb.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

decision/enum.pb.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

decision/message.pb.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

errordetails/message.pb.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

event/enum.pb.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)