Simplify the integration of custom_pom extension into the core
Project: http://git-wip-us.apache.org/repos/asf/buildr/repo Commit: http://git-wip-us.apache.org/repos/asf/buildr/commit/75e72a94 Tree: http://git-wip-us.apache.org/repos/asf/buildr/tree/75e72a94 Diff: http://git-wip-us.apache.org/repos/asf/buildr/diff/75e72a94 Branch: refs/heads/master Commit: 75e72a94f2d340deaadab9720eb2bd70bd9c8b24 Parents: ab1554b Author: Peter Donald <[email protected]> Authored: Mon Feb 20 22:32:52 2017 +1100 Committer: Peter Donald <[email protected]> Committed: Mon Feb 20 22:34:46 2017 +1100 ---------------------------------------------------------------------- addon/buildr/bnd.rb | 2 ++ lib/buildr/java/custom_pom.rb | 25 ------------------------- lib/buildr/java/packaging.rb | 3 +++ lib/buildr/packaging/artifact.rb | 24 +++++++++++++++--------- lib/buildr/packaging/package.rb | 3 ++- spec/packaging/packaging_spec.rb | 10 +++++++++- 6 files changed, 31 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/buildr/blob/75e72a94/addon/buildr/bnd.rb ---------------------------------------------------------------------- diff --git a/addon/buildr/bnd.rb b/addon/buildr/bnd.rb index fa8c331..03ec68a 100644 --- a/addon/buildr/bnd.rb +++ b/addon/buildr/bnd.rb @@ -96,6 +96,8 @@ module Buildr super @params = {} enhance do + pom.invoke rescue nil if pom && pom != self && classifier.nil? + filename = self.name # Generate BND file with same name as target jar but different extension bnd_filename = filename.sub /(\.jar)?$/, '.bnd' http://git-wip-us.apache.org/repos/asf/buildr/blob/75e72a94/lib/buildr/java/custom_pom.rb ---------------------------------------------------------------------- diff --git a/lib/buildr/java/custom_pom.rb b/lib/buildr/java/custom_pom.rb index 4a4ee9f..7f52ea8 100644 --- a/lib/buildr/java/custom_pom.rb +++ b/lib/buildr/java/custom_pom.rb @@ -256,31 +256,6 @@ module Buildr end @pom end - - after_define do |project| - project.packages.select { |pkg| pkg.is_a?(ActsAsArtifact) }.each do |pkg| - if pkg.type.to_s == 'jar' && pkg.classifier.nil? - class << pkg - def pom_xml - self.pom.content - end - - def pom - unless @pom - pom_filename = Util.replace_extension(name, 'pom') - spec = {:group => group, :id => id, :version => version, :type => :pom} - @pom = Buildr.artifact(spec, pom_filename) - buildr_project = Buildr.project(self.scope.join(':')) - @pom.content Buildr::CustomPom.pom_xml(buildr_project, self) - end - @pom - end - end - pkg.instance_variable_set('@pom', nil) - pkg.enhance([pkg.pom.to_s]) - end - end - end end end end http://git-wip-us.apache.org/repos/asf/buildr/blob/75e72a94/lib/buildr/java/packaging.rb ---------------------------------------------------------------------- diff --git a/lib/buildr/java/packaging.rb b/lib/buildr/java/packaging.rb index 86a764c..46afa50 100644 --- a/lib/buildr/java/packaging.rb +++ b/lib/buildr/java/packaging.rb @@ -210,6 +210,9 @@ module Buildr #:nodoc: def initialize(*args) #:nodoc: super + enhance do + pom.invoke rescue nil if pom && pom != self && classifier.nil? + end end # :call-seq: http://git-wip-us.apache.org/repos/asf/buildr/blob/75e72a94/lib/buildr/packaging/artifact.rb ---------------------------------------------------------------------- diff --git a/lib/buildr/packaging/artifact.rb b/lib/buildr/packaging/artifact.rb index e417273..010a8df 100644 --- a/lib/buildr/packaging/artifact.rb +++ b/lib/buildr/packaging/artifact.rb @@ -73,6 +73,8 @@ module Buildr #:nodoc: # Optional artifact classifier. attr_reader :classifier + attr_accessor :buildr_project + def snapshot? version =~ /-SNAPSHOT$/ end @@ -145,15 +147,19 @@ module Buildr #:nodoc: # # Creates POM XML for this artifact. def pom_xml - Proc.new do - xml = Builder::XmlMarkup.new(:indent=>2) - xml.instruct! - xml.project do - xml.modelVersion '4.0.0' - xml.groupId group - xml.artifactId id - xml.version version - xml.classifier classifier if classifier + if self.buildr_project + Buildr::CustomPom.pom_xml(self.buildr_project, self) + else + Proc.new do + xml = Builder::XmlMarkup.new(:indent => 2) + xml.instruct! + xml.project do + xml.modelVersion '4.0.0' + xml.groupId group + xml.artifactId id + xml.version version + xml.classifier classifier if classifier + end end end end http://git-wip-us.apache.org/repos/asf/buildr/blob/75e72a94/lib/buildr/packaging/package.rb ---------------------------------------------------------------------- diff --git a/lib/buildr/packaging/package.rb b/lib/buildr/packaging/package.rb index 4f42933..07ecc9d 100644 --- a/lib/buildr/packaging/package.rb +++ b/lib/buildr/packaging/package.rb @@ -168,6 +168,7 @@ module Buildr #:nodoc: else # Make it an artifact using the specifications, and tell it how to create a POM. package.extend ActsAsArtifact + package.buildr_project = self package.send :apply_spec, spec.only(*Artifact::ARTIFACT_ATTRIBUTES) # Create pom associated with package @@ -177,7 +178,7 @@ module Buildr #:nodoc: pom_filename = Util.replace_extension(self.name, 'pom') spec = {:group=>group, :id=>id, :version=>version, :type=>:pom} @pom = Buildr.artifact(spec, pom_filename) - @pom.content @pom.pom_xml + @pom.content Buildr::CustomPom.pom_xml(self.buildr_project, self) end @pom end http://git-wip-us.apache.org/repos/asf/buildr/blob/75e72a94/spec/packaging/packaging_spec.rb ---------------------------------------------------------------------- diff --git a/spec/packaging/packaging_spec.rb b/spec/packaging/packaging_spec.rb index 29baf6b..2a68690 100644 --- a/spec/packaging/packaging_spec.rb +++ b/spec/packaging/packaging_spec.rb @@ -361,11 +361,19 @@ describe Project, '#package' do pom.invoke read(pom.to_s).should eql(<<-POM <?xml version="1.0" encoding="UTF-8"?> -<project> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.sonatype.oss</groupId> + <artifactId>oss-parent</artifactId> + <version>7</version> + </parent> <groupId>bar</groupId> <artifactId>foo</artifactId> <version>1.0</version> + <packaging>jar</packaging> + <name>foo</name> + <description>foo</description> </project> POM )
