深くネストされた階層内の著作権ヘッダーを置き換える

深くネストされた階層内の著作権ヘッダーを置き換える

私たちのプロジェクトはオープンソースであり、すべての著作権ヘッダーを新しいライセンスに置き換える必要があります。プロジェクトは、ネストされたフォルダー階層にわたる約 1500 個の C++/Obj-C/Java ファイルで構成されています。

ヘッダーは 1 行から 5 行に及び、フォーマットも異なるため、正規表現ですべての行が見つかるとは限りません。

ここでどのようなアプローチを取るでしょうか?

例:

C++ ファイル:

/*******************************************************************************
 * 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 ファイル:

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 ファイル:

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

すべてのファイルに適用される新しいライセンス:

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

答え1

ヘッダーが大きく異なっていて、正規表現を使用してもすべて検出できるかどうかわからない場合は、最も強力なツールである正規表現が必要です。すべてのファイルをチェックアウトし、サブフォルダー内のすべてのファイルに対して正規表現ベースの置換を実行します。次に、変更されていないファイルを確認し、ヘッダーの一部を確認して、これらのヘッダーを調整された正規表現に置き換えます。完了するまで繰り返します。完了したら、1 回チェックインします。

これが唯一の方法です。

3 つのサンプル ファイルのうち 2 つで機能する、単純で見苦しい使い捨ての正規表現は次のとおりです。

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

ここでテストできます:出典:https://regex101.com/

2 番目のファイルはフォーマットが不適切で、著作権のコメントが終了せず、代わりに誤ってインポート ステートメントも含まれているため、一致しません。

複数のファイルにわたって正規表現の置換を実行するツールは多数あります。そのうちの 1 つを使用してください。

答え2

私はかつてhttp://code.mycila.com/license-maven-plugin/ソース ファイルにライセンス ヘッダーを追加します。(既存のライセンスを削除する必要はありませんでしたが、プラグインのドキュメントにはヘッダーも削除できると記載されています。)

関連情報