io.linguarobot.aws.cdk.maven.node.NodeProcessRunner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aws-cdk-maven-plugin Show documentation
Show all versions of aws-cdk-maven-plugin Show documentation
The AWS CDK Maven plugin produces and deploys CloudFormation templates based on the cloud infrastructure defined
by means of CDK. The goal of the project is to improve the experience of Java developers while working with
CDK by eliminating the need for installing Node.js and interacting with the CDK application by means of CDK
Toolkit.
package io.linguarobot.aws.cdk.maven.node;
import com.google.common.collect.ImmutableList;
import io.linguarobot.aws.cdk.maven.process.ProcessContext;
import io.linguarobot.aws.cdk.maven.process.ProcessRunner;
import java.nio.file.Path;
import java.util.List;
public class NodeProcessRunner implements NodeClient {
private final ProcessRunner processRunner;
private final Path path;
private final String node;
private final String npmCli;
private final String npxCli;
public NodeProcessRunner(ProcessRunner processRunner, Path path, Path node, Path npmCli, Path npxCli) {
this.processRunner = processRunner;
this.path = path;
this.node = node.toString();
this.npmCli = npmCli.toString();
this.npxCli = npxCli.toString();
}
@Override
public int run(List command, ProcessContext processContext) {
return processRunner.run(prepend(node, command), processContext);
}
@Override
public ProcessRunner npm() {
return (command, context) -> processRunner.run(concat(ImmutableList.of(node, npmCli), command), context);
}
@Override
public ProcessRunner npx() {
return (command, context) -> processRunner.run(concat(ImmutableList.of(node, npxCli), command), context);
}
@Override
public Path getPath() {
return path;
}
private List concat(List head, List tail) {
if (head.isEmpty() || tail.isEmpty()) {
return head.isEmpty() ? tail : head;
}
return ImmutableList.builder()
.addAll(head)
.addAll(tail)
.build();
}
private List prepend(T value, List values) {
return ImmutableList.builder()
.add(value)
.addAll(values)
.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy