Skip to content

Commit

Permalink
FORGE-1825 Revoke the overwrite flag from scaffold commands.
Browse files Browse the repository at this point in the history
The ScaffoldProvider SPI's context classes no longer carry an
overwrite parameter.
  • Loading branch information
VineetReynolds committed May 15, 2014
1 parent 1450deb commit ec3dde3
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,11 @@ public List<Resource<?>> setup(ScaffoldSetupContext setupContext)
setProject(setupContext.getProject());
String targetDir = setupContext.getTargetDirectory();
targetDir = (targetDir == null) ? "" : targetDir;
boolean overwrite = setupContext.isOverwrite();

// Setup static resources.
ArrayList<Resource<?>> result = new ArrayList<>();
WebResourcesFacet web = project.getFacet(WebResourcesFacet.class);
ProcessingStrategy strategy = new CopyResourcesStrategy(web, overwrite);
ProcessingStrategy strategy = new CopyResourcesStrategy(web);
for (ScaffoldResource scaffoldResource : getStatics(targetDir, strategy)) {
result.add(scaffoldResource.generate());
}
Expand Down Expand Up @@ -179,7 +178,6 @@ public List<Resource<?>> generateFrom(ScaffoldGenerationContext generationContex
setProject(generationContext.getProject());
String targetDir = generationContext.getTargetDirectory();
targetDir = (targetDir == null) ? "" : targetDir;
boolean overwrite = generationContext.isOverwrite();
List<Resource<?>> result = new ArrayList<>();
Collection<Resource<?>> resources = generationContext.getResources();
for (Resource<?> resource : resources)
Expand Down Expand Up @@ -247,18 +245,18 @@ public List<Resource<?>> generateFrom(ScaffoldGenerationContext generationContex
// Process the Freemarker templates with the Freemarker data model and retrieve the generated resources from
// the registry.
WebResourcesFacet web = project.getFacet(WebResourcesFacet.class);
ProcessingStrategy strategy = new ProcessTemplateStrategy(web, resourceFactory, project, templateFactory, dataModel, overwrite);
ProcessingStrategy strategy = new ProcessTemplateStrategy(web, resourceFactory, project, templateFactory, dataModel);
List<ScaffoldResource> scaffoldResources = getEntityTemplates(targetDir, entityName, strategy);
scaffoldResources.add(new ScaffoldResource("/views/detail.html.ftl", targetDir + "/views/" + entityName
+ "/detail.html", new DetailTemplateStrategy(web, resourceFactory, project, templateFactory, dataModel, overwrite)));
+ "/detail.html", new DetailTemplateStrategy(web, resourceFactory, project, templateFactory, dataModel)));
scaffoldResources.add(new ScaffoldResource("/views/search.html.ftl", targetDir + "/views/" + entityName
+ "/search.html", new SearchTemplateStrategy(web, resourceFactory, project, templateFactory, dataModel, overwrite)));
+ "/search.html", new SearchTemplateStrategy(web, resourceFactory, project, templateFactory, dataModel)));
for (ScaffoldResource scaffoldResource : scaffoldResources) {
result.add(scaffoldResource.generate());
}
}

List<Resource<?>> indexResources = generateIndex(targetDir, overwrite);
List<Resource<?>> indexResources = generateIndex(targetDir);
result.addAll(indexResources);
return result;
}
Expand Down Expand Up @@ -326,10 +324,9 @@ private void setProject(Project project)
* scaffolding run are generated here.
*
* @param targetDir The target directory for the generated scaffold artifacts.
* @param overwrite A flag that indicates whether existing resources should be overwritten or not.
* @return A list of generated {@link Resource}s
*/
public List<Resource<?>> generateIndex(String targetDir, boolean overwrite)
public List<Resource<?>> generateIndex(String targetDir)
{
ArrayList<Resource<?>> result = new ArrayList<>();

Expand Down Expand Up @@ -374,7 +371,7 @@ public boolean accept(Resource<?> resource)
dataModel.put("projectTitle", StringUtils.uncamelCase(metadata.getProjectName()));
dataModel.put("targetDir", targetDir);

ProcessingStrategy strategy = new ProcessTemplateStrategy(web, resourceFactory, project, templateFactory, dataModel, overwrite);
ProcessingStrategy strategy = new ProcessTemplateStrategy(web, resourceFactory, project, templateFactory, dataModel);
for (ScaffoldResource scaffoldResource : getGlobalTemplates(targetDir, strategy)) {
result.add(scaffoldResource.generate());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@ public class CopyResourcesStrategy implements ProcessingStrategy
{

private final WebResourcesFacet web;
private boolean overwrite;

public CopyResourcesStrategy(WebResourcesFacet web, boolean overwrite)
public CopyResourcesStrategy(WebResourcesFacet web)
{
this.web = web;
this.overwrite = overwrite;
}

@Override
public Resource execute(ScaffoldResource scaffoldResource)
{
return ScaffoldUtil.createOrOverwrite(web.getWebResource(scaffoldResource.getDestination()), getClass()
.getResourceAsStream(scaffoldResource.getSource()), true);
.getResourceAsStream(scaffoldResource.getSource()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ public class DetailTemplateStrategy implements ProcessingStrategy

private final TemplateFactory templateFactory;

private final boolean overwrite;

public DetailTemplateStrategy(WebResourcesFacet web, ResourceFactory resourceFactory, Project project,
TemplateFactory templateFactory, Map<String, Object> dataModel, boolean overwrite)
TemplateFactory templateFactory, Map<String, Object> dataModel)
{
this.web = web;
this.resourceFactory = resourceFactory;
this.project = project;
this.templateFactory = templateFactory;
this.dataModel = dataModel;
this.overwrite = overwrite;
}

@Override
Expand Down Expand Up @@ -85,7 +82,7 @@ else if (property.containsKey("lookup"))
}
dataModel.put("formProperties", formProperties.toString());
ProcessTemplateStrategy strategy = new ProcessTemplateStrategy(web, resourceFactory, project,
templateFactory, dataModel, overwrite);
templateFactory, dataModel);
return strategy.execute(scaffoldResource);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ public class JSONRestResourceFromEntityCommand implements UIWizardStep
@WithAttributes(label = "Target Package Name", required = true, type = InputType.JAVA_PACKAGE_PICKER)
private UIInput<String> packageName;

@Inject
@WithAttributes(label = "Overwrite existing classes?", enabled = false, defaultValue = "false")
private UIInput<Boolean> overwrite;

@Inject
private EntityBasedResourceGenerator defaultResourceGenerator;

Expand Down Expand Up @@ -140,8 +136,7 @@ public String convert(RestResourceGenerator source)
}
builder.add(generator)
.add(packageName)
.add(persistenceUnit)
.add(overwrite);
.add(persistenceUnit);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,14 @@ public class ProcessTemplateStrategy implements ProcessingStrategy

private final Map<String, Object> dataModel;

private final boolean overwrite;

public ProcessTemplateStrategy(WebResourcesFacet web, ResourceFactory resourceFactory, Project project,
TemplateFactory templateFactory, Map<String, Object> dataModel, boolean overwrite)
TemplateFactory templateFactory, Map<String, Object> dataModel)
{
this.web = web;
this.resourceFactory = resourceFactory;
this.project = project;
this.templateFactory = templateFactory;
this.dataModel = dataModel;
this.overwrite = overwrite;
}

@Override
Expand Down Expand Up @@ -77,7 +74,6 @@ public Resource<?> execute(ScaffoldResource scaffoldResource)
{
throw new IllegalStateException(ioEx);
}
return ScaffoldUtil.createOrOverwrite(web.getWebResource(scaffoldResource.getDestination()),
output, true);
return ScaffoldUtil.createOrOverwrite(web.getWebResource(scaffoldResource.getDestination()), output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,14 @@ public class SearchTemplateStrategy implements ProcessingStrategy

private final TemplateFactory templateFactory;

private final boolean overwrite;

public SearchTemplateStrategy(WebResourcesFacet web, ResourceFactory resourceFactory, Project project,
TemplateFactory templateFactory, Map<String, Object> dataModel, boolean overwrite)
TemplateFactory templateFactory, Map<String, Object> dataModel)
{
this.web = web;
this.resourceFactory = resourceFactory;
this.project = project;
this.templateFactory = templateFactory;
this.dataModel = dataModel;
this.overwrite = overwrite;
}

@Override
Expand All @@ -73,7 +70,7 @@ public Resource execute(ScaffoldResource scaffoldResource)
dataModel.put("searchResults", searchResults);
dataModel.put("searchResultsPaginator", searchResultsPaginator);
ProcessTemplateStrategy strategy = new ProcessTemplateStrategy(web, resourceFactory, project,
templateFactory, dataModel, overwrite);
templateFactory, dataModel);
return strategy.execute(scaffoldResource);
}

Expand Down

0 comments on commit ec3dde3

Please sign in to comment.