in toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateMojo.java [116:152]
private void generateContract(MavenProject project) {
switch (SourceType.valueOf(sourceType.toUpperCase())) {
case CODE:
// generate contract file
String contractOutput =
outputDirectory + File.separator + "contract" + File.separator + project.getBasedir().getName();
try {
FileUtils.createDirectory(contractOutput);
} catch (IOException e) {
throw new RuntimeException("Failed to generate contract", e);
}
GenerateUtil.generateContract(project, contractOutput, contractFileType, "default");
contractLocation = outputDirectory + File.separator + "contract";
if (Objects.requireNonNull(new File(contractOutput).listFiles()).length == 0) {
//noinspection ResultOfMethodCallIgnored
new File(contractOutput).delete();
LOGGER.info("No contract in the code");
return;
}
break;
case CONTRACT:
if (contractLocation == null) {
throw new RuntimeException("Invalid or not config contract location");
}
if (!new File(contractLocation).exists()) {
throw new RuntimeException("Contract path " + contractLocation + " is not exists");
}
break;
default:
throw new RuntimeException("Not support source type " + sourceType);
}
}