forked from liferay/liferay-blade-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
231 lines (172 loc) · 6.7 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
219
220
221
222
223
224
225
226
227
228
229
230
231
buildscript {
dependencies {
classpath group: "net.diibadaaba.zipdiff", name: "zipdiff", version: "1.0"
}
repositories {
mavenCentral()
}
}
import net.diibadaaba.zipdiff.DifferenceCalculator
import net.diibadaaba.zipdiff.Differences
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
FileTree bndtoolsBundles = fileTree(dir: 'bndtools', include: '**/dist/bundles/**/*.jar', exclude: '**/*latest.jar')
FileTree gradleBundles = fileTree(dir: 'gradle', include: '**/libs/*.jar')
FileTree liferayGradleBundles = fileTree(dir: 'liferay-gradle', include: '**/libs/*.jar')
FileTree liferayWorkspaceBundles = fileTree(dir: 'liferay-workspace/modules', include: '**/libs/*.jar')
FileTree mavenBundles = fileTree(dir: 'maven', include: '**/target/*.jar')
int canonicalBundlesSize = liferayGradleBundles.size()
task bundlesSizeTest << {
assert canonicalBundlesSize == bndtoolsBundles.size()
assert canonicalBundlesSize == gradleBundles.size()
assert canonicalBundlesSize == liferayWorkspaceBundles.size()
assert canonicalBundlesSize == mavenBundles.size()
}
FileTree gradleWars = fileTree(dir: 'gradle', include: '**/libs/*.war')
FileTree liferayWorkspaceWars = fileTree(dir: 'liferay-workspace/wars', include: '**/libs/*.war')
FileTree liferayGradleWars = fileTree(dir: 'liferay-gradle', include: '**/libs/*.war')
FileTree mavenWars = fileTree(dir: 'maven', include: '**/target/*.war')
int canonicalWarsSize = liferayGradleWars.size()
task warsSizeTest << {
assert canonicalWarsSize == gradleWars.size()
assert canonicalWarsSize == liferayGradleWars.size()
assert canonicalWarsSize == liferayWorkspaceWars.size()
assert canonicalWarsSize == mavenWars.size()
}
task bundlesSortTest << {
def fileNamesDiff = liferayGradleBundles.files.name.sort() - gradleBundles.files.name.sort()
assert [] == fileNamesDiff : "liferay-gradle vs gradle"
fileNamesDiff = liferayGradleBundles.files.name.sort() - bndtoolsBundles.files.name.sort()
assert [] == fileNamesDiff : "liferay-gradle vs bndtools"
fileNamesDiff = liferayGradleBundles.files.name.sort() - liferayWorkspaceBundles.files.name.sort()
assert [] == fileNamesDiff : "liferay-gradle vs liferay-workspace"
fileNamesDiff = liferayGradleBundles.files.name.sort() - mavenBundles.files.name.sort()
assert [] == fileNamesDiff : "liferay-gradle vs maven"
}
task bundlesTest << {}
bundlesTest.dependsOn bundlesSizeTest
bundlesTest.dependsOn bundlesSortTest
task warsTest << {}
warsTest.dependsOn warsSizeTest
task replicateSources << {
Closure projectFilter = {
it.isDirectory() && it.name.startsWith("blade") && !it.name.matches("\\..*")
}
def canonicalSource
if (project.hasProperty('sourceProjectProp')) {
canonicalSource = sourceProjectProp
}
else {
canonicalSource = 'liferay-gradle'
}
def canonicalProjects = file(canonicalSource).listFiles().findAll(projectFilter)
def replicationParents = files(['bndtools', 'gradle', 'liferay-gradle', 'liferay-workspace/modules', 'maven'] - canonicalSource)
canonicalProjects.each { canonicalProject ->
if ((new File(canonicalProject, "bnd.bnd").exists())) {
replicationParents.each { replicationParent ->
def replicationProjects = replicationParent.listFiles().findAll(projectFilter)
def replicationProject = replicationProjects.find{ it.name == canonicalProject.name }
if (replicationProject == null) {
replicationProject = new File(replicationParent, canonicalProject.name)
replicationProject.mkdirs()
def buildFilesProject = new File(replicationParent, "blade.portlet.jsp")
ant.copy(todir: replicationProject) {
fileset(dir: buildFilesProject, includes: "*")
}
}
ant.copy(todir: replicationProject) {
fileset(dir: canonicalProject, includes: "*.markdown")
}
def replicationSrc = new File( replicationProject, 'src/' )
replicationSrc.deleteDir()
def canonicalSrc = new File( canonicalProject, 'src/' )
ant.copy(todir: replicationSrc) {
fileset(dir: canonicalSrc, includes: "**")
}
}
}
}
}
configurations {
bnd
}
dependencies {
bnd group: "biz.aQute.bnd", name: "biz.aQute.bnd", version: "3.1.0"
}
repositories {
mavenCentral()
}
task bundlesDiffTest << {
def errorList = []
[bndtoolsBundles, gradleBundles, liferayWorkspaceBundles, mavenBundles].each { replicationFiles ->
replicationFiles.each { replicationFile ->
def liferayGradleOutputFile = liferayGradleBundles.find {
it.name == replicationFile.name
}
String exclusions = "*pom.properties, *pom.xml, Archiver-Version, Built-By, Build-Jdk, Javac-Debug, Javac-Deprecation, Javac-Encoding"
def os = new ByteArrayOutputStream()
javaexec {
args "diff", "-i", "${exclusions}", replicationFile, liferayGradleOutputFile
classpath = configurations.bnd
main = "aQute.bnd.main.bnd"
standardOutput = os
}
def errorOutput = os.toString()
if (errorOutput) {
errorList.add("${replicationFiles} - ${replicationFile.name} \n" + errorOutput)
}
}
}
if (!errorList.empty) {
throw new GradleException(errorList.toListString())
}
}
task warsDiffTest << {
[gradleWars, liferayWorkspaceWars, mavenWars].each { replicationWars ->
replicationWars.each { replicationWar ->
def liferayGradleWar = liferayGradleWars.find {
it.name == replicationWar.name.replaceAll("-1.0.0", "")
}
DifferenceCalculator differenceCalculator = new DifferenceCalculator(
replicationWar, liferayGradleWar)
differenceCalculator.setFilenameRegexToIgnore(
Collections.singleton(".*META-INF.*"))
differenceCalculator.setIgnoreTimestamps(true)
Differences differences = differenceCalculator.getDifferences()
if (differences.hasDifferences()) {
boolean realChange = false
def added = differences.getAdded()
def changed = differences.getChanged()
def removed = differences.getRemoved()
if (added.isEmpty() && !changed.isEmpty() && removed.isEmpty()) {
for (String change : changed.keySet()) {
ZipArchiveEntry[] zipArchiveEntries = changed.get(change);
ZipArchiveEntry zipArchiveEntry1 = zipArchiveEntries[0];
ZipArchiveEntry zipArchiveEntry2 = zipArchiveEntries[0];
if (zipArchiveEntry1.isDirectory() &&
zipArchiveEntry2.isDirectory() &&
(zipArchiveEntry1.getSize() ==
zipArchiveEntry2.getSize()) &&
(zipArchiveEntry1.getCompressedSize() <= 2) &&
(zipArchiveEntry2.getCompressedSize() <= 2)) {
// Skip zipdiff bug
continue;
}
realChange = true;
break;
}
}
else {
realChange = true;
}
if (realChange) {
throw new GradleException(
"WAR " + replicationWar + " and " + liferayGradleWar + " do not match:\n" +
differences)
}
}
}
}
}
task diff << {}
diff.dependsOn bundlesDiffTest
diff.dependsOn warsDiffTest