Author: mriou
Date: Thu Mar 29 15:18:32 2007
New Revision: 523851
URL: http://svn.apache.org/viewvc?view=rev&rev=523851
Log:
New headers tasks to check all Apache license headers.
Added:
incubator/ode/trunk/tasks/check_license_headers.rb
incubator/ode/trunk/tasks/headers.rake
Modified:
incubator/ode/trunk/tasks/derby.rake
Added: incubator/ode/trunk/tasks/check_license_headers.rb
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/tasks/check_license_headers.rb?view=auto&rev=523851
==============================================================================
--- incubator/ode/trunk/tasks/check_license_headers.rb (added)
+++ incubator/ode/trunk/tasks/check_license_headers.rb Thu Mar 29 15:18:32 2007
@@ -0,0 +1,125 @@
+module FileBrowser
+ def browse(root)
+ queue = Array.new.push(root)
+ while !queue.empty?
+ filename = queue.pop
+ if File.file?(filename)
+ yield(filename)
+ else
+ Dir.new(filename).each do |child|
+ unless ['..', '.','.svn'].include? child
+ queue.push(filename + "/" + child)
+ end
+ end
+ end
+ end
+ end
+end
+
+class HeadersCheck
+ EXT = ['java', 'xml', 'bpel', 'wsdl', 'c', 'cpp']
+
+ include FileBrowser
+
+ def check_files(dir, dry_run)
+ count = 0
+ browse(dir) do |filename|
+ if /\.#{EXT.join('$|\.')}$/ =~ filename
+ match = nil
+ f = File.new(filename)
+ # Checking for the Apache header in the 4 first lines
+ 4.times do
+ match ||= (/Licensed to the Apache Software Foundation/ =~
f.readline) rescue nil
+ #puts("File #{filename} too short to check.")
+ end
+ f.close
+ unless match
+ if dry_run
+ puts "Missing header in #{filename}"
+ else
+ add_header(filename)
+ end
+ count += 1
+ end
+ end
+ end
+ if dry_run
+ puts "#{count} files don't have an Apache license header."
+ else
+ puts "#{count} files have been changed to include the Apache license
header."
+ end
+ end
+
+ def add_header(filename)
+ ext = /\.([^\.]*)$/.match(filename[1..-1])[1]
+ header = HEADERS[ext]
+ content = File.new(filename, 'r').read
+ if content[0..4] == '<?xml'
+ content = content[0..content.index("\n")] + header +
content[(content.index("\n") + 1)..-1]
+ else
+ content = header + content
+ end
+ File.new(filename, 'w').write(content)
+ end
+
+end
+
+JAVA_HEADER = <<JAVA
+/*
+ * 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.
+ */
+JAVA
+
+XML_HEADER = <<XML
+<!--
+ ~ 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.
+ -->
+XML
+
+HEADERS = {
+ 'java' => JAVA_HEADER,
+ 'c' => JAVA_HEADER,
+ 'cpp' => JAVA_HEADER,
+ 'xml' => XML_HEADER,
+ 'bpel' => XML_HEADER,
+ 'wsdl' => XML_HEADER
+}
+
+# if ['-h', '--help', 'help'].include? ARGV[0]
+# puts "Scans the current directory for files with missing Apache "
+# puts "license headers."
+# puts " ruby check_license_headers.rb # list files"
+# puts " ruby check_license_headers.rb add # add headers automatically"
+# else
+# HeadersCheck.new.check_files('.', ARGV[0] != 'add')
+# end
Modified: incubator/ode/trunk/tasks/derby.rake
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/tasks/derby.rake?view=diff&rev=523851&r1=523850&r2=523851
==============================================================================
--- incubator/ode/trunk/tasks/derby.rake (original)
+++ incubator/ode/trunk/tasks/derby.rake Thu Mar 29 15:18:32 2007
@@ -7,7 +7,7 @@
def self.create(args)
db, prereqs = Rake.application.resolve_args(args)
file(db=>prereqs) do |task|
- cmd = [ Java.path_to_bin, "-cp",
artifacts(REQUIRES).join(File::PATH_SEPARATOR), "org.apache.derby.tools.ij" ]
+ cmd = [ Java.path_to_bin('java'), "-cp",
artifacts(REQUIRES).join(File::PATH_SEPARATOR), "org.apache.derby.tools.ij" ]
Open3.popen3(*cmd) do |stdin, stdout, stderr|
# Shutdown so if a database already exists, we can remove it.
stdin.puts "connect 'jdbc:derby:;shutdown=true';"
Added: incubator/ode/trunk/tasks/headers.rake
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/tasks/headers.rake?view=auto&rev=523851
==============================================================================
--- incubator/ode/trunk/tasks/headers.rake (added)
+++ incubator/ode/trunk/tasks/headers.rake Thu Mar 29 15:18:32 2007
@@ -0,0 +1,13 @@
+desc "Checks license headers."
+task('headers') do
+ puts Dir.pwd
+ require 'tasks/check_license_headers'
+ HeadersCheck.new.check_files('.', true)
+end
+
+desc "Updates license headers."
+task('headers:update') do
+ puts Dir.pwd
+ require 'tasks/check_license_headers'
+ HeadersCheck.new.check_files('.', false)
+end