Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/addlicense/tmpl.go
2492 views
1
// Copyright 2018 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
package main
16
17
import (
18
"bufio"
19
"bytes"
20
"fmt"
21
"html/template"
22
"strings"
23
"unicode"
24
)
25
26
var licenseTemplate = make(map[string]*template.Template)
27
28
func init() {
29
// licenseTemplate["apache"] = template.Must(template.New("").Parse(tmplApache))
30
licenseTemplate["mit"] = template.Must(template.New("").Parse(tmplMIT))
31
// licenseTemplate["bsd"] = template.Must(template.New("").Parse(tmplBSD))
32
// licenseTemplate["mpl"] = template.Must(template.New("").Parse(tmplMPL))
33
licenseTemplate["agpl"] = template.Must(template.New("").Parse(tmplAGPL))
34
licenseTemplate["gpshf"] = template.Must(template.New("").Parse(tmplGPSHF))
35
}
36
37
type copyrightData struct {
38
Year string
39
Holder string
40
}
41
42
// prefix will execute a license template t with data d
43
// and prefix the result with top, middle and bottom.
44
func prefix(t *template.Template, d *copyrightData, top, mid, bot string) ([]byte, error) {
45
var buf bytes.Buffer
46
if err := t.Execute(&buf, d); err != nil {
47
return nil, err
48
}
49
var out bytes.Buffer
50
if top != "" {
51
fmt.Fprintln(&out, top)
52
}
53
s := bufio.NewScanner(&buf)
54
for s.Scan() {
55
fmt.Fprintln(&out, strings.TrimRightFunc(mid+s.Text(), unicode.IsSpace))
56
}
57
if bot != "" {
58
fmt.Fprintln(&out, bot)
59
}
60
fmt.Fprintln(&out)
61
return out.Bytes(), nil
62
}
63
64
/*
65
const tmplApache = `Copyright {{.Year}} {{.Holder}}
66
67
Licensed under the Apache License, Version 2.0 (the "License");
68
you may not use this file except in compliance with the License.
69
You may obtain a copy of the License at
70
71
http://www.apache.org/licenses/LICENSE-2.0
72
73
Unless required by applicable law or agreed to in writing, software
74
distributed under the License is distributed on an "AS IS" BASIS,
75
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
76
See the License for the specific language governing permissions and
77
limitations under the License.`
78
79
const tmplBSD = `Copyright (c) {{.Year}} {{.Holder}} All rights reserved.
80
Use of this source code is governed by a BSD-style
81
license that can be found in the LICENSE file.`
82
83
const tmplMPL = `This Source Code Form is subject to the terms of the Mozilla Public
84
License, v. 2.0. If a copy of the MPL was not distributed with this
85
file, You can obtain one at https://mozilla.org/MPL/2.0/.`
86
*/
87
88
const tmplMIT = `Copyright (c) {{.Year}} {{.Holder}}. All rights reserved.
89
Licensed under the MIT License. See License-MIT.txt in the project root for license information.`
90
91
const tmplAGPL = `Copyright (c) {{.Year}} {{.Holder}}. All rights reserved.
92
Licensed under the GNU Affero General Public License (AGPL).
93
See License.AGPL.txt in the project root for license information.`
94
95
const tmplGPSHF = `Copyright (c) {{.Year}} {{.Holder}}. All rights reserved.
96
Licensed under the Gitpod Enterprise Source Code License,
97
See License.enterprise.txt in the project root folder.`
98
99