Skip to content

andrewd207/pasbuild-copyright

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pasbuild-copyright

How it works

Once installed, the plugin is invoked through pasbuild:

pasbuild copyright-check
pasbuild copyright-fix

pasbuild discovers the plugin automatically from its plugin directory and dispatches to the appropriate mode.

  • copyright-check — scans all git-tracked .pas files and exits with a non-zero status if any file is missing a copyright header or has one with an out-of-date year.

  • copyright-fix — same scan, but automatically inserts missing headers or updates stale years in-place. Requires a clean git working tree (no staged or unstaged changes).

The tool looks for a copyright line within the first 20 lines of each file. A line is recognised as a copyright if it contains the word copyright, (c), or © (case-insensitive).

Installation

Build the project with pasbuild, then run the resulting binary with --install-plugin:

./target/pasbuild-copyright --install-plugin

This copies the binary into the pasbuild plugins directory as both pasbuild-copyright-check and pasbuild-copyright-fix:

~/.pasbuild/plugins/pasbuild-copyright-check
~/.pasbuild/plugins/pasbuild-copyright-fix

After that, pasbuild copyright-check and pasbuild copyright-fix will work from any project directory.

Environment variables

PASBUILD_COPYRIGHT_FILE

Path to the copyright template file to use when inserting a new header. If not set, the plugin falls back to resources/copyright_stub.txt in the current directory. The file must contain the word copyright (case-insensitive) or it will be rejected.

PASBUILD_COPYRIGHT_AUTHOR

The author name substituted for $who in the template file. Required when the template contains $who.

PASBUILD_COPYRIGHT_BLACKLIST

Path to the blacklist file. If not set, the plugin falls back to resources/copyright_blacklist.txt in the current directory. If the file does not exist no files are excluded.

Template file

The template file is a plain text file containing the full copyright block to prepend to a Pascal file, including comment delimiters. Two variables are substituted at runtime:

$year

Replaced with the current four-digit year.

$who

Replaced with the value of PASBUILD_COPYRIGHT_AUTHOR.

The file resources/copyright_stub.txt in this repository is an example:

{
  pasbuild-copyright - A plugin for pasbuild to help administer copyright
  Copyright (c) $year $who

  SPDX-License-Identifier: BSD-3-Clause

  Licensed under the BSD 3-Clause License. See LICENSE file for details.
 }

Copy and adapt it for your own project, then point PASBUILD_COPYRIGHT_FILE at it.

Auto-generated template

If no template is configured and no resources/copyright_stub.txt exists, copyright-fix will attempt to build one automatically from the information it can discover:

  • The project name is read from pasbuild resolve (requires pasbuild to be on the PATH).

  • The SPDX license identifier is taken from the detected root license file.

  • The author is taken from PASBUILD_COPYRIGHT_AUTHOR or extracted from the root license file.

The generated header follows the same format as the example above. Any field that cannot be determined is omitted. If the author cannot be resolved and $who would appear in the result, copyright-fix exits with an error.

Blacklist file

The blacklist file lists regular expression patterns (one per line) matched against the file path. Any file whose path matches a pattern is skipped entirely — no check or fix is applied.

Path separators are normalised to / before matching, so patterns only need to use / regardless of whether the OS uses / or \.

Lines starting with // or # are treated as comments and ignored, as are blank lines. Invalid regex patterns are skipped.

The default location is resources/copyright_blacklist.txt in the current directory. Set PASBUILD_COPYRIGHT_BLACKLIST to use a different path. If the file does not exist, no files are excluded.

Example blacklist:

// ignore all files under a vendor directory (works on both / and \ systems)
vendor/

# ignore generated files in a specific directory
src/generated/.*\.pas$

# ignore a single file by exact path
src/main/pascal/GeneratedCode\.pas$

Standalone usage

When run directly (outside of pasbuild) the binary accepts explicit command-line arguments:

--install-plugin

Copies the binary into the pasbuild plugins directory as both pasbuild-copyright-check and pasbuild-copyright-fix.

--change-license <stub-file>

Replaces the copyright header in every git-tracked .pas file with a fresh one rendered from <stub-file>. Must be run from the project root (the directory that contains project.xml). Requires a completely clean git working tree — no staged or unstaged changes. The same $year and $who variables are supported as in the template file.

./target/pasbuild-copyright --change-license resources/new_copyright_stub.txt

For files whose header is a block comment ({…​} or (…​)), the entire block is removed and replaced. For line-comment headers (//), only the copyright line itself is replaced.

Author auto-detection

When $who is used in a template and PASBUILD_COPYRIGHT_AUTHOR is not set, the plugin looks for a copyright line in the root license file (e.g. LICENSE) and extracts the author name from it:

Copyright (c) 2026 Andrew Haines   →   author = "Andrew Haines"
Copyright (c) 2022-2026, Corp Ltd  →   author = "Corp Ltd"

License detection

The plugin scans for a license file in each file’s directory and in the project root. Recognised file names: LICENSE, LICENSE.txt, LICENSE.md, LICENSE.rst, LICENCE, LICENCE.txt, LICENCE.md, COPYING, COPYING.txt, COPYING.lesser, COPYRIGHT.

The detected license type is shown in brackets after each filename, e.g. [BSD-3]. Recognised license types and their display names:

License Display

MIT License

MIT

ISC License

ISC

BSD 2-Clause

BSD-2

BSD 3-Clause

BSD-3

Apache 2.0

Apache-2

Mozilla Public License 2.0

MPL-2

GNU LGPL v2/v2.1

LGPL-2

GNU LGPL v3

LGPL-3

GNU GPL v2

GPL-2

GNU GPL v3

GPL-3

GNU AGPL v3

AGPL-3

Proprietary (inferred)

Proprietary

Unrecognised

(not shown)

A warning is emitted when a subdirectory contains its own license file whose type differs from the root license, and when no license file is found in the project root at all.

Year handling

The plugin scans the copyright line from right to left and replaces the rightmost four-digit number (≥ 1900) with the current year. Scanning right-to-left means year ranges work correctly:

Copyright (c) 2022-2025 My Name  →  Copyright (c) 2022-2026 My Name  ✔

A single year also works as before:

Copyright (c) 2025 My Name  →  Copyright (c) 2026 My Name  ✔

License

BSD 3-Clause. See LICENSE for details.

About

A plugin for pasbuild to check and maintain copyright files in your project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages