community-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject svn commit: r1733856 - /comdev/tools/licensing/copy2license.pl
Date Mon, 07 Mar 2016 01:32:34 GMT
Author: rvs
Date: Mon Mar  7 01:32:34 2016
New Revision: 1733856

URL: http://svn.apache.org/viewvc?rev=1733856&view=rev
Log:
tool for converting copyright header to new license header

Added:
    comdev/tools/licensing/copy2license.pl   (with props)

Added: comdev/tools/licensing/copy2license.pl
URL: http://svn.apache.org/viewvc/comdev/tools/licensing/copy2license.pl?rev=1733856&view=auto
==============================================================================
--- comdev/tools/licensing/copy2license.pl (added)
+++ comdev/tools/licensing/copy2license.pl Mon Mar  7 01:32:34 2016
@@ -0,0 +1,148 @@
+#!/usr/bin/perl
+#
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  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.
+#
+#===================================================================
+# Change the old license header to remove the copyright ASF line
+# and replace it with the new "Licensed under the ..." text.
+# Note that this should not be applied to the collective copyright 
+# in, for example, a README file that describes the work as a whole.
+#===================================================================
+#
+# Usage: copy2license.pl -j *.java
+#    or
+#        find . -name \*.java -print0 | xargs -0 copy2license.pl -j
+#
+#===================================================================
+
+$pre   = ' *';
+$years = '1999-2005';
+
+# ensure proper usage
+if (scalar @ARGV < 1) {
+  ShowUsage();
+  exit;
+}
+
+if ($ARGV[0] eq '-y') {
+    shift;
+    $years = shift;
+}
+
+if ($ARGV[0] eq '-c') {
+    shift;
+    $pre = ' *';
+    $oldtext = <<"EOTOLD";
+ Copyright $years The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+EOTOLD
+}
+elsif ($ARGV[0] eq '-j') {
+    shift;
+    $pre = ' *';
+    $oldtext = <<"EOTOLD";
+ Copyright $years The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+EOTOLD
+}
+elsif ($ARGV[0] eq '-x') {
+    shift;
+    $pre = '  ';
+    $oldtext = <<"EOTOLD";
+ Copyright $years The Apache Software Foundation or its licensors,
+                       as applicable.
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+EOTOLD
+}
+elsif ($ARGV[0] eq '-p') {
+    shift;
+    $pre = '# ';
+    $oldtext = <<"EOTOLD";
+ Copyright $years The Apache Software Foundation or its licensors,
+#                      as applicable
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+EOTOLD
+}
+elsif ($ARGV[0] eq '-w') {
+    shift;
+    $pre = ' *';
+    $oldtext = <<"EOTOLD";
+ Copyright $years The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+EOTOLD
+}
+else {
+  ShowUsage();
+  exit;
+}
+
+
+$newtext = <<"EOTEXT";
+ Licensed to the Apache Software Foundation (ASF) under one or more
+$pre contributor license agreements.  The ASF licenses this file to You
+$pre under the Apache License, Version 2.0 (the "License"); you may not
+$pre use this file except in compliance with the License.
+EOTEXT
+
+undef $/; # slurp the whole file
+
+# process each filename that was supplied
+while ($filename = shift) {
+  open(INFILE, $filename)  || die ("Cannot read from $filename, $!\n");
+  $wholething = <INFILE>;
+  close INFILE;
+
+  if ($wholething =~ s#\Q$oldtext\E#$newtext#osm) {
+      open(OUTFILE, ">$filename") || die ("Cannot write to $filename, $!\n");
+      print OUTFILE $wholething;
+      close OUTFILE;
+  }
+}
+
+$/ = "\n"; # reset the input record separator
+
+#==================================================
+# ShowUsage
+#==================================================
+                                                                                
+sub ShowUsage {
+  print qq!
+Usage:  $0 [ -y ] ( -c | -j | -x | -p | -w ) file [ file ... ]
+                                                                                
+  where:
+
+    -y = match copyright years (e.g., '1999-2005' or '2004')
+    -c = match ' *' prefix with line break between as .. applicable.
+    -j = match ' *' prefix with line break between licensors, .. as
+    -x = match '  ' prefix with line break between licensors, .. as
+    -p = match '# ' prefix with line break between licensors, .. as
+    -w = match ' *' prefix without 'or its licensors, as applicable'
+
+  file = a file in which to substitute license text
+
+!;
+}

Propchange: comdev/tools/licensing/copy2license.pl
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message