From e5d199fdd1b883a83ea153e1bdc4a9625c5f45a2 Mon Sep 17 00:00:00 2001 From: AdmiringWorm Date: Wed, 22 Jul 2020 17:25:42 +0200 Subject: [PATCH] feat(project): add ability to include license header for source files These changes includes the ability to add a license header to all source files (.cs) when a license that recommends a license header is used. re #26 --- __tests__/project/default/aliases.cs | 6 + .../project/default/nunit/testAliasesTests.cs | 6 + .../project/default/nunit/testRunnerTests.cs | 6 + .../project/default/project/project.csproj | 2 +- __tests__/project/default/runner.cs | 6 + __tests__/project/default/settings.cs | 6 + .../project/default/testAliasesFixture.cs | 6 + .../project/default/testRunnerFixture.cs | 6 + .../project/default/xunit/testAliasesTests.cs | 6 + .../project/default/xunit/testRunnerTests.cs | 6 + __tests__/project/indexTests.ts | 253 +++++++++++++++++- __tests__/project/space/.editorconfig | 3 + __tests__/project/space/aliases.cs | 6 + __tests__/project/space/project.csproj | 2 +- __tests__/project/space/runner.cs | 6 + __tests__/project/space/settings.cs | 6 + __tests__/project/space/testAliasesFixture.cs | 6 + __tests__/project/space/testAliasesTests.cs | 6 + __tests__/project/space/testRunnerFixture.cs | 6 + __tests__/project/space/testRunnerTests.cs | 6 + __tests__/project/wyamEnabled/project.csproj | 2 +- .../TemplateAliasesFixture.cs.tmpl | 3 +- .../TemplateAliasesTests.cs.tmpl | 3 +- .../TemplateRunnerFixture.cs.tmpl | 3 +- .../TemplateRunnerTests.cs.tmpl | 3 +- .../Cake.Template/TemplateAliases.cs.tmpl | 3 +- .../Cake.Template/TemplateRunner.cs.tmpl | 3 +- .../Cake.Template/TemplateSettings.cs.tmpl | 3 +- src/project/templates/headers/Apache-2.0.tmpl | 16 ++ .../templates/headers/GPL-3.0-or-later.tmpl | 20 ++ src/project/templates/headers/MIT.tmpl | 27 ++ src/project/templates/headers/MPL-2.0.tmpl | 3 + src/project/templates/headers/Unlicense.tmpl | 0 src/project/templates/headers/WTFPL.tmpl | 0 src/project/templates/headers/csheader.tmpl | 15 ++ 35 files changed, 447 insertions(+), 13 deletions(-) create mode 100644 __tests__/project/space/.editorconfig create mode 100644 src/project/templates/headers/Apache-2.0.tmpl create mode 100644 src/project/templates/headers/GPL-3.0-or-later.tmpl create mode 100644 src/project/templates/headers/MIT.tmpl create mode 100644 src/project/templates/headers/MPL-2.0.tmpl create mode 100644 src/project/templates/headers/Unlicense.tmpl create mode 100644 src/project/templates/headers/WTFPL.tmpl create mode 100644 src/project/templates/headers/csheader.tmpl diff --git a/__tests__/project/default/aliases.cs b/__tests__/project/default/aliases.cs index 97685e55..5095f16d 100644 --- a/__tests__/project/default/aliases.cs +++ b/__tests__/project/default/aliases.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp { using Cake.Core; diff --git a/__tests__/project/default/nunit/testAliasesTests.cs b/__tests__/project/default/nunit/testAliasesTests.cs index 11531729..3fa3bb08 100644 --- a/__tests__/project/default/nunit/testAliasesTests.cs +++ b/__tests__/project/default/nunit/testAliasesTests.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp.Tests { using System; diff --git a/__tests__/project/default/nunit/testRunnerTests.cs b/__tests__/project/default/nunit/testRunnerTests.cs index 3d841843..309bd969 100644 --- a/__tests__/project/default/nunit/testRunnerTests.cs +++ b/__tests__/project/default/nunit/testRunnerTests.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp.Tests { using System; diff --git a/__tests__/project/default/project/project.csproj b/__tests__/project/default/project/project.csproj index 04d6623e..9b799eff 100644 --- a/__tests__/project/default/project/project.csproj +++ b/__tests__/project/default/project/project.csproj @@ -17,7 +17,7 @@ Copyright © $(FullYear) — Kim Nordmo Cake addin generation test https://cdn.jsdelivr.net/gh/cake-contrib/graphics/png/cake-contrib-medium.png - MIT + MPL-2.0 https://github.com/AdmiringWorm/Cake.TestApp cake;addin;testapp https://github.com/AdmiringWorm/Cake.TestApp.git diff --git a/__tests__/project/default/runner.cs b/__tests__/project/default/runner.cs index acc5c7f0..addec71f 100644 --- a/__tests__/project/default/runner.cs +++ b/__tests__/project/default/runner.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp { using System; diff --git a/__tests__/project/default/settings.cs b/__tests__/project/default/settings.cs index e61daf18..cba82a83 100644 --- a/__tests__/project/default/settings.cs +++ b/__tests__/project/default/settings.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp { using System; diff --git a/__tests__/project/default/testAliasesFixture.cs b/__tests__/project/default/testAliasesFixture.cs index 8d6e6ff4..9f7603d0 100644 --- a/__tests__/project/default/testAliasesFixture.cs +++ b/__tests__/project/default/testAliasesFixture.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp.Tests { using System.Collections.Generic; diff --git a/__tests__/project/default/testRunnerFixture.cs b/__tests__/project/default/testRunnerFixture.cs index 036c2fc9..41e9319c 100644 --- a/__tests__/project/default/testRunnerFixture.cs +++ b/__tests__/project/default/testRunnerFixture.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp.Tests { using Cake.Testing.Fixtures; diff --git a/__tests__/project/default/xunit/testAliasesTests.cs b/__tests__/project/default/xunit/testAliasesTests.cs index d0173a63..ae2a61d9 100644 --- a/__tests__/project/default/xunit/testAliasesTests.cs +++ b/__tests__/project/default/xunit/testAliasesTests.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp.Tests { using System; diff --git a/__tests__/project/default/xunit/testRunnerTests.cs b/__tests__/project/default/xunit/testRunnerTests.cs index 0b4a2695..4c9696ea 100644 --- a/__tests__/project/default/xunit/testRunnerTests.cs +++ b/__tests__/project/default/xunit/testRunnerTests.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp.Tests { using System; diff --git a/__tests__/project/indexTests.ts b/__tests__/project/indexTests.ts index aba4cc21..7a0976ed 100644 --- a/__tests__/project/indexTests.ts +++ b/__tests__/project/indexTests.ts @@ -29,6 +29,7 @@ describe("generator:project", () => { .run(generatorDir) .withOptions( getPromptConfig({ + licenseType: "MPL-2.0", "skip-dotnet": true, }) ) @@ -50,7 +51,7 @@ describe("generator:project", () => { return helpers .run(generatorDir) .withPrompts(getPromptConfig()) - .withOptions({ "skip-dotnet": true }) + .withOptions({ licenseType: "MPL-2.0", "skip-dotnet": true }) .inTmpDir((dir) => (workDir = dir)) .then(() => assert.fileContent( @@ -68,6 +69,7 @@ describe("generator:project", () => { .withPrompts( getPromptConfig({ description: "Cake addin generation test", + licenseType: "MPL-2.0", enableWyam: false, }) ) @@ -154,6 +156,7 @@ describe("generator:project", () => { .run(generatorDir) .withPrompts(getPromptConfig()) .withOptions({ + licenseType: "MPL-2.0", "skip-dotnet": true, }) .inTmpDir((dir) => (workDir2 = dir)); @@ -213,7 +216,7 @@ describe("generator:project", () => { return helpers .run(generatorDir) .withPrompts(getPromptConfig({ sourceDir: "./source" })) - .withOptions({ "skip-dotnet": true }) + .withOptions({ licenseType: "MPL-2.0", "skip-dotnet": true }) .inTmpDir((dir) => (workDir = dir)) .then(() => assert.file(path.join(workDir, "source", "Cake.TestApp.sln")) @@ -226,6 +229,7 @@ describe("generator:project", () => { .run(generatorDir) .withOptions( getPromptConfig({ + licenseType: "MPL-2.0", "skip-dotnet": true, sourceDir: "./source", }) @@ -246,6 +250,7 @@ describe("generator:project", () => { .withOptions( getPromptConfig({ build: true, + licenseType: "MPL-2.0", }) ) .inTmpDir((dir) => (workDir = dir)); @@ -277,13 +282,14 @@ describe("generator:project", () => { }) ) .withOptions({ + licenseType: "MPL-2.0", "skip-dotnet": true, "start-year": 2019, }) .inTmpDir((dir) => (workDir = dir)); }); - const tabRegex = /^($|\t*[^\s])/; + const tabRegex = /^($| \*|\t*[^\s])/; it("should create solution file with tabs instead of spaces", () => { const buffer = readFileSync( @@ -461,6 +467,7 @@ describe("generator:project", () => { description: "Cake addin generation test", enableWyam: false, indentSize: 2, + licenseType: "MPL-2.0", }) ) .withOptions({ @@ -559,4 +566,244 @@ describe("generator:project", () => { }); }); }); + + describe("licenses", () => { + describe("Apache-2.0", () => { + let workDir = ""; + beforeAll(() => { + return helpers + .run(generatorDir) + .withPrompts( + getPromptConfig({ + description: "Cake addin generation test", + enableWyam: false, + licenseType: "Apache-2.0", + }) + ) + .withOptions({ + "skip-dotnet": true, + "start-year": 2018, + }) + .inTmpDir((dir) => (workDir = dir)); + }); + + it("should generate correct apache license header", () => { + assert.fileContent( + path.join(workDir, "src", "Cake.TestApp", "TestAppSettings.cs"), + `/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */` + ); + }); + }); + + describe("GPL-3.0-or-later", () => { + let workDir = ""; + beforeAll(() => { + return helpers + .run(generatorDir) + .withPrompts( + getPromptConfig({ + description: "Cake addin generation test", + enableWyam: false, + licenseType: "GPL-3.0-or-later", + }) + ) + .withOptions({ + "skip-dotnet": true, + "start-year": 2018, + }) + .inTmpDir((dir) => (workDir = dir)); + }); + + it("should generate correct gpl 3.0 license header", () => { + assert.fileContent( + path.join(workDir, "src", "Cake.TestApp", "TestAppSettings.cs"), + `/* + * Copyright (C) 2018-${new Date().getFullYear()} Kim Nordmo + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see https://www.gnu.org/licenses/. + */` + ); + }); + }); + + describe("MIT", () => { + let workDir = ""; + beforeAll(() => { + return helpers + .run(generatorDir) + .withPrompts( + getPromptConfig({ + description: "Cake addin generation test", + enableWyam: false, + licenseType: "MIT", + }) + ) + .withOptions({ + "skip-dotnet": true, + "start-year": 2018, + }) + .inTmpDir((dir) => (workDir = dir)); + }); + + it("should generate correct mit license header", () => { + assert.fileContent( + path.join(workDir, "src", "Cake.TestApp", "TestAppSettings.cs"), + `/* + * MIT License + * + * Copyright (c) 2018-${new Date().getFullYear()} Kim Nordmo + * + * 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. + */` + ); + }); + }); + + describe("MPL-2.0", () => { + let workDir = ""; + beforeAll(() => { + return helpers + .run(generatorDir) + .withPrompts( + getPromptConfig({ + description: "Cake addin generation test", + enableWyam: false, + licenseType: "MPL-2.0", + }) + ) + .withOptions({ + "skip-dotnet": true, + "start-year": 2018, + }) + .inTmpDir((dir) => (workDir = dir)); + }); + + it("should generate correct mozilla 2.0 license header", () => { + assert.fileContent( + path.join(workDir, "src", "Cake.TestApp", "TestAppSettings.cs"), + `/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */` + ); + }); + }); + + describe("Unlicense", () => { + let workDir = ""; + beforeAll(() => { + return helpers + .run(generatorDir) + .withPrompts( + getPromptConfig({ + description: "Cake addin generation test", + enableWyam: false, + licenseType: "Unlicense", + }) + ) + .withOptions({ + "skip-dotnet": true, + "start-year": 2018, + }) + .inTmpDir((dir) => (workDir = dir)); + }); + + it("should generate correct The Unlicense header", () => { + assert.equalsFileContent( + path.join(workDir, "src", "Cake.TestApp", "TestAppSettings.cs"), + `namespace Cake.TestApp +{ + using System; + using Cake.Core.Tooling; + + public sealed class TestAppSettings : ToolSettings + { + } +} +` + ); + }); + }); + + describe("WTFPL", () => { + let workDir = ""; + beforeAll(() => { + return helpers + .run(generatorDir) + .withPrompts( + getPromptConfig({ + description: "Cake addin generation test", + enableWyam: false, + licenseType: "WTFPL", + }) + ) + .withOptions({ + "skip-dotnet": true, + "start-year": 2018, + }) + .inTmpDir((dir) => (workDir = dir)); + }); + + it("should generate correct WTFPL license header", () => { + assert.equalsFileContent( + path.join(workDir, "src", "Cake.TestApp", "TestAppSettings.cs"), + `namespace Cake.TestApp +{ + using System; + using Cake.Core.Tooling; + + public sealed class TestAppSettings : ToolSettings + { + } +} +` + ); + }); + }); + }); }); diff --git a/__tests__/project/space/.editorconfig b/__tests__/project/space/.editorconfig new file mode 100644 index 00000000..0da8f80f --- /dev/null +++ b/__tests__/project/space/.editorconfig @@ -0,0 +1,3 @@ +[*] +indent_size = 2 +indent_style = space diff --git a/__tests__/project/space/aliases.cs b/__tests__/project/space/aliases.cs index 79d23705..1dd3b4e3 100644 --- a/__tests__/project/space/aliases.cs +++ b/__tests__/project/space/aliases.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp { using Cake.Core; diff --git a/__tests__/project/space/project.csproj b/__tests__/project/space/project.csproj index f40ad64f..f8f8d8ae 100644 --- a/__tests__/project/space/project.csproj +++ b/__tests__/project/space/project.csproj @@ -17,7 +17,7 @@ Copyright © $(FullYear) — Kim Nordmo Cake addin generation test https://cdn.jsdelivr.net/gh/cake-contrib/graphics/png/cake-contrib-medium.png - MIT + MPL-2.0 https://github.com/AdmiringWorm/Cake.TestApp cake;addin;testapp https://github.com/AdmiringWorm/Cake.TestApp.git diff --git a/__tests__/project/space/runner.cs b/__tests__/project/space/runner.cs index a26afc1c..9413d4c4 100644 --- a/__tests__/project/space/runner.cs +++ b/__tests__/project/space/runner.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp { using System; diff --git a/__tests__/project/space/settings.cs b/__tests__/project/space/settings.cs index e1e9a254..ea38a8db 100644 --- a/__tests__/project/space/settings.cs +++ b/__tests__/project/space/settings.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp { using System; diff --git a/__tests__/project/space/testAliasesFixture.cs b/__tests__/project/space/testAliasesFixture.cs index 7dddbbe3..0c01b0b6 100644 --- a/__tests__/project/space/testAliasesFixture.cs +++ b/__tests__/project/space/testAliasesFixture.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp.Tests { using System.Collections.Generic; diff --git a/__tests__/project/space/testAliasesTests.cs b/__tests__/project/space/testAliasesTests.cs index b96b4713..06b92748 100644 --- a/__tests__/project/space/testAliasesTests.cs +++ b/__tests__/project/space/testAliasesTests.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp.Tests { using System; diff --git a/__tests__/project/space/testRunnerFixture.cs b/__tests__/project/space/testRunnerFixture.cs index 5f92c93e..ff9d2c4c 100644 --- a/__tests__/project/space/testRunnerFixture.cs +++ b/__tests__/project/space/testRunnerFixture.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp.Tests { using Cake.Testing.Fixtures; diff --git a/__tests__/project/space/testRunnerTests.cs b/__tests__/project/space/testRunnerTests.cs index 29b15c84..1dcd4b2b 100644 --- a/__tests__/project/space/testRunnerTests.cs +++ b/__tests__/project/space/testRunnerTests.cs @@ -1,3 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + namespace Cake.TestApp.Tests { using System; diff --git a/__tests__/project/wyamEnabled/project.csproj b/__tests__/project/wyamEnabled/project.csproj index f4f12493..ae1c33f3 100644 --- a/__tests__/project/wyamEnabled/project.csproj +++ b/__tests__/project/wyamEnabled/project.csproj @@ -17,7 +17,7 @@ Copyright © $(FullYear) — Kim Nordmo Cake addin generation test https://cdn.jsdelivr.net/gh/cake-contrib/graphics/png/cake-contrib-medium.png - MIT + MPL-2.0 https://admiringworm.github.io/Cake.TestApp cake;addin;testapp https://github.com/AdmiringWorm/Cake.TestApp.git diff --git a/src/project/templates/Cake.Template.Tests/TemplateAliasesFixture.cs.tmpl b/src/project/templates/Cake.Template.Tests/TemplateAliasesFixture.cs.tmpl index 6a25ae9f..ae17f435 100644 --- a/src/project/templates/Cake.Template.Tests/TemplateAliasesFixture.cs.tmpl +++ b/src/project/templates/Cake.Template.Tests/TemplateAliasesFixture.cs.tmpl @@ -1,4 +1,5 @@ -namespace Cake.<%= projectName %>.Tests +<%- include('../headers/csheader.tmpl', {filename: projectName + 'AliasesFixture.cs' }) +_%>namespace Cake.<%= projectName %>.Tests { using System.Collections.Generic; using System.Linq; diff --git a/src/project/templates/Cake.Template.Tests/TemplateAliasesTests.cs.tmpl b/src/project/templates/Cake.Template.Tests/TemplateAliasesTests.cs.tmpl index 2a4f5c45..67ecbcf3 100644 --- a/src/project/templates/Cake.Template.Tests/TemplateAliasesTests.cs.tmpl +++ b/src/project/templates/Cake.Template.Tests/TemplateAliasesTests.cs.tmpl @@ -1,4 +1,5 @@ -<% let unitTestAttribute = ""; +<%- include('../headers/csheader.tmpl', {filename: projectName + 'AliasesTests.cs' }) +_%><% let unitTestAttribute = ""; let usingStatements = ""; switch (unitTestLibrary) { case "xunit": diff --git a/src/project/templates/Cake.Template.Tests/TemplateRunnerFixture.cs.tmpl b/src/project/templates/Cake.Template.Tests/TemplateRunnerFixture.cs.tmpl index c12c946d..98dcb2fc 100644 --- a/src/project/templates/Cake.Template.Tests/TemplateRunnerFixture.cs.tmpl +++ b/src/project/templates/Cake.Template.Tests/TemplateRunnerFixture.cs.tmpl @@ -1,4 +1,5 @@ -namespace Cake.<%= projectName %>.Tests +<%- include('../headers/csheader.tmpl', {filename: projectName + 'RunnerFixture.cs' }) +_%>namespace Cake.<%= projectName %>.Tests { using Cake.Testing.Fixtures; diff --git a/src/project/templates/Cake.Template.Tests/TemplateRunnerTests.cs.tmpl b/src/project/templates/Cake.Template.Tests/TemplateRunnerTests.cs.tmpl index 505908b4..bf6f8870 100644 --- a/src/project/templates/Cake.Template.Tests/TemplateRunnerTests.cs.tmpl +++ b/src/project/templates/Cake.Template.Tests/TemplateRunnerTests.cs.tmpl @@ -1,4 +1,5 @@ -<% let unitTestAttribute = ""; +<%- include('../headers/csheader.tmpl', {filename: projectName + 'RunnerTests.cs' }) +_%><% let unitTestAttribute = ""; let usingStatements = ""; switch (unitTestLibrary) { case "xunit": diff --git a/src/project/templates/Cake.Template/TemplateAliases.cs.tmpl b/src/project/templates/Cake.Template/TemplateAliases.cs.tmpl index 52521dde..3946bac6 100644 --- a/src/project/templates/Cake.Template/TemplateAliases.cs.tmpl +++ b/src/project/templates/Cake.Template/TemplateAliases.cs.tmpl @@ -1,4 +1,5 @@ -namespace Cake.<%= projectName %> +<%- include('../headers/csheader.tmpl', {filename: projectName + 'Aliases.cs' }) +_%>namespace Cake.<%= projectName %> { using Cake.Core; using Cake.Core.Annotations; diff --git a/src/project/templates/Cake.Template/TemplateRunner.cs.tmpl b/src/project/templates/Cake.Template/TemplateRunner.cs.tmpl index 56fcb1a5..83327433 100644 --- a/src/project/templates/Cake.Template/TemplateRunner.cs.tmpl +++ b/src/project/templates/Cake.Template/TemplateRunner.cs.tmpl @@ -1,4 +1,5 @@ -namespace Cake.<%= projectName %> +<%- include('../headers/csheader.tmpl', {filename: projectName + 'Runner.cs' }) +_%>namespace Cake.<%= projectName %> { using System; using System.Collections.Generic; diff --git a/src/project/templates/Cake.Template/TemplateSettings.cs.tmpl b/src/project/templates/Cake.Template/TemplateSettings.cs.tmpl index 6cafdc1c..d34c626f 100644 --- a/src/project/templates/Cake.Template/TemplateSettings.cs.tmpl +++ b/src/project/templates/Cake.Template/TemplateSettings.cs.tmpl @@ -1,4 +1,5 @@ -namespace Cake.<%= projectName %> +<%- include('../headers/csheader.tmpl', {filename: projectName + 'Settings.cs' }) +_%>namespace Cake.<%= projectName %> { using System; using Cake.Core.Tooling; diff --git a/src/project/templates/headers/Apache-2.0.tmpl b/src/project/templates/headers/Apache-2.0.tmpl new file mode 100644 index 00000000..00b1481a --- /dev/null +++ b/src/project/templates/headers/Apache-2.0.tmpl @@ -0,0 +1,16 @@ +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. diff --git a/src/project/templates/headers/GPL-3.0-or-later.tmpl b/src/project/templates/headers/GPL-3.0-or-later.tmpl new file mode 100644 index 00000000..cbda207f --- /dev/null +++ b/src/project/templates/headers/GPL-3.0-or-later.tmpl @@ -0,0 +1,20 @@ +<% var currentYear = new Date().getFullYear(); + var fullYear = currentYear; + if (currentYear != startYear) { + fullYear = startYear + "-" + currentYear; + } +-%> +Copyright (C) <%= fullYear %> <%= author %> + +This program is free software: you can redistribute it and/or +modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see https://www.gnu.org/licenses/. diff --git a/src/project/templates/headers/MIT.tmpl b/src/project/templates/headers/MIT.tmpl new file mode 100644 index 00000000..8f6a4d9c --- /dev/null +++ b/src/project/templates/headers/MIT.tmpl @@ -0,0 +1,27 @@ +<% var currentYear = new Date().getFullYear(); + var fullYear = currentYear; + if (currentYear != startYear) { + fullYear = startYear + "-" + currentYear; + } +-%> +MIT License + +Copyright (c) <%= fullYear %> <%= author %> + +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. diff --git a/src/project/templates/headers/MPL-2.0.tmpl b/src/project/templates/headers/MPL-2.0.tmpl new file mode 100644 index 00000000..41dc2327 --- /dev/null +++ b/src/project/templates/headers/MPL-2.0.tmpl @@ -0,0 +1,3 @@ +This Source Code Form is subject to the terms of the Mozilla Public +License, v. 2.0. If a copy of the MPL was not distributed with this +file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/project/templates/headers/Unlicense.tmpl b/src/project/templates/headers/Unlicense.tmpl new file mode 100644 index 00000000..e69de29b diff --git a/src/project/templates/headers/WTFPL.tmpl b/src/project/templates/headers/WTFPL.tmpl new file mode 100644 index 00000000..e69de29b diff --git a/src/project/templates/headers/csheader.tmpl b/src/project/templates/headers/csheader.tmpl new file mode 100644 index 00000000..1861f094 --- /dev/null +++ b/src/project/templates/headers/csheader.tmpl @@ -0,0 +1,15 @@ +<% + var text = include(licenseType + ".tmpl").split('\n').map(s => { + if (!s || s.trim() == "") { + return " *"; + } + else { + return " * " + s; + } + }).join('\n').replace(/[\* \n\r]*$/, ''); + + if (text && text !== " *") { + text = "/*\n" + text + "\n */\n\n"; + } +-%> +<%- text -%>