forked from bndtools/bnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestIndexTask.groovy
147 lines (125 loc) · 5.16 KB
/
TestIndexTask.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
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
package aQute.bnd.gradle
import static org.gradle.testkit.runner.TaskOutcome.*
import java.util.jar.Attributes
import java.util.jar.JarFile
import java.util.zip.GZIPInputStream
import groovy.xml.XmlSlurper
import spock.lang.Specification
class TestIndexTask extends Specification {
File buildDir = new File("build")
File testResources = new File(buildDir, "testresources")
def "Simple Bnd Index Task Test"() {
given:
String testProject = "indexplugin1"
File testProjectDir = new File(testResources, testProject).canonicalFile
assert testProjectDir.isDirectory()
File testProjectBuildDir = new File(testProjectDir, "build").canonicalFile
when:
def result = TestHelper.getGradleRunner()
.withProjectDir(testProjectDir)
.withArguments("--parallel", "--stacktrace", "--debug", "indexer", "indexer2")
.withPluginClasspath()
.forwardOutput()
.build()
then:
result.task(":bundle").outcome == SUCCESS
result.task(":jar").outcome == SUCCESS
result.task(":indexer").outcome == SUCCESS
result.task(":indexer2").outcome == SUCCESS
testProjectBuildDir.isDirectory()
File jartask_bundle = new File(testProjectBuildDir, "libs/${testProject}-1.0.0.jar")
jartask_bundle.isFile()
JarFile jartask_jar = new JarFile(jartask_bundle)
Attributes jartask_manifest = jartask_jar.getManifest().getMainAttributes()
File bundletask_bundle = new File(testProjectBuildDir, "libs/${testProject}_bundle-1.1.0.jar")
bundletask_bundle.isFile()
JarFile bundletask_jar = new JarFile(bundletask_bundle)
Attributes bundletask_manifest = bundletask_jar.getManifest().getMainAttributes()
jartask_manifest.getValue("Bundle-SymbolicName") == "${testProject}"
jartask_manifest.getValue("Bundle-Version") == "1.0.0"
jartask_jar.close()
bundletask_manifest.getValue("Bundle-SymbolicName") == "${testProject}_bundle"
bundletask_manifest.getValue("Bundle-Version") == "1.1.0"
bundletask_jar.close()
when:
File xmlfile = new File(testProjectBuildDir, "index.xml")
assert xmlfile.isFile()
def repository = new XmlSlurper().parse(xmlfile)
then:
repository.@name == testProject
repository.lookupNamespace("") == "http://www.osgi.org/xmlns/repository/v1.0.0"
repository.resource.size() == 2
repository.resource[0]."*".find { node ->
node.name() == "capability" && node.@namespace == "osgi.identity"
}."*".find { node ->
node.name() == "attribute" && node.@name == "osgi.identity"
}.@value == testProject
repository.resource[0]."*".find { node ->
node.name() == "capability" && node.@namespace == "osgi.content"
}."*".find { node ->
node.name() == "attribute" && node.@name == "url"
}.@value == "libs/${testProject}-1.0.0.jar"
repository.resource[1]."*".find { node ->
node.name() == "capability" && node.@namespace == "osgi.identity"
}."*".find { node ->
node.name() == "attribute" && node.@name == "osgi.identity"
}.@value == "${testProject}_bundle"
repository.resource[1]."*".find { node ->
node.name() == "capability" && node.@namespace == "osgi.content"
}."*".find { node ->
node.name() == "attribute" && node.@name == "url"
}.@value == "libs/${testProject}_bundle-1.1.0.jar"
when:
xmlfile = new File(testProjectBuildDir, "libs/index.xml.gz")
then:
!xmlfile.isFile()
when:
xmlfile = new File(testProjectBuildDir, "index/index2.xml")
assert xmlfile.isFile()
repository = new XmlSlurper().parse(xmlfile)
then:
repository.@name == "indexer2"
repository.lookupNamespace("") == "http://www.osgi.org/xmlns/repository/v1.0.0"
repository.resource.size() == 1
repository.resource[0]."*".find { node ->
node.name() == "capability" && node.@namespace == "osgi.identity"
}."*".find { node ->
node.name() == "attribute" && node.@name == "osgi.identity"
}.@value == testProject
repository.resource[0]."*".find { node ->
node.name() == "capability" && node.@namespace == "osgi.content"
}."*".find { node ->
node.name() == "attribute" && node.@name == "url"
}.@value == "bundles/${testProject}-1.0.0.jar"
when:
xmlfile = new File(testProjectBuildDir, "index/index2.xml.gz")
assert xmlfile.isFile()
repository = new XmlSlurper().parse(new GZIPInputStream(new FileInputStream(xmlfile)))
then:
repository.@name == "indexer2"
repository.lookupNamespace("") == "http://www.osgi.org/xmlns/repository/v1.0.0"
repository.resource.size() == 1
repository.resource[0]."*".find { node ->
node.name() == "capability" && node.@namespace == "osgi.identity"
}."*".find { node ->
node.name() == "attribute" && node.@name == "osgi.identity"
}.@value == testProject
repository.resource[0]."*".find { node ->
node.name() == "capability" && node.@namespace == "osgi.content"
}."*".find { node ->
node.name() == "attribute" && node.@name == "url"
}.@value == "bundles/${testProject}-1.0.0.jar"
when:
result = TestHelper.getGradleRunner()
.withProjectDir(testProjectDir)
.withArguments("--parallel", "--stacktrace", "--debug", "indexer", "indexer2")
.withPluginClasspath()
.forwardOutput()
.build()
then:
result.task(":bundle").outcome == UP_TO_DATE
result.task(":jar").outcome == UP_TO_DATE
result.task(":indexer").outcome == UP_TO_DATE
result.task(":indexer2").outcome == UP_TO_DATE
}
}