// Copyright 2018 Google LLC1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314package main1516import (17"bufio"18"bytes"19"fmt"20"html/template"21"strings"22"unicode"23)2425var licenseTemplate = make(map[string]*template.Template)2627func init() {28// licenseTemplate["apache"] = template.Must(template.New("").Parse(tmplApache))29licenseTemplate["mit"] = template.Must(template.New("").Parse(tmplMIT))30// licenseTemplate["bsd"] = template.Must(template.New("").Parse(tmplBSD))31// licenseTemplate["mpl"] = template.Must(template.New("").Parse(tmplMPL))32licenseTemplate["agpl"] = template.Must(template.New("").Parse(tmplAGPL))33licenseTemplate["gpshf"] = template.Must(template.New("").Parse(tmplGPSHF))34}3536type copyrightData struct {37Year string38Holder string39}4041// prefix will execute a license template t with data d42// and prefix the result with top, middle and bottom.43func prefix(t *template.Template, d *copyrightData, top, mid, bot string) ([]byte, error) {44var buf bytes.Buffer45if err := t.Execute(&buf, d); err != nil {46return nil, err47}48var out bytes.Buffer49if top != "" {50fmt.Fprintln(&out, top)51}52s := bufio.NewScanner(&buf)53for s.Scan() {54fmt.Fprintln(&out, strings.TrimRightFunc(mid+s.Text(), unicode.IsSpace))55}56if bot != "" {57fmt.Fprintln(&out, bot)58}59fmt.Fprintln(&out)60return out.Bytes(), nil61}6263/*64const tmplApache = `Copyright {{.Year}} {{.Holder}}6566Licensed under the Apache License, Version 2.0 (the "License");67you may not use this file except in compliance with the License.68You may obtain a copy of the License at6970http://www.apache.org/licenses/LICENSE-2.07172Unless required by applicable law or agreed to in writing, software73distributed under the License is distributed on an "AS IS" BASIS,74WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.75See the License for the specific language governing permissions and76limitations under the License.`7778const tmplBSD = `Copyright (c) {{.Year}} {{.Holder}} All rights reserved.79Use of this source code is governed by a BSD-style80license that can be found in the LICENSE file.`8182const tmplMPL = `This Source Code Form is subject to the terms of the Mozilla Public83License, v. 2.0. If a copy of the MPL was not distributed with this84file, You can obtain one at https://mozilla.org/MPL/2.0/.`85*/8687const tmplMIT = `Copyright (c) {{.Year}} {{.Holder}}. All rights reserved.88Licensed under the MIT License. See License-MIT.txt in the project root for license information.`8990const tmplAGPL = `Copyright (c) {{.Year}} {{.Holder}}. All rights reserved.91Licensed under the GNU Affero General Public License (AGPL).92See License.AGPL.txt in the project root for license information.`9394const tmplGPSHF = `Copyright (c) {{.Year}} {{.Holder}}. All rights reserved.95Licensed under the Gitpod Enterprise Source Code License,96See License.enterprise.txt in the project root folder.`979899