Search in sources :

Example 6 with PropertySource

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));
}
Also used : NullableStringProperty(com.synopsys.integration.configuration.property.types.string.NullableStringProperty) MockEnvironment(org.springframework.mock.env.MockEnvironment) ArrayList(java.util.ArrayList) PropertySource(com.synopsys.integration.configuration.source.PropertySource) SpringConfigurationPropertySource(com.synopsys.integration.configuration.source.SpringConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 7 with PropertySource

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();
}
Also used : SourcePropertyResolution(com.synopsys.integration.configuration.config.resolution.SourcePropertyResolution) PropertyResolutionInfo(com.synopsys.integration.configuration.config.resolution.PropertyResolutionInfo) PropertySource(com.synopsys.integration.configuration.source.PropertySource) NoPropertyResolution(com.synopsys.integration.configuration.config.resolution.NoPropertyResolution)

Example 8 with PropertySource

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());
}
Also used : MapPropertySource(com.synopsys.integration.configuration.source.MapPropertySource) Gson(com.google.gson.Gson) SimplePathResolver(com.synopsys.integration.configuration.property.types.path.SimplePathResolver) PropertyConfiguration(com.synopsys.integration.configuration.config.PropertyConfiguration) Pair(org.apache.commons.lang3.tuple.Pair) MapPropertySource(com.synopsys.integration.configuration.source.MapPropertySource) PropertySource(com.synopsys.integration.configuration.source.PropertySource)

Example 9 with PropertySource

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());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) SimplePathResolver(com.synopsys.integration.configuration.property.types.path.SimplePathResolver) MapPropertySource(com.synopsys.integration.configuration.source.MapPropertySource) PropertySource(com.synopsys.integration.configuration.source.PropertySource) BdioOptions(com.synopsys.integration.detect.workflow.bdio.BdioOptions) MapPropertySource(com.synopsys.integration.configuration.source.MapPropertySource) PropertyConfiguration(com.synopsys.integration.configuration.config.PropertyConfiguration) Test(org.junit.jupiter.api.Test)

Example 10 with PropertySource

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;
}
Also used : DetectArgumentState(com.synopsys.integration.detect.configuration.help.DetectArgumentState) DetectBoot(com.synopsys.integration.detect.lifecycle.boot.DetectBoot) DetectArgumentStateParser(com.synopsys.integration.detect.configuration.help.DetectArgumentStateParser) ArrayList(java.util.ArrayList) DetectBootResult(com.synopsys.integration.detect.lifecycle.boot.DetectBootResult) DetectBootFactory(com.synopsys.integration.detect.lifecycle.boot.DetectBootFactory) PropertySource(com.synopsys.integration.configuration.source.PropertySource) SpringConfigurationPropertySource(com.synopsys.integration.configuration.source.SpringConfigurationPropertySource)

Aggregations

PropertySource (com.synopsys.integration.configuration.source.PropertySource)16 Test (org.junit.jupiter.api.Test)12 MapPropertySource (com.synopsys.integration.configuration.source.MapPropertySource)7 ArrayList (java.util.ArrayList)6 PropertyConfiguration (com.synopsys.integration.configuration.config.PropertyConfiguration)5 NullableStringProperty (com.synopsys.integration.configuration.property.types.string.NullableStringProperty)5 SimplePathResolver (com.synopsys.integration.configuration.property.types.path.SimplePathResolver)4 Gson (com.google.gson.Gson)3 HashMap (java.util.HashMap)3 PassthroughProperty (com.synopsys.integration.configuration.property.base.PassthroughProperty)2 SpringConfigurationPropertySource (com.synopsys.integration.configuration.source.SpringConfigurationPropertySource)2 BdioOptions (com.synopsys.integration.detect.workflow.bdio.BdioOptions)2 BlackDuckServerConfig (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig)1 NoPropertyResolution (com.synopsys.integration.configuration.config.resolution.NoPropertyResolution)1 PropertyResolutionInfo (com.synopsys.integration.configuration.config.resolution.PropertyResolutionInfo)1 SourcePropertyResolution (com.synopsys.integration.configuration.config.resolution.SourcePropertyResolution)1 DetectConfigurationFactory (com.synopsys.integration.detect.configuration.DetectConfigurationFactory)1 DetectPropertyConfiguration (com.synopsys.integration.detect.configuration.DetectPropertyConfiguration)1 BlackDuckConfigFactory (com.synopsys.integration.detect.configuration.connection.BlackDuckConfigFactory)1 DetectArgumentState (com.synopsys.integration.detect.configuration.help.DetectArgumentState)1