Search in sources :

Example 1 with LernaPackageDiscoverer

use of com.synopsys.integration.detectable.detectables.lerna.LernaPackageDiscoverer in project synopsys-detect by blackducksoftware.

the class DetectableFactory method createLernaDetectable.

public LernaDetectable createLernaDetectable(DetectableEnvironment environment, LernaResolver lernaResolver, NpmLockfileOptions npmLockfileOptions, LernaOptions lernaOptions, YarnLockOptions yarnLockOptions) {
    LernaPackageDiscoverer lernaPackageDiscoverer = new LernaPackageDiscoverer(executableRunner, gson, lernaOptions.getExcludedPackages(), lernaOptions.getIncludedPackages());
    LernaPackager lernaPackager = new LernaPackager(fileFinder, packageJsonReader(), yarnLockParser(), npmLockfilePackager(npmLockfileOptions), yarnPackager(yarnLockOptions), lernaOptions.getLernaPackageTypeFilter());
    LernaExtractor lernaExtractor = new LernaExtractor(lernaPackageDiscoverer, lernaPackager);
    return new LernaDetectable(environment, fileFinder, lernaResolver, lernaExtractor);
}
Also used : LernaDetectable(com.synopsys.integration.detectable.detectables.lerna.LernaDetectable) LernaPackager(com.synopsys.integration.detectable.detectables.lerna.LernaPackager) LernaExtractor(com.synopsys.integration.detectable.detectables.lerna.LernaExtractor) LernaPackageDiscoverer(com.synopsys.integration.detectable.detectables.lerna.LernaPackageDiscoverer)

Example 2 with LernaPackageDiscoverer

use of com.synopsys.integration.detectable.detectables.lerna.LernaPackageDiscoverer 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)

Aggregations

LernaPackageDiscoverer (com.synopsys.integration.detectable.detectables.lerna.LernaPackageDiscoverer)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)1 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)1 LernaDetectable (com.synopsys.integration.detectable.detectables.lerna.LernaDetectable)1 LernaExtractor (com.synopsys.integration.detectable.detectables.lerna.LernaExtractor)1 LernaPackager (com.synopsys.integration.detectable.detectables.lerna.LernaPackager)1 LernaPackage (com.synopsys.integration.detectable.detectables.lerna.model.LernaPackage)1 Executable (com.synopsys.integration.executable.Executable)1 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)1 File (java.io.File)1 Test (org.junit.jupiter.api.Test)1