-
Notifications
You must be signed in to change notification settings - Fork 166
/
AddAssociateSites.groovy
81 lines (59 loc) · 2.32 KB
/
AddAssociateSites.groovy
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
73
74
75
76
77
78
79
80
81
def addAssociateSite( root, siteUrl )
{
def refs = root.references
if( !refs || refs.size() == 0 )
{
def newRefs = new Node( root, 'references' )
newRefs.@size = "4"
refs = root.references
}
new Node( refs.get( 0 ), 'repository', [ uri:siteUrl, url:siteUrl, type:'1', options:'1'] )
new Node( refs.get( 0 ), 'repository', [ uri:siteUrl, url:siteUrl, type:'0', options:'1'] )
}
def basedir = project.basedir.canonicalPath
def repositoryDir = basedir + "/target/repository"
def contentJar = repositoryDir + "/content.jar"
def contentDir = basedir + "/target/content.jar/"
println 'Unzipping content.jar'
def ant = new AntBuilder(); // create an antbuilder
ant.unzip( src: contentJar, dest:contentDir, overwrite:"true" )
println 'Modify content.xml to add associate sites for Liferay IDE'
File contentXml = new File( contentDir, "content.xml" )
def parser = new XmlParser()
parser.setTrimWhitespace( false )
def root = parser.parseText( contentXml.text )
def m2eSite = project.properties.getProperty("m2e-site")
def m2eWtpSite = project.properties.getProperty("m2e-wtp-site")
addAssociateSite( root, m2eSite )
addAssociateSite( root, m2eWtpSite )
class MyXmlNodePrinter extends XmlNodePrinter
{
MyXmlNodePrinter(PrintWriter out)
{
super(out)
}
void printSimpleItem(Object value)
{
value = value.replaceAll("\n", "
")
out.print(value)
}
}
println 'Overwriting content.xml'
def writer = new StringWriter()
def printer = new XmlNodePrinter( new PrintWriter( writer ) )
printer.setPreserveWhitespace( true )
printer.print( root )
def result = writer.toString()
contentXml.text = result
println 'Zipping back customized content.jar'
ant.zip( destFile: contentJar, baseDir:contentDir )
def zipSite = basedir + "/target/${project.artifactId}-${project.version}.zip"
println 'Deleting old zip site'
new File( zipSite ).delete()
def unqualifiedVersion = project.properties.getProperty("unqualifiedVersion")
def buildQualifier = project.properties.getProperty("buildQualifier")
println 'Zipping updated site'
ant.zip( destFile: zipSite, baseDir:repositoryDir )
println 'Copying to final version'
File newZipSite = new File( basedir + "/target/Liferay_IDE_Maven_${unqualifiedVersion}.${buildQualifier}-updatesite.zip" )
ant.copy( file:zipSite, tofile:newZipSite )