1717
1818import org .apache .commons .lang3 .StringUtils ;
1919import org .jspecify .annotations .Nullable ;
20- import org .openrewrite .Contributor ;
2120import org .openrewrite .Recipe ;
2221import org .openrewrite .RecipeException ;
2322import org .openrewrite .style .NamedStyles ;
3534import static java .util .function .Function .identity ;
3635import static java .util .stream .Collectors .toList ;
3736import static java .util .stream .Collectors .toMap ;
38- import static org .openrewrite .config .ResourceLoader .RecipeDetail .CONTRIBUTORS ;
3937import static org .openrewrite .config .ResourceLoader .RecipeDetail .EXAMPLES ;
4038
4139public class Environment {
@@ -50,12 +48,10 @@ public List<Recipe> listRecipes() {
5048 Map <String , Recipe > dependencyRecipeMap = new HashMap <>();
5149 dependencyRecipes .forEach (r -> dependencyRecipeMap .putIfAbsent (r .getName (), r ));
5250
53- Map <String , List <Contributor >> recipeToContributors = new HashMap <>();
5451 Map <String , List <RecipeExample >> recipeExamples = new HashMap <>();
5552 for (ResourceLoader r : resourceLoaders ) {
5653 if (r instanceof YamlResourceLoader ) {
5754 recipeExamples .putAll (r .listRecipeExamples ());
58- recipeToContributors .putAll (r .listContributors ());
5955 }
6056 }
6157
@@ -65,22 +61,20 @@ public List<Recipe> listRecipes() {
6561 }
6662 for (Recipe recipe : dependencyRecipes ) {
6763 if (recipe instanceof DeclarativeRecipe ) {
68- ((DeclarativeRecipe ) recipe ).initialize (dependencyRecipeMap ::get , recipeToContributors );
64+ ((DeclarativeRecipe ) recipe ).initialize (dependencyRecipeMap ::get );
6965 }
7066 }
7167
7268 Map <String , Recipe > availableRecipeMap = new HashMap <>(dependencyRecipeMap );
7369 recipes .forEach (r -> availableRecipeMap .putIfAbsent (r .getName (), r ));
7470
7571 for (Recipe recipe : recipes ) {
76- recipe .setContributors (recipeToContributors .get (recipe .getName ()));
77-
7872 if (recipeExamples .containsKey (recipe .getName ())) {
7973 recipe .setExamples (recipeExamples .get (recipe .getName ()));
8074 }
8175
8276 if (recipe instanceof DeclarativeRecipe ) {
83- ((DeclarativeRecipe ) recipe ).initialize (availableRecipeMap ::get , recipeToContributors );
77+ ((DeclarativeRecipe ) recipe ).initialize (availableRecipeMap ::get );
8478 }
8579 }
8680 return recipes ;
@@ -93,24 +87,12 @@ public Collection<CategoryDescriptor> listCategoryDescriptors() {
9387 }
9488
9589 public Collection <RecipeDescriptor > listRecipeDescriptors () {
96- Map <String , List <Contributor >> recipeToContributors = new HashMap <>();
9790 Map <String , List <RecipeExample >> recipeToExamples = new HashMap <>();
9891 for (ResourceLoader r : resourceLoaders ) {
9992 if (r instanceof YamlResourceLoader ) {
100- recipeToContributors .putAll (r .listContributors ());
10193 recipeToExamples .putAll (r .listRecipeExamples ());
10294 } else if (r instanceof ClasspathScanningLoader ) {
10395 ClasspathScanningLoader classpathScanningLoader = (ClasspathScanningLoader ) r ;
104-
105- Map <String , List <Contributor >> contributors = classpathScanningLoader .listContributors ();
106- for (String key : contributors .keySet ()) {
107- if (recipeToContributors .containsKey (key )) {
108- recipeToContributors .get (key ).addAll (contributors .get (key ));
109- } else {
110- recipeToContributors .put (key , contributors .get (key ));
111- }
112- }
113-
11496 Map <String , List <RecipeExample >> examplesMap = classpathScanningLoader .listRecipeExamples ();
11597 for (String key : examplesMap .keySet ()) {
11698 if (recipeToExamples .containsKey (key )) {
@@ -125,17 +107,11 @@ public Collection<RecipeDescriptor> listRecipeDescriptors() {
125107 List <RecipeDescriptor > result = new ArrayList <>();
126108 for (ResourceLoader r : resourceLoaders ) {
127109 if (r instanceof YamlResourceLoader ) {
128- result .addAll ((((YamlResourceLoader ) r ).listRecipeDescriptors (emptyList (), recipeToContributors , recipeToExamples )));
110+ result .addAll ((((YamlResourceLoader ) r ).listRecipeDescriptors (emptyList (), recipeToExamples )));
129111 } else {
130112 Collection <RecipeDescriptor > descriptors = r .listRecipeDescriptors ();
131113 for (RecipeDescriptor descriptor : descriptors ) {
132- if (descriptor .getContributors () != null &&
133- recipeToContributors .containsKey (descriptor .getName ())) {
134- descriptor .getContributors ().addAll (recipeToContributors .get (descriptor .getName ()));
135- }
136-
137- if (descriptor .getExamples () != null &&
138- recipeToExamples .containsKey (descriptor .getName ())) {
114+ if (recipeToExamples .containsKey (descriptor .getName ())) {
139115 descriptor .getExamples ().addAll (recipeToExamples .get (descriptor .getName ()));
140116 }
141117 }
@@ -159,7 +135,7 @@ public Recipe activateRecipes(Collection<String> activeRecipes) {
159135 if (activeRecipes .isEmpty ()) {
160136 recipes = emptyList ();
161137 } else if (activeRecipes .size () == 1 ) {
162- Recipe recipe = loadRecipe (activeRecipes .iterator ().next (), CONTRIBUTORS , EXAMPLES );
138+ Recipe recipe = loadRecipe (activeRecipes .iterator ().next (), EXAMPLES );
163139 if (recipe != null ) {
164140 return recipe ;
165141 }
@@ -217,19 +193,12 @@ public Recipe activateRecipes(String... activeRecipes) {
217193 }
218194
219195 boolean includeExamples = ResourceLoader .RecipeDetail .EXAMPLES .includedIn (details );
220- boolean includeContributors = ResourceLoader .RecipeDetail .CONTRIBUTORS .includedIn (details );
221196
222- Map <String , List <Contributor >> recipeToContributors = new HashMap <>();
223197 Map <String , List <RecipeExample >> recipeExamples = new HashMap <>();
224- if (includeContributors || includeExamples ) {
198+ if (includeExamples ) {
225199 for (ResourceLoader r : resourceLoaders ) {
226200 if (r instanceof YamlResourceLoader ) {
227- if (includeExamples ) {
228- recipeExamples .putAll (r .listRecipeExamples ());
229- }
230- if (includeContributors ) {
231- recipeToContributors .putAll (r .listContributors ());
232- }
201+ recipeExamples .putAll (r .listRecipeExamples ());
233202 }
234203 }
235204 }
@@ -242,14 +211,10 @@ public Recipe activateRecipes(String... activeRecipes) {
242211 }
243212 for (Recipe dependency : dependencyRecipes .values ()) {
244213 if (dependency instanceof DeclarativeRecipe ) {
245- ((DeclarativeRecipe ) dependency ).initialize (dependencyRecipes ::get , recipeToContributors );
214+ ((DeclarativeRecipe ) dependency ).initialize (dependencyRecipes ::get );
246215 }
247216 }
248217
249- if (includeContributors && recipeToContributors .containsKey (recipe .getName ())) {
250- recipe .setContributors (recipeToContributors .get (recipe .getName ()));
251- }
252-
253218 if (includeExamples && recipeExamples .containsKey (recipe .getName ())) {
254219 recipe .setExamples (recipeExamples .get (recipe .getName ()));
255220 }
@@ -267,7 +232,7 @@ public Recipe activateRecipes(String... activeRecipes) {
267232 }
268233 return null ;
269234 };
270- ((DeclarativeRecipe ) recipe ).initialize (loadFunction , recipeToContributors );
235+ ((DeclarativeRecipe ) recipe ).initialize (loadFunction );
271236 }
272237 return recipe ;
273238 }
0 commit comments