You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by as...@apache.org on 2007/04/07 01:25:50 UTC
svn commit: r526318 - in /incubator/ode/trunk/tasks:
check_license_headers.rb derby.rake headers.rake hibernate.rake jbi.rake
Author: assaf
Date: Fri Apr 6 16:25:49 2007
New Revision: 526318
URL: http://svn.apache.org/viewvc?view=rev&rev=526318
Log:
Cleanup of the tasks for readability (mostly)
Removed:
incubator/ode/trunk/tasks/check_license_headers.rb
Modified:
incubator/ode/trunk/tasks/derby.rake
incubator/ode/trunk/tasks/headers.rake
incubator/ode/trunk/tasks/hibernate.rake
incubator/ode/trunk/tasks/jbi.rake
Modified: incubator/ode/trunk/tasks/derby.rake
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/tasks/derby.rake?view=diff&rev=526318&r1=526317&r2=526318
==============================================================================
--- incubator/ode/trunk/tasks/derby.rake (original)
+++ incubator/ode/trunk/tasks/derby.rake Fri Apr 6 16:25:49 2007
@@ -1,33 +1,49 @@
require "open3"
-module Derby
- VERSION = "10.1.2.1"
- REQUIRES = [ "org.apache.derby:derby:jar:#{VERSION}", "org.apache.derby:derbytools:jar:#{VERSION}" ]
+module Buildr
+ module Derby
+ REQUIRES = group("derby", "derbytools", :under=>"org.apache.derby", :version=>"10.1.2.1")
- def self.create(args)
- db, prereqs = Rake.application.resolve_args(args)
- file(db=>prereqs) do |task|
- 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';"
- rm_rf task.to_s if File.exist?(task.to_s)
- # Create a new database, and load all the prerequisites.
- stdin.puts "connect 'jdbc:derby:#{task.to_s};create=true;user=sa'"
- stdin.puts "set schema sa"
- stdin.puts "autocommit on;"
- task.prerequisites.each { |prereq| stdin.write File.read(prereq.to_s) }
- # Exiting will shutdown the database so we can copy the files around.
- stdin.puts "exit"
- stdin.close
- # Helps when dignosing SQL errors.
- stdout.read.tap { |output| puts output if Rake.application.options.trace }
+ class << self
+
+ # Returns a task that will create a new Derby database. The task name is the path to
+ # the derby database. The prerequisites are all the SQL files for inclusion in the database.
+ #
+ # For example:
+ # Derby.create "mydb"=>derby.sql
+ def create(args)
+ db, prereqs = Rake.application.resolve_args(args)
+ file(db=>prereqs) do |task|
+ cmd = [ Java.path_to_bin('java'), "-cp", requires, "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';"
+ rm_rf task.to_s if File.exist?(task.to_s)
+ # Create a new database, and load all the prerequisites.
+ stdin.puts "connect 'jdbc:derby:#{task.to_s};create=true;user=sa'"
+ stdin.puts "set schema sa"
+ stdin.puts "autocommit on;"
+ task.prerequisites.each { |prereq| stdin.write File.read(prereq.to_s) }
+ # Exiting will shutdown the database so we can copy the files around.
+ stdin.puts "exit"
+ stdin.close
+ # Helps when dignosing SQL errors.
+ stdout.read.tap { |output| puts output if Rake.application.options.trace }
+ end
+ # Copy the SQL files into the database directory.
+ filter(task.prerequisites).into(db).invoke
+ # Tell other tasks we're refreshed, this also prevents running task
+ # due to time differences between parent directory and db directory.
+ touch task.to_s
+ end
+ end
+
+ protected
+
+ # This will download all the required artifacts before returning a classpath, and we want to do this only once.
+ def requires()
+ @requires ||= artifacts(REQUIRES).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
end
- # Copy the SQL files into the database directory.
- filter(task.prerequisites).into(db).invoke
- # Tell other tasks we're refreshed, this also prevents running task
- # due to time differences between parent directory and db directory.
- touch task.to_s
end
end
-end
+end
Modified: incubator/ode/trunk/tasks/headers.rake
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/tasks/headers.rake?view=diff&rev=526318&r1=526317&r2=526318
==============================================================================
--- incubator/ode/trunk/tasks/headers.rake (original)
+++ incubator/ode/trunk/tasks/headers.rake Fri Apr 6 16:25:49 2007
@@ -1,6 +1,68 @@
-desc "Checks license headers."
-task('headers') do
- puts Dir.pwd
- require 'tasks/check_license_headers'
- HeadersCheck.new.check_files('.')
+namespace "check" do
+ desc "Checks license headers."
+ task("headers") do
+ # Define license headers based on the filename extension.
+ licenses = {}
+ licenses[".java"] = <<EOF
+/*
+ * 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.
+ */
+EOF
+ licenses[".xml"] = <<EOF
+<!--
+ ~ 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.
+ -->
+EOF
+ licenses[".bpel"] = licenses[".wsdl"] = licenses[".xml"]
+ # This also tells us which files to look at.
+ extensions = licenses.keys.join(",")
+ count = FileList["**/*{#{extensions}}"].inject(0) do |count, filename|
+ if File.readlines(filename)[0..3].join !~ /Licensed to the Apache Software Foundation/
+ when_writing "Missing header in #{filename}" do
+ # Figure the license from the file, inject it into the file and rewrite it.
+ license = licenses[filename.pathmap("%x")]
+ modified = File.read(filename).sub(/(<\?xml .*\?>\n?)(.*)/m) { "#{$1}#{license}#{$2}" }
+ File.open(filename, "w") { |file| file.write modified }
+ count + 1
+ end
+ else
+ count
+ end
+ end
+ if count > 0
+ warn "#{count} files found to have missing headers."
+ else
+ puts "All #{extensions} files checked and have the license in them."
+ end
+ end
end
Modified: incubator/ode/trunk/tasks/hibernate.rake
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/tasks/hibernate.rake?view=diff&rev=526318&r1=526317&r2=526318
==============================================================================
--- incubator/ode/trunk/tasks/hibernate.rake (original)
+++ incubator/ode/trunk/tasks/hibernate.rake Fri Apr 6 16:25:49 2007
@@ -7,37 +7,61 @@
REQUIRES.logging = "commons-logging:commons-logging:jar:1.0.3"
REQUIRES.dom4j = "dom4j:dom4j:jar:1.6.1"
REQUIRES.hibernate = "org.hibernate:hibernate:jar:3.1.2"
- REQUIRES.xdoclet = [ "xdoclet:xdoclet-hibernate-module:jar:1.2.3", "xdoclet:xdoclet-xdoclet-module:jar:1.2.3",
- "xdoclet:xdoclet:jar:1.2.3", "xdoclet:xjavadoc:jar:1.1-j5" ]
+ REQUIRES.xdoclet = group("xdoclet", "xdoclet-xdoclet-module", "xdoclet-hibernate-module",
+ :under=>"xdoclet", :version=>"1.2.3") + ["xdoclet:xjavadoc:jar:1.1-j5"]
class << self
include Ant
+ # Uses XDoclet to generate HBM files form annotated source files.
+ # Options include:
+ # * :sources -- Directory (or directories) containing source files.
+ # * :target -- The target directory.
+ # * :excludetags -- Tags to exclude (see HibernateDocletTask)
+ #
+ # For example:
+ # Java::Hibernate.xdoclet :sources=>compile.sources,
+ # :target=>compile.target, :excludedtags=>"@version,@author,@todo"
def xdoclet(options)
ant("hibernatedoclet") do |ant|
ant.taskdef :name=>"hibernatedoclet", :classname=>"xdoclet.modules.hibernate.HibernateDocletTask", :classpath=>requires
ant.hibernatedoclet :destdir=>options[:target].to_s, :excludedtags=>options[:excludedtags], :force=>"true" do
hibernate :version=>"3.0"
- fileset :dir=>options[:source].to_s, :includes=>options[:include]
+ options[:sources].to_a.each do |source|
+ fileset :dir=>source.to_s, :includes=>"**/*.java"
+ end
end
end
end
+ # Returns a new AntProject that supports the schemaexport task.
def schemaexport(name = "schemaexport")
ant(name) do |ant|
ant.taskdef :name=>"schemaexport", :classname=>"org.hibernate.tool.hbm2ddl.SchemaExportTask", :classpath=>requires
end
end
+ # Returns an new task with an accessor (ant) to an AntProject that supports
+ # the schemaexport task.
+ #
+ # For example:
+ # Java::Hibernate.schemaexport_task.enhance do |task|
+ # task.ant.schemaexport :properties=>"derby.properties", :output=>"derby.sql",
+ # :delimiter=>";", :drop=>"no", :create=>"yes" do
+ # fileset(:dir=>path_to(:java_src_dir)) { include :name=>"**/*.hbm.xml" } }
+ # end
+ # end
def schemaexport_task(name = "schemaexport")
- task(name).tap do |task|
- class << task ; attr_accessor :ant ; end
- task.enhance { |task| task.ant = schemaexport(name) }
+ unless Rake::Task.task_defined?(name)
+ class << task(name) ; attr_accessor :ant ; end
+ task(name).enhance { |task| task.ant = schemaexport(name) }
end
+ task(name)
end
protected
+ # This will download all the required artifacts before returning a classpath, and we want to do this only once.
def requires()
@requires ||= artifacts(REQUIRES.to_hash.values).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
end
Modified: incubator/ode/trunk/tasks/jbi.rake
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/tasks/jbi.rake?view=diff&rev=526318&r1=526317&r2=526318
==============================================================================
--- incubator/ode/trunk/tasks/jbi.rake (original)
+++ incubator/ode/trunk/tasks/jbi.rake Fri Apr 6 16:25:49 2007
@@ -1,99 +1,130 @@
module Buildr
- class JBITask < ZipTask
+ module Java
+ # This task creates a JBI package based on the component/bootstrap specification.
+ # It extends ZipTask, and all its over lovely options.
+ #
+ # The easiest way to use this task is through the Project#package method. For example:
+ # package(:jbi).tap do |jbi|
+ # jbi.component :type=>:service_engine=>"MyEngine", :description=>self.comment
+ # jbi.component :class_name=>"com.example.MyComponent", :delegation=>:self, :libs=>libs
+ # jbi.bootstrap :class_name=>"com.example.MyBootstrap", :delegation=>:parent, :libs=>libs
+ # end
+ class JBITask < ZipTask
+
+ # Specifies the name of a jbi.xml file to use, or a Proc/Method returning
+ # the contents of jbi.xml. Leave empty if you want to use #component and
+ # bootstrap instead.
+ attr_accessor :jbi_xml
+
+ # Component specification.
+ class Component
+ # Component name.
+ attr_accessor :name
+ # Component type, e.g. :service_engine.
+ attr_accessor :type
+ # Description of component.
+ attr_accessor :description
+ # Delegation method. Default is :parent.
+ attr_accessor :delegation
+ # Component class name.
+ attr_accessor :class_name
+ # Array of libraries used by component.
+ attr_accessor :libs
- attr_accessor :jbi_xml
-
- class Component
- attr_accessor :name
- attr_accessor :type
- attr_accessor :description
- attr_accessor :delegation
- attr_accessor :class_name
- attr_writer :libs
- def libs()
- @libs ||= []
+ def initialize()
+ @libs = []
+ end
end
- end
- class Bootstrap
- attr_accessor :delegation
- attr_accessor :class_name
- attr_writer :libs
- def libs()
- @libs ||= []
+ # Bootstrap specification.
+ class Bootstrap
+ # Delegation method. Default is :parent.
+ attr_accessor :delegation
+ # Bootstrap class name.
+ attr_accessor :class_name
+ # Array of libraries used for bootstrapping.
+ attr_accessor :libs
+
+ def initialize()
+ @libs = []
+ end
end
- end
- def []=(key, value)
- case key.to_sym
- when :name, :description, :type
- self.component.send "#{name}=", value
- when :component
- self.component value
- when :bootstrap
- self.bootstrap value
- else
- super key, value
+ def []=(key, value)
+ case key.to_sym
+ when :name, :description, :type
+ self.component.send "#{name}=", value
+ when :component, :bootstrap
+ self.send key, value
+ else
+ super key, value
+ end
+ value
end
- value
- end
- def component(args = nil)
- @component ||= Component.new
- args.each { |k, v| @component.send "#{k}=", v } if args
- @component
- end
+ # Returns the component specification for this JBI package.
+ # You can call accessor methods to configure the component
+ # specification, you can also pass a hash of settings, for example:
+ # jbi.component :type=>:service_engine, :name=>"MyEngine"
+ def component(args = nil)
+ (@component ||= Component.new).tap do |component|
+ args.each { |k, v| component.send "#{k}=", v } if args
+ end
+ end
- def bootstrap(args = nil)
- @bootstrap ||= Bootstrap.new
- args.each { |k, v| @bootstrap.send "#{k}=", v } if args
- @bootstrap
- end
+ # Returns the bootstrap specification for this JBI package.
+ # You can call accessor methods to configure the bootstrap
+ # specification, you can also pass a hash of settings, for example:
+ # jbi.bootstrap :class_name=>"com.example.jbi.MyBootstrap", :libs=>libs
+ def bootstrap(args = nil)
+ (@bootstrap ||= Bootstrap.new).tap do |bootstrap|
+ args.each { |k, v| bootstrap.send "#{k}=", v } if args
+ end
+ end
- def prerequisites()
- super + (component.libs + bootstrap.libs).flatten.uniq
- end
+ def prerequisites()
+ super + (component.libs + bootstrap.libs).flatten.uniq
+ end
- protected
+ protected
- def create(zip)
- zip.mkdir "META-INF"
- zip.file.open("META-INF/jbi.xml", "w") do |file|
- case jbi_xml
+ def create(zip)
+ zip.mkdir "META-INF"
+ # Create the jbi.xml file from provided file/code or by creating a descriptor.
+ jbi_xml_content = case jbi_xml
when String
- file.write File.read(jbi_xml)
+ File.read(jbi_xml)
when nil, true
- file.write descriptor
+ descriptor
when Proc, Method
- file.write jbi_xml.call
+ jbi_xml.call.to_s
end
- end
- path("lib").include((component.libs + bootstrap.libs).flatten.uniq)
- super zip
- end
-
- def descriptor()
- delegation = lambda { |key| "#{key || :parent}-first" }
- xml = Builder::XmlMarkup.new(:indent=>2)
- xml.instruct!
- xml.jbi :xmlns=>"http://java.sun.com/xml/ns/jbi", :version=>"1.0" do
- xml.component :type=>component.type.to_s.sub("_", "-"),
- "component-class-loader-delegation"=>delegation[component.delegation],
- "bootstrap-class-loader-delegation"=>delegation[bootstrap.delegation] do
- xml.identification do
- xml.name component.name
- xml.description component.description
- end
- xml.tag! "component-class-name", component.class_name
- xml.tag! "component-class-path" do
- component.libs.each { |lib| xml.tag! "path-element", lib.to_s }
- end
- xml.tag! "bootstrap-class-name", bootstrap.class_name
- xml.tag! "bootstrap-class-path" do
- bootstrap.libs.each { |lib| xml.tag! "path-element", lib.to_s }
+ zip.file.open("META-INF/jbi.xml", "w") { |file| file.write jbi_xml_content }
+ path("lib").include((component.libs + bootstrap.libs).flatten.uniq)
+ super zip
+ end
+
+ # Create a JBI descriptor (jbi.xml) from the component/bootstrap specification.
+ def descriptor()
+ delegation = lambda { |key| "#{key || :parent}-first" }
+ xml = Builder::XmlMarkup.new(:indent=>2)
+ xml.instruct!
+ xml.jbi :xmlns=>"http://java.sun.com/xml/ns/jbi", :version=>"1.0" do
+ xml.component :type=>component.type.to_s.sub("_", "-"),
+ "component-class-loader-delegation"=>delegation[component.delegation],
+ "bootstrap-class-loader-delegation"=>delegation[bootstrap.delegation] do
+ xml.identification do
+ xml.name component.name
+ xml.description component.description
+ end
+ xml.tag!("component-class-name", component.class_name)
+ xml.tag!("component-class-path") { component.libs.each { |lib| xml.tag! "path-element", lib.to_s } }
+ xml.tag!("bootstrap-class-name", bootstrap.class_name)
+ xml.tag!("bootstrap-class-path") { bootstrap.libs.each { |lib| xml.tag! "path-element", lib.to_s } }
end
end
end
+
end
end
@@ -108,6 +139,6 @@
end
file(file_name).tap { |jbi| jbi.include args[:include] if args[:include] }
end
+
end
end
-