use of org.eclipse.che.plugin.docker.compose.ComposeEnvironment in project che by eclipse.
the class ComposeEnvironmentParser method parse.
/**
* Parses compose file into Docker Compose model.
*
* @param recipeContent
* compose file to parse
* @throws IllegalArgumentException
* when environment or environment recipe is invalid
* @throws ServerException
* when environment recipe can not be retrieved
*/
public ComposeEnvironment parse(String recipeContent, String contentType) throws ServerException {
requireNonNull(recipeContent, "Recipe content should not be null");
requireNonNull(contentType, "Recipe content type should not be null");
ComposeEnvironment composeEnvironment;
switch(contentType) {
case "application/x-yaml":
case "text/yaml":
case "text/x-yaml":
try {
composeEnvironment = YAML_PARSER.readValue(recipeContent, ComposeEnvironment.class);
} catch (IOException e) {
throw new IllegalArgumentException("Parsing of environment configuration failed. " + e.getLocalizedMessage());
}
break;
default:
throw new IllegalArgumentException("Provided environment recipe content type '" + contentType + "' is unsupported. Supported values are: " + "application/x-yaml, text/yaml, text/x-yaml");
}
return composeEnvironment;
}
Aggregations