use of com.synopsys.integration.configuration.source.PropertySource in project synopsys-detect by blackducksoftware.
the class SpringConfigurationPropertySourceTests method verifySpringReturnsValue.
@Test
public void verifySpringReturnsValue() throws InvalidPropertyException {
MockEnvironment m = new MockEnvironment();
m.setProperty("example.key", "value");
List<PropertySource> sources = new ArrayList<>(SpringConfigurationPropertySource.fromConfigurableEnvironment(m, true));
PropertyConfiguration config = new PropertyConfiguration(sources);
NullableAlikeProperty<String> property = new NullableStringProperty("example.key");
Assertions.assertEquals(Optional.of("value"), config.getValue(property));
Assertions.assertEquals(Optional.of("mockProperties"), config.getPropertySource(property));
}
use of com.synopsys.integration.configuration.source.PropertySource in project synopsys-detect by blackducksoftware.
the class PropertyConfiguration method resolveFromPropertySources.
private PropertyResolution resolveFromPropertySources(@NotNull String key) {
Assert.notNull(key, "Cannot resolve a null key.");
for (PropertySource propertySource : orderedPropertySources) {
if (propertySource.hasKey(key)) {
String rawValue = propertySource.getValue(key);
if (rawValue != null) {
String name = propertySource.getName();
String origin = propertySource.getOrigin(key);
PropertyResolutionInfo propertyResolutionInfo = new PropertyResolutionInfo(name, origin, rawValue);
return new SourcePropertyResolution(propertyResolutionInfo);
}
}
}
return new NoPropertyResolution();
}
use of com.synopsys.integration.configuration.source.PropertySource in project synopsys-detect by blackducksoftware.
the class DetectConfigurationFactoryTestUtils method factoryOf.
@SafeVarargs
public static DetectConfigurationFactory factoryOf(Pair<Property, String>... properties) {
Map<String, String> propertyMap = Bds.of(properties).toMap(pair -> pair.getLeft().getKey(), Pair::getRight);
PropertySource inMemoryPropertySource = new MapPropertySource("test", propertyMap);
PropertyConfiguration propertyConfiguration = new PropertyConfiguration(Collections.singletonList(inMemoryPropertySource));
DetectPropertyConfiguration detectPropertyConfiguration = new DetectPropertyConfiguration(propertyConfiguration, new SimplePathResolver());
return new DetectConfigurationFactory(detectPropertyConfiguration, new Gson());
}
use of com.synopsys.integration.configuration.source.PropertySource in project synopsys-detect by blackducksoftware.
the class DetectConfigurationTest method testGenericProperty.
@Test
public void testGenericProperty() {
HashMap<String, String> values = new HashMap<>();
values.put(DetectProperties.DETECT_PROJECT_CODELOCATION_PREFIX.getKey(), "some_prefix");
List<PropertySource> propertySources = new ArrayList<>();
propertySources.add(new MapPropertySource("test", values));
PropertyConfiguration propertyConfiguration = new PropertyConfiguration(propertySources);
DetectPropertyConfiguration detectPropertyConfiguration = new DetectPropertyConfiguration(propertyConfiguration, new SimplePathResolver());
DetectConfigurationFactory detectConfigurationFactory = new DetectConfigurationFactory(detectPropertyConfiguration, new Gson());
BdioOptions bdioOptions = detectConfigurationFactory.createBdioOptions();
assertTrue(bdioOptions.getProjectCodeLocationPrefix().isPresent());
assertEquals("some_prefix", bdioOptions.getProjectCodeLocationPrefix().get());
}
use of com.synopsys.integration.configuration.source.PropertySource in project synopsys-detect by blackducksoftware.
the class Application method bootApplication.
private Optional<DetectBootResult> bootApplication(DetectRunId detectRunId, String[] sourceArgs, EventSystem eventSystem, ExitCodeManager exitCodeManager, Gson gson, DetectInfo detectInfo, FileFinder fileFinder, InstalledToolManager installedToolManager, ExceptionUtility exceptionUtility) {
Optional<DetectBootResult> bootResult = Optional.empty();
try {
logger.debug("Detect boot begin.");
DetectArgumentStateParser detectArgumentStateParser = new DetectArgumentStateParser();
DetectArgumentState detectArgumentState = detectArgumentStateParser.parseArgs(sourceArgs);
List<PropertySource> propertySources = new ArrayList<>(SpringConfigurationPropertySource.fromConfigurableEnvironmentSafely(environment, logger::error));
DetectBootFactory detectBootFactory = new DetectBootFactory(detectRunId, detectInfo, gson, eventSystem, fileFinder);
DetectBoot detectBoot = new DetectBoot(eventSystem, gson, detectBootFactory, detectArgumentState, propertySources, installedToolManager);
bootResult = detectBoot.boot(detectInfo.getDetectVersion(), detectInfo.getBuildDateString());
logger.debug("Detect boot completed.");
} catch (Exception e) {
logger.error("Detect boot failed.");
logger.error("");
exceptionUtility.logException(e);
exitCodeManager.requestExitCode(e);
logger.error("");
// TODO- should we return a DetectBootResult.exception(...) here?
}
return bootResult;
}
Aggregations