forked from dagger/java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.dang
More file actions
259 lines (232 loc) · 10.8 KB
/
Copy pathmain.dang
File metadata and controls
259 lines (232 loc) · 10.8 KB
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
"""
End-to-end checks for the Java SDK helper module.
"""
type E2e {
let outputRoot: String! = ".dagger/modules/e2e/out"
let fixtureRoot: String! = ".dagger/modules/e2e/fixtures"
let generateModulePath: String! = fixtureRoot + "/generate/app"
let lookupModulePath: String! = fixtureRoot + "/lookup/app"
let lookupNestedPath: String! = lookupModulePath + "/nested"
let depsModulePath: String! = fixtureRoot + "/deps/app"
let skipModulePath: String! = fixtureRoot + "/skip/app"
# A CLI 1.0 managed module: configured by dagger-module.toml, not dagger.json.
let managedTomlModulePath: String! = fixtureRoot + "/managed-toml/app"
# A module using a different SDK; this SDK must never manage it.
let nonJavaModulePath: String! = fixtureRoot + "/lookup/not-java"
"""
Fail the current check when a condition is false.
"""
let assert(condition: Boolean!, message: String!): Void {
if (condition == false) { raise message }
null
}
"""
Return true when a list contains the exact string.
"""
let contains(values: [String!]!, want: String!): Boolean! {
values.filter { value => value == want }.length > 0
}
"""
Assert that a changeset added a path.
"""
let assertAdded(changes: Changeset!, path: String!): Void {
assert(contains(changes.addedPaths, path), "expected added path: " + path)
}
"""
Assert that a string contains a substring.
"""
let assertContains(value: String!, want: String!, message: String!): Void {
assert(value.contains(want), message)
}
"""
New Java modules should target this repository's build/package-only runtime
rather than a builtin SDK name.
"""
targetRuntimeCheck: Void @check {
assert(
javaSdk.targetRuntime == "github.com/dagger/java-sdk/runtime",
"targetRuntime should be the in-repo build/package-only runtime",
)
null
}
"""
The generate skip marker filename should be stable.
"""
skipGenerateFilenameCheck: Void @check {
assert(
javaSdk.skipGenerateFilename == ".dagger-java-sdk-skip-generate",
"skip marker filename changed",
)
null
}
"""
initModule should seed only the SDK-owned template files: a two-pass pom
defaulting dagger.proc=none and the module sources, with the module name
substituted into paths and contents. Engine-owned files (dagger-module.toml,
the legacy dagger.json) are produced by the engine, not by initModule, and no
existing files are touched.
"""
initCheck(ws: Workspace!): Void @check {
let p = outputRoot + "/init-default"
let changes = javaSdk.initModule(ws, name: "init-default", path: p)
assertAdded(changes, p + "/pom.xml")
assertAdded(changes, p + "/src/main/java/io/dagger/modules/initdefault/InitDefault.java")
assertAdded(changes, p + "/src/main/java/io/dagger/modules/initdefault/package-info.java")
assert(
contains(changes.addedPaths, p + "/dagger-module.toml") == false,
"initModule should not write the engine-owned dagger-module.toml",
)
assert(
contains(changes.addedPaths, p + "/dagger.json") == false,
"initModule should not write the engine-owned dagger.json",
)
assert(changes.modifiedPaths.length == 0, "init unexpectedly modified existing files")
assert(changes.removedPaths.length == 0, "init unexpectedly removed files")
let pom = changes.layer.file(p + "/pom.xml").contents
assertContains(pom, "<dagger.proc>none</dagger.proc>", "pom should default dagger.proc to none")
assertContains(pom, "<artifactId>init-default</artifactId>", "pom artifactId should be the kebab-case module name")
let module = changes.layer.file(p + "/src/main/java/io/dagger/modules/initdefault/InitDefault.java").contents
assertContains(module, "class InitDefault", "module class should be the camel-case module name")
null
}
let testWS(ws: Workspace!): Workspace! {
ws.directory("/").withoutFile("dagger.toml").asWorkspace(cwd: ".dagger/modules/e2e/fixtures")
}
"""
From the workspace root the whole workspace is in scope, so modules() should
return every Java SDK module this workspace manages — whether it is configured
by the legacy dagger.json or the CLI 1.0 dagger-module.toml — and nothing that
isn't managed by this SDK (e.g. a sibling module using another SDK).
"""
modulesCheck(ws: Workspace!): Void @check {
let pathRecords = javaSdk.modules(testWS(ws)).{{rootPath}}
assert(
pathRecords.filter { r => r.rootPath == lookupModulePath }.length > 0,
"lookup Java module should be listed",
)
assert(
pathRecords.filter { r => r.rootPath == skipModulePath }.length > 0,
"skip-marked Java module should still be listed (skip only affects generate)",
)
assert(
pathRecords.filter { r => r.rootPath == generateModulePath }.length > 0,
"generate Java module should be listed",
)
assert(
pathRecords.filter { r => r.rootPath == depsModulePath }.length > 0,
"deps Java module should be listed",
)
assert(
pathRecords.filter { r => r.rootPath == managedTomlModulePath }.length > 0,
"a dagger-module.toml (CLI 1.0) managed module should be listed",
)
assert(
pathRecords.filter { r => r.rootPath == nonJavaModulePath }.length == 0,
"a module not managed by this SDK should be excluded from modules listing",
)
null
}
"""
Discovery is anchored at the client's cwd, not the workspace root. Re-anchoring
the workspace to a subdirectory scopes modules() to the managed modules in that
cone (walk-down) plus the nearest enclosing one (find-up), and excludes managed
modules that live outside it.
"""
modulesCwdCheck(ws: Workspace!): Void @check {
# A stable snapshot of the workspace, re-anchorable at any cwd. It has to
# carry the fixture dagger.toml, which is where currentModule.asSDK reads the
# managed-module list from, and lookup/app/nested, the config-less
# subdirectory the find-up case is anchored in.
let root = testWS(ws).directory("/")
# Walk-down: from fixtures/generate only generate/app is in the cone; the
# sibling managed modules live outside it and must be excluded. Its
# cwd-relative path is "app" — a directory beneath the cwd.
let fromGenerate = javaSdk.modules(
root.asWorkspace(cwd: fixtureRoot + "/generate"),
)
let fromGenerateRoots = fromGenerate.{{rootPath}}
assert(
fromGenerateRoots.filter { r => r.rootPath == generateModulePath }.length > 0,
"cwd=generate: the managed module in the cone should be discovered",
)
assert(
fromGenerateRoots.filter { r => r.rootPath == lookupModulePath }.length == 0,
"cwd=generate: lookup/app is outside the cone and must be excluded",
)
assert(
fromGenerateRoots.filter { r => r.rootPath == depsModulePath }.length == 0,
"cwd=generate: deps/app is outside the cone and must be excluded",
)
assert(
fromGenerateRoots.filter { r => r.rootPath == skipModulePath }.length == 0,
"cwd=generate: skip/app is outside the cone and must be excluded",
)
assert(fromGenerateRoots.length == 1, "cwd=generate: exactly one managed module is in the cone")
assert(fromGenerate.{{path}}.filter { r => r.path == "app" }.length > 0, "cwd=generate: the discovered module's path should be cwd-relative (app)")
# Find-up: from inside lookup/app (a nested subdir with no config of its own)
# the enclosing managed module is discovered; siblings are not. Its
# cwd-relative path is ".." — an ancestor of the cwd.
let fromNested = javaSdk.modules(root.asWorkspace(cwd: lookupNestedPath))
let fromNestedRoots = fromNested.{{rootPath}}
assert(
fromNestedRoots.filter { r => r.rootPath == lookupModulePath }.length > 0,
"cwd=lookup/app/nested: find-up should discover the enclosing lookup/app",
)
assert(
fromNestedRoots.filter { r => r.rootPath == generateModulePath }.length == 0,
"cwd=lookup/app/nested: generate/app is outside the cone",
)
assert(fromNestedRoots.length == 1, "cwd=lookup/app/nested: only the enclosing module should be discovered")
assert(fromNested.{{path}}.filter { r => r.path == ".." }.length > 0, "cwd=lookup/app/nested: the enclosing module's path should be cwd-relative (..)")
# Root cwd: the whole workspace is in scope, so every managed module — and
# only the managed ones — is discovered, whether marked by dagger.json or
# dagger-module.toml.
# Using the fixture root where the test specific workspace is defined
let fromRoot = javaSdk.modules(root.asWorkspace(cwd: fixtureRoot)).{{rootPath}}
assert(
fromRoot.filter { r => r.rootPath == generateModulePath }.length > 0,
"cwd=/: generate/app should be listed",
)
assert(fromRoot.filter { r => r.rootPath == lookupModulePath }.length > 0, "cwd=/: lookup/app should be listed")
assert(fromRoot.filter { r => r.rootPath == depsModulePath }.length > 0, "cwd=/: deps/app should be listed")
assert(fromRoot.filter { r => r.rootPath == skipModulePath }.length > 0, "cwd=/: skip/app should be listed")
assert(
fromRoot.filter { r => r.rootPath == managedTomlModulePath }.length > 0,
"cwd=/: the dagger-module.toml managed module should be listed",
)
assert(fromRoot.length == 5, "cwd=/: exactly the five managed modules should be listed")
null
}
"""
Generation from a subdirectory must resolve managed module root paths from
the workspace root, not relative to the caller's cwd, and must return a
changeset whose paths are relative to that cwd — the form the engine applies
a generator's result in.
"""
generateCwdCheck(ws: Workspace!): Void @check {
# Prepare a valid module in memory and remove the fixture-wide skip marker
# so this check can exercise generation without changing committed fixtures.
let initialized = javaSdk.initModule(ws, name: "generate-app", path: generateModulePath)
let root = testWS(ws)
.directory("/", exclude: [fixtureRoot + "/.dagger-java-sdk-skip-generate"])
.withDirectory(".", initialized.layer)
# Module-relative paths of the two artifacts generation stages.
let vendoredClient = "sdk/src/main/java/io/dagger/client/Dagger.java"
let entrypoint = "src/generated/java/io/dagger/gen/entrypoint/Entrypoint.java"
# From the module's parent the module is one level down, so its changes are
# rooted at "app" — the same cwd-relative path modulesCwdCheck expects.
let fromParent = javaSdk.generateAll(
root.asWorkspace(cwd: fixtureRoot + "/generate"),
)
assertAdded(fromParent, "app/" + vendoredClient)
assertAdded(fromParent, "app/" + entrypoint)
# From the module itself the cwd is the module root, so its changes carry no
# prefix at all.
let fromModule = javaSdk.generateAll(
root.asWorkspace(cwd: generateModulePath),
)
assertAdded(fromModule, vendoredClient)
assertAdded(fromModule, entrypoint)
null
}
}