Search in sources :

Example 1 with ResourceGenerator

use of org.raml.jaxrs.generator.builders.resources.ResourceGenerator in project raml-for-jax-rs by mulesoft-labs.

the class CurrentBuild method generate.

public void generate(final File rootDirectory) throws IOException {
    try {
        if (resources.size() > 0) {
            ResponseSupport.buildSupportClasses(rootDirectory, getSupportPackage());
        }
        for (TypeGenerator typeGenerator : builtTypes.values()) {
            if (typeGenerator instanceof RamlToPojoTypeGenerator) {
                RamlToPojoTypeGenerator ramlToPojoTypeGenerator = (RamlToPojoTypeGenerator) typeGenerator;
                ramlToPojoTypeGenerator.output(new CodeContainer<ResultingPojos>() {

                    @Override
                    public void into(ResultingPojos g) throws IOException {
                        g.createFoundTypes(rootDirectory.getAbsolutePath());
                    }
                });
            }
            if (typeGenerator instanceof JavaPoetTypeGenerator) {
                buildTypeTree(rootDirectory, (JavaPoetTypeGenerator) typeGenerator);
                continue;
            }
            if (typeGenerator instanceof CodeModelTypeGenerator) {
                CodeModelTypeGenerator b = (CodeModelTypeGenerator) typeGenerator;
                b.output(new CodeContainer<JCodeModel>() {

                    @Override
                    public void into(JCodeModel g) throws IOException {
                        g.build(rootDirectory);
                    }
                });
            }
        }
        for (ResourceGenerator resource : resources) {
            resource.output(new CodeContainer<TypeSpec>() {

                @Override
                public void into(TypeSpec g) throws IOException {
                    JavaFile.Builder file = JavaFile.builder(getResourcePackage(), g).skipJavaLangImports(true);
                    file.build().writeTo(rootDirectory);
                }
            });
        }
        for (JavaPoetTypeGenerator typeGenerator : supportGenerators) {
            typeGenerator.output(new CodeContainer<TypeSpec.Builder>() {

                @Override
                public void into(TypeSpec.Builder g) throws IOException {
                    JavaFile.Builder file = JavaFile.builder(getSupportPackage(), g.build()).skipJavaLangImports(true);
                    file.build().writeTo(rootDirectory);
                }
            });
        }
    } finally {
        if (schemaRepository != null) {
            FileUtils.deleteDirectory(schemaRepository);
        }
    }
}
Also used : ResourceGenerator(org.raml.jaxrs.generator.builders.resources.ResourceGenerator) IOException(java.io.IOException) JCodeModel(com.sun.codemodel.JCodeModel) TypeSpec(com.squareup.javapoet.TypeSpec)

Aggregations

TypeSpec (com.squareup.javapoet.TypeSpec)1 JCodeModel (com.sun.codemodel.JCodeModel)1 IOException (java.io.IOException)1 ResourceGenerator (org.raml.jaxrs.generator.builders.resources.ResourceGenerator)1