-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmavenInjector.rb
72 lines (60 loc) · 1.87 KB
/
mavenInjector.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#/usr/bin/env ruby
require 'rexml/document.rb'
require 'fileutils.rb'
class MavenInjector
def inject(path)
if(path == nil)
puts 'Must provide the root path of the node to inject under.'
exit
end
poms = Dir[Dir.pwd() + "/**/pom.xml"]
for pom in poms do
if(!File.writable?(pom))
FileUtils.chmod 0644, pom
end
pomXML = REXML::Document.new(File.new(pom))
element = pomXML.get_elements(path)[0]
if(element == nil)
parentElement = pomXML.get_elements("/project/build")[0]
element = REXML::Element.new("plugins", parentElement)
end
for plugin in getElementsToInject() do
element.add_element(plugin)
end
formatter = REXML::Formatters::Default.new(4)
formatter.write(pomXML, File.new(pom, "w+"))
end
end
def getElementsToInject()
elementXML = REXML::Document.new(SNIPPET)
return elementXML.get_elements("/inject/plugin")
end
end
SNIPPET = <<HEAD
<inject>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<formats>
<format>html</format>
</formats>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<enableFilesSummary>false</enableFilesSummary>
<enableRulesSummary>false</enableRulesSummary>
<outputFileFormat>plain</outputFileFormat>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>javancss-maven-plugin</artifactId>
<version>2.0-beta-2</version>
</plugin>
</inject>
HEAD
MavenInjector.new.inject(ARGV[0])