1

Our project is open source and I need to substitute all our copyright headers for our new license's. The project consists of about 1500 C++/Obj-C/Java files across a nested folder hierarchy.

A header spans from 1 to 5 lines with different formatting, so a regex is not assured to find it in all of them.

What approach would you take here?

Example:

C++ file:

/*******************************************************************************
 * Copyright 1996: Börk Börk Inc. All Rights
 * Reserved. Proprietary and Confidential information of BOBO. Disclosure,
 * Use, or Reproduction without written authorization of BOBO is prohibited.
 *******************************************************************************/
#ifndef Things_cpp
#define Things_cpp

#include <LibOne.hpp>
#include <LibTwo.hpp>


Namespacington::ClassName::HereBeMethod(void)
{
}
#endif

Java file:

package com.bork.bork.boooork;

/*******************************************************
 * Copyright 1996: Börk Börk Inc. All Rights Reserved.
 * Proprietary and Confidential information of BOBO. 
 * Disclosure, Use, or Reproduction without written 
 * authorization of BOBO is prohibited.
 *******************************************************

import java.util.List;

/**
 * <p>
 * Callback interface/protocol for a proxy factory.
 * </p>
 */

@SuppressWarnings("all")
public interface ProxyFactorize
{
    /**
     * <p>
     * Do the thing
     * </p>
     * @param bork Spices
     * @param borkbork Condiments
     */

    void apply(double bork, double borkbork);

}

Obj-C file:

/*******************************************************
 * Copyright 1996: Börk Börk Inc.
 * All Rights Reserved.
 * Proprietary and Confidential information of BOBO. 
 * Disclosure, Use, or Reproduction without written 
 * authorization of BOBO is prohibited.
 ********************************************************/

#import <Bork/Booork.h>
@class Biorjk;

/**
 * Bork bork bork booooork
 *
 * @warning Bork?
 *
 * @warning Bork
 *
 */
@interface Biorjk : Borkburk

@end

New license to be applied to all files:

/* Copyright 2015 Bork Bork
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. */
5
  • FYI this question has 3 close votes as being too broad. Please provide some more details or examples of what you have or what you want. Aug 14, 2015 at 14:58
  • A little bit more detail will help with giving you the right steps & tools to use.
    – Alex S
    Aug 14, 2015 at 20:08
  • [EditPlus][1] has an interesting Multi-Line Search and Replace. It also supports Regular Expressions. Maybe this can help. stackoverflow.com/questions/268045/…
    – Alex S
    Aug 14, 2015 at 20:11
  • See the tool copyright-header (uses ruby).
    – harrymc
    Aug 18, 2015 at 6:42
  • @harrymc Thank you! It only does the easy part of the job tho :P Aug 18, 2015 at 10:42

2 Answers 2

1
+50

If the headers are so different you can't be sure that even with a regex you'll catch them all, then you need the strongest tool there is: Regex. Just checkout all files, do a regular expression based replace all across all files in subfolders. Then check which files have not been modified, have a look at some of their headers, replace the headers in these with an adjusted regex. Repeat until you're done. Once done, make a single check in.

This is the only way.

A simple ugly throwaway regex that works with 2 out of the 3 example files is as follows:

[^\{\}\(\)\/]{0,200}(\/\*[*\s]*[Cc]opyright[^\n\r]*Börk Börk[a-zA-Z0-9\s\*,.]*\*\/)

You can test it here: https://regex101.com/

It won't match the second file because that file is badly formatted and the comment of the copyright doesn't end and instead accidentally includes the import statement as well.

There are plenty of tools that do a regex replace across multiple files, just use any one of them.

3
  • 1
    Worked like a charm, for reference I went through each file type using in the project's root git ls-files | egrep '.*\.EXTENSION$' | xargs sublime and modify all on sublime; then using git ls-files | egrep '.*\.EXTENSION$' | wc -l to count the entries and compare against the changes. Aug 19, 2015 at 14:22
  • 1
    To count the changes on command-line, git whatchanged -1 --format=oneline | wc -l Aug 19, 2015 at 14:28
  • That's to get just against the latest commit. Before that, you can use git diff --name-only | wc -l Aug 19, 2015 at 22:20
0

I once used the http://code.mycila.com/license-maven-plugin/ to add a license header to my source files. (I didn't need to remove an existing license, but the plugin documentation says that it can also remove headers.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .