Search in sources :

Example 1 with PlatformSpecificManifest

use of com.amazon.aws.iot.greengrass.component.common.PlatformSpecificManifest in project aws-greengrass-nucleus by aws-greengrass.

the class RecipeLoader method loadFromFile.

/**
 * Converts from the recipe file with platform resolving.
 *
 * @param recipeFileContent recipe file content
 * @return Optional package recipe
 * @throws PackageLoadingException when failed to convert recipe file.
 */
public Optional<ComponentRecipe> loadFromFile(String recipeFileContent) throws PackageLoadingException {
    com.amazon.aws.iot.greengrass.component.common.ComponentRecipe componentRecipe = parseRecipe(recipeFileContent, RecipeFormat.YAML);
    if (componentRecipe.getManifests() == null || componentRecipe.getManifests().isEmpty()) {
        throw new PackageLoadingException(String.format("Recipe file %s-%s.yaml is missing manifests", componentRecipe.getComponentName(), componentRecipe.getComponentVersion().toString()));
    }
    Optional<PlatformSpecificManifest> optionalPlatformSpecificManifest = platformResolver.findBestMatch(componentRecipe.getManifests());
    if (!optionalPlatformSpecificManifest.isPresent()) {
        return Optional.empty();
    }
    PlatformSpecificManifest platformSpecificManifest = optionalPlatformSpecificManifest.get();
    Set<String> selectors = collectAllSelectors(componentRecipe.getManifests());
    Map<String, DependencyProperties> dependencyPropertiesMap = new HashMap<>();
    if (componentRecipe.getComponentDependencies() != null) {
        dependencyPropertiesMap.putAll(componentRecipe.getComponentDependencies());
    }
    ComponentRecipe packageRecipe = ComponentRecipe.builder().componentName(componentRecipe.getComponentName()).version(componentRecipe.getComponentVersion()).publisher(componentRecipe.getComponentPublisher()).recipeTemplateVersion(componentRecipe.getRecipeFormatVersion()).componentType(componentRecipe.getComponentType()).dependencies(dependencyPropertiesMap).lifecycle(convertLifecycleFromFile(componentRecipe.getLifecycle(), platformSpecificManifest, selectors)).artifacts(convertArtifactsFromFile(platformSpecificManifest.getArtifacts())).componentConfiguration(componentRecipe.getComponentConfiguration()).build();
    return Optional.of(packageRecipe);
}
Also used : PlatformSpecificManifest(com.amazon.aws.iot.greengrass.component.common.PlatformSpecificManifest) HashMap(java.util.HashMap) PackageLoadingException(com.aws.greengrass.componentmanager.exceptions.PackageLoadingException) DependencyProperties(com.amazon.aws.iot.greengrass.component.common.DependencyProperties) ComponentRecipe(com.aws.greengrass.componentmanager.models.ComponentRecipe)

Aggregations

DependencyProperties (com.amazon.aws.iot.greengrass.component.common.DependencyProperties)1 PlatformSpecificManifest (com.amazon.aws.iot.greengrass.component.common.PlatformSpecificManifest)1 PackageLoadingException (com.aws.greengrass.componentmanager.exceptions.PackageLoadingException)1 ComponentRecipe (com.aws.greengrass.componentmanager.models.ComponentRecipe)1 HashMap (java.util.HashMap)1