Git Product home page Git Product logo

copyright-header's Introduction

Cloud Posse

copyright-header Build Status Latest Release Slack Community

Copyright Header is a utility to manipulate licenses on source code.

Features

  • Add/remove a copyright headers recursively on source files
  • Customize the syntax configuration for how to write out comments
  • Built-in support for GPL3 and MIT licenses
  • Supports custom licenes with --license-file argument
  • ERB template support

Caveats

  • Will only remove headers to files that have exactly the same header as the one we added
  • Will only add headers to files which do not contain the case-sensitive pattern /[Cc]opyright|[Lc]icense/ in the first N lines
  • Will not properly format arguments that contain new-line ("\n") characters.

Requirements

  • Ruby 1.9.2 (supported version, might work with older rubies but not guaranteed)

Installation

Install Copyright Header from RubyForge:

gem install copyright-header

This project is part of our comprehensive "SweetOps" approach towards DevOps.

It's 100% Open Source and licensed under the GNU General Public License.

Usage

Full list of supported arguments:

Usage: copyright-header options [file]
    -n, --dry-run                    Output the parsed files to STDOUT
    -o, --output-dir DIR             Use DIR as output directory
        --license-file FILE          Use FILE as header (instead of using --license argument)
        --license [AGPL3|ASL2|BSD-2-CLAUSE|BSD-3-CLAUSE|BSD-4-CLAUSE|GPL3|MIT]
                                     Use LICENSE as header
        --copyright-software NAME    The common name for this piece of software (e.g. "Copyright Header")
        --copyright-software-description DESC
                                     The detailed description for this piece of software (e.g. "A utility to manipulate copyright headers on source code files")
        --copyright-holder NAME      The legal owner of the copyright for the software. (e.g. "Erik Osterman <[email protected]>"). Repeat argument for multiple names.
        --copyright-year YEAR        The years for which the copyright exists (e.g. "2012-2017"). Repeat argument for multiple years.
    -w, --word-wrap LEN              Maximum number of characters per line for license (default: 80)
    -a, --add-path PATH              Recursively insert header in all files found in path (allows multiple paths separated by platform path-separator ":")
    -r, --remove-path PATH           Recursively remove header in all files found in path (allows multiple paths separated by platform path-separator ":")
    -g, --guess-extension            Use the GitHub Linguist gem to guess the extension of the source code when no extension can be determined (experimental).
    -c, --syntax FILE                Syntax configuration file
    -V, --version                    Display version information
    -h, --help                       Display this screen

Examples

Discover available parameters by passing the --help argument

copyright-header --help

Add a GPL3 License header to a file:

copyright-header --add-path /tmp/test.rb \
                 --license GPL3 \
                 --copyright-holder 'Joe Shmoe' \
                 --copyright-software 'Example Software' \
                 --copyright-software-description "This is the description of the software." \
                 --copyright-year 2012-2017 \
                 --output-dir /tmp \
                 --dry-run

Remove the header created in the previous step (without --dry-run argument):

copyright-header --remove-path /tmp/test.rb \
                 --license GPL3 \
                 --copyright-holder 'Joe Shmoe' \
                 --copyright-software 'Example Software' \
                 --copyright-software-description 'This is the description of the software.' \
                 --copyright-year 2012-2017 \
                 --output-dir /tmp \
                 --dry-run

Command used to generate copyright headers for this script:

copyright-header  --license GPL3  \
                  --add-path lib/:bin/ \
                  --guess-extension \
                  --copyright-holder 'Erik Osterman <[email protected]>' \
                  --copyright-software 'Copyright Header' \
                  --copyright-software-description "A utility to manipulate copyright headers on source code files" \
                  --copyright-year 2012-2017 \
                  --word-wrap 100 \
                  --output-dir ./

Paths can be either files or directories. It will recursively traverse the directory tree ignoring all dot files.

You can specify an alternative syntax configuration file using the --syntax argument.

Rake

The above example can be performed as rake task inside a Rakefile:

task :headers do
  require 'rubygems'
  require 'copyright_header'

  args = {
    :license => 'GPL3',
    :copyright_software => 'Copyright Header',
    :copyright_software_description => "A utility to manipulate copyright headers on source code files",
    :copyright_holders => ['Erik Osterman <[email protected]>'],
    :copyright_years => ['2012-2017'],
    :add_path => 'lib',
    :output_dir => '.'
  }

  command_line = CopyrightHeader::CommandLine.new( args )
  command_line.execute
end

Docker

docker run --rm --volume `pwd`:/usr/src/ osterman/copyright-header:latest \
  --license GPL3 \
  --add-path . \
  --guess-extension \
  --copyright-holder 'Erik Osteman <[email protected]>' \
  --copyright-software 'Copyright Header' \
  --copyright-software-description 'A utility to manipulate copyright headers on source code files' \
  --copyright-year 2012-2017 \
  --word-wrap 100 \
  --output-dir /usr/src/

Make

Here is how we typically use it in our Makefile.

Check out the Cloud Posse build-harness for other neat tricks.

Help

Got a question?

File a GitHub issue, send us an email or join our Slack Community.

Commerical Support

Work directly with our team of DevOps experts via email, slack, and video conferencing.

We provide commercial support for all of our Open Source projects. As a Dedicated Support customer, you have access to our team of subject matter experts at a fraction of the cost of a fulltime engineer.

E-Mail

  • Questions. We'll use a Shared Slack channel between your team and ours.
  • Troubleshooting. We'll help you triage why things aren't working.
  • Code Reviews. We'll review your Pull Requests and provide constructive feedback.
  • Bug Fixes. We'll rapidly work to fix any bugs in our projects.
  • Build New Terraform Modules. We'll develop original modules to provision infrastructure.
  • Cloud Architecture. We'll assist with your cloud strategy and design.
  • Implementation. We'll provide hands on support to implement our reference architectures.

Community Forum

Get access to our Open Source Community Forum on Slack. It's FREE to join for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build sweet infrastructure.

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Developing

If you are interested in being a contributor and want to get involved in developing this project or help out with our other projects, we would love to hear from you! Shoot us an email.

In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull Request so that we can review your changes

NOTE: Be sure to merge the latest changes from "upstream" before making a pull request!

Copyright

Copyright © 2017-2018 Cloud Posse, LLC

License

License: GPL v3

GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

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/.

Trademarks

All other trademarks referenced herein are the property of their respective owners.

About

This project is maintained and funded by Cloud Posse, LLC. Like it? Please let us know at [email protected]

Cloud Posse

We're a DevOps Professional Services company based in Los Angeles, CA. We love Open Source Software!

We offer paid support on all of our projects.

Check out our other projects, apply for a job, or hire us to help with your cloud strategy and implementation.

Contributors

Erik Osterman
Erik Osterman
Leo O'Donnell
Leo O'Donnell
Christian Meier
Christian Meier
Gabriel de Perthuis
Gabriel de Perthuis
Thomas Russell Murphy
Thomas Russell Murphy
Kongqun Yang
Kongqun Yang
Vincent Billey
Vincent Billey
arximboldi
arximboldi
David
David
Rafał Rzepecki
Rafał Rzepecki
David Yip
David Yip
Daniel Freedman
Daniel Freedman
Mitch Souders
Mitch Souders
Mads Bondo Dydensborg
Mads Bondo Dydensborg
Psy-Q
Psy-Q
Bryan
Bryan
Colin Dean
Colin Dean
Wahaj Shamim
Wahaj Shamim
halo
halo
Lloyd Dewolf
Lloyd Dewolf

copyright-header's People

Contributors

arximboldi avatar bstopp avatar colindean avatar crzysdrs avatar dfreedm avatar dividedmind avatar dwlf avatar dylanbannon avatar fenntasy avatar g2p avatar halo avatar hannahwhy avatar kqyang avatar leopoldodonnell avatar mbd-dbc-dk avatar mkristian avatar osterman avatar psy-q avatar ryanfaircloth avatar sagebati avatar tagc avatar thomasrussellmurphy avatar vadim-hleif avatar wshamim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

copyright-header's Issues

Extend option for removing headers

Would be nice if tool could clean up any header (so the new one can be added then). Cleaning up could be defined as: remove all lines from the top (or after <?php in case of PHP, etc) of the file until first non-comment line.

Adding lincense into .php files creates redundant opening and closing tags

Output:

<?php
/*
 * Example Software - This is the description of the software.
 * Copyright (C) 2012 Joe Shmoe
 *
 * <... copyright ...>
 */ ?>
<?php

echo 123;

Expected output:

<?php
/*
 * Example Software - This is the description of the software.
 * Copyright (C) 2012 Joe Shmoe
 *
 * <... copyright ...>
 */ 

echo 123;

Script strips newline at end of file

After I ran the script to add headers to my source, I noticed that all of the files had their newline stripped from the end of the file. This causes many problems related to source control, parsing, and compiling.

Unable to install on MacOS

I seem to have a very specific problem related to installing copyright-header. Do these log messages make any sense to the community here ?

`Building native extensions. This could take a while...
ERROR: Error installing copyright-header:
ERROR: Failed to build gem native extension.

current directory: /Library/Ruby/Gems/2.6.0/gems/charlock_holmes-0.7.7/ext/charlock_holmes

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20200127-56162-bdzg0i.rb extconf.rb
checking for -licui18n... yes
checking for unicode/ucnv.h... yes
checking for -lz... yes
checking for -licuuc... yes
checking for -licudata... yes
creating Makefile

current directory: /Library/Ruby/Gems/2.6.0/gems/charlock_holmes-0.7.7/ext/charlock_holmes
make "DESTDIR=" clean

current directory: /Library/Ruby/Gems/2.6.0/gems/charlock_holmes-0.7.7/ext/charlock_holmes
make "DESTDIR="
compiling converter.c
compiling encoding_detector.c
compiling ext.c
compiling transliterator.cpp
In file included from transliterator.cpp:1:
In file included from ./common.h:9:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby.h:33:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19/ruby/config.h:413:31: error: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wreserved-user-defined-literal]
#define RUBY_ARCH "universal-"RUBY_PLATFORM_OS
^

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19/ruby/config.h:414:35: error: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wreserved-user-defined-literal]
#define RUBY_PLATFORM "universal."RUBY_PLATFORM_CPU"-"RUBY_PLATFORM_OS
^

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19/ruby/config.h:414:55: error: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wreserved-user-defined-literal]
#define RUBY_PLATFORM "universal."RUBY_PLATFORM_CPU"-"RUBY_PLATFORM_OS
^

In file included from transliterator.cpp:1:
In file included from ./common.h:9:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby.h:33:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:2111:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/intern.h:56:19: warning: 'register' storage class specifier is deprecated and incompatible with C++17 [-Wdeprecated-register]
void rb_mem_clear(register VALUE*, register long);
^~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/intern.h:56:36: warning: 'register' storage class specifier is deprecated and incompatible with C++17 [-Wdeprecated-register]
void rb_mem_clear(register VALUE*, register long);
^~~~~~~~~
2 warnings and 3 errors generated.
make: *** [transliterator.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/charlock_holmes-0.7.7 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/charlock_holmes-0.7.7/gem_make.out
`

Installation fails

Hi,
when I run gem install copyright-header, I get this error

gem install copyright-header
Building native extensions.  This could take a while...
ERROR:  Error installing copyright-header:
    ERROR: Failed to build gem native extension.

    /Users/jan/.rvm/rubies/ruby-2.1.5/bin/ruby -r ./siteconf20150504-59663-1x75e2k.rb extconf.rb
checking for main() in -licui18n... no
checking for main() in -licui18n... no


***************************************************************************************
*********** icu required (brew install icu4c or apt-get install libicu-dev) ***********
***************************************************************************************
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/jan/.rvm/rubies/ruby-2.1.5/bin/ruby
    --with-icu-dir
    --without-icu-dir
    --with-icu-include
    --without-icu-include=${icu-dir}/include
    --with-icu-lib
    --without-icu-lib=${icu-dir}/lib
    --with-icui18nlib
    --without-icui18nlib
    --with-icui18nlib
    --without-icui18nlib

extconf failed, exit code 1

Gem files will remain installed in /Users/jan/.rvm/gems/ruby-2.1.5/gems/charlock_holmes-0.7.3 for inspection.
Results logged to /Users/jan/.rvm/gems/ruby-2.1.5/extensions/x86_64-darwin-14/2.1.0-static/charlock_holmes-0.7.3/gem_make.out

Feature request: exclude by pattern

I am using C#, but there are many C# files that shouldn't have a license file, as it would mess with the IDE. I would like to exclude *.designer.cs and *AssemblyInfo.cs while including all other *.cs files. Is there a way to do this in the syntax file?

Add multiple paths.

Is it possible to add multiple paths with through :add_path in case you want both ~/lib and ~/bin processed?

Unable to add copyright to file with UTF-8 characters

I've got a couple of Rust source files (added syntax in #41) with the non-ASCII character for ellipses:. copyright-header doesn't seem to like that:

SKIP src/logging.rs; invalid byte sequence in US-ASCII
SKIP src/update.rs; detected existing license
SKIP src/main.rs; invalid byte sequence in US-ASCII

It's not a huge deal for us because it's only two files but I'm sure others might hit this at some point. I can't quite tell from the error where in the process the file is being opened as US-ASCII.

Examples don't work

The example copyright-header --add-path /tmp/test.rb --license GPL3 --dry-run from the documentation results in a Missing --copyright-software argument error.

Duplicates license in files containing # -*- coding: utf-8 -*-

Subject says it all.

#!/usr/bin/env python

# Copyright (c) blah

# -*- coding: utf-8 -*-

# Copyright (c) blah

Used:
copyright-header --guess-extension --license-file LICENSE.txt --add-path . --output-dir .

Test case:

%> cat test.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

%> copyright-header --guess-extension --license-file LICENSE.txt --add-path . --output-dir .
SKIP ./LICENSE.txt; excluded
UPDATE ./test.py [output-dir ./.]

%> ls -lrt
total 8
-rw-r--r--+ 1 bedge admin 198 Nov  6 13:09 LICENSE.txt
-rw-r--r--+ 1 bedge admin 463 Nov  6 13:10 test.py

%> cat test.py
#!/usr/bin/env python

# Copyright (c) blah

# -*- coding: UTF-8 -*-

# Copyright (c) blah

include Apache 2 license

I have converted the license boiler plate for the Apache 2 license found here: http://opensource.org/licenses/Apache-2.0 to an .erb file. You may want to add this to the distribution.

<%=copyright_software%> - <%=copyright_software_description%>

Copyright <%=copyright_years.join(', ')%> <%=copyright_holders.join(', ')%>

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.

Don't ignore explicitly added dot files

Expected:

% copyright-header --license-file LICENSE --add-path .gitlab-ci.yml -o .
UPDATE .gitlab-ci.yml [output-dir ./.]

Instead:

% copyright-header --license-file LICENSE --add-path .gitlab-ci.yml -o .
SKIP .gitlab-ci.yml; excluded

Failed to build native extensions on OSX with `icu` installed via MacPorts

I have installed icu using MacPorts (sudo port install icu), but remain unable to install copyright-header due to failing build of native extensions.

$ gem install copyright-header
Building native extensions.  This could take a while...
ERROR:  Error installing copyright-header:
    ERROR: Failed to build gem native extension.

    /Users/thomasrussellmurphy/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20160730-39908-rh3jr6.rb extconf.rb
checking for main() in -licui18n... no
checking for main() in -licui18n... no


***************************************************************************************
*********** icu required (brew install icu4c or apt-get install libicu-dev) ***********
***************************************************************************************
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/thomasrussellmurphy/.rvm/rubies/ruby-2.2.1/bin/$(RUBY_BASE_NAME)
    --with-icu-dir
    --without-icu-dir
    --with-icu-include
    --without-icu-include=${icu-dir}/include
    --with-icu-lib
    --without-icu-lib=${icu-dir}/lib
    --with-icui18nlib
    --without-icui18nlib
    --with-icui18nlib
    --without-icui18nlib

extconf failed, exit code 1

I'm currently using gem 2.4.6 and ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14].

Where in my environment or this gem are things going wrong?

Copyright Header not applied to files with the word copyright in the first ten lines of the file

Hello,
I created a rake task for running the copyright header add in my project, and I was surprised to find that it was ignoring the file that contained my rake task. After some digging, I found this in the copyright-header code:

def has_copyright?(lines = 10)
   @contents.split(/\n/)[0..lines].select { |line| line =~ /(?!class\s+)([Cc]opyright|[Ll]icense)\s/ }.length > 0
end

So, this method return true on the presence of the word 'copyright' or 'license' in the first 10 lines of code, which is kind of weak for verifying that the license code is present.

Also, if the wrong license is present, but contains the words copyright or license, it will still return true.

I think my team is willing to do the work to make this more robust, but I also think some discussion is needed as to what the proper solution should be.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.