forked from AlfrescoArchive/alfresco-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
218 lines (174 loc) · 4.97 KB
/
build.gradle
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
apply plugin: 'java'
apply plugin: 'eclipse'
sourceJavaDir = 'source/java'
alfrescoBaseVersion='4.2.a'
warFileName='alfresco.war'
configDir = 'config'
explodedDepsDir = 'explodedDeps'
explodedLibsDir = "${explodedDepsDir}/lib"
explodedConfigDir = "${explodedDepsDir}/config"
assembleDir = 'build/assemble'
sourceWebDir = 'source/web'
buildDistDir = 'build/dist'
buildLibDir = 'build/libs'
configModuleDir = "config/alfresco/module/${moduleid}"
moduleProperties = 'module.properties'
fileMapping = 'file-mapping.properties'
baseName = "${groupid}-${appName}-${version}-${build}"
jarFile = "${baseName}.jar"
ampFile = "${baseName}.amp"
jarFilePath = "${buildLibDir}/${jarFile}"
warFile = "${explodedDepsDir}/${warFileName}"
buildscript {
repositories {
maven {
url "https://artifacts.alfresco.com/nexus/content/groups/public/"
}
mavenCentral()
}
dependencies {
classpath 'com.yahoo.platform.yui:yuicompressor:2.4.6'
classpath 'org.alfresco:alfresco-mmt:4.2.b'
}
}
sourceSets {
main {
java {
srcDir sourceJavaDir
}
}
}
repositories {
maven {
url "https://artifacts.alfresco.com/nexus/content/groups/public/"
}
mavenCentral()
}
dependencies {
testRuntime group: 'org.alfresco', name: 'alfresco', version: alfrescoBaseVersion, type: 'war'
compile fileTree(dir: explodedLibsDir, include: '*.jar')
compile fileTree(dir: 'lib', include: '*.jar')
compile 'javax.servlet:servlet-api:2.5'
runtime 'postgresql:postgresql:9.0-801.jdbc4'
testCompile 'org.springframework:spring-test:2.5'
testRuntime files(explodedConfigDir)
testRuntime files(configDir)
}
eclipse {
classpath {
file {
withXml {
Map<String, String> map = new HashMap<String, String>()
map.put('kind', 'src')
map.put('path', configDir)
def node = it.asNode()
node.appendNode('classpathentry', map)
}
}
}
}
task fetchWarFile(type:Copy) {
from configurations.testRuntime
into explodedDepsDir
include '*.war'
rename { String filename -> warFileName }
}
// make sure that the dependancies have been unpacked before compiling the Java
compileJava.doFirst {
explodeDeps.execute()
}
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'
jar.archiveName = jarFile
task explodeDeps << {
explodedDir = file(explodedDepsDir)
explodedLibDir = file(explodedLibsDir)
explodedConfigDir = file("${explodedDepsDir}/config")
warFileObj = file(warFile)
// if the WAR file still isn't there raise an error
if (warFileObj.exists() == true) {
logger.lifecycle "${warFile} was found. Checking dependancies ..."
if (explodedDir.exists() == false) {
println(" ... creating destination dir ${explodedDir}")
explodedDir.mkdir()
}
if (isUnpacked(explodedLibDir) == false) {
println(" ... unpacking libs into ${explodedLibDir}")
ant.unzip(src: warFileObj, dest: explodedLibDir) {
ant.patternset {
ant.include(name: 'WEB-INF/lib/*.jar')
}
ant.mapper(type: 'flatten')
}
}
if (isUnpacked(explodedConfigDir) == false) {
println(" ... unpacking config into ${explodedConfigDir}")
ant.unzip(src: warFileObj, dest: explodedDir) {
ant.patternset {
ant.include(name: 'WEB-INF/classes/**/*')
}
}
copy {
from "${explodedDir}/WEB-INF/classes"
into explodedConfigDir
}
// TODO understand why this doesn't delete the folder as expected
ant.delete(includeEmptyDirs: 'true') {
ant.fileset(dir: "${explodedDir}/WEB-INF", includes: '**/*')
}
}
}
else {
logger.error "Dependant WAR file ${warFile} can not be found. Please place it in ${warFileObj.getPath()} to continue."
throw new TaskInstantiationException("Dependant WAR file ${warFile} can not be found. Please place it in ${warFileObj.getPath()} or execute fetchWarFile to continue.")
}
}
task amp(dependsOn: 'jar') << {
delete assembleDir
copy {
from "${configModuleDir}"
include "${moduleProperties}"
include "${fileMapping}"
into assembleDir
}
copy {
from jarFilePath
into "${assembleDir}/lib"
}
copy {
from configDir
exclude "**/${moduleProperties}"
exclude "**/${fileMapping}"
into "${assembleDir}/config"
}
copy {
from sourceWebDir
include '**/*'
into "${assembleDir}/web"
}
tree = fileTree("${assembleDir}/web") {
include '**/*.js'
exclude '**/*-min.js'
}
tree.each {File file ->
destinationFile = new File(file.getPath().replaceFirst('\\.js', '-min.js'))
file.withReader{ reader ->
compressor = new com.yahoo.platform.yui.compressor.JavaScriptCompressor(reader, null)
destinationFile.withWriter { writer ->
compressor.compress(writer, -1, false, false, false, false)
}
}
}
ant.zip(destfile: "${buildDistDir}/${ampFile}", update: 'true') {
ant.zipfileset(dir: assembleDir)
}
}
/** Utility function - indicates wether the provided dir is unpacked (ie exists and has some contents) */
Boolean isUnpacked(dir) {
if (dir.exists() == true && dir.list().length > 0) {
return true
}
else {
return false
}
}