Skip to content

Commit 1188743

Browse files
committed
add more profile activation DSL
1 parent dfa9b27 commit 1188743

File tree

8 files changed

+198
-189
lines changed

8 files changed

+198
-189
lines changed

lib/maven/tools/dsl.rb

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def licenses
416416
alias :plugin_repositories :licenses
417417
alias :resources :licenses
418418
alias :testResources :licenses
419-
alias :plugins :licenses
419+
alias :profiles :licenses
420420

421421
def extensions(*args)
422422
if @context == :plugin || @context == :report_plugin
@@ -632,6 +632,19 @@ def file( options )
632632
@current.file = file
633633
end
634634

635+
def os( options )
636+
os = ActivationOS.new
637+
os.family = options[ :family ] || options[ 'family' ]
638+
os.version = options[ :version ] || options[ 'version' ]
639+
os.arch = options[ :arch ] || options[ 'arch' ]
640+
os.name = options[ :name ] || options[ 'name' ]
641+
@current.os = os
642+
end
643+
644+
def jdk( version )
645+
@current.jdk = version
646+
end
647+
635648
def activation( &block )
636649
activation = Activation.new
637650
nested_block( :activation, activation, block ) if block
@@ -934,21 +947,25 @@ def plugin_gav( *gav )
934947
end
935948
private :plugin_gav
936949

937-
def plugins
938-
if @current.respond_to? :build
939-
@current.build ||= Build.new
940-
if @context == :overrides
941-
@current.build.plugin_management ||= PluginManagement.new
942-
@current.build.plugin_management.plugins
943-
else
944-
@current.build.plugins
945-
end
950+
def plugins(&block)
951+
if block
952+
block.call
946953
else
947-
if @context == :overrides
948-
@current.plugin_management ||= PluginManagement.new
949-
@current.plugin_management.plugins
954+
if @current.respond_to? :build
955+
@current.build ||= Build.new
956+
if @context == :overrides
957+
@current.build.plugin_management ||= PluginManagement.new
958+
@current.build.plugin_management.plugins
959+
else
960+
@current.build.plugins
961+
end
950962
else
951-
@current.plugins
963+
if @context == :overrides
964+
@current.plugin_management ||= PluginManagement.new
965+
@current.plugin_management.plugins
966+
else
967+
@current.plugins
968+
end
952969
end
953970
end
954971
end

lib/maven/tools/model.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,15 @@ class Build
295295
attribute :plugin_management, PluginManagement
296296
attribute :plugins, Array[ Plugin ]
297297
end
298-
class Os
298+
class ActivationOS
299299
include Base
300300

301301
attribute :name, String
302302
attribute :family, String
303303
attribute :arch, String
304304
attribute :version, String
305305
end
306-
class Property
306+
class ActivationProperty
307307
include Base
308308

309309
attribute :name, String
@@ -320,8 +320,8 @@ class Activation
320320

321321
attribute :active_by_default, Boolean
322322
attribute :jdk, String
323-
attribute :os, Os
324-
attribute :property, Property
323+
attribute :os, ActivationOS
324+
attribute :property, ActivationProperty
325325
attribute :file, ActivationFile
326326
end
327327
class Profile

lib/maven/tools/visitor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def accept_hash( name, hash )
146146
end
147147

148148
def escape_value( value )
149-
value = value.to_s
149+
value = value.to_s.dup
150150
value.gsub!( /&/, '&' )
151151
# undo double quote, somehow xyz.gemspec.rz have encoded values
152152
value.gsub!( /&(amp|lt|gt);/, '&\1;' )

spec/mavenfile/Mavenfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ plugin 'org.codehaus.mojo:exec-maven-plugin' do
265265
end
266266

267267
plugin_management do
268+
jruby_plugin( :gem, '1.1.5', :scope => :compile,
269+
:gems => {
270+
'thread_safe' => '0.3.3',
271+
'jdbc-mysql' => '5.1.30'
272+
} )
268273
plugin( "org.mortbay.jetty:jetty-maven-plugin:8.1",
269274
:path => '/',
270275
:connectors => [ { :@implementation => "org.eclipse.jetty.server.nio.SelectChannelConnector",
@@ -277,6 +282,16 @@ plugin_management do
277282
:httpConnector => { :port => '${run.port}' } )
278283
end
279284

285+
profile :id => 'one' do
286+
activation do
287+
active_by_default false
288+
jdk '1.7'
289+
os :family => 'nix', :version => '2.7', :arch => 'x86_64', :name => 'linux'
290+
file :missing => 'required_file', :exists => 'optional'
291+
property :name => 'test', :value => 'extended'
292+
end
293+
end
294+
280295
# <groupId/>
281296
# <artifactId/>
282297
# <version/>

spec/pom.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,18 @@
314314
<finalName>myproject</finalName>
315315
<pluginManagement>
316316
<plugins>
317+
<plugin>
318+
<groupId>de.saumya.mojo</groupId>
319+
<artifactId>gem-maven-plugin</artifactId>
320+
<version>1.1.5</version>
321+
<configuration>
322+
<scope>compile</scope>
323+
<gems>
324+
<thread_safe>0.3.3</thread_safe>
325+
<jdbc-mysql>5.1.30</jdbc-mysql>
326+
</gems>
327+
</configuration>
328+
</plugin>
317329
<plugin>
318330
<groupId>org.mortbay.jetty</groupId>
319331
<artifactId>jetty-maven-plugin</artifactId>
@@ -424,4 +436,27 @@
424436
</plugin>
425437
</plugins>
426438
</build>
439+
<profiles>
440+
<profile>
441+
<id>one</id>
442+
<activation>
443+
<activeByDefault>false</activeByDefault>
444+
<jdk>1.7</jdk>
445+
<os>
446+
<name>linux</name>
447+
<family>nix</family>
448+
<arch>x86_64</arch>
449+
<version>2.7</version>
450+
</os>
451+
<property>
452+
<name>test</name>
453+
<value>extended</value>
454+
</property>
455+
<file>
456+
<missing>required_file</missing>
457+
<exists>optional</exists>
458+
</file>
459+
</activation>
460+
</profile>
461+
</profiles>
427462
</project>

spec/pom_maven_alternative_style/pom.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@
207207
end
208208

209209
overrides do
210+
jruby_plugin( :gem, '1.1.5', :scope => :compile,
211+
:gems => {
212+
'thread_safe' => '0.3.3',
213+
'jdbc-mysql' => '5.1.30'
214+
} )
210215
plugin( "org.mortbay.jetty:jetty-maven-plugin:8.1",
211216
:path => '/',
212217
:connectors => [ { :@implementation => "org.eclipse.jetty.server.nio.SelectChannelConnector",
@@ -220,6 +225,15 @@
220225
end
221226

222227
end
228+
profile :id => 'one' do
229+
activation do
230+
active_by_default false
231+
jdk '1.7'
232+
os :family => 'nix', :version => '2.7', :arch => 'x86_64', :name => 'linux'
233+
file :missing => 'required_file', :exists => 'optional'
234+
property :name => 'test', :value => 'extended'
235+
end
236+
end
223237
end
224238

225239
# <build>

spec/pom_maven_hash_style/pom.rb

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,33 +216,45 @@
216216
plugin 'org.codehaus.mojo:exec-maven-plugin' do
217217
execute_goal( 'exec',
218218
:id => 'invoker-generator',
219-
'arguments' => [ '-Djruby.bytecode.version=${base.java.version}',
219+
:arguments => [ '-Djruby.bytecode.version=${base.java.version}',
220220
'-classpath',
221221
xml( '<classpath/>' ),
222222
'org.jruby.anno.InvokerGenerator',
223223
'${anno.sources}/annotated_classes.txt',
224224
'${project.build.outputDirectory}' ],
225-
'executable' => 'java',
226-
'classpathScope' => 'compile' )
225+
:executable => 'java',
226+
:classpath_scope => 'compile' )
227227
end
228228

229229
plugin_management do
230+
jruby_plugin( :gem, '1.1.5', :scope => :compile,
231+
:gems => {
232+
'thread_safe' => '0.3.3',
233+
'jdbc-mysql' => '5.1.30'
234+
} )
230235
plugin( "org.mortbay.jetty:jetty-maven-plugin:8.1",
231236
:path => '/',
232237
:connectors => [ { :@implementation => "org.eclipse.jetty.server.nio.SelectChannelConnector",
233238
:port => '${run.port}' },
234239
{ :@implementation => "org.eclipse.jetty.server.ssl.SslSelectChannelConnector",
235240
:port => '${run.sslport}',
236241
:keystore => '${run.keystore}',
237-
:keyPassword => '${run.keystore.pass}',
238-
:trustPassword => '${run.truststore.pass}' } ],
239-
:httpConnector => { :port => '${run.port}' } )
242+
:key_password => '${run.keystore.pass}',
243+
:trust_password => '${run.truststore.pass}' } ],
244+
:http_connector => { :port => '${run.port}' } )
245+
end
246+
end
247+
profile :id => 'one' do
248+
activation do
249+
active_by_default false
250+
jdk '1.7'
251+
os :family => 'nix', :version => '2.7', :arch => 'x86_64', :name => 'linux'
252+
file :missing => 'required_file', :exists => 'optional'
253+
property :name => 'test', :value => 'extended'
240254
end
241255
end
242256
end
243257

244-
# <directory/>
245-
# <finalName/>
246258
# <filters/>
247259
# </build>
248260

0 commit comments

Comments
 (0)