本文整理了Java中info.magnolia.config.source.yaml.YamlConfigurationSource
类的一些代码示例,展示了YamlConfigurationSource
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlConfigurationSource
类的具体详情如下:
包路径:info.magnolia.config.source.yaml.YamlConfigurationSource
类名称:YamlConfigurationSource
[英]Configuration source for yaml configuration files.
[中]yaml配置文件的配置源。
代码示例来源:origin: info.magnolia.core/magnolia-configuration
@Override
public void bindTo(Registry<?> registry) {
final Pattern pathPattern = validatePathPattern(this.pathPattern);
if (registry == null) {
throw new NullPointerException("Must pass a registry instance");
}
new YamlConfigurationSource<>(origin, map2BeanTransformer, registry, pathPattern, yamlReader, magnoliaConfigurationProperties, moduleRegistry).start();
}
代码示例来源:origin: info.magnolia.core/magnolia-configuration
@Override
protected void startDecoration() {
registerDefinitionDecoratorResolver(new FilePathBasedYamlDefinitionDecoratorResolver(map2BeanTransformer, getRegistry(), magnoliaConfigurationProperties));
super.startDecoration();
}
代码示例来源:origin: info.magnolia.core/magnolia-configuration
@Before
public void setUp() throws Exception {
final ModuleRegistry moduleRegistry = mock(ModuleRegistry.class);
when(moduleRegistry.getModuleNames()).thenReturn(Sets.newHashSet("info/magnolia/config/source/yaml/samples/decorators/fooModule"));
this.registry = new DummyRegistry();
this.resourceOrigin.mountClasspathLocation("info/magnolia/config/source/yaml/samples/decorators", "/foo/decoration");
MagnoliaConfigurationProperties magnoliaProperties = mock(MagnoliaConfigurationProperties.class);
YamlConfigurationSource<DummyThing> yamlSource =
new YamlConfigurationSource<>(mock(ResourceOrigin.class),
map2BeanTransformer,
registry,
Pattern.compile("/(fooModule)/(.*)\\.yaml"),
new YamlReader(),
magnoliaProperties,
mock(ModuleRegistry.class));
yamlSource.start();
yamlSource.loadAndRegister(singleResource(foo, "/fooModule/a.yaml", getResource(DEFINITION_RESOURCE).openStream()));
this.definitionReference = new DefaultDefinitionReference("fooModule", "a", "a");
}
代码示例来源:origin: info.magnolia.core/magnolia-configuration
@Test
public void detectsYamlDefinitionDecoratorUponStart() throws Exception {
// GIVEN
final DummyResource dummyDecoratorResource = DummyResourceOrigin.singleResource(foo, "/fooModule/decorations/barModule/dummyThings/qux.yaml", mock(Reader.class, ""));
// WHEN
final YamlConfigurationSource<DummyThing> src = newDummyYamlSource(".*", new DummyRegistry(), dummyDecoratorResource.getOrigin());
src.start();
// THEN
assertThat(src.getResolvedDefinitionDecorators().entrySet(), hasSize(1));
}
代码示例来源:origin: info.magnolia.core/magnolia-configuration
private DummyRegistry loadSingleFileInRegistry(Path path, String pathPattern) throws Exception {
final DummyRegistry registry = new DummyRegistry();
final YamlConfigurationSource<DummyThing> src = newDummyYamlSource(pathPattern, registry);
assertThat(registry.getAllProviders(), is(empty()));
assertTrue("pre-flight check for existence of " + path, Files.exists(path));
final Reader reader = Files.newBufferedReader(path, Charset.forName("UTF-8"));
String resourcePath = "/" + rootPath.relativize(path);
// WHEN
src.loadAndRegister(DummyResourceOrigin.singleResource(foo, resourcePath, reader));
return registry;
}
代码示例来源:origin: info.magnolia.core/magnolia-configuration
private YamlConfigurationSource<DummyThing> newDummyYamlSource(String pathPattern, DummyRegistry registry, ResourceOrigin resourceOrigin) throws IOException {
return new YamlConfigurationSource<>(resourceOrigin, map2BeanTransformer, registry, Pattern.compile(pathPattern), new YamlReader(), magnoliaConfigurationProperties.get(), mock(ModuleRegistry.class));
}
代码示例来源:origin: info.magnolia.core/magnolia-configuration
final DefinitionProviderBuilder<T> builder = relatedSource.getRegistry().newDefinitionProviderBuilder();
final DefinitionMetadataBuilder metadataBuilder = relatedSource.createMetadata(yamlResource);
String currentModule = metadataBuilder.getModule();
yamlReader.registerCustomMultiConstruct(InheritDefinition.TAG_PREFIX, new InheritDefinition<>(this.relatedSource.getRegistry(), moduleRegistry, currentModule, metadataBuilder.getName(), problemCollector));
yamlReader.registerCustomMultiConstruct(IncludeFileYamlWithModificationPossibility.TAG_PREFIX, new IncludeFileYamlWithModificationPossibility(yamlReader, resourceOrigin, problemCollector));
yamlReader.registerCustomMultiConstruct(WrapMetadata.TAG_PREFIX, new WrapMetadata(problemCollector));
if (NamedDefinition.class.isAssignableFrom(relatedSource.getRootType())) {
final Object nameValue = filteredMap.get(NAME_PROPERTY);
if (nameValue instanceof String) {
return builder.buildFromTransformationResult(map2BeanTransformer.transform(filteredMap, relatedSource.getRootType()));
代码示例来源:origin: info.magnolia.core/magnolia-configuration
@Override
public void loadAndRegister(Resource resource) {
if (resource == null) {
throw new IllegalStateException("Resource cannot be null");
}
final YamlDefinitionProvider<T> definitionProvider = new YamlDefinitionProvider<>(
this,
resource,
map2BeanTransformer,
yamlReader,
moduleRegistry);
getRegistry().register(definitionProvider);
log.info("Registered definition from YAML file [{}]: {}", resource.getPath(), definitionProvider.getMetadata());
DefinitionProviderProblemLogger
.withLoggingContext(log, magnoliaConfigurationProperties.getBooleanProperty("magnolia.develop"))
.logProblems(definitionProvider);
}
}
代码示例来源:origin: info.magnolia.core/magnolia-configuration
final JcrConfigurationSource<DummyThing> source = new JcrConfigurationSource<>(registry, "dummies", Predicate.TRUE, moduleRegistry, map2BeanTransformer);
final YamlConfigurationSource<DummyThing> yamlSource =
new YamlConfigurationSource<>(mock(ResourceOrigin.class),
map2BeanTransformer,
registry,
yamlSource.start();
final DummyResource yamlResource = DummyResourceOrigin.singleResource(foo, "/fooModule/a_yaml.yaml", conversionResult);
yamlSource.loadAndRegister(yamlResource);
代码示例来源:origin: info.magnolia.core/magnolia-configuration
@Test
public void definitionDecoratorsRemovedUponWholeDecorationFolderRemoval() throws Exception {
// GIVEN
tempFileSystemResourceOrigin.addResource("/fooModule/decorations/barModule/dummyThings/qux.yaml", "");
// WHEN
final YamlConfigurationSource<DummyThing> src = newDummyYamlSource(".*", new DummyRegistry(), tempFileSystemResourceOrigin.get());
src.start();
// THEN
assertThat(src.getResolvedDefinitionDecorators().entrySet(), hasSize(1));
// WHEN
tempFileSystemResourceOrigin.deleteResource("/fooModule/decorations/");
// THEN
assertThat(src.getResolvedDefinitionDecorators().entrySet(), empty());
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
private void prepareItem(String contentTypeName) throws Exception {
String appFileName = String.format("apps/%sApp.yaml", contentTypeName);
String appDescriptorContent = String.format("!with-type:%s", contentTypeName);
appYamlConfigSource.loadAndRegister(tempFileSystemResourceOrigin.addResource(appFileName, appDescriptorContent));
contentTypeDefinition = (ConfiguredContentTypeDefinition) contentTypeRegistry.getProvider(contentTypeName).get();
Node rootNode = MgnlContext.getJCRSession(((ConfiguredJcrDataSourceDefinition) contentTypeDefinition.getDatasource()).getWorkspace()).getRootNode();
Node baseNode = rootNode.addNode("item");
item = new JcrNodeAdapter(baseNode);
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
private <T> YamlConfigurationSource<T> mapRegistryWithYamlFolder(AbstractRegistry registry, String pathPattern) {
YamlConfigurationSource yamlSource = new YamlConfigurationSource<T>(resourceOrigin,
map2BeanTransformer,
registry,
Pattern.compile(pathPattern),
yamlReader,
magnoliaProperties,
moduleRegistry);
yamlSource.start();
return yamlSource;
}
代码示例来源:origin: info.magnolia.core/magnolia-configuration
@Test
public void registerProviderWithNullResource() throws Exception {
// GIVEN
final DummyRegistry registry = new DummyRegistry();
final YamlConfigurationSource<DummyThing> src = newDummyYamlSource(".*", registry);
assertThat(registry.getAllProviders(), is(empty()));
// WHEN
assertThat(() -> src.loadAndRegister(null), throwsAnException(strictlyInstanceOf(IllegalStateException.class).withMessage(containsString("Resource cannot be null"))));
}
代码示例来源:origin: info.magnolia.core/magnolia-configuration
new YamlConfigurationSource<>(
resourceOrigin.get(),
map2BeanTransformer,
);
sourceCreator.apply(dummyRegistry).start();
sourceCreator.apply(dummyRegistryWithNameAsId).start();
代码示例来源:origin: info.magnolia.core/magnolia-configuration
@Test
public void registerProviderEvenIfFileCantBeLoaded() throws Exception {
// GIVEN
final DummyResource resource = DummyResourceOrigin.singleResource("/this.file.does.not.exist");
final DummyRegistry registry = new DummyRegistry();
final YamlConfigurationSource<DummyThing> src = newDummyYamlSource(".*", registry);
assertThat(registry.getAllProviders(), is(empty()));
// WHEN
src.loadAndRegister(resource);
// THEN
assertThat(registry.getAllProviders(), hasSize(1));
final DefinitionProvider<DummyThing> registeredProvider = registry.getAllProviders().iterator().next();
final DefinitionMetadata metadata = registeredProvider.getMetadata();
assertFalse(registeredProvider.isValid());
assertThat(registeredProvider::get, throwsAnException(strictlyInstanceOf(Registry.InvalidDefinitionException.class).withMessage(matchesRegex("yaml:this.file.does.not"))));
assertThat(registeredProvider.getProblems(), contains(
problem()
.withDetails(containsString("Illegal state: reader() is not implemented for anything"))
.withType(RESOLUTION)
.withSeverityType(Problem.SeverityType.SEVERE)));
assertNotNull(metadata);
assertEquals(ExampleDefinitionTypes.dummyThing, metadata.getType());
assertEquals("/this.file.does.not.exist", metadata.getLocation());
assertEquals("yaml:this.file.does.not", metadata.getReferenceId());
assertEquals("yaml", metadata.getModule()); // This is the default from info.magnolia.config.source.yaml.RegexBasedPathToMetadataInferrer.moduleName
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
@Before
public void setUp() throws Exception {
tempFileSystemResourceOrigin.mountClasspathLocation("fooModule", "");
resourceOrigin = tempFileSystemResourceOrigin.get();
ComponentsTestUtil.setImplementation(ContentTypeDefinition.class, ConfiguredContentTypeDefinition.class);
ComponentsTestUtil.setImplementation(DataSourceDefinition.class, ConfiguredJcrDataSourceDefinition.class);
ComponentsTestUtil.setImplementation(ModelDefinition.class, ConfiguredJcrModelDefinition.class);
ComponentsTestUtil.setImplementation(SubModelDefinition.class, ConfiguredJcrSubModelDefinition.class);
ComponentsTestUtil.setImplementation(PropertyDefinition.class, ConfiguredPropertyDefinition.class);
moduleRegistry = mock(ModuleRegistry.class);
appDescriptorRegistry = mock(AppDescriptorRegistry.class);
eventBus = mock(EventBus.class);
contentTypeRegistry = new ContentTypeRegistry(moduleRegistry, eventBus);
yamlReader = new YamlReader();
AppWithContentType appWithContentType = new AppWithContentType(contentTypeRegistry, appDescriptorRegistry, yamlReader, resourceOrigin);
yamlReader.registerCustomMultiConstruct(AppWithContentType.TAG_PREFIX, appWithContentType);
map2BeanTransformer = new Map2BeanTransformer(Components.getComponentProvider(), new TypeMappingImpl(), new PreConfiguredBeanUtils(), new BeanTypeResolver());
magnoliaProperties = mock(MagnoliaConfigurationProperties.class);
YamlConfigurationSource<ContentTypeDefinition> contentTypesYamlSource =
new YamlConfigurationSource<>(resourceOrigin,
map2BeanTransformer,
contentTypeRegistry,
Pattern.compile("/contentTypes/(.*)\\.yaml"),
new YamlReader(),
magnoliaProperties,
moduleRegistry);
contentTypesYamlSource.start();
contentTypeDefinition = (ConfiguredContentTypeDefinition) contentTypeRegistry.getProvider("pizza").get();
modelDefinition = (ConfiguredJcrModelDefinition) contentTypeDefinition.getModel();
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
new YamlConfigurationSource<>(resourceOrigin,
map2BeanTransformer,
appDescriptorRegistry,
moduleRegistry);
appsYamlSource.start();
内容来源于网络,如有侵权,请联系作者删除!