use of io.automatiko.engine.codegen.GeneratedFile in project automatiko-engine by automatiko-io.
the class JsonSchemaGeneratorTest method testJsonSchemaGeneratorInputOutput.
@Test
public void testJsonSchemaGeneratorInputOutput() throws IOException {
Collection<GeneratedFile> files = new JsonSchemaGenerator.Builder(Stream.of(PersonInputOutputParams.class)).build().generate();
assertEquals(1, files.size());
GeneratedFile file = files.iterator().next();
assertEquals("InputOutput_test.json", file.relativePath());
assertSchema(file, SchemaVersion.DRAFT_7);
}
use of io.automatiko.engine.codegen.GeneratedFile in project automatiko-engine by automatiko-io.
the class JsonSchemaGeneratorTest method testJsonSchemaGeneratorDraft2019.
@Test
public void testJsonSchemaGeneratorDraft2019() throws IOException {
Collection<GeneratedFile> files = new JsonSchemaGenerator.Builder(Stream.of(PersonInputParams.class, PersonOutputParams.class, IgnoredClass.class)).withSchemaVersion("DRAFT_2019_09").build().generate();
assertEquals(1, files.size());
GeneratedFile file = files.iterator().next();
assertEquals("test_test.json", file.relativePath());
assertSchema(file, SchemaVersion.DRAFT_2019_09);
}
use of io.automatiko.engine.codegen.GeneratedFile in project automatiko-engine by automatiko-io.
the class AutomatikoQuarkusProcessor method generatePersistenceInfo.
private void generatePersistenceInfo(AutomatikoBuildTimeConfig config, PackageConfig pconfig, AppPaths appPaths, BuildProducer<GeneratedBeanBuildItem> generatedBeans, BuildProducer<AdditionalIndexedClassesBuildItem> additionalIndexClass, IndexView index, LaunchModeBuildItem launchMode, BuildProducer<NativeImageResourceBuildItem> resource, CurateOutcomeBuildItem curateOutcomeBuildItem) throws Exception, BootstrapDependencyProcessingException {
ClassInfo persistenceClass = index.getClassByName(createDotName(persistenceFactoryClass));
boolean usePersistence = persistenceClass != null;
List<String> parameters = new ArrayList<>();
if (usePersistence) {
for (MethodInfo mi : persistenceClass.methods()) {
if (mi.name().equals("<init>") && !mi.parameters().isEmpty()) {
parameters = mi.parameters().stream().map(p -> p.name().toString()).collect(Collectors.toList());
break;
}
}
}
Collection<GeneratedFile> generatedFiles = getGeneratedPersistenceFiles(config, appPaths, index, usePersistence, parameters);
if (!generatedFiles.isEmpty()) {
writeGeneratedFiles(appPaths, generatedFiles);
compile(appPaths, curateOutcomeBuildItem.getApplicationModel(), generatedFiles, launchMode.getLaunchMode(), generatedBeans, additionalIndexClass, GeneratedBeanBuildItem::new, pconfig);
}
}
use of io.automatiko.engine.codegen.GeneratedFile in project automatiko-engine by automatiko-io.
the class PersistenceGenerator method mongodbBasedPersistence.
protected void mongodbBasedPersistence(List<GeneratedFile> generatedFiles) {
ClassOrInterfaceDeclaration persistenceProviderClazz = new ClassOrInterfaceDeclaration().setName("ProcessInstancesFactoryImpl").setModifiers(Modifier.Keyword.PUBLIC).addExtendedType("io.automatiko.engine.addons.persistence.AbstractProcessInstancesFactory");
CompilationUnit compilationUnit = new CompilationUnit("io.automatiko.engine.addons.persistence.impl");
compilationUnit.getTypes().add(persistenceProviderClazz);
persistenceProviderClazz.addConstructor(Keyword.PUBLIC);
ConstructorDeclaration constructor = persistenceProviderClazz.addConstructor(Keyword.PUBLIC).addParameter("com.mongodb.client.MongoClient", "mongoClient").addParameter("io.automatiko.engine.api.config.MongodbPersistenceConfig", "config");
BlockStmt body = new BlockStmt();
ExplicitConstructorInvocationStmt superExp = new ExplicitConstructorInvocationStmt(false, null, NodeList.nodeList(new NameExpr("mongoClient"), new NameExpr("config")));
body.addStatement(superExp);
constructor.setBody(body);
if (useInjection()) {
annotator.withApplicationComponent(persistenceProviderClazz);
annotator.withInjection(constructor);
addCodecComponents(persistenceProviderClazz);
}
String packageName = compilationUnit.getPackageDeclaration().map(pd -> pd.getName().toString()).orElse("");
String clazzName = packageName + "." + persistenceProviderClazz.findFirst(ClassOrInterfaceDeclaration.class).map(c -> c.getName().toString()).get();
generatedFiles.add(new GeneratedFile(GeneratedFile.Type.CLASS, clazzName.replace('.', '/') + ".java", compilationUnit.toString().getBytes(StandardCharsets.UTF_8)));
persistenceProviderClazz.getMembers().sort(new BodyDeclarationComparator());
}
use of io.automatiko.engine.codegen.GeneratedFile in project automatiko-engine by automatiko-io.
the class PersistenceGenerator method fileSystemBasedPersistence.
protected void fileSystemBasedPersistence(List<GeneratedFile> generatedFiles) {
ClassOrInterfaceDeclaration persistenceProviderClazz = new ClassOrInterfaceDeclaration().setName("ProcessInstancesFactoryImpl").setModifiers(Modifier.Keyword.PUBLIC).addExtendedType("io.automatiko.engine.addons.persistence.AbstractProcessInstancesFactory");
CompilationUnit compilationUnit = new CompilationUnit("io.automatiko.engine.addons.persistence.impl");
compilationUnit.getTypes().add(persistenceProviderClazz);
if (useInjection()) {
annotator.withApplicationComponent(persistenceProviderClazz);
FieldDeclaration pathField = new FieldDeclaration().addVariable(new VariableDeclarator().setType(new ClassOrInterfaceType(null, new SimpleName(Optional.class.getCanonicalName()), NodeList.nodeList(new ClassOrInterfaceType(null, String.class.getCanonicalName())))).setName(PATH_NAME));
annotator.withConfigInjection(pathField, PERSISTENCE_FS_PATH_PROP);
// allow to inject path for the file system storage
BlockStmt pathMethodBody = new BlockStmt();
pathMethodBody.addStatement(new ReturnStmt(new MethodCallExpr(new NameExpr(PATH_NAME), "orElse").addArgument(new StringLiteralExpr("/tmp"))));
MethodDeclaration pathMethod = new MethodDeclaration().addModifier(Keyword.PUBLIC).setName(PATH_NAME).setType(String.class).setBody(pathMethodBody);
persistenceProviderClazz.addMember(pathField);
persistenceProviderClazz.addMember(pathMethod);
addCodecComponents(persistenceProviderClazz);
}
String packageName = compilationUnit.getPackageDeclaration().map(pd -> pd.getName().toString()).orElse("");
String clazzName = packageName + "." + persistenceProviderClazz.findFirst(ClassOrInterfaceDeclaration.class).map(c -> c.getName().toString()).get();
generatedFiles.add(new GeneratedFile(GeneratedFile.Type.CLASS, clazzName.replace('.', '/') + ".java", compilationUnit.toString().getBytes(StandardCharsets.UTF_8)));
persistenceProviderClazz.getMembers().sort(new BodyDeclarationComparator());
}
Aggregations