Improve support for auto-detection of ejb and web descriptors within Intellij IDEA...
authorPeter Donald <donaldp@apache.org>
Wed, 25 Sep 2013 23:54:49 +0000 (23:54 +0000)
committerPeter Donald <donaldp@apache.org>
Wed, 25 Sep 2013 23:54:49 +0000 (23:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/buildr/trunk@1526335 13f79535-47bb-0310-9956-ffa450edef68

CHANGELOG
lib/buildr/ide/idea.rb
spec/ide/idea_spec.rb

index 2c50caa..541b08c 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,6 @@
 1.4.13 (Pending)
+* Added:  Improve support for auto-detection of ejb and web descriptors
+          within Intellij IDEA project generation.
 * Change: Default to setting the "User-Agent" header to "Buildr-VERSION"
           when accessing http resources. Maven Central rejects requests
           without a User-Agent string.
index b861c19..72f92d5 100644 (file)
@@ -302,7 +302,11 @@ module Buildr #:nodoc:
         buildr_project.assets.paths.each {|p| default_webroots[p] = "/" }
         webroots = options[:webroots] || default_webroots
         default_deployment_descriptors = []
-        ['web.xml', 'glassfish-web.xml', 'context.xml'].each do |descriptor|
+        ['web.xml', 'sun-web.xml', 'glassfish-web.xml', 'jetty-web.xml', 'geronimo-web.xml',
+         'context.xml', 'weblogic.xml',
+         'jboss-deployment-structure.xml', 'jboss-web.xml',
+         'ibm-web-bnd.xml', 'ibm-web-ext.xml', 'ibm-web-ext-pme.xml'].
+          each do |descriptor|
           webroots.each_pair do |path, relative_url|
             next unless relative_url == "/"
             d = "#{path}/WEB-INF/#{descriptor}"
@@ -375,15 +379,27 @@ module Buildr #:nodoc:
 
       def add_ejb_facet(options = {})
         name = options[:name] || "EJB"
-        default_ejb_xml = buildr_project._(:source, :main, :resources, "WEB-INF/ejb-jar.xml")
-        ejb_xml = options[:ejb_xml] || default_ejb_xml
-        ejb_roots = options[:ejb_roots] || [buildr_project.compile.sources, buildr_project.resources.sources].flatten
+
+        default_ejb_roots = [buildr_project.compile.sources, buildr_project.resources.sources].flatten
+        ejb_roots = options[:ejb_roots] || default_ejb_roots
+
+        default_deployment_descriptors = []
+        ['ejb-jar.xml', 'glassfish-ejb-jar.xml', 'ibm-ejb-jar-bnd.xml', 'ibm-ejb-jar-ext-pme.xml', 'ibm-ejb-jar-ext.xml',
+         'jboss.xml', 'jbosscmp-jdbc.xml', 'openejb-jar.xml', 'sun-cmp-mapping.xml', 'sun-ejb-jar.xml',
+         'weblogic-cmp-rdbms-jar.xml', 'weblogic-ejb-jar.xml'].
+          each do |descriptor|
+          ejb_roots.each do |path|
+            d = "#{path}/WEB-INF/#{descriptor}"
+            default_deployment_descriptors << d if File.exist?(d)
+          end
+        end
+        deployment_descriptors = options[:deployment_descriptors] || default_deployment_descriptors
 
         add_facet(name, "ejb") do |facet|
           facet.configuration do |c|
             c.descriptors do |d|
-              if File.exist?(ejb_xml) || default_ejb_xml != ejb_xml
-                d.deploymentDescriptor :name => 'ejb-jar.xml', :url => file_path(ejb_xml)
+              deployment_descriptors.each do |deployment_descriptor|
+                d.deploymentDescriptor :name => File.basename(deployment_descriptor), :url => file_path(deployment_descriptor)
               end
             end
             c.ejbRoots do |e|
index ca057e2..4196e45 100644 (file)
@@ -296,6 +296,206 @@ describe Buildr::IntellijIdea do
       end\r
     end\r
 \r
+    describe "using add_web_facet" do\r
+      before do\r
+        write "src/main/webapp/WEB-INF/web.xml"\r
+        write "src/main/webapp/WEB-INF/glassfish-web.xml"\r
+        write "src/main/webapp/WEB-INF/context.xml"\r
+        write "src/main/webapp/WEB-INF/faces-config.xml"\r
+\r
+        @foo = define "foo" do\r
+          iml.add_web_facet\r
+        end\r
+        invoke_generate_task\r
+      end\r
+\r
+      it "generates a web facet with appropriate deployment descriptors" do\r
+        doc = xml_document(@foo._("foo.iml"))\r
+        facet_xpath = "/module/component[@name='FacetManager']/facet"\r
+        doc.should have_nodes(facet_xpath, 1)\r
+        web_facet_xpath = "#{facet_xpath}[@type='web', @name='Web']"\r
+        doc.should have_xpath(web_facet_xpath)\r
+        deployment_descriptor_xpath = "#{web_facet_xpath}/configuration/descriptors/deploymentDescriptor"\r
+        doc.should have_xpath("#{deployment_descriptor_xpath}[@name='web.xml',  url='file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml']")\r
+        doc.should have_xpath("#{deployment_descriptor_xpath}[@name='glassfish-web.xml',  url='file://$MODULE_DIR$/src/main/webapp/WEB-INF/glassfish-web.xml']")\r
+      end\r
+\r
+      it "generates a web facet with derived webroots" do\r
+        doc = xml_document(@foo._("foo.iml"))\r
+        facet_xpath = "/module/component[@name='FacetManager']/facet"\r
+        doc.should have_nodes(facet_xpath, 1)\r
+        web_facet_xpath = "#{facet_xpath}[@type='web', @name='Web']"\r
+        doc.should have_xpath(web_facet_xpath)\r
+        doc.should have_xpath("#{web_facet_xpath}/configuration/webroots/root[@url='file://$MODULE_DIR$/src/main/webapp', @realtive='/']")\r
+      end\r
+\r
+      it "generates a web facet with jsf facet auto-detected" do\r
+        doc = xml_document(@foo._("foo.iml"))\r
+        facet_xpath = "/module/component[@name='FacetManager']/facet"\r
+        doc.should have_nodes(facet_xpath, 1)\r
+        web_facet_xpath = "#{facet_xpath}[@type='web', @name='Web']"\r
+        doc.should have_xpath(web_facet_xpath)\r
+        doc.should have_xpath("#{web_facet_xpath}/facet[@type='jsf', @name='JSF']")\r
+      end\r
+    end\r
+\r
+    describe "using add_web_facet with specified parameters" do\r
+      before do\r
+        @foo = define "foo" do\r
+          iml.add_web_facet(:deployment_descriptors => ["src/main/webapp2/WEB-INF/web.xml"],\r
+                            :enable_jsf => true,\r
+                            :webroots => {"src/main/webapp2" => "/", "src/main/css" => "/css"})\r
+        end\r
+        invoke_generate_task\r
+      end\r
+\r
+      it "generates a web facet with appropriate deployment descriptors" do\r
+        doc = xml_document(@foo._("foo.iml"))\r
+        facet_xpath = "/module/component[@name='FacetManager']/facet"\r
+        doc.should have_nodes(facet_xpath, 1)\r
+        web_facet_xpath = "#{facet_xpath}[@type='web', @name='Web']"\r
+        doc.should have_xpath(web_facet_xpath)\r
+        deployment_descriptor_xpath = "#{web_facet_xpath}/configuration/descriptors/deploymentDescriptor"\r
+        doc.should have_xpath("#{deployment_descriptor_xpath}[@name='web.xml',  url='file://$MODULE_DIR$/src/main/webapp2/WEB-INF/web.xml']")\r
+      end\r
+\r
+      it "generates a web facet with specified webroots" do\r
+        doc = xml_document(@foo._("foo.iml"))\r
+        facet_xpath = "/module/component[@name='FacetManager']/facet"\r
+        doc.should have_nodes(facet_xpath, 1)\r
+        web_facet_xpath = "#{facet_xpath}[@type='web', @name='Web']"\r
+        doc.should have_xpath(web_facet_xpath)\r
+        doc.should have_xpath("#{web_facet_xpath}/configuration/webroots/root[@url='file://$MODULE_DIR$/src/main/webapp2', @realtive='/']")\r
+        doc.should have_xpath("#{web_facet_xpath}/configuration/webroots/root[@url='file://$MODULE_DIR$/src/main/css', @realtive='/css']")\r
+      end\r
+\r
+      it "generates a web facet with jsf facet enabled" do\r
+        doc = xml_document(@foo._("foo.iml"))\r
+        facet_xpath = "/module/component[@name='FacetManager']/facet"\r
+        doc.should have_nodes(facet_xpath, 1)\r
+        web_facet_xpath = "#{facet_xpath}[@type='web', @name='Web']"\r
+        doc.should have_xpath(web_facet_xpath)\r
+        doc.should have_xpath("#{web_facet_xpath}/facet[@type='jsf', @name='JSF']")\r
+      end\r
+    end\r
+\r
+    describe "using add_ejb_facet" do\r
+      before do\r
+        write "src/main/java/com/bin/foo.java"\r
+        write "src/main/resources/WEB-INF/ejb-jar.xml"\r
+\r
+        @foo = define "foo" do\r
+          iml.add_ejb_facet\r
+        end\r
+        invoke_generate_task\r
+      end\r
+\r
+      it "generates an ejb facet with appropriate deployment descriptors" do\r
+        doc = xml_document(@foo._("foo.iml"))\r
+        facet_xpath = "/module/component[@name='FacetManager']/facet"\r
+        doc.should have_nodes(facet_xpath, 1)\r
+        web_facet_xpath = "#{facet_xpath}[@type='ejb', @name='EJB']"\r
+        doc.should have_xpath(web_facet_xpath)\r
+        deployment_descriptor_xpath = "#{web_facet_xpath}/configuration/descriptors/deploymentDescriptor"\r
+        doc.should have_xpath("#{deployment_descriptor_xpath}[@name='ejb-jar.xml',  url='file://$MODULE_DIR$/src/main/resources/WEB-INF/ejb-jar.xml']")\r
+      end\r
+\r
+      it "generates an ejb facet with derived ejbRoots" do\r
+        doc = xml_document(@foo._("foo.iml"))\r
+        facet_xpath = "/module/component[@name='FacetManager']/facet"\r
+        doc.should have_nodes(facet_xpath, 1)\r
+        web_facet_xpath = "#{facet_xpath}[@type='ejb', @name='EJB']"\r
+        doc.should have_xpath(web_facet_xpath)\r
+        doc.should have_xpath("#{web_facet_xpath}/configuration/ejbRoots/root[@url='file://$MODULE_DIR$/src/main/java']")\r
+        doc.should have_xpath("#{web_facet_xpath}/configuration/ejbRoots/root[@url='file://$MODULE_DIR$/src/main/resources']")\r
+      end\r
+    end\r
+\r
+\r
+    describe "using add_ejb_facet specifying parameters" do\r
+      before do\r
+        @foo = define "foo" do\r
+          iml.add_ejb_facet(:ejb_roots => ["generated/main/java","generated/main/resources"],\r
+          :deployment_descriptors => ["generated/main/resources/WEB-INF/ejb-jar.xml"])\r
+        end\r
+        invoke_generate_task\r
+      end\r
+\r
+      it "generates an ejb facet with appropriate deployment descriptors" do\r
+        doc = xml_document(@foo._("foo.iml"))\r
+        facet_xpath = "/module/component[@name='FacetManager']/facet"\r
+        doc.should have_nodes(facet_xpath, 1)\r
+        web_facet_xpath = "#{facet_xpath}[@type='ejb', @name='EJB']"\r
+        doc.should have_xpath(web_facet_xpath)\r
+        deployment_descriptor_xpath = "#{web_facet_xpath}/configuration/descriptors/deploymentDescriptor"\r
+        doc.should have_xpath("#{deployment_descriptor_xpath}[@name='ejb-jar.xml',  url='file://$MODULE_DIR$/generated/main/resources/WEB-INF/ejb-jar.xml']")\r
+      end\r
+\r
+      it "generates an ejb facet with derived ejbRoots" do\r
+        doc = xml_document(@foo._("foo.iml"))\r
+        facet_xpath = "/module/component[@name='FacetManager']/facet"\r
+        doc.should have_nodes(facet_xpath, 1)\r
+        web_facet_xpath = "#{facet_xpath}[@type='ejb', @name='EJB']"\r
+        doc.should have_xpath(web_facet_xpath)\r
+        doc.should have_xpath("#{web_facet_xpath}/configuration/ejbRoots/root[@url='file://$MODULE_DIR$/generated/main/java']")\r
+        doc.should have_xpath("#{web_facet_xpath}/configuration/ejbRoots/root[@url='file://$MODULE_DIR$/generated/main/resources']")\r
+      end\r
+    end\r
+\r
+    describe "using add_jruby_facet" do\r
+      before do\r
+\r
+        @foo = define "foo" do\r
+          iml.add_jruby_facet\r
+        end\r
+        invoke_generate_task\r
+      end\r
+\r
+      it "generates a jruby facet with appropriate sdk" do\r
+        doc = xml_document(@foo._("foo.iml"))\r
+        facet_xpath = "/module/component[@name='FacetManager']/facet"\r
+        doc.should have_nodes(facet_xpath, 1)\r
+        jruby_facet_xpath = "#{facet_xpath}[@type='JRUBY', @name='JRuby']"\r
+        doc.should have_xpath(jruby_facet_xpath)\r
+        doc.should have_xpath("#{jruby_facet_xpath}/configuration/JRUBY_FACET_CONFIG_ID[@NAME='JRUBY_SDK_NAME', VALUE='jruby-1.6.7.2']")\r
+      end\r
+\r
+      it "generates a jruby facet with appropriate paths" do\r
+        doc = xml_document(@foo._("foo.iml"))\r
+        prefix = "/module/component[@name='FacetManager']/facet[@type='JRUBY', @name='JRuby']/configuration"\r
+        doc.should have_xpath("#{prefix}/LOAD_PATH[@number='0']")\r
+        doc.should have_xpath("#{prefix}/I18N_FOLDERS[@number='0']")\r
+      end\r
+    end\r
+\r
+    describe "using add_jruby_facet with .ruby-version specified" do\r
+      before do\r
+\r
+        write ".ruby-version", "jruby-1.7.2"\r
+\r
+        @foo = define "foo" do\r
+          iml.add_jruby_facet\r
+        end\r
+        invoke_generate_task\r
+      end\r
+\r
+      it "generates a jruby facet with appropriate sdk" do\r
+        doc = xml_document(@foo._("foo.iml"))\r
+        facet_xpath = "/module/component[@name='FacetManager']/facet"\r
+        doc.should have_nodes(facet_xpath, 1)\r
+        jruby_facet_xpath = "#{facet_xpath}[@type='JRUBY', @name='JRuby']"\r
+        doc.should have_xpath(jruby_facet_xpath)\r
+        doc.should have_xpath("#{jruby_facet_xpath}/configuration/JRUBY_FACET_CONFIG_ID[@NAME='JRUBY_SDK_NAME', VALUE='rbenv: jruby-1.7.2']")\r
+      end\r
+\r
+      it "generates a jruby facet with appropriate paths" do\r
+        doc = xml_document(@foo._("foo.iml"))\r
+        prefix = "/module/component[@name='FacetManager']/facet[@type='JRUBY', @name='JRuby']/configuration"\r
+        doc.should have_xpath("#{prefix}/LOAD_PATH[@number='0']")\r
+        doc.should have_xpath("#{prefix}/I18N_FOLDERS[@number='0']")\r
+      end\r
+    end\r
+\r
     describe "with artifacts added to root project" do\r
       before do\r
         @foo = define "foo" do\r