Search in sources :

Example 1 with ExtensionTypeDescriptorModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty in project mule by mulesoft.

the class MulePluginDescriptorGenerator method generateResource.

/**
 * {@inheritDoc}
 */
@Override
public Optional<GeneratedResource> generateResource(ExtensionModel extensionModel) {
    final Optional<ExtensionTypeDescriptorModelProperty> typeProperty = extensionModel.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
    if (!typeProperty.isPresent()) {
        return empty();
    }
    final ExportedArtifactsCollector exportCollector = new ExportedArtifactsCollector(extensionModel, new DefaultClassPackageFinder(processingEnvironment));
    final MulePluginModelBuilder builder = new MulePluginModelBuilder();
    // Set only for testing purposes, the value will be reset by the plugin packager.
    builder.setName(extensionModel.getName());
    builder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptorBuilder().setId(MULE_LOADER_ID).addProperty(EXPORTED_PACKAGES, exportCollector.getExportedPackages()).addProperty(EXPORTED_RESOURCES, exportCollector.getExportedResources()).addProperty(PRIVILEGED_EXPORTED_PACKAGES, exportCollector.getPrivilegedExportedPackages()).addProperty(PRIVILEGED_ARTIFACTS_IDS, exportCollector.getPrivilegedArtifacts()).build());
    builder.withExtensionModelDescriber().setId(getLoaderId(extensionModel)).addProperty(TYPE_PROPERTY_NAME, typeProperty.get().getType().getTypeName()).addProperty("version", extensionModel.getVersion());
    builder.withBundleDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
    final Optional<LicenseModelProperty> licenseModelPropertyOptional = extensionModel.getModelProperty(LicenseModelProperty.class);
    builder.setRequiredProduct(extensionModel.getCategory().equals(COMMUNITY) ? MULE : MULE_EE);
    licenseModelPropertyOptional.ifPresent(licenseModelProperty -> {
        builder.setRequiredProduct(licenseModelProperty.requiresEeLicense() ? MULE_EE : MULE);
        if (licenseModelProperty.requiresEeLicense()) {
            builder.withLicenseModel().setAllowsEvaluationLicense(licenseModelProperty.isAllowsEvaluationLicense());
            licenseModelProperty.getRequiredEntitlement().ifPresent(requiredEntitlement -> builder.withLicenseModel().setProvider(extensionModel.getVendor()).setRequiredEntitlement(requiredEntitlement));
        }
    });
    final String descriptorJson = new MulePluginModelJsonSerializer().serialize(builder.build());
    return of(new GeneratedResource(AUTO_GENERATED_MULE_ARTIFACT_DESCRIPTOR, descriptorJson.getBytes()));
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) ExportedArtifactsCollector(org.mule.runtime.module.extension.internal.resources.manifest.ExportedArtifactsCollector) MuleArtifactLoaderDescriptorBuilder(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) MulePluginModelJsonSerializer(org.mule.runtime.api.deployment.persistence.MulePluginModelJsonSerializer) DefaultClassPackageFinder(org.mule.runtime.module.extension.internal.resources.manifest.DefaultClassPackageFinder) GeneratedResource(org.mule.runtime.extension.api.resources.GeneratedResource) MulePluginModelBuilder(org.mule.runtime.api.deployment.meta.MulePluginModel.MulePluginModelBuilder) LicenseModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.LicenseModelProperty)

Example 2 with ExtensionTypeDescriptorModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty in project mule by mulesoft.

the class ConfigModelLoaderDelegate method declareConfiguration.

private void declareConfiguration(ExtensionDeclarer declarer, ExtensionElement extensionType, ComponentElement configType) {
    checkConfigurationIsNotAnOperation(extensionType, configType);
    ConfigurationDeclarer configurationDeclarer;
    Optional<Configuration> configurationAnnotation = configType.getAnnotation(Configuration.class);
    if (configurationAnnotation.isPresent()) {
        final Configuration configuration = configurationAnnotation.get();
        String configName = isBlank(configuration.name()) ? DEFAULT_CONFIG_NAME : configuration.name();
        configurationDeclarer = declarer.withConfig(configName);
    } else {
        configurationDeclarer = declarer.withConfig(DEFAULT_CONFIG_NAME).describedAs(DEFAULT_CONFIG_DESCRIPTION);
    }
    Class<?> extensionClass = extensionType.getDeclaringClass().orElse(Object.class);
    Class<?> configClass = configType.getDeclaringClass().orElse(Object.class);
    ClassLoader classLoader = extensionClass.getClassLoader() != null ? extensionClass.getClassLoader() : Thread.currentThread().getContextClassLoader();
    TypeAwareConfigurationFactory typeAwareConfigurationFactory = new TypeAwareConfigurationFactory(configClass, classLoader);
    configurationDeclarer.withModelProperty(new ConfigurationFactoryModelProperty(typeAwareConfigurationFactory)).withModelProperty(new ImplementingTypeModelProperty(configClass));
    configurationDeclarer.withModelProperty(new ExtensionTypeDescriptorModelProperty(configType));
    loader.parseExternalLibs(configType, configurationDeclarer);
    ParameterDeclarationContext context = new ParameterDeclarationContext(CONFIGURATION, configurationDeclarer.getDeclaration());
    loader.getFieldParametersLoader().declare(configurationDeclarer, configType.getParameters(), context);
    getOperationLoaderDelegate().declareOperations(declarer, configurationDeclarer, configType);
    getSourceModelLoaderDelegate().declareMessageSources(declarer, configurationDeclarer, configType);
    getFunctionModelLoaderDelegate().declareFunctions(declarer, configurationDeclarer, configType);
    getConnectionProviderModelLoaderDelegate().declareConnectionProviders(configurationDeclarer, configType);
}
Also used : ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) Configuration(org.mule.runtime.extension.api.annotation.Configuration) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ConfigurationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclarer) ConfigurationFactoryModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ConfigurationFactoryModelProperty) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty)

Example 3 with ExtensionTypeDescriptorModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty in project mule by mulesoft.

the class ConnectionProviderModelLoaderDelegate method declareConnectionProvider.

private void declareConnectionProvider(HasConnectionProviderDeclarer declarer, ConnectionProviderElement providerType) {
    ConnectionProviderDeclarer providerDeclarer = connectionProviderDeclarers.get(providerType);
    if (providerDeclarer != null) {
        declarer.withConnectionProvider(providerDeclarer);
        return;
    }
    String name = providerType.getAlias();
    String description = providerType.getDescription();
    if (providerType.getName().equals(providerType.getAlias())) {
        name = DEFAULT_CONNECTION_PROVIDER_NAME;
    }
    List<Type> providerGenerics = providerType.getInterfaceGenerics(ConnectionProvider.class);
    if (providerGenerics.size() != 1) {
        // TODO: MULE-9220: Add a syntax validator for this
        throw new IllegalConnectionProviderModelDefinitionException(format("Connection provider class '%s' was expected to have 1 generic type " + "(for the connection type) but %d were found", providerType.getName(), providerGenerics.size()));
    }
    providerDeclarer = declarer.withConnectionProvider(name).describedAs(description);
    ConnectionProviderDeclarer finalProviderDeclarer = providerDeclarer;
    providerType.getDeclaringClass().ifPresent(clazz -> finalProviderDeclarer.withModelProperty(new ConnectionProviderFactoryModelProperty(new DefaultConnectionProviderFactory<>(clazz, getExtensionClassLoader()))).withModelProperty(new ImplementingTypeModelProperty(clazz)));
    providerDeclarer.withModelProperty(new ConnectionTypeModelProperty(providerGenerics.get(0))).withModelProperty(new ExtensionTypeDescriptorModelProperty(providerType));
    loader.parseExternalLibs(providerType, providerDeclarer);
    ConnectionManagementType managementType = NONE;
    if (providerType.isAssignableTo(PoolingConnectionProvider.class)) {
        managementType = POOLING;
    } else if (providerType.isAssignableTo(CachedConnectionProvider.class)) {
        managementType = CACHED;
    }
    parseOAuthGrantType(providerType, providerDeclarer);
    providerDeclarer.withConnectionManagementType(managementType);
    providerDeclarer.supportsConnectivityTesting(!providerType.isAssignableTo(NoConnectivityTest.class));
    connectionProviderDeclarers.put(providerType, providerDeclarer);
    ParameterDeclarationContext context = new ParameterDeclarationContext(CONNECTION_PROVIDER, providerDeclarer.getDeclaration());
    loader.getFieldParametersLoader().declare(providerDeclarer, providerType.getParameters(), context);
}
Also used : ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ConnectionManagementType(org.mule.runtime.api.meta.model.connection.ConnectionManagementType) CachedConnectionProvider(org.mule.runtime.api.connection.CachedConnectionProvider) IllegalConnectionProviderModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalConnectionProviderModelDefinitionException) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) ConnectionManagementType(org.mule.runtime.api.meta.model.connection.ConnectionManagementType) AuthorizationCodeGrantType(org.mule.runtime.extension.api.connectivity.oauth.AuthorizationCodeGrantType) ConnectionProviderDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer) HasConnectionProviderDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasConnectionProviderDeclarer) ConnectionProviderFactoryModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ConnectionProviderFactoryModelProperty) ConnectionTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ConnectionTypeModelProperty) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty)

Example 4 with ExtensionTypeDescriptorModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty in project mule by mulesoft.

the class SourceModelLoaderDelegate method declareMessageSource.

void declareMessageSource(ExtensionDeclarer extensionDeclarer, HasSourceDeclarer declarer, SourceElement sourceType, boolean supportsConfig) {
    // TODO: MULE-9220 - Add a syntax validator which checks that the sourceType doesn't implement
    if (isLifecycle(sourceType)) {
        throw new IllegalSourceModelDefinitionException(format("Source class '%s' implements a lifecycle interface. Sources are not allowed to", sourceType.getName()));
    }
    final Optional<ExtensionParameter> configParameter = loader.getConfigParameter(sourceType);
    final Optional<ExtensionParameter> connectionParameter = loader.getConnectionParameter(sourceType);
    if (loader.isInvalidConfigSupport(supportsConfig, configParameter, connectionParameter)) {
        throw new IllegalSourceModelDefinitionException(format("Source '%s' is defined at the extension level but it requires a config parameter. " + "Remove such parameter or move the source to the proper config", sourceType.getName()));
    }
    HasSourceDeclarer actualDeclarer = (HasSourceDeclarer) loader.selectDeclarerBasedOnConfig(extensionDeclarer, (Declarer) declarer, configParameter, connectionParameter);
    SourceDeclarer existingDeclarer = sourceDeclarers.get(sourceType);
    if (existingDeclarer != null) {
        actualDeclarer.withMessageSource(existingDeclarer);
        return;
    }
    SourceDeclarer sourceDeclarer = actualDeclarer.withMessageSource(sourceType.getAlias());
    sourceDeclarer.withModelProperty(new ExtensionTypeDescriptorModelProperty(sourceType));
    List<Type> sourceGenerics = sourceType.getSuperClassGenerics();
    if (sourceGenerics.size() != 2) {
        // TODO: MULE-9220: Add a syntax validator for this
        throw new IllegalModelDefinitionException(format("Message source class '%s' was expected to have 2 generic types " + "(one for the Payload type and another for the Attributes type) but %d were found", sourceType.getName(), sourceGenerics.size()));
    }
    sourceDeclarer.hasResponse(sourceType.isAnnotatedWith(EmitsResponse.class)).requiresConnection(connectionParameter.isPresent());
    sourceType.getDeclaringClass().ifPresent(clazz -> sourceDeclarer.withModelProperty(new SourceFactoryModelProperty(new DefaultSourceFactory((Class<? extends Source>) clazz))).withModelProperty(new ImplementingTypeModelProperty(clazz)));
    processMimeType(sourceDeclarer, sourceType);
    processComponentConnectivity(sourceDeclarer, sourceType, sourceType);
    resolveOutputTypes(sourceDeclarer, sourceType);
    loader.addExceptionEnricher(sourceType, sourceDeclarer);
    declareSourceParameters(sourceType, sourceDeclarer);
    declareSourceCallback(sourceType, sourceDeclarer);
    sourceDeclarers.put(sourceType, sourceDeclarer);
}
Also used : ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) IllegalSourceModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalSourceModelDefinitionException) HasSourceDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasSourceDeclarer) SourceFactoryModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.SourceFactoryModelProperty) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) MetadataType(org.mule.metadata.api.model.MetadataType) DefaultSourceFactory(org.mule.runtime.module.extension.internal.runtime.source.DefaultSourceFactory) SourceDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclarer) HasSourceDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasSourceDeclarer) SourceDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclarer) HasSourceDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasSourceDeclarer) ParameterizedDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclarer) ParameterDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclarer) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) Declarer(org.mule.runtime.api.meta.model.declaration.fluent.Declarer) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty)

Example 5 with ExtensionTypeDescriptorModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty in project mule by mulesoft.

the class JavaExportedTypesDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    Optional<ExtensionTypeDescriptorModelProperty> modelProperty = extensionLoadingContext.getExtensionDeclarer().getDeclaration().getModelProperty(ExtensionTypeDescriptorModelProperty.class);
    modelProperty.map(ExtensionTypeDescriptorModelProperty::getType).flatMap(type -> type.getValueFromAnnotation(Export.class)).ifPresent(exportAnnotation -> {
        ExtensionDeclarer declarer = extensionLoadingContext.getExtensionDeclarer();
        exportAnnotation.getClassArrayValue(Export::classes).stream().map(Type::asMetadataType).forEach(type -> registerType(declarer, type));
        exportAnnotation.getArrayValue(Export::resources).forEach(declarer::withResource);
    });
}
Also used : ObjectType(org.mule.metadata.api.model.ObjectType) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) DeclarationEnricherPhase(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) Export(org.mule.runtime.extension.api.annotation.Export) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) ObjectFieldType(org.mule.metadata.api.model.ObjectFieldType) ArrayType(org.mule.metadata.api.model.ArrayType) IntersectionType(org.mule.metadata.api.model.IntersectionType) MetadataType(org.mule.metadata.api.model.MetadataType) Optional(java.util.Optional) UnionType(org.mule.metadata.api.model.UnionType) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) INITIALIZE(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase.INITIALIZE) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)

Aggregations

ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)15 Type (org.mule.runtime.module.extension.api.loader.java.type.Type)9 ExtensionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)6 MetadataType (org.mule.metadata.api.model.MetadataType)5 ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)5 ImplementingTypeModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty)4 Optional (java.util.Optional)3 ObjectType (org.mule.metadata.api.model.ObjectType)3 IllegalModelDefinitionException (org.mule.runtime.extension.api.exception.IllegalModelDefinitionException)3 ExtensionLoadingContext (org.mule.runtime.extension.api.loader.ExtensionLoadingContext)3 ArrayType (org.mule.metadata.api.model.ArrayType)2 DeclarationEnricherPhase (org.mule.runtime.extension.api.loader.DeclarationEnricherPhase)2 INITIALIZE (org.mule.runtime.extension.api.loader.DeclarationEnricherPhase.INITIALIZE)2 AnnotationValueFetcher (org.mule.runtime.module.extension.api.loader.java.type.AnnotationValueFetcher)2 ParameterDeclarationContext (org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext)2 String.format (java.lang.String.format)1 Arrays.stream (java.util.Arrays.stream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional.ofNullable (java.util.Optional.ofNullable)1