Search in sources :

Example 1 with DetectFileFinder

use of com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder in project hub-detect by blackducksoftware.

the class DirectoryManagerTest method extractFinalPieceFromPath.

@Test
public void extractFinalPieceFromPath() {
    final DetectFileFinder detectFileManager = new DetectFileFinder();
    Assert.assertEquals("a", detectFileManager.extractFinalPieceFromPath("/a"));
    Assert.assertEquals("a", detectFileManager.extractFinalPieceFromPath("/a/"));
    Assert.assertEquals("c", detectFileManager.extractFinalPieceFromPath("/a/b/c"));
    Assert.assertEquals("c", detectFileManager.extractFinalPieceFromPath("/a/b/c/"));
}
Also used : DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) Test(org.junit.Test)

Example 2 with DetectFileFinder

use of com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder in project hub-detect by blackducksoftware.

the class CodeLocationNameGeneratorTest method testBomCodeLocationName.

@Test
public void testBomCodeLocationName() {
    final String expected = "hub-common-rest/child/group/name/version npm/bom";
    // = path/externalId tool/type
    final ExternalIdFactory factory = new ExternalIdFactory();
    final ExternalId externalId = factory.createMavenExternalId("group", "name", "version");
    final DetectFileFinder detectFileFinder = new DetectFileFinder();
    final CodeLocationNameGenerator codeLocationNameGenerator = new CodeLocationNameGenerator(detectFileFinder);
    final String sourcePath = "/Users/ekerwin/Documents/source/integration/hub-common-rest";
    final String codeLocationPath = "/Users/ekerwin/Documents/source/integration/hub-common-rest/child";
    final String prefix = "";
    final String suffix = "";
    final String actual = codeLocationNameGenerator.createBomCodeLocationName(sourcePath, codeLocationPath, externalId, DetectCodeLocationType.NPM, prefix, suffix);
    assertEquals(expected, actual);
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) Test(org.junit.Test)

Example 3 with DetectFileFinder

use of com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder in project hub-detect by blackducksoftware.

the class NugetSolutionExtractionDebugger method debug.

public void debug(LoggedDetectExtraction extraction, DetectRunInfo detectRunInfo, DetectConfiguration detectConfiguration) {
    String id = extraction.extractionIdentifier;
    try {
        NugetInspectorPackager packager = new NugetInspectorPackager(new Gson(), new ExternalIdFactory());
        DetectFileFinder detectFileFinder = new DetectFileFinder();
        File extractionFolder = new File(detectRunInfo.getExtractionsFolder(), extraction.extractionIdentifier);
        List<File> extractionFiles = Arrays.asList(extractionFolder.listFiles());
        DetectFileFinder mock = Mockito.mock(DetectFileFinder.class);
        Mockito.when(mock.findFiles(Mockito.any(), Mockito.any())).thenReturn(extractionFiles);
        NugetInspectorExtractor nugetInspectorExtractor = new NugetInspectorExtractor(packager, mock, detectConfiguration);
        NugetInspector inspector = Mockito.mock(NugetInspector.class);
        Mockito.when(inspector.execute(Mockito.any(), Mockito.any())).thenReturn(new ExecutableOutput("", ""));
        File mockTarget = Mockito.mock(File.class);
        Mockito.when(mockTarget.toString()).thenReturn("mock/target");
        File mockOutput = Mockito.mock(File.class);
        Mockito.when(mockOutput.getCanonicalPath()).thenReturn("mock/output");
        Mockito.when(mockOutput.toString()).thenReturn("mock/output");
        Extraction newExtraction = nugetInspectorExtractor.extract(mockTarget, mockOutput, inspector, new ExtractionId(DetectorType.NUGET, id));
        logger.info("We did it: " + newExtraction.result.toString());
    } catch (Exception e) {
        logger.info("We did not do it: " + e.toString());
        throw new RuntimeException(e);
    }
}
Also used : NugetInspectorExtractor(com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorExtractor) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Gson(com.google.gson.Gson) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) NugetInspectorPackager(com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorPackager) NugetInspector(com.blackducksoftware.integration.hub.detect.detector.nuget.inspector.NugetInspector) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) LoggedDetectExtraction(com.synopsys.detect.doctor.logparser.LoggedDetectExtraction) ExtractionId(com.blackducksoftware.integration.hub.detect.detector.ExtractionId) File(java.io.File)

Example 4 with DetectFileFinder

use of com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder in project hub-detect by blackducksoftware.

the class DetectFileFinderTest method testIsFileUnderDir.

@Test
public void testIsFileUnderDir() {
    final DetectFileFinder finder = new DetectFileFinder();
    File targetDir = new File("src/test/resources");
    assertTrue(finder.isFileUnderDir(targetDir, new File("src/test/resources/clang")));
    assertTrue(finder.isFileUnderDir(targetDir, new File("src/test/resources/")));
    assertTrue(finder.isFileUnderDir(targetDir, new File("src/test/resources/clang/../clang")));
    assertFalse(finder.isFileUnderDir(targetDir, new File("src/test/groovy")));
}
Also used : DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) File(java.io.File) Test(org.junit.Test)

Example 5 with DetectFileFinder

use of com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder in project hub-detect by blackducksoftware.

the class DetectFileFinderTest method testFindAllFilesToDepth.

@Test
public void testFindAllFilesToDepth() {
    final DetectFileFinder finder = new DetectFileFinder();
    File targetDir = new File("src/test/resources/fileFinder");
    List<File> filesFound = finder.findAllFilesToDepth(targetDir, new StringBuilder("Maximum search depth hit during test at %s"), 2, "*.txt");
    assertEquals(1, filesFound.size());
}
Also used : DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) File(java.io.File) Test(org.junit.Test)

Aggregations

DetectFileFinder (com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder)15 Test (org.junit.Test)13 File (java.io.File)10 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)6 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)5 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)5 ExtractionId (com.blackducksoftware.integration.hub.detect.detector.ExtractionId)4 ExecutableRunner (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)4 DirectoryManager (com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 LoggedDetectExtraction (com.synopsys.detect.doctor.logparser.LoggedDetectExtraction)2 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)2 GradleInspectorExtractor (com.blackducksoftware.integration.hub.detect.detector.gradle.GradleInspectorExtractor)1 GradleReportParser (com.blackducksoftware.integration.hub.detect.detector.gradle.GradleReportParser)1 NugetInspectorExtractor (com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorExtractor)1 NugetInspectorPackager (com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorPackager)1 NugetInspector (com.blackducksoftware.integration.hub.detect.detector.nuget.inspector.NugetInspector)1 Gson (com.google.gson.Gson)1