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);
}
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"));
}
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"));
}
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");
}
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");
}
Aggregations