Search in sources :

Example 1 with BitbakeEnvironment

use of com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment in project synopsys-detect by blackducksoftware.

the class BuildFileFinderTest method testFindingBasedOnLicenseDir.

@Test
void testFindingBasedOnLicenseDir() {
    Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS);
    File buildDir = FunctionalTestFiles.asFile("/bitbake/builddir_env");
    File licenseDir = FunctionalTestFiles.asFile("/bitbake/builddir_env/envprovidedpath/licenses");
    File lastModifiedManifestFile = new File(licenseDir, "targetimage-last-modified-architecture/license.manifest");
    File wrongManifestFile = new File(licenseDir, "targetimage-wrong-architecture/license.manifest");
    long currentTime = System.currentTimeMillis();
    assertTrue(lastModifiedManifestFile.setLastModified(currentTime), "The test needs to be able to set the last modified.");
    assertTrue(wrongManifestFile.setLastModified(currentTime - 1000), "The test needs to be able to set the last modified.");
    // This test adds license directory
    BitbakeEnvironment bitbakeEnvironment = new BitbakeEnvironment(null, licenseDir.getAbsolutePath());
    Optional<File> licensesManifestFile = finder.findLicenseManifestFile(buildDir, "targetimage", bitbakeEnvironment);
    assertTrue(licensesManifestFile.isPresent());
    assertTrue(licensesManifestFile.get().isFile());
    assertEquals(licenseDir.getAbsolutePath() + "/targetimage-last-modified-architecture/license.manifest", licensesManifestFile.get().getAbsolutePath());
}
Also used : BitbakeEnvironment(com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment) File(java.io.File) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) FunctionalTest(com.synopsys.integration.detectable.annotations.FunctionalTest)

Example 2 with BitbakeEnvironment

use of com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment in project synopsys-detect by blackducksoftware.

the class BuildFileFinderTest method testFindingInDefaultAndCustom.

@ParameterizedTest
@ValueSource(strings = { "/bitbake/builddir_default", "/bitbake/builddir_custom" })
void testFindingInDefaultAndCustom(String directoryPath) {
    File buildDir = FunctionalTestFiles.asFile(directoryPath);
    BitbakeEnvironment bitbakeEnvironment = new BitbakeEnvironment(null, null);
    Optional<File> licensesManifestFile = finder.findLicenseManifestFile(buildDir, "targetimage", bitbakeEnvironment);
    assertTrue(licensesManifestFile.isPresent());
    assertTrue(licensesManifestFile.get().isFile());
}
Also used : BitbakeEnvironment(com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment) File(java.io.File) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with BitbakeEnvironment

use of com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment in project synopsys-detect by blackducksoftware.

the class BitbakeEnvironmentParserTest method testParseEnvironment.

@Test
void testParseEnvironment() {
    BitbakeEnvironmentParser parser = new BitbakeEnvironmentParser();
    BitbakeEnvironment environment = parser.parseArchitecture(lines);
    assertTrue(environment.getMachineArch().isPresent());
    assertEquals(ARCH, environment.getMachineArch().get());
    assertTrue(environment.getLicensesDirPath().isPresent());
    assertEquals(LICENSES_DIR, environment.getLicensesDirPath().get());
}
Also used : BitbakeEnvironment(com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment) BitbakeEnvironmentParser(com.synopsys.integration.detectable.detectables.bitbake.parse.BitbakeEnvironmentParser) Test(org.junit.jupiter.api.Test)

Example 4 with BitbakeEnvironment

use of com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment in project synopsys-detect by blackducksoftware.

the class BitbakeEnvironmentParser method parseArchitecture.

public BitbakeEnvironment parseArchitecture(List<String> bitbakeEnvironmentCmdOutput) {
    Optional<String> architecture = bitbakeEnvironmentCmdOutput.stream().filter(isArchitectureLine).map(line -> isolateVariableValue(line, ARCHITECTURE_VARIABLE_NAME)).map(s -> StringUtils.strip(s, QUOTE_CHARS)).findFirst();
    Optional<String> licensesDirPath = bitbakeEnvironmentCmdOutput.stream().filter(isLicensesDirLine).map(line -> isolateVariableValue(line, LICENSES_DIR_VARIABLE_NAME)).map(s -> StringUtils.strip(s, QUOTE_CHARS)).findFirst();
    BitbakeEnvironment bitbakeEnvironment = new BitbakeEnvironment(architecture.orElse(null), licensesDirPath.orElse(null));
    logger.debug("Bitbake environment: {}", bitbakeEnvironment);
    return bitbakeEnvironment;
}
Also used : BitbakeEnvironment(com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment) List(java.util.List) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) LoggerFactory(org.slf4j.LoggerFactory) Optional(java.util.Optional) StringUtils(org.apache.commons.lang3.StringUtils) BitbakeEnvironment(com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment)

Example 5 with BitbakeEnvironment

use of com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment in project synopsys-detect by blackducksoftware.

the class BitbakeExtractor method extract.

public Extraction extract(File sourceDirectory, ExecutableTarget bashExecutable, File buildEnvironmentFile) throws ExecutableFailedException, IOException {
    toolVersionLogger.log(() -> bitbakeCommandRunner.runBitbakeVersion(sourceDirectory, bashExecutable, buildEnvironmentFile));
    File buildDirectory = determineBuildDirectory(sourceDirectory, bashExecutable, buildEnvironmentFile);
    BitbakeEnvironment bitbakeEnvironment = executeBitbakeForEnvironment(sourceDirectory, bashExecutable, buildEnvironmentFile);
    ShowRecipesResults showRecipesResults = executeBitbakeForRecipeLayerCatalog(sourceDirectory, bashExecutable, buildEnvironmentFile);
    List<CodeLocation> codeLocations = packageNames.stream().map(targetPackage -> generateCodeLocationForTargetPackage(targetPackage, sourceDirectory, bashExecutable, buildEnvironmentFile, buildDirectory, showRecipesResults, bitbakeEnvironment)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    if (codeLocations.isEmpty()) {
        return Extraction.failure("No Code Locations were generated during extraction");
    } else {
        return Extraction.success(codeLocations);
    }
}
Also used : BitbakeEnvironment(com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) IntegrationException(com.synopsys.integration.exception.IntegrationException) Extraction(com.synopsys.integration.detectable.extraction.Extraction) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) BitbakeDependencyGraphTransformer(com.synopsys.integration.detectable.detectables.bitbake.transform.BitbakeDependencyGraphTransformer) ToolVersionLogger(com.synopsys.integration.detectable.util.ToolVersionLogger) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) PwdOutputParser(com.synopsys.integration.detectable.detectables.bitbake.parse.PwdOutputParser) Charset(java.nio.charset.Charset) Map(java.util.Map) ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) BitbakeGraph(com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph) Logger(org.slf4j.Logger) EnumListFilter(com.synopsys.integration.detectable.detectable.util.EnumListFilter) BitbakeGraphTransformer(com.synopsys.integration.detectable.detectables.bitbake.transform.BitbakeGraphTransformer) GraphParser(com.paypal.digraph.parser.GraphParser) BuildFileFinder(com.synopsys.integration.detectable.detectables.bitbake.collect.BuildFileFinder) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) BitbakeEnvironmentParser(com.synopsys.integration.detectable.detectables.bitbake.parse.BitbakeEnvironmentParser) BitbakeEnvironment(com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment) BitbakeCommandRunner(com.synopsys.integration.detectable.detectables.bitbake.collect.BitbakeCommandRunner) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ShowRecipesResults(com.synopsys.integration.detectable.detectables.bitbake.data.ShowRecipesResults) Optional(java.util.Optional) BitbakeRecipesParser(com.synopsys.integration.detectable.detectables.bitbake.parse.BitbakeRecipesParser) LicenseManifestParser(com.synopsys.integration.detectable.detectables.bitbake.parse.LicenseManifestParser) InputStream(java.io.InputStream) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Optional(java.util.Optional) ShowRecipesResults(com.synopsys.integration.detectable.detectables.bitbake.data.ShowRecipesResults) File(java.io.File)

Aggregations

BitbakeEnvironment (com.synopsys.integration.detectable.detectables.bitbake.data.BitbakeEnvironment)6 File (java.io.File)4 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 FunctionalTest (com.synopsys.integration.detectable.annotations.FunctionalTest)2 BitbakeEnvironmentParser (com.synopsys.integration.detectable.detectables.bitbake.parse.BitbakeEnvironmentParser)2 List (java.util.List)2 Optional (java.util.Optional)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 GraphParser (com.paypal.digraph.parser.GraphParser)1 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 ExecutableFailedException (com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException)1 EnumListFilter (com.synopsys.integration.detectable.detectable.util.EnumListFilter)1 BitbakeCommandRunner (com.synopsys.integration.detectable.detectables.bitbake.collect.BitbakeCommandRunner)1 BuildFileFinder (com.synopsys.integration.detectable.detectables.bitbake.collect.BuildFileFinder)1 ShowRecipesResults (com.synopsys.integration.detectable.detectables.bitbake.data.ShowRecipesResults)1 BitbakeGraph (com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph)1