Search in sources :

Example 1 with Recipe

use of com.android.tools.idea.templates.recipe.Recipe in project android by JetBrains.

the class ServiceXmlParser method analyzeRecipe.

private void analyzeRecipe(boolean findOnlyReferences, @Nullable Collection<File> openFiles, @Nullable SetMultimap<String, String> dependencies, @Nullable Collection<String> classpathEntries, @Nullable Collection<String> plugins, @Nullable Collection<File> sourceFiles, @Nullable Collection<File> targetFiles) {
    RenderingContext context = null;
    try {
        File moduleRoot = new File(myModule.getModuleFilePath()).getParentFile();
        // @formatter:off
        context = RenderingContext.Builder.newContext(myRootPath, myModule.getProject()).withParams(myContext.toValueMap()).withOutputRoot(moduleRoot).withModuleRoot(moduleRoot).withFindOnlyReferences(findOnlyReferences).withGradleSync(false).intoOpenFiles(openFiles).intoDependencies(dependencies).intoClasspathEntries(classpathEntries).intoPlugins(plugins).intoSourceFiles(sourceFiles).intoTargetFiles(targetFiles).build();
        // @formatter:on
        String xml = FreemarkerUtils.processFreemarkerTemplate(context, myRecipeFile, null);
        Recipe recipe = Recipe.parse(new StringReader(xml));
        RecipeExecutor recipeExecutor = context.getRecipeExecutor();
        recipe.execute(recipeExecutor);
    } catch (TemplateProcessingException e) {
        // TODO(b/31039466): Extra logging to track down a rare issue.
        LOG.warn("Template processing exception with context in the following state: " + context);
        throw new RuntimeException(e);
    } catch (JAXBException e) {
        throw new RuntimeException(e);
    }
}
Also used : RenderingContext(com.android.tools.idea.templates.recipe.RenderingContext) Recipe(com.android.tools.idea.templates.recipe.Recipe) JAXBException(javax.xml.bind.JAXBException) StringReader(java.io.StringReader) TemplateProcessingException(com.android.tools.idea.templates.FreemarkerUtils.TemplateProcessingException) File(java.io.File) RecipeExecutor(com.android.tools.idea.templates.recipe.RecipeExecutor)

Aggregations

TemplateProcessingException (com.android.tools.idea.templates.FreemarkerUtils.TemplateProcessingException)1 Recipe (com.android.tools.idea.templates.recipe.Recipe)1 RecipeExecutor (com.android.tools.idea.templates.recipe.RecipeExecutor)1 RenderingContext (com.android.tools.idea.templates.recipe.RenderingContext)1 File (java.io.File)1 StringReader (java.io.StringReader)1 JAXBException (javax.xml.bind.JAXBException)1