Search in sources :

Example 6 with GeneratedResource

use of org.mule.runtime.extension.api.resources.GeneratedResource in project mule by mulesoft.

the class ExtensionsTestLoaderResourcesGenerator method dumpAll.

List<GeneratedResource> dumpAll() {
    List<GeneratedResource> allResources = contents.entrySet().stream().map(entry -> new GeneratedResource(entry.getKey(), entry.getValue().toString().getBytes())).collect(toImmutableList());
    allResources.forEach(resource -> {
        File targetFile = new File(resource.getPath());
        try {
            stringToFile(targetFile.getAbsolutePath(), new String(resource.getContent()));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    return allResources;
}
Also used : GeneratedResourceFactory(org.mule.runtime.extension.api.resources.spi.GeneratedResourceFactory) List(java.util.List) Collectors.toImmutableList(org.mule.runtime.api.util.collection.Collectors.toImmutableList) Paths(java.nio.file.Paths) Collection(java.util.Collection) Map(java.util.Map) GeneratedResource(org.mule.runtime.extension.api.resources.GeneratedResource) IOException(java.io.IOException) HashMap(java.util.HashMap) FileUtils.stringToFile(org.mule.runtime.core.api.util.FileUtils.stringToFile) AbstractResourcesGenerator(org.mule.runtime.module.extension.internal.resources.AbstractResourcesGenerator) File(java.io.File) GeneratedResource(org.mule.runtime.extension.api.resources.GeneratedResource) IOException(java.io.IOException) FileUtils.stringToFile(org.mule.runtime.core.api.util.FileUtils.stringToFile) File(java.io.File)

Example 7 with GeneratedResource

use of org.mule.runtime.extension.api.resources.GeneratedResource in project mule by mulesoft.

the class AbstractXmlResourceFactory method generateResource.

@Override
public Optional<GeneratedResource> generateResource(ExtensionModel extensionModel) {
    Set<ImportedTypeModel> importedTypes = extensionModel.getImportedTypes();
    DslResolvingContext dslContext = importedTypes.isEmpty() ? new NullDslResolvingContext() : new ClasspathBasedDslContext(extensionModel.getModelProperty(ImplementingTypeModelProperty.class).map(mp -> mp.getType().getClassLoader()).orElse(Thread.currentThread().getContextClassLoader()));
    return generateResource(extensionModel, dslContext);
}
Also used : Optional.empty(java.util.Optional.empty) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) Properties(java.util.Properties) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) Optional.of(java.util.Optional.of) GeneratedResource(org.mule.runtime.extension.api.resources.GeneratedResource) Set(java.util.Set) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) GeneratedResourceFactory(org.mule.runtime.extension.api.resources.spi.GeneratedResourceFactory) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) DslResourceFactory(org.mule.runtime.extension.api.dsl.syntax.resources.spi.DslResourceFactory) Optional(java.util.Optional) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext)

Example 8 with GeneratedResource

use of org.mule.runtime.extension.api.resources.GeneratedResource in project mule by mulesoft.

the class ExtensionDescriptionDocumenterTestCase method persistDocumentation.

@Test
public void persistDocumentation() throws Exception {
    InputStream in = getClass().getResourceAsStream(expectedProductPath);
    assertThat(in, is(notNullValue()));
    String expectedXml = IOUtils.toString(in);
    TestProcessor processor = new TestProcessor(extensionClass);
    doCompile(processor);
    ExtensionDocumentationResourceGenerator generator = new ExtensionDocumentationResourceGenerator();
    GeneratedResource resource = generator.generateResource(processor.getExtensionModel()).orElseThrow(() -> new RuntimeException("No Documentation Generated"));
    compareXML(expectedXml, new String(resource.getContent()));
}
Also used : ExtensionDocumentationResourceGenerator(org.mule.runtime.module.extension.internal.resources.documentation.ExtensionDocumentationResourceGenerator) InputStream(java.io.InputStream) GeneratedResource(org.mule.runtime.extension.api.resources.GeneratedResource) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 9 with GeneratedResource

use of org.mule.runtime.extension.api.resources.GeneratedResource in project mule by mulesoft.

the class ExtensionDocumentationResourceGenerator method generateResource.

@Override
public Optional<GeneratedResource> generateResource(ExtensionModel extensionModel) {
    final ExtensionDescriptionsSerializer serializer = new ExtensionDescriptionsSerializer();
    ExtensionDocumenterWalker walker = new ExtensionDocumenterWalker();
    walker.walk(extensionModel);
    String documenter = serializer.serialize(getDocumenter(extensionModel, walker.getConfigs(), walker.getConnections(), walker.getOperations(), walker.getSources(), getTypesDocumentation(extensionModel)));
    return Optional.of(new GeneratedResource(serializer.getFileName(extensionModel.getName()), documenter.getBytes()));
}
Also used : GeneratedResource(org.mule.runtime.extension.api.resources.GeneratedResource)

Aggregations

GeneratedResource (org.mule.runtime.extension.api.resources.GeneratedResource)9 File (java.io.File)3 Test (org.junit.Test)3 GeneratedResourceFactory (org.mule.runtime.extension.api.resources.spi.GeneratedResourceFactory)3 SmallTest (org.mule.tck.size.SmallTest)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 DslResolvingContext (org.mule.runtime.api.dsl.DslResolvingContext)2 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)2 DslResourceFactory (org.mule.runtime.extension.api.dsl.syntax.resources.spi.DslResourceFactory)2 ImmutableList.copyOf (com.google.common.collect.ImmutableList.copyOf)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 String.format (java.lang.String.format)1 Thread.currentThread (java.lang.Thread.currentThread)1 Method (java.lang.reflect.Method)1