Search in sources :

Example 1 with DirectoryManager

use of com.synopsys.integration.detect.workflow.file.DirectoryManager in project synopsys-detect by blackducksoftware.

the class BinaryUploadOperationTest method testDirExclusion.

@Test
public void testDirExclusion() throws DetectUserFriendlyException, IOException, IntegrationException {
    SimpleFileFinder fileFinder = new SimpleFileFinder();
    DirectoryManager directoryManager = Mockito.mock(DirectoryManager.class);
    File rootDirectory = Files.createTempDirectory("BinaryScannerTest").toFile();
    createDirWithFiles(rootDirectory, "includedDir");
    createDirWithFiles(rootDirectory, "excludedDir");
    ArrayList<String> targetPaths = new ArrayList<>();
    targetPaths.add("*.txt");
    Mockito.when(directoryManager.getSourceDirectory()).thenReturn(rootDirectory);
    Mockito.when(directoryManager.getBinaryOutputDirectory()).thenReturn(rootDirectory);
    BinaryScanFindMultipleTargetsOperation multipleTargets = new BinaryScanFindMultipleTargetsOperation(fileFinder, directoryManager);
    DetectDirectoryFileFilter fileFilter = new DetectDirectoryFileFilter(Arrays.asList("excludedDir"), targetPaths);
    Optional<File> zip = multipleTargets.searchForMultipleTargets(fileFilter, false, 3);
    Assertions.assertTrue(zip.isPresent());
    List<String> entries = getZipEntries(zip);
    Assertions.assertTrue(entries.contains("includedDir/binaryTestFile_1.txt"));
    Assertions.assertFalse(entries.contains("includedDir/binaryTestFile_2.text"));
    Assertions.assertFalse(entries.contains("excludedDir/binaryTestFile_1.txt"));
    Assertions.assertFalse(entries.contains("excludedDir/binaryTestFile_2.text"));
    FileUtils.deleteDirectory(rootDirectory);
}
Also used : SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) DetectDirectoryFileFilter(com.synopsys.integration.detect.util.finder.DetectDirectoryFileFilter) DirectoryManager(com.synopsys.integration.detect.workflow.file.DirectoryManager) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 2 with DirectoryManager

use of com.synopsys.integration.detect.workflow.file.DirectoryManager in project synopsys-detect by blackducksoftware.

the class BinaryUploadOperationTest method testMultipleTargetPaths.

@Test
public void testMultipleTargetPaths() throws DetectUserFriendlyException, IOException, IntegrationException {
    SimpleFileFinder fileFinder = new SimpleFileFinder();
    DirectoryManager directoryManager = Mockito.mock(DirectoryManager.class);
    File rootDirectory = Files.createTempDirectory("BinaryScannerTest").toFile();
    createDirWithFiles(rootDirectory, "BinaryScannerSubDirectory");
    ArrayList<String> targetPaths = new ArrayList<>();
    targetPaths.add("binaryTestFile_1.txt");
    targetPaths.add("*.text");
    Mockito.when(directoryManager.getSourceDirectory()).thenReturn(rootDirectory);
    Mockito.when(directoryManager.getBinaryOutputDirectory()).thenReturn(rootDirectory);
    BinaryScanFindMultipleTargetsOperation multipleTargets = new BinaryScanFindMultipleTargetsOperation(fileFinder, directoryManager);
    DetectDirectoryFileFilter fileFilter = new DetectDirectoryFileFilter(Collections.emptyList(), targetPaths);
    Optional<File> zip = multipleTargets.searchForMultipleTargets(fileFilter, false, 3);
    Assertions.assertTrue(zip.isPresent());
    List<String> entries = getZipEntries(zip);
    Assertions.assertTrue(entries.contains("BinaryScannerSubDirectory/binaryTestFile_1.txt"));
    Assertions.assertTrue(entries.contains("BinaryScannerSubDirectory/binaryTestFile_2.text"));
    FileUtils.deleteDirectory(rootDirectory);
}
Also used : SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) DetectDirectoryFileFilter(com.synopsys.integration.detect.util.finder.DetectDirectoryFileFilter) DirectoryManager(com.synopsys.integration.detect.workflow.file.DirectoryManager) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 3 with DirectoryManager

use of com.synopsys.integration.detect.workflow.file.DirectoryManager 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);
}
Also used : InstalledToolLocator(com.synopsys.integration.detect.tool.cache.InstalledToolLocator) DirectoryManager(com.synopsys.integration.detect.workflow.file.DirectoryManager) Gson(com.google.gson.Gson) SimplePathResolver(com.synopsys.integration.configuration.property.types.path.SimplePathResolver) ArtifactResolver(com.synopsys.integration.detect.workflow.ArtifactResolver) ConnectionFactory(com.synopsys.integration.detect.configuration.connection.ConnectionFactory) InstalledToolManager(com.synopsys.integration.detect.tool.cache.InstalledToolManager) DetectFontInstaller(com.synopsys.integration.detect.workflow.blackduck.font.DetectFontInstaller) DirectoryOptions(com.synopsys.integration.detect.workflow.file.DirectoryOptions) DetectPropertyConfiguration(com.synopsys.integration.detect.configuration.DetectPropertyConfiguration) DetectConfigurationFactory(com.synopsys.integration.detect.configuration.DetectConfigurationFactory) OnlineDetectFontLocator(com.synopsys.integration.detect.workflow.blackduck.font.OnlineDetectFontLocator) PropertyConfiguration(com.synopsys.integration.configuration.config.PropertyConfiguration) DetectPropertyConfiguration(com.synopsys.integration.detect.configuration.DetectPropertyConfiguration) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with DirectoryManager

use of com.synopsys.integration.detect.workflow.file.DirectoryManager 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 5 with DirectoryManager

use of com.synopsys.integration.detect.workflow.file.DirectoryManager in project synopsys-detect by blackducksoftware.

the class ShutdownManager method shutdown.

public void shutdown(DetectBootResult detectBootResult, ShutdownDecision shutdownDecision) {
    if (shutdownDecision.getDiagnosticSystem() != null) {
        shutdownDecision.getDiagnosticSystem().finish();
    }
    if (detectBootResult.getDirectoryManager().isPresent() && shutdownDecision.getCleanupDecision().shouldCleanup()) {
        DirectoryManager directoryManager = detectBootResult.getDirectoryManager().get();
        try {
            List<File> cleanupToSkip = determineSkippedCleanupFiles(shutdownDecision.getCleanupDecision(), directoryManager);
            cleanupUtility.cleanup(directoryManager.getRunHomeDirectory(), cleanupToSkip);
        } catch (Exception e) {
            logger.debug("Error trying cleanup: ", e);
        }
    } else {
        logger.info("Skipping cleanup, it is disabled.");
    }
    if (shutdownDecision.getPhoneHomeManager() != null) {
        try {
            logger.debug("Ending phone home.");
            shutdownDecision.getPhoneHomeManager().endPhoneHome();
        } catch (Exception e) {
            logger.debug(String.format("Error trying to end the phone home task: %s", e.getMessage()));
        }
    }
}
Also used : DirectoryManager(com.synopsys.integration.detect.workflow.file.DirectoryManager) File(java.io.File)

Aggregations

DirectoryManager (com.synopsys.integration.detect.workflow.file.DirectoryManager)7 File (java.io.File)6 Test (org.junit.jupiter.api.Test)4 Gson (com.google.gson.Gson)2 SimpleFileFinder (com.synopsys.integration.common.util.finder.SimpleFileFinder)2 PropertyConfiguration (com.synopsys.integration.configuration.config.PropertyConfiguration)2 SimplePathResolver (com.synopsys.integration.configuration.property.types.path.SimplePathResolver)2 DetectConfigurationFactory (com.synopsys.integration.detect.configuration.DetectConfigurationFactory)2 DetectPropertyConfiguration (com.synopsys.integration.detect.configuration.DetectPropertyConfiguration)2 InstalledToolLocator (com.synopsys.integration.detect.tool.cache.InstalledToolLocator)2 DetectDirectoryFileFilter (com.synopsys.integration.detect.util.finder.DetectDirectoryFileFilter)2 DirectoryOptions (com.synopsys.integration.detect.workflow.file.DirectoryOptions)2 NameVersion (com.synopsys.integration.util.NameVersion)2 ArrayList (java.util.ArrayList)2 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 DeveloperScanComponentResultView (com.synopsys.integration.blackduck.api.manual.view.DeveloperScanComponentResultView)1 PathResolver (com.synopsys.integration.configuration.property.types.path.PathResolver)1 MapPropertySource (com.synopsys.integration.configuration.source.MapPropertySource)1