Skip to content

Commit 714b507

Browse files
committed
WEBSITE-175 Allow site generation to succeed in development profile even if release poms are not avaialable
1 parent 0911b65 commit 714b507

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

_ext/release_file_parser.rb

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def createHashForRelease(hash, file, site, group_id, artifact_id)
6969
end
7070
releaseHash = site.engine.load_yaml( file )
7171
if( group_id != nil && artifact_id != nil)
72-
releaseHash['dependencies'] = ReleaseDependencies.new(group_id, artifact_id, releaseHash['version'])
72+
releaseHash['dependencies'] = ReleaseDependencies.new(site, group_id, artifact_id, releaseHash['version'])
7373
end
7474
# use a regexp to get the file name without extension into the pattern buffer.
7575
# file name == version
@@ -124,21 +124,24 @@ def to_s
124124
class ReleaseDependencies
125125
Nexus_base_url = 'https://repository.jboss.org/nexus/content/repositories/public/'
126126

127-
def initialize(group_id, artifact_id, version)
127+
def initialize(site, group_id, artifact_id, version)
128128
# init instance variables
129129
@properties = Hash.new
130130
@dependencies = Hash.new
131+
@site = site
131132

132133
# try loading the pom
133134
uri = get_uri(group_id, artifact_id, version)
134135
doc = create_doc(uri)
135-
if has_parent(doc)
136-
# parent pom needs to be loaded first
137-
parent_uri = get_uri(doc.xpath('//parent/groupId').text, doc.xpath('//parent/artifactId').text, doc.xpath('//parent/version').text)
138-
parent_doc = create_doc(parent_uri)
139-
process_doc(parent_doc)
136+
unless doc.nil?
137+
if has_parent(doc)
138+
# parent pom needs to be loaded first
139+
parent_uri = get_uri(doc.xpath('//parent/groupId').text, doc.xpath('//parent/artifactId').text, doc.xpath('//parent/version').text)
140+
parent_doc = create_doc(parent_uri)
141+
process_doc(parent_doc)
142+
end
143+
process_doc(doc)
140144
end
141-
process_doc(doc)
142145
end
143146

144147
def get_value(property)
@@ -170,8 +173,14 @@ def create_doc(uri)
170173
doc = Nokogiri::XML(open(uri))
171174
# cache the pom
172175
File.open(cached_pom, 'w') { |f| f.print(doc.to_xml) }
173-
rescue OpenURI::HTTPError => error
174-
raise "Unable to access uri #{uri}. Reason: #{error}"
176+
rescue => error
177+
$LOG.warn "Release POM #{uri.split('/').last} not locally cached and unable to retrieve it from JBoss Nexus"
178+
if @site.profile == 'production'
179+
abort "Aborting site generation, since the production build requires the release POM information"
180+
else
181+
$LOG.warn "Continue build since we are building the '#{@site.profile}' profile. Note that variables interpolated from the release poms will not display\n"
182+
return nil
183+
end
175184
end
176185
end
177186
doc.remove_namespaces!

_spec/release_dependencies_spec.rb

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
1+
require 'awestruct/logger'
2+
# need to create the logger prior to loading the engine module to avoid errors when the code
3+
# tries to access the logger
4+
$LOG = Logger.new(Awestruct::AwestructLoggerMultiIO.new)
5+
$LOG.level = Logger::DEBUG
6+
$LOG.formatter = Awestruct::AwestructLogFormatter.new
7+
18
require_relative '../_ext/release_file_parser'
29

310
describe Awestruct::Extensions::ReleaseDependencies do
411

512
before :all do
13+
site_dir = File.join(File.dirname(__FILE__), '..')
14+
opts = Awestruct::CLI::Options.new
15+
opts.source_dir = site_dir
16+
@config = Awestruct::Config.new( opts )
17+
18+
@engine = Awestruct::Engine.new( @config )
19+
@engine.load_default_site_yaml
20+
@site = Awestruct::Site.new( @engine, @config )
21+
622
@deps = [
7-
Awestruct::Extensions::ReleaseDependencies.new('org.hibernate', 'hibernate-core', '4.0.0.Beta1'),
8-
Awestruct::Extensions::ReleaseDependencies.new('org.hibernate', 'hibernate-search-parent', '3.4.0.Final'),
9-
Awestruct::Extensions::ReleaseDependencies.new('org.hibernate', 'hibernate-search', '3.4.0.Final')
23+
Awestruct::Extensions::ReleaseDependencies.new(@site, 'org.hibernate', 'hibernate-core', '4.0.0.Beta1'),
24+
Awestruct::Extensions::ReleaseDependencies.new(@site, 'org.hibernate', 'hibernate-search-parent', '3.4.0.Final'),
25+
Awestruct::Extensions::ReleaseDependencies.new(@site, 'org.hibernate', 'hibernate-search', '3.4.0.Final')
1026
]
1127
end
1228

1329
describe "#initalize" do
14-
it 'raises error for invalid project/version' do
15-
expect { Awestruct::Extensions::ReleaseDependencies.new('org.hibernate', 'hibernate-core', '0.Final') }
16-
.to raise_error(/Unable to access uri/)
17-
end
30+
it 'raises error when pom cannot be accessed for production profile' do
31+
site = Awestruct::Site.new( @engine, @config )
32+
site.profile = 'production'
33+
expect { Awestruct::Extensions::ReleaseDependencies.new(site, 'org.hibernate', 'hibernate-core', '0.Final') }
34+
.to raise_error(/Aborting site generation, since the production build requires the release POM information/)
35+
end
1836
end
1937

2038
describe "#get_value" do

0 commit comments

Comments
 (0)