use of com.synopsys.integration.detect.configuration.DetectConfigurationFactory 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;
}
}
}
use of com.synopsys.integration.detect.configuration.DetectConfigurationFactory in project synopsys-detect by blackducksoftware.
the class FontLoaderTestIT method createTempDirectory.
@BeforeEach
public void createTempDirectory() throws Exception {
fontDirectory = Files.createTempDirectory("junit_test_font_loader").toFile();
PropertyConfiguration propertyConfiguration = new PropertyConfiguration(Collections.emptyList());
Gson gson = new Gson();
DetectConfigurationFactory detectConfigurationFactory = new DetectConfigurationFactory(new DetectPropertyConfiguration(propertyConfiguration, new SimplePathResolver()), gson);
ConnectionFactory connectionFactory = new ConnectionFactory(detectConfigurationFactory.createConnectionDetails());
ArtifactResolver artifactResolver = new ArtifactResolver(connectionFactory, gson);
InstalledToolManager installedToolManager = new InstalledToolManager();
InstalledToolLocator installedToolLocator = new InstalledToolLocator(Paths.get(""), new Gson());
DetectFontInstaller installer = new DetectFontInstaller(artifactResolver, installedToolManager, installedToolLocator);
DirectoryOptions directoryOptions = new DirectoryOptions(null, null, null, null, fontDirectory.toPath(), null);
DirectoryManager directoryManager = new DirectoryManager(directoryOptions, DetectRunId.createDefault());
detectFontLocator = new OnlineDetectFontLocator(installer, directoryManager);
}
use of com.synopsys.integration.detect.configuration.DetectConfigurationFactory 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));
}
use of com.synopsys.integration.detect.configuration.DetectConfigurationFactory in project synopsys-detect by blackducksoftware.
the class DetectFontInstallerTestIT method testFontInstall.
@Test
public void testFontInstall() throws Exception {
Gson gson = new Gson();
PropertyConfiguration propertyConfiguration = new PropertyConfiguration(Collections.emptyList());
DetectConfigurationFactory detectConfigurationFactory = new DetectConfigurationFactory(new DetectPropertyConfiguration(propertyConfiguration, new SimplePathResolver()), gson);
ConnectionFactory connectionFactory = new ConnectionFactory(detectConfigurationFactory.createConnectionDetails());
ArtifactResolver artifactResolver = new ArtifactResolver(connectionFactory, gson);
InstalledToolManager installedToolManager = new InstalledToolManager();
InstalledToolLocator installedToolLocator = new InstalledToolLocator(Paths.get(""), new Gson());
DetectFontInstaller installer = new DetectFontInstaller(artifactResolver, installedToolManager, installedToolLocator);
installer.installFonts(targetDirectory);
String[] fileList = targetDirectory.list();
assertNotNull(fileList);
assertTrue(fileList.length > 0);
}
Aggregations