in packages/infrastructure/src/projects/java/infrastructure-java-project.ts [66:195]
constructor(options: InfrastructureJavaProjectOptions) {
const groupId = options.groupId ?? "software.aws.infra";
const artifactId = options.artifactId ?? "infra";
super({
...options,
cdkVersion: options.cdkVersion ?? "2.133.0",
cdkVersionPinning: true,
sample: false,
junit: false,
groupId,
artifactId,
mainClass: `${groupId}.Main`,
version: options.version ?? "0.0.0",
name: options.name,
readme: {
contents: fs
.readFileSync(
path.resolve(
__dirname,
"../../../samples/infrastructure/java/README.md"
)
)
.toString(),
},
});
// Pin constructs version
this.deps.removeDependency(
"software.constructs/constructs",
DependencyType.RUNTIME
);
[
"software.constructs/constructs@10.3.0",
"io.github.cdklabs/cdknag@2.15.16",
].forEach((d) => this.addDependency(d));
InfrastructureCommands.ensure(this);
this.pom.addPlugin("org.apache.maven.plugins/maven-surefire-plugin@3.1.2");
this.pom.addPlugin("org.apache.maven.plugins/maven-compiler-plugin@3.8.1", {
configuration: {
release: "11",
},
});
if (options.junit !== false) {
[
"org.junit.jupiter/junit-jupiter-api@5.10.2",
"org.junit.jupiter/junit-jupiter-engine@5.10.2",
"io.github.origin-energy/java-snapshot-testing-junit5@4.0.7",
"io.github.origin-energy/java-snapshot-testing-plugin-jackson@4.0.7",
"org.slf4j/slf4j-simple@2.0.0-alpha0",
].forEach((d) => this.addTestDependency(d));
this.testTask.exec("mvn test");
}
this.addDependency(`software.aws/pdk@${ProjectUtils.getPdkVersion()}`);
const srcDir = path.resolve(
__dirname,
"../../../samples/infrastructure/java/src"
);
const testDir = path.resolve(
__dirname,
"../../../samples/infrastructure/java/test"
);
const typeSafeApis = [
...(options.typeSafeApis || []),
...(options.typeSafeApi ? [options.typeSafeApi] : []),
];
const cloudscapeReactTsWebsites = [
...(options.cloudscapeReactTsWebsites || []),
...(options.cloudscapeReactTsWebsite
? [options.cloudscapeReactTsWebsite]
: []),
];
typeSafeApis.forEach((tsApi) => {
if (!tsApi.infrastructure.java) {
throw new Error(
"Cannot pass in a Type Safe Api without Java Infrastructure configured!"
);
}
NxProject.ensure(this).addJavaDependency(tsApi.infrastructure.java);
// Ensure handlers are built before infra
tsApi.all.handlers?.forEach((handler) => {
NxProject.ensure(this).addImplicitDependency(handler);
});
});
cloudscapeReactTsWebsites.forEach((csWebsite) => {
// Ensure website is built before infra
NxProject.ensure(this).addImplicitDependency(csWebsite);
});
const mustacheConfig = {
stackName: options.stackName || DEFAULT_STACK_NAME,
allowSignup: options.allowSignup ?? false,
groupId,
stages: options.stages || [],
typeSafeApis: this.generateTypeSafeMustacheConfig(groupId, typeSafeApis),
cloudscapeReactTsWebsites: cloudscapeReactTsWebsites.map((csWebsite) => {
const websiteName = this.capitalize(
csWebsite.package.packageName
.replace(/[^a-z0-9_]+/gi, "")
.replace(/^[0-9]+/gi, "")
);
return {
websiteName,
websiteNameLowercase: websiteName.toLowerCase(),
groupId,
websiteDistRelativePath: path.relative(
this.outdir,
`${csWebsite.outdir}/build`
),
typeSafeApis: this.generateTypeSafeMustacheConfig(
groupId,
csWebsite.typeSafeApis
),
};
}),
};
options.sample !== false &&
this.emitSampleFiles(srcDir, ["src", "main"], mustacheConfig);
options.sample !== false &&
this.emitSampleFiles(testDir, ["src", "test"], mustacheConfig);
}