Search in sources :

Example 6 with MapPropertySource

use of com.synopsys.integration.configuration.source.MapPropertySource in project synopsys-detect by blackducksoftware.

the class BlackDuckConnectionDecisionBranch method traverse.

@Override
public void traverse(InteractivePropertySourceBuilder propertySourceBuilder, InteractiveWriter writer) {
    boolean shouldReconfigureServer = true;
    BlackDuckConnectivityResult blackDuckConnectivityResult = BlackDuckConnectivityResult.failure("Connection has yet to be attempted.");
    BlackDuckServerDecisionBranch blackDuckServerDecisionBranch = new BlackDuckServerDecisionBranch();
    while (!blackDuckConnectivityResult.isSuccessfullyConnected() && shouldReconfigureServer) {
        blackDuckServerDecisionBranch.traverse(propertySourceBuilder, writer);
        Boolean testConnection = writer.askYesOrNo(SHOULD_TEST_CONNECTION);
        if (testConnection) {
            try {
                MapPropertySource interactivePropertySource = propertySourceBuilder.build();
                List<PropertySource> propertySources = new ArrayList<>(this.existingPropertySources);
                propertySources.add(0, interactivePropertySource);
                PropertyConfiguration propertyConfiguration = new PropertyConfiguration(propertySources);
                DetectPropertyConfiguration detectConfiguration = new DetectPropertyConfiguration(propertyConfiguration, new SimplePathResolver());
                DetectConfigurationFactory detectConfigurationFactory = new DetectConfigurationFactory(detectConfiguration, gson);
                BlackDuckConfigFactory blackDuckConfigFactory = new BlackDuckConfigFactory(detectInfo, detectConfigurationFactory.createBlackDuckConnectionDetails());
                BlackDuckServerConfig blackDuckServerConfig = blackDuckConfigFactory.createServerConfig(new SilentIntLogger());
                blackDuckConnectivityResult = blackDuckConnectivityChecker.determineConnectivity(blackDuckServerConfig);
            } catch (Exception e) {
                blackDuckConnectivityResult = BlackDuckConnectivityResult.failure("Failed to test connection. " + System.lineSeparator() + e);
            }
            if (!blackDuckConnectivityResult.isSuccessfullyConnected()) {
                writer.println(blackDuckConnectivityResult.getFailureReason());
                shouldReconfigureServer = writer.askYesOrNo(SHOULD_RETRY_CONNECTION);
            }
        } else {
            shouldReconfigureServer = false;
        }
    }
}
Also used : BlackDuckConnectivityResult(com.synopsys.integration.detect.lifecycle.boot.product.BlackDuckConnectivityResult) ArrayList(java.util.ArrayList) SimplePathResolver(com.synopsys.integration.configuration.property.types.path.SimplePathResolver) MapPropertySource(com.synopsys.integration.configuration.source.MapPropertySource) PropertySource(com.synopsys.integration.configuration.source.PropertySource) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) SilentIntLogger(com.synopsys.integration.log.SilentIntLogger) DetectPropertyConfiguration(com.synopsys.integration.detect.configuration.DetectPropertyConfiguration) MapPropertySource(com.synopsys.integration.configuration.source.MapPropertySource) DetectConfigurationFactory(com.synopsys.integration.detect.configuration.DetectConfigurationFactory) DetectPropertyConfiguration(com.synopsys.integration.detect.configuration.DetectPropertyConfiguration) PropertyConfiguration(com.synopsys.integration.configuration.config.PropertyConfiguration) BlackDuckConfigFactory(com.synopsys.integration.detect.configuration.connection.BlackDuckConfigFactory)

Example 7 with MapPropertySource

use of com.synopsys.integration.configuration.source.MapPropertySource in project synopsys-detect by blackducksoftware.

the class DetectConfigurationTest method testPhoneHomePassthroughProperties.

@Test
public void testPhoneHomePassthroughProperties() {
    final String givenKeyPhoneHomePart = "x.y.z";
    final String givenKeyFull = "detect.phone.home.passthrough." + givenKeyPhoneHomePart;
    final String givenValue = "testValue";
    HashMap<String, String> values = new HashMap<>();
    values.put(givenKeyFull, givenValue);
    List<PropertySource> propertySources = new ArrayList<>();
    propertySources.add(new MapPropertySource("test", values));
    PropertyConfiguration propertyConfiguration = new PropertyConfiguration(propertySources);
    Map<String, String> phoneHomePropertiesMap = propertyConfiguration.getRaw(DetectProperties.PHONEHOME_PASSTHROUGH);
    assertEquals(givenValue, phoneHomePropertiesMap.get(givenKeyPhoneHomePart));
}
Also used : HashMap(java.util.HashMap) MapPropertySource(com.synopsys.integration.configuration.source.MapPropertySource) ArrayList(java.util.ArrayList) PropertyConfiguration(com.synopsys.integration.configuration.config.PropertyConfiguration) MapPropertySource(com.synopsys.integration.configuration.source.MapPropertySource) PropertySource(com.synopsys.integration.configuration.source.PropertySource) Test(org.junit.jupiter.api.Test)

Example 8 with MapPropertySource

use of com.synopsys.integration.configuration.source.MapPropertySource in project synopsys-detect by blackducksoftware.

the class InteractiveModeDecisionTreeEndToEndTest method testTraverse.

public void testTraverse(Map<String, String> callToResponse, Map<Property, String> expectedProperties) {
    DetectInfo detectInfo = new DetectInfo("synopsys_detect", OperatingSystemType.LINUX, "unknown");
    InteractiveModeDecisionTree decisionTree = new InteractiveModeDecisionTree(detectInfo, new BlackDuckConnectivityChecker(), new ArrayList<>(), new Gson());
    InteractiveWriter mockWriter = mockWriter(callToResponse);
    InteractivePropertySourceBuilder propertySourceBuilder = new InteractivePropertySourceBuilder(mockWriter);
    decisionTree.traverse(propertySourceBuilder, mockWriter);
    MapPropertySource actualPropertySource = propertySourceBuilder.build();
    expectedProperties.forEach((key, value) -> assertHasPropertyWithValue(actualPropertySource, key, value));
    assertEquals(expectedProperties.keySet().size(), actualPropertySource.getKeys().size());
}
Also used : DetectInfo(com.synopsys.integration.detect.configuration.DetectInfo) MapPropertySource(com.synopsys.integration.configuration.source.MapPropertySource) BlackDuckConnectivityChecker(com.synopsys.integration.detect.lifecycle.boot.product.BlackDuckConnectivityChecker) Gson(com.google.gson.Gson)

Example 9 with MapPropertySource

use of com.synopsys.integration.configuration.source.MapPropertySource in project synopsys-detect by blackducksoftware.

the class DetectBoot method boot.

public Optional<DetectBootResult> boot(String detectVersion, String detectBuildDate) throws IOException, IllegalAccessException {
    if (detectArgumentState.isHelp() || detectArgumentState.isDeprecatedHelp() || detectArgumentState.isVerboseHelp()) {
        HelpPrinter helpPrinter = new HelpPrinter();
        helpPrinter.printAppropriateHelpMessage(DEFAULT_PRINT_STREAM, DetectProperties.allProperties().getProperties(), Arrays.asList(DetectGroup.values()), DetectGroup.BLACKDUCK_SERVER, detectArgumentState);
        return Optional.of(DetectBootResult.exit(new PropertyConfiguration(propertySources)));
    }
    if (detectArgumentState.isHelpJsonDocument()) {
        HelpJsonManager helpJsonManager = detectBootFactory.createHelpJsonManager();
        helpJsonManager.createHelpJsonDocument(String.format("synopsys-detect-%s-help.json", detectVersion));
        return Optional.of(DetectBootResult.exit(new PropertyConfiguration(propertySources)));
    }
    DEFAULT_PRINT_STREAM.println();
    DEFAULT_PRINT_STREAM.println("Detect Version: " + detectVersion);
    DEFAULT_PRINT_STREAM.println();
    if (detectArgumentState.isInteractive()) {
        InteractiveManager interactiveManager = detectBootFactory.createInteractiveManager(propertySources);
        MapPropertySource interactivePropertySource = interactiveManager.executeInteractiveMode();
        propertySources.add(0, interactivePropertySource);
    }
    PropertyConfiguration propertyConfiguration = new PropertyConfiguration(propertySources);
    SortedMap<String, String> maskedRawPropertyValues = collectMaskedRawPropertyValues(propertyConfiguration);
    publishCollectedPropertyValues(maskedRawPropertyValues);
    logger.debug("Configuration processed completely.");
    DetectConfigurationBootManager detectConfigurationBootManager = detectBootFactory.createDetectConfigurationBootManager(propertyConfiguration);
    DeprecationResult deprecationResult = detectConfigurationBootManager.createDeprecationNotesAndPublishEvents(propertyConfiguration);
    detectConfigurationBootManager.printConfiguration(maskedRawPropertyValues, deprecationResult.getAdditionalNotes());
    Optional<DetectUserFriendlyException> possiblePropertyParseError = detectConfigurationBootManager.validateForPropertyParseErrors();
    if (possiblePropertyParseError.isPresent()) {
        return Optional.of(DetectBootResult.exception(possiblePropertyParseError.get(), propertyConfiguration));
    }
    logger.info("Detect build date: {}", detectBuildDate);
    logger.debug("Initializing Detect.");
    Configuration freemarkerConfiguration = detectBootFactory.createFreemarkerConfiguration();
    PathResolver pathResolver = detectBootFactory.createPathResolver();
    DetectPropertyConfiguration detectConfiguration = new DetectPropertyConfiguration(propertyConfiguration, new SimplePathResolver());
    DetectConfigurationFactory detectConfigurationFactory = new DetectConfigurationFactory(detectConfiguration, gson);
    DirectoryManager directoryManager = detectBootFactory.createDirectoryManager(detectConfigurationFactory);
    InstalledToolLocator installedToolLocator = new InstalledToolLocator(directoryManager.getPermanentDirectory().toPath(), gson);
    DiagnosticSystem diagnosticSystem = null;
    DiagnosticDecision diagnosticDecision = DiagnosticDecision.decide(detectArgumentState, propertyConfiguration);
    if (diagnosticDecision.shouldCreateDiagnosticSystem()) {
        diagnosticSystem = detectBootFactory.createDiagnosticSystem(diagnosticDecision.isExtended(), propertyConfiguration, directoryManager, maskedRawPropertyValues);
    }
    logger.debug("Main boot completed. Deciding what Detect should do.");
    if (detectArgumentState.isGenerateAirGapZip()) {
        try {
            AirGapType airGapType = new AirGapTypeDecider().decide(detectArgumentState);
            AirGapCreator airGapCreator = detectBootFactory.createAirGapCreator(detectConfigurationFactory.createConnectionDetails(), detectConfigurationFactory.createDetectExecutableOptions(), freemarkerConfiguration, installedToolManager, installedToolLocator);
            String gradleInspectorVersion = propertyConfiguration.getValueOrEmpty(DetectProperties.DETECT_GRADLE_INSPECTOR_VERSION).orElse(null);
            File airGapZip = airGapCreator.createAirGapZip(airGapType, directoryManager.getRunHomeDirectory(), gradleInspectorVersion);
            return Optional.of(DetectBootResult.exit(propertyConfiguration, airGapZip, directoryManager, diagnosticSystem));
        } catch (DetectUserFriendlyException e) {
            return Optional.of(DetectBootResult.exception(e, propertyConfiguration, directoryManager, diagnosticSystem));
        }
    }
    logger.info("");
    ProductRunData productRunData;
    try {
        ProductDecider productDecider = new ProductDecider();
        BlackDuckDecision blackDuckDecision = productDecider.decideBlackDuck(detectConfigurationFactory.createBlackDuckConnectionDetails(), detectConfigurationFactory.createScanMode());
        // TODO: Move to proper decision home. -jp
        RunDecision runDecision = new RunDecision(detectConfigurationFactory.createDetectTarget() == DetectTargetType.IMAGE);
        DetectToolFilter detectToolFilter = detectConfigurationFactory.createToolFilter(runDecision, blackDuckDecision);
        oneRequiresTheOther(detectConfigurationFactory.createDetectTarget() == DetectTargetType.IMAGE, detectToolFilter.shouldInclude(DetectTool.DOCKER), "Detect target type is set to IMAGE, but the DOCKER tool was excluded.");
        logger.debug("Decided what products will be run. Starting product boot.");
        ProductBoot productBoot = detectBootFactory.createProductBoot(detectConfigurationFactory);
        productRunData = productBoot.boot(blackDuckDecision, detectToolFilter);
    } catch (DetectUserFriendlyException e) {
        return Optional.of(DetectBootResult.exception(e, propertyConfiguration, directoryManager, diagnosticSystem));
    }
    if (productRunData == null) {
        logger.info("No products to run, Detect is complete.");
        return Optional.of(DetectBootResult.exit(propertyConfiguration, directoryManager, diagnosticSystem));
    }
    DetectableOptionFactory detectableOptionFactory;
    try {
        ProxyInfo detectableProxyInfo = detectConfigurationFactory.createBlackDuckProxyInfo();
        detectableOptionFactory = new DetectableOptionFactory(detectConfiguration, diagnosticSystem, pathResolver, detectableProxyInfo);
        oneRequiresTheOther(detectConfigurationFactory.createDetectTarget() == DetectTargetType.IMAGE, detectableOptionFactory.createDockerDetectableOptions().hasDockerImageOrTar(), "Detect target type is set to IMAGE, but no docker image was specified.");
    } catch (DetectUserFriendlyException e) {
        return Optional.of(DetectBootResult.exception(e, propertyConfiguration, directoryManager, diagnosticSystem));
    }
    BootSingletons bootSingletons = detectBootFactory.createRunDependencies(productRunData, propertyConfiguration, detectableOptionFactory, detectConfigurationFactory, directoryManager, freemarkerConfiguration, installedToolManager, installedToolLocator);
    return Optional.of(DetectBootResult.run(bootSingletons, propertyConfiguration, productRunData, directoryManager, diagnosticSystem));
}
Also used : BootSingletons(com.synopsys.integration.detect.lifecycle.run.singleton.BootSingletons) ProductDecider(com.synopsys.integration.detect.lifecycle.boot.decision.ProductDecider) DeprecationResult(com.synopsys.integration.detect.configuration.validation.DeprecationResult) PropertyConfiguration(com.synopsys.integration.configuration.config.PropertyConfiguration) DetectPropertyConfiguration(com.synopsys.integration.detect.configuration.DetectPropertyConfiguration) Configuration(freemarker.template.Configuration) InteractiveManager(com.synopsys.integration.detect.interactive.InteractiveManager) DetectConfigurationBootManager(com.synopsys.integration.detect.configuration.validation.DetectConfigurationBootManager) AirGapCreator(com.synopsys.integration.detect.workflow.airgap.AirGapCreator) ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) AirGapType(com.synopsys.integration.detect.workflow.airgap.AirGapType) DetectToolFilter(com.synopsys.integration.detect.util.filter.DetectToolFilter) ProductBoot(com.synopsys.integration.detect.lifecycle.boot.product.ProductBoot) PropertyConfiguration(com.synopsys.integration.configuration.config.PropertyConfiguration) DetectPropertyConfiguration(com.synopsys.integration.detect.configuration.DetectPropertyConfiguration) HelpPrinter(com.synopsys.integration.detect.configuration.help.print.HelpPrinter) DirectoryManager(com.synopsys.integration.detect.workflow.file.DirectoryManager) InstalledToolLocator(com.synopsys.integration.detect.tool.cache.InstalledToolLocator) SimplePathResolver(com.synopsys.integration.configuration.property.types.path.SimplePathResolver) PathResolver(com.synopsys.integration.configuration.property.types.path.PathResolver) SimplePathResolver(com.synopsys.integration.configuration.property.types.path.SimplePathResolver) RunDecision(com.synopsys.integration.detect.lifecycle.boot.decision.RunDecision) DetectableOptionFactory(com.synopsys.integration.detect.configuration.DetectableOptionFactory) ProductRunData(com.synopsys.integration.detect.lifecycle.run.data.ProductRunData) DiagnosticDecision(com.synopsys.integration.detect.workflow.diagnostic.DiagnosticDecision) DiagnosticSystem(com.synopsys.integration.detect.workflow.diagnostic.DiagnosticSystem) DetectPropertyConfiguration(com.synopsys.integration.detect.configuration.DetectPropertyConfiguration) MapPropertySource(com.synopsys.integration.configuration.source.MapPropertySource) DetectConfigurationFactory(com.synopsys.integration.detect.configuration.DetectConfigurationFactory) HelpJsonManager(com.synopsys.integration.detect.configuration.help.json.HelpJsonManager) AirGapTypeDecider(com.synopsys.integration.detect.workflow.airgap.AirGapTypeDecider) File(java.io.File) BlackDuckDecision(com.synopsys.integration.detect.lifecycle.boot.decision.BlackDuckDecision)

Example 10 with MapPropertySource

use of com.synopsys.integration.configuration.source.MapPropertySource in project synopsys-detect by blackducksoftware.

the class DiagnosticDecisionTest method createPropertyConfiguration.

private PropertyConfiguration createPropertyConfiguration(boolean isDiagnostic, boolean isExtended) {
    HashMap<String, String> propertySourceMap = new HashMap<>();
    propertySourceMap.put(DetectProperties.DETECT_DIAGNOSTIC.getKey(), String.valueOf(isDiagnostic));
    propertySourceMap.put(DetectProperties.DETECT_DIAGNOSTIC_EXTENDED.getKey(), String.valueOf(isExtended));
    MapPropertySource mapPropertySource = new MapPropertySource(TEST_PROPERTY_SOURCE_NAME, propertySourceMap);
    return new PropertyConfiguration(Collections.singletonList(mapPropertySource));
}
Also used : HashMap(java.util.HashMap) MapPropertySource(com.synopsys.integration.configuration.source.MapPropertySource) PropertyConfiguration(com.synopsys.integration.configuration.config.PropertyConfiguration)

Aggregations

MapPropertySource (com.synopsys.integration.configuration.source.MapPropertySource)10 PropertyConfiguration (com.synopsys.integration.configuration.config.PropertyConfiguration)7 PropertySource (com.synopsys.integration.configuration.source.PropertySource)7 SimplePathResolver (com.synopsys.integration.configuration.property.types.path.SimplePathResolver)5 Gson (com.google.gson.Gson)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Test (org.junit.jupiter.api.Test)4 DetectConfigurationFactory (com.synopsys.integration.detect.configuration.DetectConfigurationFactory)2 DetectPropertyConfiguration (com.synopsys.integration.detect.configuration.DetectPropertyConfiguration)2 BdioOptions (com.synopsys.integration.detect.workflow.bdio.BdioOptions)2 BlackDuckServerConfig (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig)1 PathResolver (com.synopsys.integration.configuration.property.types.path.PathResolver)1 DetectInfo (com.synopsys.integration.detect.configuration.DetectInfo)1 DetectUserFriendlyException (com.synopsys.integration.detect.configuration.DetectUserFriendlyException)1 DetectableOptionFactory (com.synopsys.integration.detect.configuration.DetectableOptionFactory)1 BlackDuckConfigFactory (com.synopsys.integration.detect.configuration.connection.BlackDuckConfigFactory)1 HelpJsonManager (com.synopsys.integration.detect.configuration.help.json.HelpJsonManager)1 HelpPrinter (com.synopsys.integration.detect.configuration.help.print.HelpPrinter)1 DeprecationResult (com.synopsys.integration.detect.configuration.validation.DeprecationResult)1