Author: donaldp
Date: Sat Dec 4 23:43:58 2010
New Revision: 1042263
URL: http://svn.apache.org/viewvc?rev=1042263&view=rev
Log:
BUILDR-555 - Add support for the jaxb binding compiler
Added:
buildr/trunk/addon/buildr/jaxb_xjc.rb
buildr/trunk/spec/addon/jaxb_xjc_spec.rb
- copied, changed from r1042121, buildr/trunk/spec/addon/bnd_spec.rb
Modified:
buildr/trunk/CHANGELOG
buildr/trunk/doc/more_stuff.textile
buildr/trunk/spec/sandbox.rb
Modified: buildr/trunk/CHANGELOG
URL:
http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=1042263&r1=1042262&r2=1042263&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Sat Dec 4 23:43:58 2010
@@ -1,4 +1,5 @@
1.4.5 (Pending)
+* Added: BUILDR-555 Add support for the jaxb binding compiler (Mark Petrovic)
* Added: BUILDR-554 Add support for OSGi bundle packages by importing the
buildr_bnd plugin
* Added: BUILDR-125 Add support for <security-role> in application.xml of
Added: buildr/trunk/addon/buildr/jaxb_xjc.rb
URL:
http://svn.apache.org/viewvc/buildr/trunk/addon/buildr/jaxb_xjc.rb?rev=1042263&view=auto
==============================================================================
--- buildr/trunk/addon/buildr/jaxb_xjc.rb (added)
+++ buildr/trunk/addon/buildr/jaxb_xjc.rb Sat Dec 4 23:43:58 2010
@@ -0,0 +1,72 @@
+# 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.
+
+module Buildr
+ module JaxbXjc
+ class << self
+
+ def jaxb_version
+ "2.2.1"
+ end
+
+ # The specs for requirements
+ def dependencies
+ [
+ "javax.xml.bind:jaxb-api:jar:#{jaxb_version}",
+ "com.sun.xml.bind:jaxb-impl:jar:#{jaxb_version}",
+ "com.sun.xml.bind:jaxb-xjc:jar:#{jaxb_version}"
+ ]
+ end
+
+ # Repositories containing the requirements
+ def remote_repository
+ "http://download.java.net/maven/2"
+ end
+
+ def xjc(*args)
+ cp = Buildr.artifacts(self.dependencies).each(&:invoke).map(&:to_s)
+ Java::Commands.java 'com.sun.tools.xjc.XJCFacade', *(args + [{
:classpath => cp }])
+ end
+ end
+
+ def compile_jaxb(files, *args)
+ options = Hash === args.last ? args.pop.dup : {}
+ rake_check_options options, :directory, :keep_content, :package, :id
+ args = args.dup
+ files = Array === files ? files.flatten : [files]
+
+ target_dir = options[:directory] || path_to(:target, :generated, :jaxb)
+ timestamp_file = File.expand_path("#{target_dir}/jaxb-#{options[:id] ||
1}.cache")
+
+ file(target_dir => timestamp_file)
+
+ file(timestamp_file => files.flatten) do |task|
+ rm_rf target_dir unless options[:keep_content]
+ mkdir_p target_dir
+ args << "-d" << target_dir
+ args << "-p" << options[:package] if options[:package]
+ args += files.collect{|f| f.to_s}
+ JaxbXjc.xjc args
+ touch timestamp_file
+ end
+
+ target_dir
+ end
+ end
+end
+
+class Buildr::Project
+ include Buildr::JaxbXjc
+end
\ No newline at end of file
Modified: buildr/trunk/doc/more_stuff.textile
URL:
http://svn.apache.org/viewvc/buildr/trunk/doc/more_stuff.textile?rev=1042263&r1=1042262&r2=1042263&view=diff
==============================================================================
--- buildr/trunk/doc/more_stuff.textile (original)
+++ buildr/trunk/doc/more_stuff.textile Sat Dec 4 23:43:58 2010
@@ -464,6 +464,27 @@ $ buildr --require buildr/jdepend jdepen
$ buildr -rbuildr/java/cobertura cobertura:html
{% endhighlight %}
+h2(#jaxb_xjc). JAXB Xjc Compiler
+
+Buildr includes an extension that provides the ability to invoke jaxb xjc
binding compiler. A typical project that uses the extension may look something
like;
+
+{% highlight ruby %}
+require 'buildr/jaxb_xjc'
+
+define "foo" do
+ project.version = "1.0.0"
+ compile.from compile_jaxb(_('src/schemas/wildfire-1.3.xsd'),
+ "-quiet",
+ :package => "org.foo.api")
+ package :jar
+end
+{% endhighlight %}
+
+The method compile_jaxb accepts either an array of files or a single file as
the first parameter. It then accepts 0 or more arguments that are passed to the
underlying XJC compiler. The arguments are documented on the "jaxb
site":https://jaxb.dev.java.net/nonav/2.2.1/docs/xjc.html. If the last argument
is an options hash then the extension handles the options hash specially. The
supported options include:
+
+* <tt>:directory</tt>: The directory to which source is generated. Defaults to
<tt>_(:target, :generated, :jaxb)</tt>
+* <tt>:keep_content</tt>: By default the generated directory will be deleted.
If <tt>true</tt> is specified for this parameter the directory will not be
deleted.
+* <tt>:package</tt>: The package in which the source is generated.
h2(#anything_ruby). Anything Ruby Can Do
Copied: buildr/trunk/spec/addon/jaxb_xjc_spec.rb (from r1042121,
buildr/trunk/spec/addon/bnd_spec.rb)
URL:
http://svn.apache.org/viewvc/buildr/trunk/spec/addon/jaxb_xjc_spec.rb?p2=buildr/trunk/spec/addon/jaxb_xjc_spec.rb&p1=buildr/trunk/spec/addon/bnd_spec.rb&r1=1042121&r2=1042263&rev=1042263&view=diff
==============================================================================
--- buildr/trunk/spec/addon/bnd_spec.rb (original)
+++ buildr/trunk/spec/addon/jaxb_xjc_spec.rb Sat Dec 4 23:43:58 2010
@@ -15,316 +15,111 @@
require File.expand_path('../spec_helpers', File.dirname(__FILE__))
-Sandbox.require_optional_extension 'buildr/bnd'
+Sandbox.require_optional_extension 'buildr/jaxb_xjc'
-def open_zip_file(file = 'target/foo-2.1.3.jar')
- jar_filename = @foo._(file)
- File.should be_exist(jar_filename)
- Zip::ZipFile.open(jar_filename) do |zip|
- yield zip
- end
-end
-
-def open_main_manifest_section(file = 'target/foo-2.1.3.jar')
- jar_filename = @foo._(file)
- File.should be_exist(jar_filename)
- yield Buildr::Packaging::Java::Manifest.from_zip(jar_filename).main
-end
-
-describe Buildr::Bnd do
-
- describe "package :bundle" do
- describe "with a valid bundle" do
- before do
- write "src/main/java/com/biz/Foo.java", <<SRC
-package com.biz;
-public class Foo {}
-SRC
- write "src/main/resources/IRIS-INF/iris.config", <<SRC
-some=setting
-SRC
- write "bar/src/main/java/com/biz/bar/Bar.java", <<SRC
-package com.biz.bar;
-public class Bar {}
-SRC
- @foo = define "foo" do
- project.version = "2.1.3"
- project.group = "mygroup"
- manifest["Magic-Food"] = "Chocolate"
- manifest["Magic-Drink"] = "Wine"
- package(:bundle).tap do |bnd|
- bnd["Export-Package"] = "com.*"
- end
-
- define "bar" do
- project.version = "2.2"
- package(:bundle).tap do |bnd|
- bnd["Magic-Food"] = "Cheese"
- bnd["Export-Package"] = "com.*"
- end
- end
- end
- task('package').invoke
- end
-
- it "produces a .bnd in the correct location for root project" do
- File.should be_exist(@foo._("target/foo-2.1.3.bnd"))
- end
-
- it "produces a .jar in the correct location for root project" do
- File.should be_exist(@foo._("target/foo-2.1.3.jar"))
- end
-
- it "produces a .jar containing correct .class files for root project" do
- open_zip_file do |zip|
- zip.file.exist?('com/biz/Foo.class').should be_true
- end
- end
-
- it "produces a .jar containing resoruces from resource directory root
project" do
- open_zip_file do |zip|
- zip.file.exist?('IRIS-INF/iris.config').should be_true
- end
- end
-
- it "produces a .jar containing expected manifest entries derived from
project.bnd for root project" do
- open_main_manifest_section do |attribs|
- attribs['Bundle-Name'].should eql('foo')
- attribs['Bundle-Version'].should eql('2.1.3')
- attribs['Bundle-SymbolicName'].should eql('mygroup.foo')
- attribs['Export-Package'].should eql('com.biz')
- attribs['Import-Package'].should eql('com.biz')
- end
- end
-
- it "produces a .jar containing expected manifest entries derived from
project.manifest root project" do
- open_main_manifest_section do |attribs|
- attribs['Magic-Drink'].should eql('Wine')
- attribs['Magic-Food'].should eql('Chocolate')
- end
- end
-
- it "produces a .bnd in the correct location for subproject project" do
- File.should be_exist(@foo._("bar/target/foo-bar-2.2.bnd"))
- end
-
- it "produces a .jar in the correct location for subproject project" do
- File.should be_exist(@foo._("bar/target/foo-bar-2.2.jar"))
- end
-
- it "produces a .jar containing correct .class files for subproject
project" do
- open_zip_file('bar/target/foo-bar-2.2.jar') do |zip|
- zip.file.exist?('com/biz/bar/Bar.class').should be_true
- end
- end
-
- it "produces a .jar containing expected manifest entries derived from
project.bnd for subproject project" do
- open_main_manifest_section('bar/target/foo-bar-2.2.jar') do |attribs|
- attribs['Bundle-Name'].should eql('foo:bar')
- attribs['Bundle-Version'].should eql('2.2')
- attribs['Bundle-SymbolicName'].should eql('mygroup.foo.bar')
- attribs['Export-Package'].should eql('com.biz.bar')
- attribs['Import-Package'].should eql('com.biz.bar')
- end
- end
-
- it "produces a .jar containing expected manifest entries derived from
project.manifest subproject project" do
- open_main_manifest_section('bar/target/foo-bar-2.2.jar') do |attribs|
- attribs['Magic-Drink'].should eql('Wine')
- attribs['Magic-Food'].should eql('Cheese')
- end
- end
- end
-
- describe "with an invalid bundle" do
- before do
- # bundle invalid as no source
- @foo = define "foo" do
- project.version = "2.1.3"
- project.group = "mygroup"
- package(:bundle).tap do |bnd|
- bnd["Export-Package"] = "*"
- end
- end
- end
-
- it "raise an error if unable to build a valid bundle" do
- lambda { task('package').invoke }.should raise_error
- end
-
- it "raise not produce an invalid jar file" do
- lambda { task('package').invoke }.should raise_error
- File.should_not be_exist(@foo._("target/foo-2.1.3.jar"))
- end
- end
-
- describe "using classpath_element to specify dependency" do
- before do
- @foo = define "foo" do
- project.version = "2.1.3"
- project.group = "mygroup"
- package(:bundle).tap do |bnd|
- bnd['Export-Package'] = 'org.apache.tools.zip.*'
- Buildr::Ant.dependencies.each do |d|
- bnd.classpath_element d
- end
- end
- end
- end
-
- it "should not raise an error during packaging" do
- lambda { task('package').invoke }.should_not raise_error
- end
+XSD_CONTENT = <<XSD
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
- it "should generate package with files exported from dependency" do
- task('package').invoke
- open_main_manifest_section do |attribs|
- attribs['Export-Package'].should eql('org.apache.tools.zip')
- end
- end
- end
-
- describe "using classpath to specify dependencies" do
- before do
- write "src/main/java/com/biz/Foo.java", <<SRC
-package com.biz;
-public class Foo {}
-SRC
- write "bar/src/main/java/com/biz/bar/Bar.java", <<SRC
-package com.biz.bar;
-public class Bar {}
-SRC
- @foo = define "foo" do
- project.version = "2.1.3"
- project.group = "mygroup"
- package(:bundle).tap do |bnd|
- bnd['Export-Package'] = 'org.apache.tools.zip.*'
- bnd.classpath = bnd.classpath + Buildr::Ant.dependencies
- end
- end
- end
-
- it "should not raise an error during packaging" do
- lambda { task('package').invoke }.should_not raise_error
- end
-
- it "should generate package with files exported from dependency" do
- task('package').invoke
- open_main_manifest_section do |attribs|
- attribs['Export-Package'].should eql('org.apache.tools.zip')
- end
- end
- end
-
- describe "using compile dependencies to specify dependency" do
- before do
- @foo = define "foo" do
- project.version = "2.1.3"
- project.group = "mygroup"
- compile.with Buildr::Ant.dependencies
- package(:bundle).tap do |bnd|
- bnd['Export-Package'] = 'org.apache.tools.zip.*'
- end
- end
- end
-
- it "should not raise an error during packaging" do
- lambda { task('package').invoke }.should_not raise_error
- end
-
- it "should generate package with files exported from dependency" do
- task('package').invoke
- open_main_manifest_section do |attribs|
- attribs['Export-Package'].should eql('org.apache.tools.zip')
- end
- end
- end
- end
-
- describe "project.bnd defaults" do
+ <xsd:simpleType name="agency">
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="DSE"/>
+ <xsd:enumeration value="PV"/>
+ <xsd:enumeration value="CFA"/>
+ <xsd:enumeration value="DPI"/>
+ <xsd:enumeration value="VF"/>
+ <xsd:enumeration value="Unknown"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <xsd:complexType name="latLongCoordinate">
+ <xsd:all>
+ <xsd:element name="latitude" type="xsd:float"/>
+ <xsd:element name="longitude" type="xsd:float"/>
+ </xsd:all>
+ </xsd:complexType>
+
+ <xsd:element name="wildfire">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="name" type="xsd:string"/>
+ <xsd:element name="district" type="xsd:string">
+ <xsd:annotation>
+ <xsd:documentation xml:lang="en">
+ The name of the district WITHOUT the "FIRE DISTRICT" suffix.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <xsd:element name="status">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="GOING"/>
+ <xsd:enumeration value="CONTAINED"/>
+ <xsd:enumeration value="UNDER CONTROL - 1"/>
+ <xsd:enumeration value="UNDER CONTROL - 2"/>
+ <xsd:enumeration value="SAFE"/>
+ <xsd:enumeration value="SAFE - OVERRUN"/>
+ <xsd:enumeration value="SAFE - NOT FOUND"/>
+ <xsd:enumeration value="SAFE - FALSE ALARM"/>
+ <xsd:enumeration value="NOT FOUND"/>
+ <xsd:enumeration value="UNKNOWN"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:element>
+ <xsd:element name="reported-at" type="xsd:dateTime"/>
+ <xsd:element name="lead-agency" type="xsd:string"/>
+ <xsd:element name="origin" type="latLongCoordinate" minOccurs="0">
+ <xsd:annotation>
+ <xsd:documentation xml:lang="en">
+ This is a grid reference in lat/long format.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <xsd:element name="area" type="xsd:decimal" minOccurs="0"/>
+ <xsd:element name="number">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:integer">
+ <xsd:minInclusive value="0"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:element>
+ <xsd:element name="global-id">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:integer">
+ <xsd:minInclusive value="0"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:element>
+ <xsd:element name="data-source" type="xsd:string"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+</xsd:schema>
+XSD
+describe Buildr::JaxbXjc do
+ describe "compiled with specified xsd" do
before do
- write "src/main/java/com/biz/Foo.java", <<SRC
-package com.biz;
-public class Foo {}
-SRC
- write "bar/src/main/java/com/biz/bar/Bar.java", <<SRC
-package com.biz.bar;
-public class Bar {}
-SRC
-
+ write "src/main/xsd/wildfire-1.3.xsd", XSD_CONTENT
@foo = define "foo" do
project.version = "2.1.3"
- project.group = "mygroup"
- package :bundle
- compile.with Buildr::Ant.dependencies
- desc "My Bar Project"
- define "bar" do
- package :bundle
- end
- end
- @bar = @foo.project('bar')
- end
-
- it "defaults Bundle-Version to project.version" do
- @foo.packages[0].to_params['Bundle-Version'].should eql('2.1.3')
- @bar.packages[0].to_params['Bundle-Version'].should eql('2.1.3')
- end
-
- it "defaults -classpath to compile path and dependencies" do
- @foo.packages[0].to_params['-classpath'].should
include(@foo.compile.target.to_s)
- @foo.packages[0].to_params['-classpath'].should
include(Buildr.artifacts(Buildr::Ant.dependencies[0]).to_s)
- @bar.packages[0].to_params['-classpath'].should
include(@bar.compile.target.to_s)
- end
-
- it "classpath method returns compile path and dependencies" do
- @foo.packages[0].classpath.should include(@foo.compile.target)
- Buildr::Ant.dependencies.each do |dependency|
- @foo.packages[0].classpath.to_s.should
include(Buildr.artifacts(dependency).to_s)
+ compile.from compile_jaxb("src/main/xsd/wildfire-1.3.xsd", "-quiet",
:package => "org.foo.api")
+ package :jar
end
- @bar.packages[0].classpath.should include(@bar.compile.target)
- end
-
- it "defaults Bundle-SymbolicName to combination of group and name" do
- @foo.packages[0].to_params['Bundle-SymbolicName'].should
eql('mygroup.foo')
- @bar.packages[0].to_params['Bundle-SymbolicName'].should
eql('mygroup.foo.bar')
- end
-
- it "defaults Export-Package to nil" do
- @foo.packages[0].to_params['Export-Package'].should be_nil
- @bar.packages[0].to_params['Export-Package'].should be_nil
- end
-
- it "defaults Import-Package to nil" do
- @foo.packages[0].to_params['Import-Package'].should be_nil
- @bar.packages[0].to_params['Import-Package'].should be_nil
+ task('compile').invoke
end
- it "defaults Bundle-Name to project.name if comment not present" do
- @foo.packages[0].to_params['Bundle-Name'].should eql('foo')
+ it "produce .java files in the correct location" do
+ File.should
be_exist(@foo._("target/generated/jaxb/org/foo/api/Agency.java"))
+ File.should
be_exist(@foo._("target/generated/jaxb/org/foo/api/LatLongCoordinate.java"))
+ File.should
be_exist(@foo._("target/generated/jaxb/org/foo/api/ObjectFactory.java"))
+ File.should
be_exist(@foo._("target/generated/jaxb/org/foo/api/Wildfire.java"))
end
- it "defaults Bundle-Name to comment if present" do
- @bar.packages[0].to_params['Bundle-Name'].should eql('My Bar Project')
- end
-
- it "defaults Bundle-Description to project.full_comment" do
- @foo.packages[0].to_params['Bundle-Description'].should be_nil
- @bar.packages[0].to_params['Bundle-Description'].should eql('My Bar
Project')
- end
-
- it "defaults -removeheaders to" do
- @foo.packages[0].to_params['-removeheaders'].should
eql("Include-Resource,Bnd-LastModified,Created-By,Implementation-Title,Tool")
- end
- end
-
- describe "project extension" do
- it "provides an 'bnd:print' task" do
- Rake::Task.tasks.detect { |task| task.to_s == "bnd:print" }.should_not
be_nil
- end
-
- it "documents the 'bnd:print' task" do
- Rake::Task.tasks.detect { |task| task.to_s == "bnd:print"
}.comment.should_not be_nil
+ it "produce .class files in the correct location" do
+ File.should be_exist(@foo._("target/classes/org/foo/api/Agency.class"))
+ File.should
be_exist(@foo._("target/classes/org/foo/api/LatLongCoordinate.class"))
+ File.should
be_exist(@foo._("target/classes/org/foo/api/ObjectFactory.class"))
+ File.should be_exist(@foo._("target/classes/org/foo/api/Wildfire.class"))
end
end
-end
\ No newline at end of file
+end
Modified: buildr/trunk/spec/sandbox.rb
URL:
http://svn.apache.org/viewvc/buildr/trunk/spec/sandbox.rb?rev=1042263&r1=1042262&r2=1042263&view=diff
==============================================================================
--- buildr/trunk/spec/sandbox.rb (original)
+++ buildr/trunk/spec/sandbox.rb Sat Dec 4 23:43:58 2010
@@ -29,12 +29,14 @@ require 'buildr/clojure'
require 'buildr/groovy'
require 'buildr/scala'
require 'buildr/bnd'
+require 'buildr/jaxb_xjc'
Java.load # Anything added to the classpath.
artifacts(
TestFramework.frameworks.map(&:dependencies).flatten,
JUnit.ant_taskdef,
Buildr::Groovy.dependencies,
+ Buildr::JaxbXjc.dependencies,
Buildr::Bnd.dependencies,
Buildr::Scala::Specs.dependencies,
Buildr::Shell::BeanShell.artifact,