use of com.android.tools.idea.templates.recipe.RecipeExecutor 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);
}
}
use of com.android.tools.idea.templates.recipe.RecipeExecutor in project android by JetBrains.
the class RecipeUtils method getRecipeMetadata.
@NotNull
public static RecipeMetadata getRecipeMetadata(@NotNull Recipe recipe, @NotNull Module module) {
Pair key = new Pair(recipe, module.getProject());
if (myRecipeMetadataCache.containsKey(key)) {
List<RecipeMetadata> metadataSet = myRecipeMetadataCache.get(key);
for (RecipeMetadata metadata : metadataSet) {
if (metadata.getRecipe().equals(recipe)) {
return metadata;
}
}
}
SetMultimap<String, String> dependencies = LinkedHashMultimap.create();
Set<String> classpathEntries = Sets.newHashSet();
Set<String> plugins = Sets.newHashSet();
List<File> sourceFiles = Lists.newArrayList();
List<File> targetFiles = Lists.newArrayList();
RecipeMetadata metadata = new RecipeMetadata(recipe, module);
RenderingContext context = null;
try {
File moduleRoot = new File(module.getModuleFilePath()).getParentFile();
// TODO: do we care about this path?
File RootPath = new File(FileUtil.generateRandomTemporaryPath(), "unused");
RootPath.deleteOnExit();
context = RenderingContext.Builder.newContext(RootPath, module.getProject()).withOutputRoot(moduleRoot).withModuleRoot(moduleRoot).withFindOnlyReferences(true).withGradleSync(false).intoDependencies(dependencies).intoClasspathEntries(classpathEntries).intoPlugins(plugins).intoSourceFiles(sourceFiles).intoTargetFiles(targetFiles).build();
RecipeExecutor recipeExecutor = context.getRecipeExecutor();
recipe.execute(recipeExecutor);
} catch (FreemarkerUtils.TemplateProcessingException e) {
// TODO(b/31039466): Extra logging to track down a rare issue.
getLog().warn("Template processing exception with context in the following state: " + context);
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
// Ignore test configurations here.
for (String d : dependencies.get(SdkConstants.GRADLE_COMPILE_CONFIGURATION)) {
metadata.addDependency(d);
}
for (String c : classpathEntries) {
metadata.addClasspathEntry(c);
}
for (String p : plugins) {
metadata.addPlugin(p);
}
for (File f : sourceFiles) {
if (f.getName().equals(SdkConstants.FN_ANDROID_MANIFEST_XML)) {
parseManifestForPermissions(f, metadata);
}
}
for (File f : targetFiles) {
metadata.addModifiedFile(f);
}
return metadata;
}
use of com.android.tools.idea.templates.recipe.RecipeExecutor in project android by JetBrains.
the class RecipeUtils method execute.
public static void execute(@NotNull Recipe recipe, @NotNull Module module) {
List<File> filesToOpen = Lists.newArrayList();
File moduleRoot = new File(module.getModuleFilePath()).getParentFile();
File RootPath = null;
try {
RootPath = new File(FileUtil.generateRandomTemporaryPath(), "unused");
} catch (IOException e) {
throw new RuntimeException(e);
}
RenderingContext context = RenderingContext.Builder.newContext(RootPath, module.getProject()).withOutputRoot(moduleRoot).withModuleRoot(moduleRoot).intoOpenFiles(filesToOpen).build();
RecipeExecutor recipeExecutor = context.getRecipeExecutor();
new WriteCommandAction.Simple(module.getProject(), "Executing recipe instructions") {
@Override
protected void run() throws Throwable {
recipe.execute(recipeExecutor);
}
}.execute();
TemplateUtils.openEditors(module.getProject(), filesToOpen, true);
}
Aggregations