Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Apache license headers with SPDX ID #5808

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/hotrod/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2019 The Jaeger Authors.
// Copyright (c) 2017 Uber Technologies, Inc.
// SPDX-License-Identifier: Apache-2.0

package main

Expand Down
2 changes: 1 addition & 1 deletion internal/safeexpvar/safeexpvar_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2024 The Jaeger Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// SPDX-License-Identifier: Apache-2.0

package safeexpvar

Expand Down
57 changes: 57 additions & 0 deletions scripts/replace_license_headers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
# Copyright (c) 2024 The Jaeger Authors.
# SPDX-License-Identifier: Apache-2.0

# Replace Apache 2.0 license headers with SPDX license identifiers.

import re
import sys

def replace_license_header(file_path, dry_run=False):
with open(file_path, 'r') as file:
content = file.read()

# Pattern to match the entire old header, including multiple copyright lines
header_pattern = re.compile(r'(?s)^(// Copyright.*?(?:\n// Copyright.*?)*\n//\n// Licensed under the Apache License.*?limitations under the License\.)\s*\n')
Dismissed Show dismissed Hide dismissed

match = header_pattern.match(content)
if match:
old_header = match.group(1)
if "SPDX-License-Identifier: Apache-2.0" in old_header:
print(f"Skipping {file_path}: SPDX identifier already present")
return False

if dry_run:
print(f"Would update {file_path}")
return True

# Preserve all copyright lines and add SPDX identifier
copyright_lines = re.findall(r'// Copyright.*', old_header)
new_header = "\n".join(copyright_lines) + "\n// SPDX-License-Identifier: Apache-2.0\n\n"

new_content = header_pattern.sub(new_header, content, count=1)

with open(file_path, 'w') as file:
file.write(new_content)
print(f"Updated {file_path}")
return True
else:
print(f"Warning: {file_path} - Could not find expected license header")
return False

def main():
dry_run = '--dry-run' in sys.argv
files = [f for f in sys.argv[1:] if f != '--dry-run']

if not files:
print("Usage: python replace_license_headers.py [--dry-run] <file> [<file> ...]")
sys.exit(1)

if dry_run:
print("Performing dry run - no files will be modified")

total_updated = sum(replace_license_header(file, dry_run) for file in files)
print(f"Total files {'that would be' if dry_run else ''} updated: {total_updated}")

if __name__ == "__main__":
main()
Loading