Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getMavenClasspathDependencies(p: Project): Promise {
const lp = p as LocalProject;
const log = new StringCapturingProgressLog();
const tempFile = await new TmpDir().getTempFile({prefix: "classpath", suffix: ".txt"});
await spawnLog(await determineMavenCommand(p), ["dependency:build-classpath", `-Dmdep.outputFile=${tempFile}`], {log, cwd: lp.baseDir});
const classpath = await fs.readFile(tempFile, "UTF-8");
return classpath
.split(path.delimiter)
.map(element => {
return element.substr(element.lastIndexOf(path.sep) + 1);
});
}
async function getGradleClasspathDependencies(p: Project): Promise {
const lp = p as LocalProject;
const initScript = `allprojects {
apply plugin: "java"
task listCompilePath(dependsOn: configurations.compileClasspath) {
doLast {
println "classpath=\${configurations.testCompileClasspath.collect { File file -> file }.join('${path.delimiter}')}"
}
}
}`;
const tempFile = await new TmpDir().getTempFile({prefix: "init", suffix: ".gradle"});
await fs.writeFile(tempFile, initScript);
const log = new StringCapturingProgressLog();
await spawnLog(await determineGradleCommand(p), ["--init-script", tempFile, "listCompilePath"], {log, cwd: lp.baseDir});
const result = /classpath=(.*)/.exec(log.log);
if (result) {
return result[1]
.split(path.delimiter)
.map(element => {
return element.substr(element.lastIndexOf(path.sep) + 1);
});
} else {
return [];
}
}
export async function getCompileClasspath(p: LocalProject, module?: string): Promise {
const initScript = `
allprojects {
task generateCompileClasspath {
def output = new File(rootDir, ".atomist-dependencies.txt");
doLast {
output.text = configurations.compileClasspath.resolve()
}
}
}
`;
const log = new StringCapturingProgressLog();
p.addFileSync(".atomist.gradle", initScript);
if (module) {
await spawnLog(await determineGradleCommand(p),
["--init-script", ".atomist.gradle", "-q", `:${module}:generateCompileClasspath`], {log, cwd: p.baseDir});
} else {
await spawnLog(await determineGradleCommand(p),
["--init-script", ".atomist.gradle", "-q", `:generateCompileClasspath`], {log, cwd: p.baseDir});
}
p.deleteFileSync(".atomist.gradle");
const output = await (await p.getFile(".atomist-dependencies.txt")).getContent();
p.deleteFileSync(".atomist-dependencies.txt");
const dependencies = output.substring(1, output.length - 1);
return dependencies.split(", ");
}
export async function getRuntimeClasspath(p: LocalProject, module?: string): Promise {
const initScript = `
allprojects {
task generateRuntimeClasspath {
def output = new File(rootDir, ".atomist-dependencies.txt");
doLast {
output.text = configurations.runtimeClasspath.resolve()
}
}
}
`;
const log = new StringCapturingProgressLog();
p.addFileSync(".atomist.gradle", initScript);
if (module) {
await spawnLog(await determineGradleCommand(p),
["--init-script", ".atomist.gradle", "-q", `:${module}:generateRuntimeClasspath`], {log, cwd: p.baseDir});
} else {
await spawnLog(await determineGradleCommand(p),
["--init-script", ".atomist.gradle", "-q", `:generateRuntimeClasspath`], {log, cwd: p.baseDir});
}
p.deleteFileSync(".atomist.gradle");
const output = await (await p.getFile(".atomist-dependencies.txt")).getContent();
p.deleteFileSync(".atomist-dependencies.txt");
const dependencies = output.substring(1, output.length - 1);
return dependencies.split(", ");
}
apply: async (p, papi) => {
const fp = papi.parameters.fp;
if (fp.data.length !== 1) {
return p;
}
if (!(await p.hasFile(PackageJsonName))) {
return p;
}
if (!(p as LocalProject).baseDir) {
return p;
}
const log = new StringCapturingProgressLog();
log.stripAnsi = true;
const result = await spawnLog(
"npm",
["install", `typescript@${fp.data[0]}`, "--save-dev", "--safe-exact"],
{ cwd: (p as LocalProject).baseDir, log });
if (result.code !== 0) {
return {
edited: false,
success: false,
target: p,
error: new Error(`npm install typescript@${fp.data[0]} failed:\n\n${log.log}`),
};
}
return p;
},
export async function cleanCompletedJobs() {
const deploymentName = process.env.ATOMIST_DEPLOYMENT_NAME || configurationValue("name");
const deploymentNamespace = process.env.ATOMIST_DEPLOYMENT_NAMESPACE || "default";
let log = new StringCapturingProgressLog();
await spawnAndWatch({
command: "kubectl",
args: ["get", "jobs", "-n", deploymentNamespace, "-o", "json"],
},
{},
log,
{
errorFinder: SuccessIsReturn0ErrorFinder,
logCommand: false,
},
);
const jobs = JSON.parse(log.log).items;
const sdmJobs = jobs.filter(j => j.metadata.name.startsWith(`${deploymentName}-job-`));
const completedSdmJobs =
return async p => {
const log = new StringCapturingProgressLog();
spawnLog("kscript", [opts.kscriptLocation, "--path", (p as LocalProject).baseDir], {log});
return p;
};
}