MCPcopy Index your code
hub / github.com/dagger/dagger / generateCode

Method generateCode

sdk/java/runtime/main.go:251–294  ·  view source on GitHub ↗

generateCode builds and returns the generated source code and java classes

(
	ctx context.Context,
	ctr *dagger.Container,
	introspectionJSON *dagger.File,
)

Source from the content-addressed store, hash-verified

249
250// generateCode builds and returns the generated source code and java classes
251func (m *JavaSdk) generateCode(
252 ctx context.Context,
253 ctr *dagger.Container,
254 introspectionJSON *dagger.File,
255) (*dagger.Directory, error) {
256 // generate the java sdk dependencies
257 javaDeps, err := m.buildJavaDependencies(ctx, introspectionJSON)
258 if err != nil {
259 return nil, err
260 }
261 // generate the entrypoint class based on the user module
262 entrypoint := ctr.
263 // set the module name as an environment variable so we ensure constructor is only on main object
264 WithEnvVariable(javaSdkModuleNameEnv, m.moduleConfig.name).
265 // generate the entrypoint
266 WithExec(m.mavenCommand(
267 "mvn",
268 "clean",
269 "compile",
270 ))
271 return dag.
272 Directory().
273 // copy all user files
274 WithDirectory(
275 m.moduleConfig.modulePath(),
276 ctr.Directory(m.moduleConfig.modulePath())).
277 // copy the generated entrypoint under target/generated-sources/annotations
278 WithDirectory(
279 filepath.Join(m.moduleConfig.modulePath(), "target", "generated-sources", "entrypoint"),
280 entrypoint.Directory(filepath.Join(m.moduleConfig.modulePath(), "target", "generated-sources", "annotations"))).
281 // copy the sdk source code under target/generated-sources/dagger-io
282 // this is not really generated-sources, this is the sdk. But we don't want it as the user source code
283 // and we don't want to install it on the user machine. That way the java classes are made available
284 // to a build system or an IDE without to interfere with the user source code
285 WithDirectory(
286 filepath.Join(m.moduleConfig.modulePath(), "target", "generated-sources", "dagger-io"),
287 javaDeps.Directory(filepath.Join(GenPath, "dagger-java-sdk", "src", "main", "java"))).
288 // copy the generated SDK files to target/generated-sources/dagger-module
289 // those are all the types generated from the introspection
290 WithDirectory(
291 filepath.Join(m.moduleConfig.modulePath(), "target", "generated-sources", "dagger-module"),
292 javaDeps.Directory(filepath.Join(GenPath, "dagger-java-sdk", "target", "generated-sources", "dagger"))).
293 Directory(ModSourceDirPath), nil
294}
295
296func (m *JavaSdk) ModuleRuntime(
297 ctx context.Context,

Callers 1

CodegenMethod · 0.95

Calls 7

buildJavaDependenciesMethod · 0.95
mavenCommandMethod · 0.95
DirectoryMethod · 0.65
WithExecMethod · 0.45
WithEnvVariableMethod · 0.45
WithDirectoryMethod · 0.45
modulePathMethod · 0.45

Tested by

no test coverage detected