Search in sources :

Example 1 with DslResolvingContext

use of org.mule.runtime.api.dsl.DslResolvingContext in project mule by mulesoft.

the class DefaultExtensionSchemaGeneratorTestCase method loadExtension.

public static ExtensionModel loadExtension(Class<?> clazz, ExtensionModelLoader loader) {
    Map<String, Object> params = new HashMap<>();
    params.put(TYPE_PROPERTY_NAME, clazz.getName());
    params.put(VERSION, getProductVersion());
    // TODO MULE-11797: as this utils is consumed from org.mule.runtime.module.extension.internal.capability.xml.schema.AbstractXmlResourceFactory.generateResource(org.mule.runtime.api.meta.model.ExtensionModel), this util should get dropped once the ticket gets implemented.
    final DslResolvingContext dslResolvingContext = getDefault(new LinkedHashSet<>(extensionModels.values()));
    return loader.loadExtensionModel(clazz.getClassLoader(), dslResolvingContext, params);
}
Also used : HashMap(java.util.HashMap) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) IOUtils.getResourceAsString(org.mule.runtime.core.api.util.IOUtils.getResourceAsString)

Example 2 with DslResolvingContext

use of org.mule.runtime.api.dsl.DslResolvingContext in project mule by mulesoft.

the class AbstractXmlExtensionMuleArtifactFunctionalTestCase method addBuilders.

@Override
protected void addBuilders(List<ConfigurationBuilder> builders) {
    super.addBuilders(builders);
    builders.add(new AbstractConfigurationBuilder() {

        @Override
        protected void doConfigure(MuleContext muleContext) throws Exception {
            ExtensionManager extensionManager;
            if (muleContext.getExtensionManager() == null) {
                extensionManager = createDefaultExtensionManager();
                muleContext.setExtensionManager(extensionManager);
                initialiseIfNeeded(extensionManager, muleContext);
            }
            extensionManager = muleContext.getExtensionManager();
            registerXmlExtensions(extensionManager);
        }

        private void registerXmlExtensions(ExtensionManager extensionManager) {
            // take all the plugins loaded by org.mule.test.runner.api.IsolatedClassLoaderExtensionsManagerConfigurationBuilder in the extension manager
            final Set<ExtensionModel> extensions = new HashSet<>(extensionManager.getExtensions());
            for (String modulePath : getModulePaths()) {
                Map<String, Object> params = new HashMap<>();
                params.put(XmlExtensionModelLoader.RESOURCE_XML, modulePath);
                params.put(XmlExtensionModelLoader.VALIDATE_XML, shouldValidateXml());
                operationsOutputPath().ifPresent(path -> params.put(XmlExtensionModelLoader.RESOURCE_DECLARATION, path));
                final DslResolvingContext dslResolvingContext = getDefault(extensions);
                final ExtensionModel extensionModel = new XmlExtensionModelLoader().loadExtensionModel(getClass().getClassLoader(), dslResolvingContext, params);
                extensions.add(extensionModel);
            }
            for (ExtensionModel extension : extensions) {
                extensionManager.registerExtension(extension);
            }
        }
    });
}
Also used : XmlExtensionModelLoader(org.mule.runtime.extension.api.loader.xml.XmlExtensionModelLoader) AbstractConfigurationBuilder(org.mule.runtime.core.api.config.builders.AbstractConfigurationBuilder) Set(java.util.Set) HashMap(java.util.HashMap) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) MuleExtensionUtils.createDefaultExtensionManager(org.mule.runtime.module.extension.api.util.MuleExtensionUtils.createDefaultExtensionManager) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) XmlExtensionLoaderDelegate(org.mule.runtime.extension.internal.loader.XmlExtensionLoaderDelegate) HashSet(java.util.HashSet) List(java.util.List) MuleContext(org.mule.runtime.core.api.MuleContext) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) Map(java.util.Map) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) ConfigurationBuilder(org.mule.runtime.core.api.config.ConfigurationBuilder) Optional(java.util.Optional) MuleArtifactFunctionalTestCase(org.mule.functional.junit4.MuleArtifactFunctionalTestCase) ArtifactClassLoaderRunnerConfig(org.mule.test.runner.ArtifactClassLoaderRunnerConfig) DslResolvingContext.getDefault(org.mule.runtime.api.dsl.DslResolvingContext.getDefault) AbstractConfigurationBuilder(org.mule.runtime.core.api.config.builders.AbstractConfigurationBuilder) Set(java.util.Set) HashSet(java.util.HashSet) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) MuleContext(org.mule.runtime.core.api.MuleContext) MuleExtensionUtils.createDefaultExtensionManager(org.mule.runtime.module.extension.api.util.MuleExtensionUtils.createDefaultExtensionManager) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) HashMap(java.util.HashMap) Map(java.util.Map) XmlExtensionModelLoader(org.mule.runtime.extension.api.loader.xml.XmlExtensionModelLoader)

Example 3 with DslResolvingContext

use of org.mule.runtime.api.dsl.DslResolvingContext in project mule by mulesoft.

the class ExtensionsTestInfrastructureDiscoverer method generateDslResources.

public List<GeneratedResource> generateDslResources(File generatedResourcesDirectory, ExtensionModel forExtensionModel) {
    DslResolvingContext context;
    if (extensionManager.getExtensions().stream().anyMatch(e -> !e.getImportedTypes().isEmpty())) {
        HashSet<ExtensionModel> models = new HashSet<>(extensionManager.getExtensions());
        models.add(MuleExtensionModelProvider.getExtensionModel());
        context = DslResolvingContext.getDefault(models);
    } else {
        context = new NullDslResolvingContext();
    }
    ExtensionsTestDslResourcesGenerator dslResourceGenerator = new ExtensionsTestDslResourcesGenerator(getDslResourceFactories(), generatedResourcesDirectory, context);
    extensionManager.getExtensions().stream().filter(runtimeExtensionModel -> forExtensionModel != null ? runtimeExtensionModel.equals(forExtensionModel) : true).forEach(dslResourceGenerator::generateFor);
    return dslResourceGenerator.dumpAll();
}
Also used : Manifest(java.util.jar.Manifest) MuleManifest.getProductVersion(org.mule.runtime.core.api.config.MuleManifest.getProductVersion) GeneratedResource(org.mule.runtime.extension.api.resources.GeneratedResource) HashMap(java.util.HashMap) Thread.currentThread(java.lang.Thread.currentThread) MuleManifest(org.mule.runtime.core.api.config.MuleManifest) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) GeneratedResourceFactory(org.mule.runtime.extension.api.resources.spi.GeneratedResourceFactory) HashSet(java.util.HashSet) Collections.singleton(java.util.Collections.singleton) ByteArrayInputStream(java.io.ByteArrayInputStream) TYPE_PROPERTY_NAME(org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader.TYPE_PROPERTY_NAME) Map(java.util.Map) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) ServiceRegistry(org.mule.runtime.core.api.registry.ServiceRegistry) ExtensionModelLoader(org.mule.runtime.extension.api.loader.ExtensionModelLoader) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) IOException(java.io.IOException) ImmutableList.copyOf(com.google.common.collect.ImmutableList.copyOf) String.format(java.lang.String.format) File(java.io.File) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) List(java.util.List) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) VERSION(org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader.VERSION) ExtensionSchemaGenerator(org.mule.runtime.extension.api.dsl.syntax.resources.spi.ExtensionSchemaGenerator) FileUtils(org.mule.runtime.core.api.util.FileUtils) DslResourceFactory(org.mule.runtime.extension.api.dsl.syntax.resources.spi.DslResourceFactory) ResourcesGenerator(org.mule.runtime.extension.api.resources.ResourcesGenerator) MuleExtensionModelProvider(org.mule.runtime.core.api.extension.MuleExtensionModelProvider) DslResolvingContext.getDefault(org.mule.runtime.api.dsl.DslResolvingContext.getDefault) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) HashSet(java.util.HashSet)

Example 4 with DslResolvingContext

use of org.mule.runtime.api.dsl.DslResolvingContext 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 5 with DslResolvingContext

use of org.mule.runtime.api.dsl.DslResolvingContext in project mule by mulesoft.

the class ExtensionModelJsonGeneratorTestCase method loadExtension.

public static ExtensionModel loadExtension(Class<?> clazz, ExtensionModelLoader loader) {
    Map<String, Object> params = new HashMap<>();
    params.put(TYPE_PROPERTY_NAME, clazz.getName());
    params.put(VERSION, "4.0.0-SNAPSHOT");
    // TODO MULE-11797: as this utils is consumed from
    // org.mule.runtime.module.extension.internal.capability.xml.schema.AbstractXmlResourceFactory.generateResource(org.mule.runtime.api.meta.model.ExtensionModel),
    // this util should get dropped once the ticket gets implemented.
    final DslResolvingContext dslResolvingContext = getDefault(emptySet());
    return loader.loadExtensionModel(clazz.getClassLoader(), dslResolvingContext, params);
}
Also used : HashMap(java.util.HashMap) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) IOUtils.getResourceAsString(org.mule.runtime.core.api.util.IOUtils.getResourceAsString)

Aggregations

DslResolvingContext (org.mule.runtime.api.dsl.DslResolvingContext)9 HashMap (java.util.HashMap)5 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)5 NullDslResolvingContext (org.mule.runtime.internal.dsl.NullDslResolvingContext)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 DslResolvingContext.getDefault (org.mule.runtime.api.dsl.DslResolvingContext.getDefault)2 ExtensionManager (org.mule.runtime.core.api.extension.ExtensionManager)2 IOUtils.getResourceAsString (org.mule.runtime.core.api.util.IOUtils.getResourceAsString)2 DslResourceFactory (org.mule.runtime.extension.api.dsl.syntax.resources.spi.DslResourceFactory)2 GeneratedResource (org.mule.runtime.extension.api.resources.GeneratedResource)2 GeneratedResourceFactory (org.mule.runtime.extension.api.resources.spi.GeneratedResourceFactory)2 DefaultJavaExtensionModelLoader (org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader)2 ImmutableList.copyOf (com.google.common.collect.ImmutableList.copyOf)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1