取代深層嵌套層次結構中的版權標頭

取代深層嵌套層次結構中的版權標頭

我們的專案是開源的,我需要用我們的新許可證替換所有版權標頭。本專案由約 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

如果標頭如此不同,您無法確定即使使用正規表示式也能捕獲所有標頭,那麼您需要最強大的工具:正規表示式。只需簽出所有文件,對子資料夾中的所有文件進行基於正規表示式的替換即可。然後檢查哪些檔案尚未修改,查看其中的一些標頭,用調整後的正規表示式取代其中的標頭。重複直到完成。完成後,進行一次簽入。

這是唯一的辦法。

一個簡單的醜陋的一次性正規表示式適用於 3 個範例文件中的 2 個,如下所示:

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

您可以在這裡測試:https://regex101.com/

它與第二個文件不匹配,因為該文件格式錯誤,並且版權註釋沒有結束,反而意外地包含了導入語句。

有許多工具可以跨多個文件進行正規表示式替換,只需使用其中任何一個即可。

答案2

我曾經使用過http://code.mycila.com/license-maven-plugin/將許可證標頭新增至我的來源檔案。 (我不需要刪除現有許可證,但插件文件說它也可以刪除標頭。)

相關內容