Skip to content

Fix applicable recipe list holder #822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.context.ProjectContextHolder;
import org.springframework.sbm.engine.recipe.Action;
import org.springframework.sbm.engine.recipe.ApplicableRecipesListHolder;
import org.springframework.sbm.engine.recipe.Recipe;
import org.springframework.shell.Availability;
import org.springframework.shell.CompletionContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class ScanShellCommand {
private final PreconditionVerificationRenderer preconditionVerificationRenderer;
private final ScanCommandHeaderRenderer scanCommandHeaderRenderer;
private final ConsolePrinter consolePrinter;
private final ApplicableRecipesListHolder applicableRecipesListHolder;

@ShellMethod(key = {"scan", "s"},
value = "Scans the target project directory and get the list of applicable recipes.")
Expand All @@ -51,8 +50,6 @@ public String scan(
help = "The root directory of the target application.")
String projectRoot) {

applicableRecipesListHolder.clear();

List<Resource> resources = scanCommand.scanProjectRoot(projectRoot);
String scanCommandHeader = scanCommandHeaderRenderer.renderHeader(projectRoot);
PreconditionVerificationResult result = scanCommand.checkPreconditions(projectRoot, resources);
Expand All @@ -70,7 +67,6 @@ public String scan(
ProjectContext projectContext = scanCommand.execute(projectRoot);
contextHolder.setProjectContext(projectContext);
List<Recipe> recipes = applicableRecipeListCommand.execute(projectContext);
applicableRecipesListHolder.setRecipes(recipes);
AttributedString recipeList = applicableRecipeListRenderer.render(recipes);
stringBuilder.append(recipeList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.context.ProjectContextHolder;
import org.springframework.sbm.engine.precondition.PreconditionVerificationResult;
import org.springframework.sbm.engine.recipe.ApplicableRecipesListHolder;
import org.springframework.sbm.engine.recipe.Recipe;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void beforeEach() {
recipes = List.of();
projectContext = mock(ProjectContext.class);

sut = new ScanShellCommand(scanCommand, applicationRecipeListRenderer, applicableRecipeListCommand, contextHolder, preconditionVerificationRenderer, scanCommandHeaderRenderer, consolePrinter, new ApplicableRecipesListHolder());
sut = new ScanShellCommand(scanCommand, applicationRecipeListRenderer, applicableRecipeListCommand, contextHolder, preconditionVerificationRenderer, scanCommandHeaderRenderer, consolePrinter);
}

private void recordMocks(String projectRoot, ScanCommand scanCommand, ApplicableRecipeListRenderer applicationRecipeListRenderer, ApplicableRecipeListCommand applicableRecipeListCommand, List<Resource> resources, List<Recipe> recipes, ProjectContext projectContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.sbm.engine.recipe.RecipesBuilder;
import org.springframework.sbm.project.parser.ProjectContextInitializer;
import org.springframework.sbm.scopes.ExecutionScope;
import org.springframework.sbm.engine.recipe.ApplicableRecipesListHolder;
import org.springframework.stereotype.Component;

import java.util.List;
Expand All @@ -38,23 +39,28 @@ public class ApplicableRecipeListCommand extends AbstractCommand<List<Recipe>> {
private final ConfigurableListableBeanFactory beanFactory;

private final ExecutionScope executionScope;
private final ApplicableRecipesListHolder applicableRecipesListHolder;

protected ApplicableRecipeListCommand(ProjectRootPathResolver projectRootPathResolver, RecipesBuilder recipesBuilder, ProjectContextInitializer projectContextBuilder, ConfigurableListableBeanFactory beanFactory, ExecutionScope executionScope) {
protected ApplicableRecipeListCommand(ProjectRootPathResolver projectRootPathResolver, RecipesBuilder recipesBuilder, ProjectContextInitializer projectContextBuilder, ConfigurableListableBeanFactory beanFactory, ExecutionScope executionScope, ApplicableRecipesListHolder applicableRecipesListHolder) {
super(COMMAND_NAME);
this.projectRootPathResolver = projectRootPathResolver;
this.recipesBuilder = recipesBuilder;
this.projectContextBuilder = projectContextBuilder;
this.beanFactory = beanFactory;
this.executionScope = executionScope;
this.applicableRecipesListHolder = applicableRecipesListHolder;
}

public List<Recipe> execute(ProjectContext projectContext) {
return getApplicableRecipes(projectContext);
}

private List<Recipe> getApplicableRecipes(ProjectContext context) {
applicableRecipesListHolder.clear();
Recipes recipes = recipesBuilder.buildRecipes();
return recipes.getApplicable(context);
List<Recipe> applicable = recipes.getApplicable(context);
applicableRecipesListHolder.setRecipes(applicable);
return applicable;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.sbm.shell;
package org.springframework.sbm.engine.recipe;

import org.springframework.sbm.engine.recipe.Recipe;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.openrewrite.java.tree.J;
import org.springframework.sbm.project.resource.SbmApplicationProperties;
import org.springframework.sbm.scopes.annotations.ScanScope;
import org.springframework.sbm.engine.annotations.StatefulComponent;
import org.springframework.sbm.project.resource.SbmApplicationProperties;
import org.springframework.stereotype.Component;

import java.nio.file.Path;
Expand Down