|
| 1 | +#!/usr/bin/env groovy |
| 2 | +/* |
| 3 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 4 | + * or more contributor license agreements. See the NOTICE file |
| 5 | + * distributed with this work for additional information |
| 6 | + * regarding copyright ownership. The ASF licenses this file |
| 7 | + * to you under the Apache License, Version 2.0 (the |
| 8 | + * "License"); you may not use this file except in compliance |
| 9 | + * with the License. You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, |
| 14 | + * software distributed under the License is distributed on an |
| 15 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | + * KIND, either express or implied. See the License for the |
| 17 | + * specific language governing permissions and limitations |
| 18 | + * under the License. |
| 19 | + */ |
| 20 | +import java.nio.file.* |
| 21 | + |
| 22 | +def ASF_MARKER = "Licensed to the Apache Software Foundation (ASF) under one" |
| 23 | +def HEADER = '''# |
| 24 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 25 | +# or more contributor license agreements. See the NOTICE file |
| 26 | +# distributed with this work for additional information |
| 27 | +# regarding copyright ownership. The ASF licenses this file |
| 28 | +# to you under the Apache License, Version 2.0 (the |
| 29 | +# "License"); you may not use this file except in compliance |
| 30 | +# with the License. You may obtain a copy of the License at |
| 31 | +# |
| 32 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 33 | +# |
| 34 | +# Unless required by applicable law or agreed to in writing, |
| 35 | +# software distributed under the License is distributed on an |
| 36 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 37 | +# KIND, either express or implied. See the License for the |
| 38 | +# specific language governing permissions and limitations |
| 39 | +# under the License. |
| 40 | +# |
| 41 | +''' |
| 42 | + |
| 43 | +String targetPath = args && args[0] ? args[0] : '.' |
| 44 | +def root = Paths.get(targetPath).toRealPath() |
| 45 | + |
| 46 | +Files.walk(root) |
| 47 | + .filter { path -> Files.isRegularFile(path) && path.toString().endsWith(".sh") } |
| 48 | + .each { path -> |
| 49 | + def text = path.toFile().getText("UTF-8") |
| 50 | + if (!text.contains(ASF_MARKER)) { |
| 51 | + println "📄 Adding ASF header to ${path}" |
| 52 | + // Prepend header + existing content |
| 53 | + path.toFile().withWriter("UTF-8") { writer -> |
| 54 | + writer << HEADER |
| 55 | + writer << text |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | +println "✅ Done." |
0 commit comments