Search in sources :

Example 41 with ExecutableOutput

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

the class DpkgPackageManagerTest method test.

// TODO: Split into 2 tests - one for VersionResolution and one for FullResolution
@Test
public void test() throws ExecutableRunnerException, NotOwnedByAnyPkgException {
    StringBuilder sb = new StringBuilder();
    sb.append("garbage\n");
    sb.append("nonsense\n");
    sb.append("libc6-dev:amd64: /usr/include/stdlib.h\n");
    String pkgMgrOwnedByOutput = sb.toString();
    sb = new StringBuilder();
    sb.append("Package: libc6-dev\n");
    sb.append("Status: install ok installed\n");
    sb.append("Priority: optional\n");
    sb.append("Section: libdevel\n");
    sb.append("Installed-Size: 18812\n");
    sb.append("Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>\n");
    sb.append("Architecture: amd64\n");
    sb.append("Multi-Arch: same\n");
    sb.append("Source: glibc\n");
    sb.append("Version: 2.27-3ubuntu1\n");
    sb.append("Provides: libc-dev\n");
    sb.append("Depends: libc6 (= 2.27-3ubuntu1), libc-dev-bin (= 2.27-3ubuntu1), linux-libc-dev\n");
    sb.append("Suggests: glibc-doc, manpages-dev\n");
    sb.append("Breaks: binutils (<< 2.26), binutils-gold (<< 2.20.1-11), cmake (<< 2.8.4+dfsg.1-5), gcc-4.4 (<< 4.4.6-4), gcc-4.5 (<< 4.5.3-2), gcc-4.6 (<< 4.6.0-12), libhwloc-dev (<< 1.2-3), libjna-java (<< 3.2.7-4), liblouis-dev (<< 2.3.0-2), liblouisxml-dev (<< 2.4.0-2), libperl5.26 (<< 5.26.1-3), make (<< 3.81-8.1), pkg-config (<< 0.26-1)\n");
    sb.append("Conflicts: libc0.1-dev, libc0.3-dev, libc6.1-dev\n");
    sb.append("Description: GNU C Library: Development Libraries and Header Files\n");
    sb.append(" Contains the symlinks, headers, and object files needed to compile\n");
    sb.append(" and link programs which use the standard C library.\n");
    sb.append("Homepage: https://www.gnu.org/software/libc/libc.html\n");
    sb.append("Original-Maintainer: GNU Libc Maintainers <debian-glibc@lists.debian.org>\n");
    String pkgMgrVersionOutput = sb.toString();
    final String packageNameWithArch = "libc6-dev:amd64";
    DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
    Mockito.when(executableRunner.execute(null, "dpkg", Arrays.asList("-s", packageNameWithArch))).thenReturn(new ExecutableOutput(0, pkgMgrVersionOutput, ""));
    DpkgPkgDetailsResolver dpkgVersionResolver = new DpkgPkgDetailsResolver();
    DpkgPackageManagerResolver pkgMgr = new DpkgPackageManagerResolver(dpkgVersionResolver);
    List<PackageDetails> pkgs = pkgMgr.resolvePackages(new ClangPackageManagerInfoFactory().dpkg(), executableRunner, null, pkgMgrOwnedByOutput);
    assertEquals(1, pkgs.size());
    assertEquals("libc6-dev", pkgs.get(0).getPackageName());
    assertEquals("2.27-3ubuntu1", pkgs.get(0).getPackageVersion());
    assertEquals("amd64", pkgs.get(0).getPackageArch());
}
Also used : ClangPackageManagerInfoFactory(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfoFactory) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) DpkgPackageManagerResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPackageManagerResolver) DpkgPkgDetailsResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPkgDetailsResolver) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails) Test(org.junit.jupiter.api.Test)

Example 42 with ExecutableOutput

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

the class LernaDetectableTest method setup.

@Override
public void setup() throws IOException {
    addFile("lerna.json");
    addPackageJson(Paths.get(""), "lernaTest", "package-version", Collections.singletonList(new NameVersion("brace-expansion", "~1")), Collections.singletonList(new NameVersion("concat-map", "~1")), Collections.singletonList(new NameVersion("peer-example", "~1")));
    addFile(Paths.get("package-lock.json"), "{", "   \"name\": \"lerna-project-name\",", "   \"version\": \"1.0.0\",", "   \"dependencies\": {", "       \"balanced-match\": {", "           \"version\": \"1.0.0\",", "           \"resolved\": \"https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz\",", "           \"integrity\": \"sha1-ibTRmasr7kneFk6gK4nORi1xt2c=\"", "       },", "       \"brace-expansion\": {", "           \"version\": \"1.1.8\",", "           \"resolved\": \"https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz\",", "           \"integrity\": \"sha1-wHshHHyVLsH479Uad+8NHTmQopI=\",", "           \"requires\": {", "               \"balanced-match\": \"1.0.0\",", "               \"concat-map\": \"0.0.1\"", "           }", "       },", "       \"concat-map\": {", "           \"version\": \"0.0.1\",", "           \"resolved\": \"https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz\",", "           \"integrity\": \"sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=\",", "           \"dev\": true", "       },", "       \"peer-example\": {", "           \"version\": \"1.0.0\",", "           \"resolved\": \"https://synopsys.com/404/peer-example-1.0.0.tgz\",", "           \"integrity\": \"sha1-5Hlr13/Wjfd5OnMDajug1UBdR3c=\",", "           \"peer\": true", "       }", "   }", "}");
    ExecutableOutput executableOutput = createStandardOutput("[", "  {", "    \"name\": \"@lerna/packageA\",", "    \"version\": \"1.2.3\",", "    \"private\": false,", "    \"location\": " + gson.toJson(getSourceDirectory() + "/packages/packageA"), "  },", "  {", "    \"name\": \"@lerna/packageB\",", "    \"version\": \"3.2.1\",", "    \"private\": true,", "    \"location\": " + gson.toJson(getSourceDirectory() + "/source/packages/packageB"), "  }", "]");
    addExecutableOutput(executableOutput, "lerna", "ls", "--all", "--json");
    Path packagesDirectory = addDirectory(Paths.get("packages"));
    Path packageADirectory = addDirectory(packagesDirectory.resolve("packageA"));
    addPackageJson(packageADirectory, "packageA", "1.2.3", new NameVersion("brace-expansion", "~1"));
    Path packageBDirectory = addDirectory(packagesDirectory.resolve("packageB"));
    addPackageJson(packageBDirectory, "packageB", "3.2.1", new NameVersion("concat-map", "0.0.1"));
}
Also used : Path(java.nio.file.Path) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) NameVersion(com.synopsys.integration.util.NameVersion)

Example 43 with ExecutableOutput

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

the class LernaExternalDetectableTest method setup.

@Override
public void setup() throws IOException {
    // Package is not in package lock file but is present in lerna.
    addFile("lerna.json");
    addPackageJson(Paths.get(""), "lernaTest", "package-version", new NameVersion("concat-map", "~1"));
    addFile(Paths.get("package-lock.json"), "{", "   \"name\": \"lerna-project-name\",", "   \"version\": \"1.0.0\",", "   \"dependencies\": {", "   }", "}");
    ExecutableOutput executableOutput = createStandardOutput("[", "  {", "    \"name\": \"packageA\",", "    \"version\": \"1.2.3\",", "    \"private\": false,", "    \"location\": " + gson.toJson(getSourceDirectory() + "/packages/packageA"), "  },", "  {", "    \"name\": \"packageB\",", "    \"version\": \"3.2.1\",", "    \"private\": false,", "    \"location\": " + gson.toJson(getSourceDirectory() + "/packages/packageB"), "  }", "]");
    addExecutableOutput(executableOutput, "lerna", "ls", "--all", "--json");
    Path packagesDirectory = addDirectory(Paths.get("packages"));
    Path packageADirectory = addDirectory(packagesDirectory.resolve("packageA"));
    addPackageJson(packageADirectory, "packageA", "1.2.3", new NameVersion("packageB", "~1"));
    Path packageBDirectory = addDirectory(packagesDirectory.resolve("packageB"));
    addPackageJson(packageBDirectory, "packageB", "3.2.1");
}
Also used : Path(java.nio.file.Path) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) NameVersion(com.synopsys.integration.util.NameVersion)

Example 44 with ExecutableOutput

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

the class LernaPackageDiscovererTest method discoverLernaPackages.

@Test
void discoverLernaPackages() throws ExecutableRunnerException {
    File workingDirectory = new File("workingDir");
    ExecutableTarget lernaExecutable = ExecutableTarget.forCommand("lerna");
    DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
    Mockito.when(executableRunner.execute(Mockito.any(Executable.class))).thenReturn(new ExecutableOutput(0, String.join(System.lineSeparator(), "[", "  {", "    \"name\": \"@lerna/packageA\",", "    \"version\": \"1.2.3\",", "    \"private\": false,", "    \"location\": \"/source/packages/packageA\"", "  },", "  {", "    \"name\": \"@lerna/packageB\",", "    \"version\": \"3.2.1\",", "    \"private\": true,", "    \"location\": \"/source/packages/packageB\"", "  },", "  {", "    \"name\": \"@lerna/packageC\",", "    \"version\": \"1.1.1\",", "    \"private\": true,", "    \"location\": \"/source/packages/packageC\"", "  }", "]"), ""));
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    LernaPackageDiscoverer lernaPackageDiscoverer = new LernaPackageDiscoverer(executableRunner, gson, Collections.singletonList("@lerna/packageC"), new LinkedList<>());
    List<LernaPackage> lernaPackages = lernaPackageDiscoverer.discoverLernaPackages(workingDirectory, lernaExecutable);
    Assertions.assertEquals(2, lernaPackages.size(), "Expected to find two Lerna packages.");
    LernaPackage lernaPackageA = lernaPackages.get(0);
    Assertions.assertEquals("@lerna/packageA", lernaPackageA.getName());
    Assertions.assertEquals("1.2.3", lernaPackageA.getVersion());
    Assertions.assertFalse(lernaPackageA.isPrivate());
    Assertions.assertEquals("/source/packages/packageA", lernaPackageA.getLocation());
    LernaPackage lernaPackageB = lernaPackages.get(1);
    Assertions.assertEquals("@lerna/packageB", lernaPackageB.getName());
    Assertions.assertEquals("3.2.1", lernaPackageB.getVersion());
    Assertions.assertTrue(lernaPackageB.isPrivate());
    Assertions.assertEquals("/source/packages/packageB", lernaPackageB.getLocation());
}
Also used : DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) GsonBuilder(com.google.gson.GsonBuilder) LernaPackageDiscoverer(com.synopsys.integration.detectable.detectables.lerna.LernaPackageDiscoverer) Gson(com.google.gson.Gson) LernaPackage(com.synopsys.integration.detectable.detectables.lerna.model.LernaPackage) Executable(com.synopsys.integration.executable.Executable) File(java.io.File) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) Test(org.junit.jupiter.api.Test)

Example 45 with ExecutableOutput

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

the class IntermediateStepExecuteBazelOnEachLineTest method testNoInput.

@Test
public void testNoInput() throws ExecutableRunnerException, IntegrationException, ExecutableFailedException {
    File workspaceDir = new File(".");
    DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
    ExecutableTarget bazelExe = ExecutableTarget.forCommand("/usr/bin/bazel");
    ExecutableOutput bazelCmdExecutableOutput = Mockito.mock(ExecutableOutput.class);
    Mockito.when(bazelCmdExecutableOutput.getReturnCode()).thenReturn(0);
    Mockito.when(bazelCmdExecutableOutput.getStandardOutput()).thenReturn("@org_apache_commons_commons_io//jar:jar\n@com_google_guava_guava//jar:jar");
    Mockito.when(executableRunner.executeSuccessfully(Mockito.any(Executable.class))).thenReturn(bazelCmdExecutableOutput);
    BazelCommandExecutor bazelCommandExecutor = new BazelCommandExecutor(executableRunner, workspaceDir, bazelExe);
    BazelVariableSubstitutor bazelVariableSubstitutor = new BazelVariableSubstitutor("//:ProjectRunner", null);
    IntermediateStep executor = new IntermediateStepExecuteBazelOnEachLine(bazelCommandExecutor, bazelVariableSubstitutor, Arrays.asList("cquery", "filter(\\\"@.*:jar\\\", deps(${detect.bazel.target}))"), false);
    List<String> input = new ArrayList<>(0);
    List<String> output = executor.process(input);
    assertEquals(1, output.size());
    assertEquals("@org_apache_commons_commons_io//jar:jar\n@com_google_guava_guava//jar:jar", output.get(0));
}
Also used : DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) IntermediateStep(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.IntermediateStep) ArrayList(java.util.ArrayList) BazelVariableSubstitutor(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelVariableSubstitutor) Executable(com.synopsys.integration.executable.Executable) File(java.io.File) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) BazelCommandExecutor(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelCommandExecutor) IntermediateStepExecuteBazelOnEachLine(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.IntermediateStepExecuteBazelOnEachLine) Test(org.junit.jupiter.api.Test)

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