Repository: buildr
Updated Branches:
  refs/heads/master 877e57b93 -> dd2271cfa


Add support for iml.prefix and ipr.prefix settings that prefix the generated 
IntelliJ IDEA project and module files.


Project: http://git-wip-us.apache.org/repos/asf/buildr/repo
Commit: http://git-wip-us.apache.org/repos/asf/buildr/commit/96579700
Tree: http://git-wip-us.apache.org/repos/asf/buildr/tree/96579700
Diff: http://git-wip-us.apache.org/repos/asf/buildr/diff/96579700

Branch: refs/heads/master
Commit: 965797005df5e7864a13ba494a8984335473d160
Parents: 877e57b
Author: Peter Donald <[email protected]>
Authored: Sat Feb 28 20:16:46 2015 +1100
Committer: Peter Donald <[email protected]>
Committed: Sat Feb 28 20:16:46 2015 +1100

----------------------------------------------------------------------
 CHANGELOG              |  2 ++
 doc/more_stuff.textile | 18 +++++++++++++++
 lib/buildr/ide/idea.rb |  8 ++++++-
 spec/ide/idea_spec.rb  | 54 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 81 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/buildr/blob/96579700/CHANGELOG
----------------------------------------------------------------------
diff --git a/CHANGELOG b/CHANGELOG
index a3b66f7..5fca8dc 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,6 @@
 1.4.22 (Pending)
+* Added:  Add support for iml.prefix and ipr.prefix settings that prefix the 
generated
+          IntelliJ IDEA project and module files.
 * Change: Update the buildr gemspec so that rspec is no longer a required 
dependency.
           This enables end-users to use a different version of rspec and 
buildr in
           the same project. The rspec version MUST be be compatible with the 
version

http://git-wip-us.apache.org/repos/asf/buildr/blob/96579700/doc/more_stuff.textile
----------------------------------------------------------------------
diff --git a/doc/more_stuff.textile b/doc/more_stuff.textile
index 043f80f..e1697e6 100644
--- a/doc/more_stuff.textile
+++ b/doc/more_stuff.textile
@@ -528,6 +528,24 @@ foo-suffix2.iml
 bar/bar-suffix2.iml
 </pre>
 
+h5. Example: Setting prefix
+
+{% highlight ruby %}
+define "foo" do
+  ipr.prefix = "prefix1-"
+  iml.prefix = "prefix2-"
+  define "bar"
+end
+{% endhighlight %}
+
+Will generate:
+
+<pre>
+prefix1-foo.ipr
+prefix2-foo.iml
+bar/prefix2-bar.iml
+</pre>
+
 h4. Disabling project file generation
 
 The extension will not generate an iml file for a project if the 
"project.no_iml" method is invoked. Generation of ipr files can be disabled by 
invoking the method "project.no_ipr".

http://git-wip-us.apache.org/repos/asf/buildr/blob/96579700/lib/buildr/ide/idea.rb
----------------------------------------------------------------------
diff --git a/lib/buildr/ide/idea.rb b/lib/buildr/ide/idea.rb
index 9c5a46b..893f93b 100644
--- a/lib/buildr/ide/idea.rb
+++ b/lib/buildr/ide/idea.rb
@@ -21,10 +21,12 @@ module Buildr #:nodoc:
 
     # Abstract base class for IdeaModule and IdeaProject
     class IdeaFile
+      DEFAULT_PREFIX = ''
       DEFAULT_SUFFIX = ''
       DEFAULT_LOCAL_REPOSITORY_ENV_OVERRIDE = 'MAVEN_REPOSITORY'
 
       attr_reader :buildr_project
+      attr_writer :prefix
       attr_writer :suffix
       attr_writer :id
       attr_accessor :template
@@ -34,6 +36,10 @@ module Buildr #:nodoc:
         @local_repository_env_override = DEFAULT_LOCAL_REPOSITORY_ENV_OVERRIDE
       end
 
+      def prefix
+        @prefix ||= DEFAULT_PREFIX
+      end
+
       def suffix
         @suffix ||= DEFAULT_SUFFIX
       end
@@ -72,7 +78,7 @@ module Buildr #:nodoc:
       end
 
       def name
-        "#{self.id}#{suffix}"
+        "#{prefix}#{self.id}#{suffix}"
       end
 
       protected

http://git-wip-us.apache.org/repos/asf/buildr/blob/96579700/spec/ide/idea_spec.rb
----------------------------------------------------------------------
diff --git a/spec/ide/idea_spec.rb b/spec/ide/idea_spec.rb
index a60c29a..5b95702 100644
--- a/spec/ide/idea_spec.rb
+++ b/spec/ide/idea_spec.rb
@@ -1293,6 +1293,60 @@ describe Buildr::IntellijIdea do
           doc.should 
have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}' and 
@filepath='#{module_ref}']", 1)
         end
       end
+
+      describe "and a prefix defined" do
+        before do
+          @foo = define "foo" do
+            ipr.prefix = 'ipr-prefix-'
+            iml.prefix = 'iml-prefix-'
+          end
+          invoke_generate_task
+        end
+
+        it "generate an IPR in the root directory" do
+          File.should be_exist(@foo._("ipr-prefix-foo.ipr"))
+        end
+
+        it "generates an IML in the root directory" do
+          File.should be_exist(@foo._("iml-prefix-foo.iml"))
+        end
+
+        it "generate an IPR with the reference to correct module file" do
+          File.should be_exist(@foo._("ipr-prefix-foo.ipr"))
+          doc = xml_document(@foo._("ipr-prefix-foo.ipr"))
+          doc.should have_nodes("#{xpath_to_module}", 1)
+          module_ref = "$PROJECT_DIR$/iml-prefix-foo.iml"
+          doc.should 
have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}' and 
@filepath='#{module_ref}']", 1)
+        end
+      end
+
+      describe "and a suffix and a prefix defined" do
+        before do
+          @foo = define "foo" do
+            ipr.suffix = '-ipr-suffix'
+            iml.suffix = '-iml-suffix'
+            ipr.prefix = 'ipr-prefix-'
+            iml.prefix = 'iml-prefix-'
+          end
+          invoke_generate_task
+        end
+
+        it "generate an IPR in the root directory" do
+          File.should be_exist(@foo._("ipr-prefix-foo-ipr-suffix.ipr"))
+        end
+
+        it "generates an IML in the root directory" do
+          File.should be_exist(@foo._("iml-prefix-foo-iml-suffix.iml"))
+        end
+
+        it "generate an IPR with the reference to correct module file" do
+          File.should be_exist(@foo._("ipr-prefix-foo-ipr-suffix.ipr"))
+          doc = xml_document(@foo._("ipr-prefix-foo-ipr-suffix.ipr"))
+          doc.should have_nodes("#{xpath_to_module}", 1)
+          module_ref = "$PROJECT_DIR$/iml-prefix-foo-iml-suffix.iml"
+          doc.should 
have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}' and 
@filepath='#{module_ref}']", 1)
+        end
+      end
     end
 
     describe "with a subproject" do

Reply via email to