|
| 1 | +apply plugin: 'java' |
| 2 | + |
| 3 | +buildDir = 'target' |
| 4 | + |
| 5 | +def codexRuntimeDirectory = file("${projectDir}/resources/codex") |
| 6 | +def codexPackageJson = file("${codexRuntimeDirectory}/package.json") |
| 7 | +def codexPackageLock = file("${codexRuntimeDirectory}/package-lock.json") |
| 8 | +def codexNodeModules = file("${codexRuntimeDirectory}/node_modules") |
| 9 | +def npmExecutable = System.getProperty('os.name').toLowerCase().contains('windows') ? 'npm.cmd' : 'npm' |
| 10 | + |
| 11 | +sourceSets { |
| 12 | + main { |
| 13 | + resources { |
| 14 | + srcDirs = ['resources'] |
| 15 | + } |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +tasks.register('checkCodexAgentRuntimeTooling') { |
| 20 | + group = 'build' |
| 21 | + description = 'Check that the Codex agent runtime tooling is available.' |
| 22 | + |
| 23 | + doLast { |
| 24 | + if (!codexRuntimeDirectory.isDirectory()) { |
| 25 | + throw new GradleException("Missing Codex runtime directory: ${codexRuntimeDirectory}") |
| 26 | + } |
| 27 | + |
| 28 | + if (!codexPackageJson.isFile()) { |
| 29 | + throw new GradleException("Missing Codex runtime package.json: ${codexPackageJson}") |
| 30 | + } |
| 31 | + |
| 32 | + def npmVersionOutput = new ByteArrayOutputStream() |
| 33 | + def npmVersionResult = exec { |
| 34 | + commandLine npmExecutable, '--version' |
| 35 | + workingDir codexRuntimeDirectory |
| 36 | + standardOutput = npmVersionOutput |
| 37 | + errorOutput = npmVersionOutput |
| 38 | + ignoreExitValue = true |
| 39 | + } |
| 40 | + |
| 41 | + if (npmVersionResult.exitValue != 0) { |
| 42 | + throw new GradleException( |
| 43 | + "npm is required to install the Codex agent runtime dependencies. " + |
| 44 | + "Checked command '${npmExecutable} --version' and it failed with: ${npmVersionOutput.toString().trim()}" |
| 45 | + ) |
| 46 | + } |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +tasks.register('installCodexAgent', Exec) { |
| 51 | + group = 'build' |
| 52 | + description = 'Install the Codex agent runtime npm dependencies.' |
| 53 | + dependsOn tasks.named('checkCodexAgentRuntimeTooling') |
| 54 | + workingDir codexRuntimeDirectory |
| 55 | + commandLine npmExecutable, 'install' |
| 56 | + inputs.file(codexPackageJson) |
| 57 | + if (codexPackageLock.exists()) { |
| 58 | + inputs.file(codexPackageLock) |
| 59 | + } |
| 60 | + outputs.dir(codexNodeModules) |
| 61 | +} |
0 commit comments