Skip to content

Commit

Permalink
refactor: split license headers into separate template files
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Mar 21, 2021
1 parent 286a9f5 commit 8371320
Show file tree
Hide file tree
Showing 17 changed files with 162 additions and 165 deletions.
16 changes: 16 additions & 0 deletions resources/templates/header/AGPL-3.0-or-later.twig
@@ -0,0 +1,16 @@
{{ packageName }} is free software: you can redistribute it
and/or modify it under the terms of the GNU Affero General Public
License as published by the Free Software Foundation, either version
3 of the License, or (at your option) any later version.

{{ packageName }} 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 Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public
License along with {{ packageName }}.
If not, see <https://www.gnu.org/licenses/>.

@copyright {{ copyright }}
@license https://opensource.org/licenses/AGPL-3.0 GNU Affero General Public License v3.0 or later
14 changes: 14 additions & 0 deletions resources/templates/header/Apache-2.0.twig
@@ -0,0 +1,14 @@
Licensed 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.

@copyright {{ copyright }}
@license https://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
13 changes: 13 additions & 0 deletions resources/templates/header/BSD-2-Clause.twig
@@ -0,0 +1,13 @@
{{ packageName }} is open source software: you can distribute
it and/or modify it under the terms of the BSD 2-Clause "Simplified"
License (the "License"). You may not use this file except in
compliance with the License.

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.

@copyright {{ copyright }}
@license https://opensource.org/licenses/BSD-2-Clause BSD 2-Clause "Simplified" License
13 changes: 13 additions & 0 deletions resources/templates/header/BSD-3-Clause.twig
@@ -0,0 +1,13 @@
{{ packageName }} is open source software: you can distribute
it and/or modify it under the terms of the BSD 3-Clause "New" or
"Revised" License (the "License"). You may not use this file except
in compliance with the License.

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.

@copyright {{ copyright }}
@license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause "New" or "Revised" License
16 changes: 16 additions & 0 deletions resources/templates/header/GPL-3.0-or-later.twig
@@ -0,0 +1,16 @@
{{ packageName }} 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.

{{ packageName }} 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 {{ packageName }}.
If not, see <https://www.gnu.org/licenses/>.

@copyright {{ copyright }}
@license https://opensource.org/licenses/GPL-3.0 GNU General Public License v3.0 or later
13 changes: 13 additions & 0 deletions resources/templates/header/Hippocratic-2.1.twig
@@ -0,0 +1,13 @@
{{ packageName }} is Ethical Open Source (EOS) software: you can
distribute it and/or modify it under the terms of the Hippocratic
License version 2.1 (the "License"). You may not use this file
except in compliance with the License.

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.

@copyright {{ copyright }}
@license https://spdx.org/licenses/Hippocratic-2.1.html Hippocratic License 2.1
16 changes: 16 additions & 0 deletions resources/templates/header/LGPL-3.0-or-later.twig
@@ -0,0 +1,16 @@
{{ packageName }} is free software: you can redistribute it
and/or modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either version
3 of the License, or (at your option) any later version.

{{ packageName }} 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with {{ packageName }}.
If not, see <https://www.gnu.org/licenses/>.

@copyright {{ copyright }}
@license https://opensource.org/licenses/LGPL-3.0 GNU Lesser General Public License v3.0 or later
13 changes: 13 additions & 0 deletions resources/templates/header/MIT-0.twig
@@ -0,0 +1,13 @@
{{ packageName }} is open source software: you can distribute
it and/or modify it under the terms of the MIT No Attribution
license (the "License"). You may not use this file except in
compliance with the License.

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.

@copyright {{ copyright }}
@license https://opensource.org/licenses/MIT-0 MIT No Attribution
13 changes: 13 additions & 0 deletions resources/templates/header/MIT.twig
@@ -0,0 +1,13 @@
{{ packageName }} is open source software: you can distribute
it and/or modify it under the terms of the MIT License
(the "License"). You may not use this file except in
compliance with the License.

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.

@copyright {{ copyright }}
@license https://opensource.org/licenses/MIT MIT License
6 changes: 6 additions & 0 deletions resources/templates/header/MPL-2.0.twig
@@ -0,0 +1,6 @@
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 https://mozilla.org/MPL/2.0/.

@copyright {{ copyright }}
@license https://opensource.org/licenses/MPL-2.0 Mozilla Public License 2.0
1 change: 1 addition & 0 deletions resources/templates/header/Proprietary.twig
@@ -0,0 +1 @@
@copyright {{ copyright }}. All rights reserved.
5 changes: 5 additions & 0 deletions resources/templates/header/Unlicense.twig
@@ -0,0 +1,5 @@
{{ packageName }} is free and unencumbered software released
into the public domain. For more information, please view the
UNLICENSE file that was distributed with this source code.

@license https://opensource.org/licenses/Unlicense The Unlicense
9 changes: 9 additions & 0 deletions resources/templates/header/source-file-header.twig
@@ -0,0 +1,9 @@
{% set headerTemplate %}header/{{ license }}.twig{% endset %}
{% set copyright %}Copyright (c) {{ copyrightHolder }}{% if copyrightEmail %} <{{ copyrightEmail }}>{% elseif copyrightUrl %} <{{ copyrightUrl }}>{% endif %}{% endset %}
{% set licenseStatement %}{{ include(headerTemplate) }}{% endset %}

/**
* This file is part of {{ packageName }}
*
{{ licenseStatement|preg_replace('/^/m', ' * ')|preg_replace('/\\s+$/m', '')|trim }}
*/
162 changes: 0 additions & 162 deletions resources/templates/source-file-header.twig

This file was deleted.

13 changes: 12 additions & 1 deletion src/LibraryStarterKit/Setup.php
Expand Up @@ -32,9 +32,11 @@
use Symfony\Component\Process\Process;
use Twig\Environment as TwigEnvironment;
use Twig\Loader\FilesystemLoader;
use Twig\TwigFilter;

use function array_map;
use function implode;
use function preg_replace;

use const DIRECTORY_SEPARATOR;

Expand Down Expand Up @@ -157,14 +159,23 @@ public function getBuild(SymfonyStyle $console, Answers $answers): Build
*/
public function getTwigEnvironment(): TwigEnvironment
{
return new TwigEnvironment(
$pregReplaceFilter = new TwigFilter(
'preg_replace',
fn (string $s, string $p, string $r): string => (string) preg_replace($p, $r, $s),
);

$twig = new TwigEnvironment(
new FilesystemLoader($this->getProject()->getPath() . '/resources/templates'),
[
'debug' => true,
'strict_variables' => true,
'autoescape' => false,
],
);

$twig->addFilter($pregReplaceFilter);

return $twig;
}

/**
Expand Down
Expand Up @@ -44,7 +44,7 @@ public function build(): void
$this->getConsole()->note('Updating source file headers');

$newFileHeader = $this->getEnvironment()->getTwigEnvironment()->render(
'source-file-header.twig',
'header/source-file-header.twig',
$this->getAnswers()->getArrayCopy(),
);

Expand Down
Expand Up @@ -26,7 +26,7 @@ public function testBuild(): void
$twig = $this->mockery(TwigEnvironment::class);
$twig
->expects()
->render('source-file-header.twig', $this->answers->getArrayCopy())
->render('header/source-file-header.twig', $this->answers->getArrayCopy())
->andReturn($this->getTwigGeneratedHeader());

$file1 = $this->mockery(SplFileInfo::class, [
Expand Down

0 comments on commit 8371320

Please sign in to comment.