private Optional<ConfigurationDeclaration> findMatchingConfiguration(ExtensionDeclaration declaration, TypeElement element) { List<ConfigurationDeclaration> configurations = declaration.getConfigurations(); if (configurations.size() == 1) { return Optional.of(configurations.get(0)); } return configurations.stream() .filter(config -> { Configuration configurationAnnotation = element.getAnnotation(Configuration.class); String name = config.getName(); String annotationName = configurationAnnotation != null ? configurationAnnotation.name() : ""; String defaultNaming = hyphenize(element.getSimpleName().toString()); return name.equals(defaultNaming) || name.equals(annotationName) || name.equals(DEFAULT_CONFIG_NAME); }) .findAny(); } }
@Override public void enrich(ExtensionLoadingContext extensionLoadingContext) { ExtensionDeclarer extensionDeclarer = extensionLoadingContext.getExtensionDeclarer(); extensionDeclarer .getDeclaration() .getModelProperty(ExtensionTypeDescriptorModelProperty.class) .map(ExtensionTypeDescriptorModelProperty::getType) .flatMap(type -> type.getValueFromAnnotation(PrivilegedExport.class)) .ifPresent(valueFetcher -> { valueFetcher.getArrayValue(PrivilegedExport::artifacts).forEach(extensionDeclarer::withPrivilegedArtifact); valueFetcher.getArrayValue(PrivilegedExport::packages).forEach(extensionDeclarer::withPrivilegedPackage); }); } }
extensionDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class); if (!extensionType.isPresent()) { return; format("There should be only one Import declaration for any given type in extension [%s]." + " Multiple imports of the same type are not allowed", extensionDeclaration.getName())); .addImportedType(new ImportedTypeModel((ObjectType) importedType)); });
private XmlDslModel getXmlLanguageModel(Xml xml, ExtensionDeclaration extensionDeclaration) { final Optional<String> extensionNamespace = xml != null ? ofNullable(xml.prefix()) : empty(); final Optional<String> extensionNamespaceLocation = xml != null ? ofNullable(xml.namespace()) : empty(); return createXmlLanguageModel(extensionNamespace, extensionNamespaceLocation, extensionDeclaration.getName(), extensionDeclaration.getVersion()); } }
@Override public void enrich(ExtensionLoadingContext extensionLoadingContext) { ExtensionDeclarer declarer = extensionLoadingContext.getExtensionDeclarer(); ExtensionDeclaration extensionDeclaration = declarer.getDeclaration(); Optional<ExtensionTypeDescriptorModelProperty> implementingType = extensionDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class); if (!implementingType.isPresent()) { return; } Type type = implementingType.get().getType(); List<AnnotationValueFetcher<SubTypeMapping>> typeMappings = parseRepeatableAnnotation(type, SubTypeMapping.class, c -> ((SubTypesMapping) c).value()); if (!typeMappings.isEmpty()) { declareSubTypesMapping(declarer, typeMappings, extensionDeclaration.getName()); } }
@Test public void extension() { assertThat(extensionDeclaration.getName(), is(VEGAN)); assertThat(extensionDeclaration.getConfigurations(), hasSize(6)); assertOperation(APPLE, "eatApple"); assertOperation(BANANA, "eatBanana"); assertOperation(KIWI, "eatKiwi"); }
private Set<ErrorModel> getSoapErrors(ExtensionDeclarer declarer) { ErrorsModelFactory factory = new ErrorsModelFactory(SoapErrors.class.getEnumConstants(), declarer.getDeclaration().getName()); return factory.getErrorModels(); } }
@Before public void setUp() { when(loadingContext.getExtensionDeclarer().getDeclaration()).thenReturn(declaration); when(declaration.getConnectionProviders()).thenReturn(singletonList(connectionProviderDeclaration)); when(declaration.getConfigurations()).thenReturn(singletonList(configurationDeclaration)); ExtensionParameterDescriptorModelProperty descriptorModelProperty = mock(ExtensionParameterDescriptorModelProperty.class); when(parameterDeclaration.getModelProperty(ExtensionParameterDescriptorModelProperty.class)) .thenReturn(Optional.of(descriptorModelProperty)); when(parameterDeclaration.getName()).thenReturn(REQUIRED_PARAM); when(descriptorModelProperty.getExtensionParameter()).thenReturn(extensionParameter); }
private void assertTestModuleMessageSource(ExtensionDeclaration extensionDeclaration) throws Exception { assertThat(extensionDeclaration.getMessageSources(), hasSize(1)); SourceDeclaration source = extensionDeclaration.getMessageSources().get(0); assertThat(source.getName(), is(DEA_SOURCE_NAME)); final MetadataType outputType = source.getOutput().getType(); assertThat(outputType, is(instanceOf(ArrayType.class))); MetadataType outputMetadataType = IntrospectionUtils.getReturnType(new TypeWrapper(Object.class, TYPE_LOADER)); assertMessageType(((ArrayType) outputType).getType(), STRING_TYPE, TYPE_LOADER.load(DEAOfficerAttributes.class)); assertThat(source.getOutputAttributes().getType(), equalTo(outputMetadataType)); ConfigurationDeclaration config = extensionDeclaration.getConfigurations().get(0); assertThat(config.getMessageSources(), hasSize(3)); assertHeisenbergSource(config.getMessageSources().get(0), ASYNC_SOURCE_NAME, AsyncHeisenbergSource.class); assertHeisenbergSource(config.getMessageSources().get(1), SOURCE_NAME, HeisenbergSource.class); }
private void assertTestModuleOperations(ExtensionDeclaration extensionDeclaration) throws Exception { assertThat(extensionDeclaration.getOperations(), hasSize(53)); WithOperationsDeclaration withOperationsDeclaration = extensionDeclaration.getConfigurations().get(0); assertThat(withOperationsDeclaration.getOperations().size(), is(19)); assertOperation(withOperationsDeclaration, SAY_MY_NAME_OPERATION, "");
ExtensionDeclaration declaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration(); Optional<ExtensionTypeDescriptorModelProperty> extensionType = declaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class); String extensionNamespace = getExtensionsNamespace(declaration); ClassTypeLoader typeLoader = ExtensionsTypeLoaderFactory.getDefault().createTypeLoader(); NotificationModel model = new ImmutableNotificationModel(extensionNamespace, ((Enum) action).name(), typeLoader.load(action.getDataType().getType())); declaration.addNotificationModel(model); notificationModels.put(action, model); });
/** * @return the extension's error namespace for a given {@link ExtensionDeclaration} */ public static String getExtensionsNamespace(ExtensionDeclaration extensionDeclaration) { return getExtensionsNamespace(extensionDeclaration.getXmlDslModel()); }
/** * Sets the description of the given {@link ExtensionDeclaration} and its inner configs and operations by extracting information * of the AST tree represented by {@code extensionElement} and {@code roundEnvironment} * * @param extensionDeclaration a {@link ExtensionDeclaration} on which configurations and operations have already been declared * @param extensionElement a {@link TypeElement} generated by an annotation {@link Processor} */ void document(ExtensionDeclaration extensionDeclaration, TypeElement extensionElement) { extensionDeclaration.setDescription(processor.getJavaDocSummary(processingEnv, extensionElement)); sourceDocumenter.document(extensionElement, extensionDeclaration); operationDocumenter.document(extensionElement, extensionDeclaration); documentConfigurations(extensionDeclaration, extensionElement); }
private void declareExportedTypes(ClassTypeLoader typeLoader, ExtensionDeclarer extensionDeclarer) { extensionDeclarer.getDeclaration().addType((ObjectType) typeLoader.load(ObjectStore.class)); }
private void assertExtensionProperties(ExtensionDeclaration extensionDeclaration, String expectedName) { assertThat(extensionDeclaration, is(notNullValue())); assertThat(extensionDeclaration.getName(), is(expectedName)); assertThat(extensionDeclaration.getVersion(), is(MULE_VERSION)); }
@Override public void enrich(ExtensionLoadingContext extensionLoadingContext) { ExtensionDeclarer declarer = extensionLoadingContext.getExtensionDeclarer(); ExtensionDeclaration extensionDeclaration = declarer.getDeclaration(); Optional<ExtensionTypeDescriptorModelProperty> implementingType = extensionDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class); if (!implementingType.isPresent()) { return; } Type type = implementingType.get().getType(); List<AnnotationValueFetcher<SubTypeMapping>> typeMappings = parseRepeatableAnnotation(type, SubTypeMapping.class, c -> ((SubTypesMapping) c).value()); if (!typeMappings.isEmpty()) { declareSubTypesMapping(declarer, typeMappings, extensionDeclaration.getName()); } }
/** * {@inheritDoc} */ @Override public void enrich(ExtensionLoadingContext loadingContext) { String name = loadingContext.getExtensionDeclarer().getDeclaration().getName(); ClassLoader classLoader = loadingContext.getExtensionClassLoader(); try (InputStream resource = classLoader.getResourceAsStream("META-INF/" + serializer.getFileName(name))) { if (resource != null) { XmlExtensionDocumentation documenter = withContextClassLoader( ExtensionDescriptionsEnricher.class .getClassLoader(), () -> serializer .deserialize(IOUtils.toString(resource))); document(loadingContext.getExtensionDeclarer().getDeclaration(), documenter); } } catch (IOException e) { throw new RuntimeException("Cannot get descriptions persisted in the extensions-descriptions.xml file", e); } }
@Before public void before() throws Exception { when(extensionLoadingContext.getExtensionDeclarer()).thenReturn(extensionDeclarer); when(extensionDeclarer.getDeclaration()).thenReturn(extensionDeclaration); when(extensionDeclaration.getConfigurations()).thenReturn(asList(configurationDeclaration)); when(extensionDeclaration.getConnectionProviders()).thenReturn(asList(connectionProviderDeclaration)); mockImplementingProperty(configurationDeclaration, TestNameAwareConfig.class); mockImplementingProperty(connectionProviderDeclaration, TestNameAwareConnectionProvider.class); configNameField = getAllFields(TestNameAwareConfig.class, withAnnotation(RefName.class)).iterator().next(); providerNameField = getAllFields(TestNameAwareConnectionProvider.class, withAnnotation(RefName.class)).iterator().next(); }
@Test public void declareStaticAndDynamicTypesInSource() { List<SourceDeclaration> messageSources = declaration.getConfigurations().get(0).getMessageSources(); SourceDeclaration sourceDynamicAttributes = getDeclaration(messageSources, "MetadataSource"); assertOutputType(sourceDynamicAttributes.getOutput(), TYPE_BUILDER.objectType() .with(new ClassInformationAnnotation(Map.class, asList(String.class, Object.class))) .openWith(TYPE_LOADER.load(Object.class)).build(), true); assertOutputType(sourceDynamicAttributes.getOutputAttributes(), toMetadataType(StringAttributes.class), false); assertParameterType(getDeclaration(sourceDynamicAttributes.getAllParameters(), "type"), toMetadataType(String.class)); messageSources = declaration.getMessageSources(); SourceDeclaration sourceStaticAttributes = getDeclaration(messageSources, "MetadataSourceWithMultilevel"); assertOutputType(sourceStaticAttributes.getOutput(), TYPE_BUILDER.objectType() .with(new ClassInformationAnnotation(Map.class, asList(String.class, Object.class))) .openWith(TYPE_LOADER.load(Object.class)).build(), true); assertOutputType(sourceStaticAttributes.getOutputAttributes(), toMetadataType(StringAttributes.class), false); List<ParameterDeclaration> locationKey = sourceStaticAttributes.getAllParameters(); assertParameterType(getDeclaration(locationKey, "continent"), toMetadataType(String.class)); assertParameterType(getDeclaration(locationKey, "country"), toMetadataType(String.class)); assertParameterType(getDeclaration(locationKey, "city"), toMetadataType(String.class)); }
@Test public void declareStaticAndDynamicTypesInOperation() { List<ParameterDeclaration> params; List<OperationDeclaration> operations = declaration.getConfigurations().get(0).getOperations(); MetadataType outputMetadataType = IntrospectionUtils.getReturnType(new TypeWrapper(Object.class, TYPE_LOADER)); MetadataType objectParameterMetadataType = (new ParameterTypeWrapper(Object.class, TYPE_LOADER)).asMetadataType(); assertParameterType(getDeclaration(params, "content"), objectParameterMetadataType); operations = declaration.getOperations(); OperationDeclaration dynamicOutputAndAttributes = getDeclaration(operations, "outputAttributesWithDynamicMetadata"); assertOutputType(dynamicOutputAndAttributes.getOutput(), toMetadataType(Object.class), true);