Skip to content

Commit

Permalink
Merge pull request #23 from kakulisen/fix-plugin-bug
Browse files Browse the repository at this point in the history
SCB-1456 Fix the plugin bug that throws some exception when specifyin…
  • Loading branch information
MabinGo committed Aug 23, 2019
2 parents 80aa35a + 8cfd928 commit ebd754e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Expand Up @@ -122,16 +122,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
}

CodegenConfigurator configurator = new CodegenConfigurator();
commonConfig(configurator, service);
configurator.setOutputDir(codeOutput)
.setLang("ServiceComb")
.setApiPackage(service.getPackageName())
.setGroupId(service.getGroupId())
.setArtifactId(service.getArtifactId())
.setModelPackage(service.getPackageName())
.setLibrary(service.getProgrammingModel())
.addAdditionalProperty("mainClassPackage", service.getPackageName())
.setArtifactVersion(service.getArtifactVersion())
.addAdditionalProperty(ProjectMetaConstant.SERVICE_TYPE, service.getServiceType())
.addAdditionalProperty(GeneratorExternalConfigConstant.PROVIDER_PROJECT_NAME,
file.getParent().getFileName() + providerProjectNameSuffix)
.addAdditionalProperty(GeneratorExternalConfigConstant.CONSUMER_PROJECT_NAME,
Expand All @@ -152,10 +144,35 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
} else {

CodegenConfigurator configurator = new CodegenConfigurator();
commonConfig(configurator, service);
configurator.setOutputDir(codeOutput)
.addAdditionalProperty(GeneratorExternalConfigConstant.PROVIDER_PROJECT_NAME,
contractFile.getParentFile().getName() + providerProjectNameSuffix)
.addAdditionalProperty(GeneratorExternalConfigConstant.CONSUMER_PROJECT_NAME,
contractFile.getParentFile().getName() + consumerProjectNameSuffix)
.addAdditionalProperty(GeneratorExternalConfigConstant.MODEL_PROJECT_NAME,
contractFile.getParentFile().getName() + modelProjectNameSuffix)
.addAdditionalProperty("apiName", contractFile.getName().split("\\.")[0])
.addAdditionalProperty("microserviceName", contractFile.getParentFile().getName());

configurator.setInputSpec(contractLocation);
Objects.requireNonNull(codeGenerator)
.configure(Collections.singletonMap("configurators", Collections.singletonList(configurator)));
codeGenerator.generate();
}
}

private static void commonConfig(CodegenConfigurator configurator, ServiceConfig service) {

configurator
.setLang("ServiceComb")
.setApiPackage(service.getPackageName())
.setGroupId(service.getGroupId())
.setArtifactId(service.getArtifactId())
.setModelPackage(service.getPackageName())
.setLibrary(service.getProgrammingModel())
.addAdditionalProperty("mainClassPackage", service.getPackageName())
.setArtifactVersion(service.getArtifactVersion())
.addAdditionalProperty(ProjectMetaConstant.SERVICE_TYPE, service.getServiceType());
}
}
Expand Up @@ -84,6 +84,11 @@ public void testGenerateCode() throws Exception {
} catch (RuntimeException e) {
assertEquals("Cannot found code generator's implementation", e.getMessage());
}

// Test the scenario where the configuration property contractLocation is specified as a file
generateCode(service, contractLocation + File.separator + "HelloEndPoint.yaml", projectOutput,
Collections.EMPTY_MAP, "default");
assertNotEquals(0, Objects.requireNonNull(new File(projectOutput).listFiles()).length);
}

@Test
Expand Down

0 comments on commit ebd754e

Please sign in to comment.