Skip to content

Commit

Permalink
FORGE-1501 Execute scaffold plugin setup during generation.
Browse files Browse the repository at this point in the history
THis ensures that if the scaffold setup command was not run
previously, then it is effectively run during scaffold generation.
  • Loading branch information
VineetReynolds authored and lincolnthree committed May 21, 2014
1 parent 40e35b3 commit d9cb145
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public List<Resource<?>> setup(Project project, ScaffoldSetupContext setupContex
}

@Override
public boolean isSetup(ScaffoldSetupContext setupContext)
public boolean isSetup(Project project, ScaffoldSetupContext setupContext)
{
WebResourcesFacet web = project.getFacet(WebResourcesFacet.class);
String targetDir = setupContext.getTargetDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jboss.forge.addon.scaffold.spi.ResourceCollection;
import org.jboss.forge.addon.scaffold.spi.ScaffoldGenerationContext;
import org.jboss.forge.addon.scaffold.spi.ScaffoldProvider;
import org.jboss.forge.addon.scaffold.spi.ScaffoldSetupContext;
import org.jboss.forge.addon.ui.context.UIBuilder;
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.context.UIExecutionContext;
Expand Down Expand Up @@ -59,7 +60,13 @@ public NavigationResult next(UINavigationContext context) throws Exception
public Result execute(UIExecutionContext context) throws Exception
{
Map<Object, Object> attributeMap = context.getUIContext().getAttributeMap();
boolean requiresScaffoldSetup = (boolean) attributeMap.get(ScaffoldGenerateCommandImpl.REQUIRES_SCAFFOLD_SETUP);
ScaffoldProvider selectedProvider = (ScaffoldProvider) attributeMap.get(ScaffoldProvider.class);
if(requiresScaffoldSetup)
{
ScaffoldSetupContext setupContext = (ScaffoldSetupContext) attributeMap.get(ScaffoldSetupContext.class);
selectedProvider.setup(getSelectedProject(context), setupContext);
}
ResourceCollection resourceCollection = (ResourceCollection) attributeMap.get(ResourceCollection.class);
selectedProvider.generateFrom(getSelectedProject(context),
populateGenerationContext(context.getUIContext(), resourceCollection.getResources()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jboss.forge.addon.projects.ui.AbstractProjectCommand;
import org.jboss.forge.addon.scaffold.spi.ScaffoldGenerationContext;
import org.jboss.forge.addon.scaffold.spi.ScaffoldProvider;
import org.jboss.forge.addon.scaffold.spi.ScaffoldSetupContext;
import org.jboss.forge.addon.scaffold.ui.ScaffoldGenerateCommand;
import org.jboss.forge.addon.ui.context.UIBuilder;
import org.jboss.forge.addon.ui.context.UIContext;
Expand All @@ -42,6 +43,8 @@
*/
public class ScaffoldGenerateCommandImpl extends AbstractProjectCommand implements ScaffoldGenerateCommand
{
public static final String REQUIRES_SCAFFOLD_SETUP = "REQUIRES_SCAFFOLD_SETUP";

@Inject
@WithAttributes(label = "Scaffold Type", required = true)
private UISelectOne<ScaffoldProvider> provider;
Expand Down Expand Up @@ -113,14 +116,26 @@ public NavigationResult next(UINavigationContext context) throws Exception
attributeMap.put(ScaffoldProvider.class, selectedProvider);
attributeMap.put(ScaffoldGenerationContext.class, populateGenerationContext(uiContext));

// Get the step sequence from the selected scaffold provider
NavigationResult setupFlow = null;
Project project = getSelectedProject(uiContext);

// Verify if the selected provider is installed
// If not, add the setup flow and inform the generation step to setup the scaffold.
ScaffoldSetupContext setupContext = populateSetupContext();
if (!selectedProvider.isSetup(project, setupContext))
{
setupFlow = selectedProvider.getSetupFlow(project);
attributeMap.put(REQUIRES_SCAFFOLD_SETUP, true);
attributeMap.put(ScaffoldSetupContext.class, setupContext);
}

// Get the step sequence from the selected scaffold provider
NavigationResult generationFlow = selectedProvider.getGenerationFlow(project);

// Add the execution logic step in the end so that the scaffold generation step is executed last after all other
// steps
NavigationResultBuilder builder = NavigationResultBuilder.create(generationFlow);
NavigationResult navigationResult = builder.add(ScaffoldExecuteGenerationStep.class).build();
NavigationResultBuilder builder = NavigationResultBuilder.create(setupFlow);
NavigationResult navigationResult = builder.add(generationFlow).add(ScaffoldExecuteGenerationStep.class).build();

return navigationResult;
}
Expand Down Expand Up @@ -154,4 +169,9 @@ private ScaffoldGenerationContext populateGenerationContext(UIContext context)
}
}

private ScaffoldSetupContext populateSetupContext()
{
return new ScaffoldSetupContext(webRoot.getValue(), overwrite.getValue());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public interface ScaffoldProvider
*
* @return boolean value indicating whether the provider was setup
*/
boolean isSetup(ScaffoldSetupContext setupContext);
boolean isSetup(Project project, ScaffoldSetupContext setupContext);

/**
* Generate a set of create, read, update, delete pages for the given collection of {@link Resource}s present in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void testCanSetupScaffoldProvider() throws Exception
scaffoldProvider.setup(project, setupContext);

// Verify
assertTrue(scaffoldProvider.isSetup(setupContext));
assertTrue(scaffoldProvider.isSetup(project, setupContext));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public List<Resource<?>> setup(Project project, ScaffoldSetupContext setupContex
}

@Override
public boolean isSetup(ScaffoldSetupContext setupContext)
public boolean isSetup(Project project, ScaffoldSetupContext setupContext)
{
return isSetup;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ public NavigationResultBuilder add(UICommand command)
return this;
}

/**
* Add a UICommand instance to create a single navigation entry.
*
* @param result The NavigationResult to add
* @return This NavigationResultBuilder instance
*/
public NavigationResultBuilder add(NavigationResult result)
{
if (result != null && result.getNext() != null)
{
entries.addAll(Arrays.asList(result.getNext()));
}
return this;
}

/**
* Add multiple UICommand types to create a single navigation entry. Every invocation of this method creates a
* separate navigation entry. UIWizard types must not be provided as arguments since wizards and wizard steps cannot
Expand Down

0 comments on commit d9cb145

Please sign in to comment.