Search in sources :

Example 16 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.

the class GoModCliExtractorTest method handleGoModWhyExceptionTest.

@Test
public void handleGoModWhyExceptionTest() throws ExecutableRunnerException, ExecutableFailedException, DetectableException {
    DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
    File directory = new File("");
    ExecutableTarget goExe = ExecutableTarget.forFile(new File(""));
    Answer<ExecutableOutput> executableAnswer = new Answer<ExecutableOutput>() {

        String[] goListArgs = { "list", "-m", "-json" };

        String[] goListJsonArgs = { "list", "-m", "-json", "all" };

        String[] goModGraphArgs = { "mod", "graph" };

        String[] goModWhyArgs = { "mod", "why", "-m", "all" };

        @Override
        public ExecutableOutput answer(InvocationOnMock invocation) throws Throwable {
            Executable executable = invocation.getArgument(0, Executable.class);
            List<String> commandLine = executable.getCommandWithArguments();
            ExecutableOutput result = null;
            if (commandLine.containsAll(Arrays.asList(goListJsonArgs))) {
                result = goListJsonOutput();
            } else if (commandLine.containsAll(Arrays.asList(goListArgs))) {
                result = goListOutput();
            } else if (commandLine.containsAll(Arrays.asList(goModGraphArgs))) {
                result = goModGraphOutput();
            } else if (commandLine.containsAll(Arrays.asList(goModWhyArgs))) {
                throw new ExecutableRunnerException(new DetectableException("Unit Test Go Mod Why error"));
            } else {
                result = new ExecutableOutput(0, "", "");
            }
            return result;
        }
    };
    GoModCliExtractor goModCliExtractor = buildGoModCliExtractor(executableRunner, executableAnswer);
    boolean wasSuccessful = true;
    Extraction extraction = goModCliExtractor.extract(directory, goExe);
    if (extraction.getError() instanceof ArrayIndexOutOfBoundsException) {
        wasSuccessful = false;
    }
    Assertions.assertTrue(wasSuccessful);
}
Also used : ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) Answer(org.mockito.stubbing.Answer) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) GoModCliExtractor(com.synopsys.integration.detectable.detectables.go.gomod.GoModCliExtractor) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Executable(com.synopsys.integration.executable.Executable) File(java.io.File) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) Test(org.junit.jupiter.api.Test)

Example 17 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.

the class GradleInspectorDetectableTest method setup.

@Override
protected void setup() throws IOException {
    addFile(Paths.get("build.gradle"), "buildscript {", "    repositories {", "        jcenter()", "        mavenCentral()", "        maven { url 'https://plugins.gradle.org/m2/' }", "    }", "    dependencies { classpath 'com.blackducksoftware.integration:common-gradle-plugin:0.0.+' }", "}", "", "version = '13.1.1-SNAPSHOT'", "", "apply plugin: 'com.blackducksoftware.integration.library'", "", "dependencies {", "    compile 'org.apache.httpcomponents:httpmime:4.5.6'", "    compile group: 'commons-collections', name: 'commons-collections', version: '3.2.2'", "    compile 'org.apache.commons:commons-lang3:3.7'", "}");
    ExecutableOutput gradleDependenciesOutput = createStandardOutput("");
    addExecutableOutput(gradleDependenciesOutput, new File("gradle").getCanonicalPath(), "gatherDependencies", "--init-script=gradle-inspector", "-DGRADLEEXTRACTIONDIR=" + getOutputDirectory().toFile().getCanonicalPath(), "--info");
    addOutputFile(Paths.get("rootProjectMetadata.txt"), Arrays.asList("DETECT META DATA START", "rootProjectDirectory:/Users/ekerwin/Documents/source/integration/hub-detect", "rootProjectGroup:com.blackducksoftware.integration", "rootProjectName:hub-detect", "rootProjectVersion:2.0.0-SNAPSHOT", "DETECT META DATA END"));
    addOutputFile(Paths.get("_dependencyGraph.txt"), Arrays.asList("------------------------------------------------------------", "Root project", "------------------------------------------------------------", "", "compile - Dependencies for source set 'main'.", "+--- com.blackducksoftware.integration:hub-common:11.0.0-SNAPSHOT", "|    +--- com.blackducksoftware.integration:hub-common-rest:1.0.0", "|    |    +--- com.blackducksoftware.integration:integration-common:5.2.1", "|    |    |    +--- org.apache.commons:commons-lang3:3.5", "|    |    |    +--- commons-io:commons-io:2.5", "|    |    |    +--- commons-codec:commons-codec:1.10", "|    |    |    \\--- org.slf4j:slf4j-api:1.7.21 -> 1.7.22"));
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) File(java.io.File)

Example 18 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.

the class GradleReplacementDetectableTest method setup.

@Override
protected void setup() throws IOException {
    addFile(Paths.get("build.gradle"), "no content");
    ExecutableOutput gradleDependenciesOutput = createStandardOutput("no content");
    addExecutableOutput(gradleDependenciesOutput, new File("gradle").getCanonicalPath(), "gatherDependencies", "--init-script=gradle-inspector", "-DGRADLEEXTRACTIONDIR=" + getOutputDirectory().toFile().getCanonicalPath(), "--info");
    addOutputFile(Paths.get("rootProjectMetadata.txt"), Arrays.asList("DETECT META DATA START", "rootProjectName:root", "DETECT META DATA END"));
    addOutputFile(Paths.get("root_dependencyGraph.txt"), Arrays.asList("compile - project a has replacement root does not have'.", "\\--- org.replacement:replaced:1.0.0 -> 3.0.0", "DETECT META DATA START", "projectName:root", "DETECT META DATA END"));
    addOutputFile(Paths.get("projectA_dependencyGraph.txt"), Arrays.asList("compile - project a has replacement root does not have'.", "\\--- org.replacement:replaced:1.0.0 -> 2.0.0", "DETECT META DATA START", "projectName:projectA", "DETECT META DATA END"));
    addOutputFile(Paths.get("projectB_dependencyGraph.txt"), Arrays.asList("compile - project b uses the unreplaced version'.", "\\--- org.replacement:replaced:1.0.0", "DETECT META DATA START", "projectName:projectB", "DETECT META DATA END"));
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) File(java.io.File)

Example 19 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.

the class GoModDetectableVendoredTest method setup.

@Override
protected void setup() throws IOException {
    addFile(Paths.get("go.mod"));
    ExecutableOutput goListOutput = createStandardOutputFromResource("/go/go-list.xout");
    addExecutableOutput(goListOutput, "go", "list", "-m", "-json");
    ExecutableOutput goVersionOutput = createStandardOutput("go version go1.16.5 darwin/amd64");
    addExecutableOutput(goVersionOutput, "go", "version");
    ExecutableOutput goListUJsonOutput = createStandardOutputFromResource("/go/go-list-all.xout");
    addExecutableOutput(goListUJsonOutput, "go", "list", "-mod=readonly", "-m", "-json", "all");
    ExecutableOutput goModGraphOutput = createStandardOutput("github.com/gin-gonic/gin golang.org/x/text@v0.3.0", "github.com/gin-gonic/gin sigs.k8s.io/yaml@v1.2.0", "golang.org/x/text@v0.3.0 golang.org/x/tools@v0.0.0-20180917221912-90fa682c2a6e", "gopkg.in/yaml.v2@v2.2.8 gopkg.in/check.v1@v0.0.0-20161208181325-20d25e280405", "sigs.k8s.io/yaml@v1.2.0 github.com/davecgh/go-spew@v1.1.1", "sigs.k8s.io/yaml@v1.2.0 gopkg.in/yaml.v2@v2.2.8");
    addExecutableOutput(goModGraphOutput, "go", "mod", "graph");
    ExecutableOutput goModWhyOutput = createStandardOutput("# github.com/gin-gonic/gin", "github.com/gin-gonic/gin", "", "# github.com/davecgh/go-spew", "(main module does not need to vendor module github.com/davecgh/go-spew)", "", "# golang.org/x/text", "github.com/gin-gonic/gin", "golang.org/x/text/language", "", "# golang.org/x/tools", "(main module does not need to vendor module golang.org/x/tools)", "", "# gopkg.in/check.v1", "(main module does not need to vendor module gopkg.in/check.v1)", "", "# gopkg.in/yaml.v2", "(main module does not need to vendor module gopkg.in/yaml.v2)", "", "# sigs.k8s.io/yaml", "(main module does not need to vendor module sigs.k8s.io/yaml)");
    addExecutableOutput(goModWhyOutput, "go", "mod", "why", "-m", "-vendor", "all");
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput)

Example 20 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput in project synopsys-detect by blackducksoftware.

the class MavenPomDetectableTest method setup.

@Override
protected void setup() throws IOException {
    addFile(Paths.get("pom.xml"));
    ExecutableOutput mavenDependencyTreeOutput = createStandardOutput("7275 [main] [INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ hub-teamcity-common ---", "7450 [main] [INFO] com.blackducksoftware.integration:hub-teamcity-common:jar:3.2.0-SNAPSHOT", "7509 [main] [INFO] +- com.blackducksoftware.integration:hub-common:jar:13.1.2:compile", "7560 [main] [INFO] |  +- com.blackducksoftware.integration:hub-common-rest:jar:2.1.3:compile", "7638 [main] [INFO] |  |  +- com.blackducksoftware.integration:integration-common:jar:6.0.2:compile", "9623 [main] [INFO] +- junit:junit:jar:4.12:test", "9868 [main] [INFO] |  \\- org.hamcrest:hamcrest-core:jar:1.3:test", "10331 [main] [INFO] +- org.powermock:powermock-api-mockito:jar:1.6.6:test", "10424 [main] [INFO] |  +- org.mockito:mockito-core:jar:1.10.19:test", "10849 [main] [INFO] |  \\- org.powermock:powermock-api-mockito-common:jar:1.6.6:test", "11063 [main] [INFO] |     \\- org.powermock:powermock-api-support:jar:1.6.6:test");
    addExecutableOutput(mavenDependencyTreeOutput, new File("maven").getAbsolutePath(), "test", "dependency:tree", "-T1");
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) File(java.io.File)

Aggregations

ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)53 File (java.io.File)18 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)14 ArrayList (java.util.ArrayList)14 Extraction (com.synopsys.integration.detectable.extraction.Extraction)13 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)13 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)10 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)9 Executable (com.synopsys.integration.executable.Executable)9 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)8 Test (org.junit.jupiter.api.Test)7 NameVersion (com.synopsys.integration.util.NameVersion)6 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)5 HashMap (java.util.HashMap)5 List (java.util.List)5 StringUtils (org.apache.commons.lang3.StringUtils)5 ExecutableUtils (com.synopsys.integration.detectable.ExecutableUtils)4 IOException (java.io.IOException)4 Optional (java.util.Optional)4 Gson (com.google.gson.Gson)3