Background
Source code contributions to Apache CloudStack must meet RAT requirements, which stipulate that source files include the Apache license header.
Problem
The Apache license header must be applied to each source and configuration file to be checked into the Apache CloudStack repo. Applying this header to each file is very time consuming.
Solution
Create a bash script using ed.
Let's elaborate on what each step involves...
Using ed
The follow bash script uses ed to apply the license header to the start of every file in every folder off of the current folder.#!/bin/bash FILES=$( find ./rdpclient-0.21 -type f) for f in $FILES do echo "processing $f file" ed -s $f << EOF 0a // Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you 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. . w EOF done
Non-Java files
The commenting style used in the script is suitable for Java and C#.For bash files, XML and Windows .bat files, a different comment style is requried.
Final Remarks
The script seems to miss files that start with a dot ('.'). To help make sure you've added the license header to all relevant files, use the mvn build's ability to check for RAT compliance. E.g.
mvn --projects='org.apache.cloudstack:cloudstack' org.apache.rat:apache-rat-plugin:0.10:check
1 comment :
The bash script worked like a charm. Thank you.
Post a Comment