From ebc26d9d426e243511d003e39e5556e7b881d475 Mon Sep 17 00:00:00 2001 From: Mike Stockdale Date: Tue, 6 Dec 2022 15:05:31 -0700 Subject: [PATCH] publish copy of FrontPage as index.html --- FitNesseRoot/FitNesse/ReleaseNotes/content.txt | 3 +-- src/fitnesse/FitNesseExpediter.java | 12 +++++------- src/fitnesse/responders/ImportAndViewResponder.java | 3 ++- src/fitnesse/responders/files/Publisher.java | 10 +++++++++- .../responders/refactoring/DeletePageResponder.java | 8 +++++--- .../responders/refactoring/RenamePageResponder.java | 3 ++- src/fitnesse/wiki/WikiPageUtil.java | 1 + test/fitnesse/responders/files/PublisherTest.java | 7 +++++++ 8 files changed, 32 insertions(+), 15 deletions(-) diff --git a/FitNesseRoot/FitNesse/ReleaseNotes/content.txt b/FitNesseRoot/FitNesse/ReleaseNotes/content.txt index b9cb038424..855b75c8b9 100644 --- a/FitNesseRoot/FitNesse/ReleaseNotes/content.txt +++ b/FitNesseRoot/FitNesse/ReleaseNotes/content.txt @@ -1,8 +1,7 @@ -!2 Latest Release ${FITNESSE_VERSION} !2 Pending Changes * Add a new optional command line parameter to specify the maximum number of workers to use for handling incoming requests. * Ability to ignore the rest of a script table or test page by throwing an exception. ([[1350][https://github.com/unclebob/fitnesse/pull/1350]]) - * Change the publish responder to use Apache Velocity ([[1387][https://github.com/unclebob/fitnesse/issues/1387]]) + * Change the publish responder to use Apache Velocity, and create index page ([[1387][https://github.com/unclebob/fitnesse/issues/1387]]) !2 20221102 * Ability to create plugins for new markup syntax. ([[1382][https://github.com/unclebob/fitnesse/pull/1382]]) diff --git a/src/fitnesse/FitNesseExpediter.java b/src/fitnesse/FitNesseExpediter.java index 67162a6b16..fbd57dd260 100644 --- a/src/fitnesse/FitNesseExpediter.java +++ b/src/fitnesse/FitNesseExpediter.java @@ -5,6 +5,7 @@ import fitnesse.components.LogData; import fitnesse.http.*; import fitnesse.responders.ErrorResponder; +import fitnesse.wiki.WikiPageUtil; import org.apache.commons.lang3.StringUtils; import java.io.IOException; @@ -90,12 +91,9 @@ private Response makeResponse(final Request request) throws Exception { Response response; try { try { - executorService.submit(new Callable() { - @Override - public Request call() throws Exception { - request.parse(); - return request; - } + executorService.submit(() -> { + request.parse(); + return request; }).get(requestParsingTimeLimit, TimeUnit.MILLISECONDS); } catch (ExecutionException e) { if (e.getCause() instanceof Exception) { @@ -139,7 +137,7 @@ public Request call() throws Exception { public Response createGoodResponse(Request request) throws Exception { if (StringUtils.isBlank(request.getResource()) && StringUtils.isBlank(request.getQueryString())) - request.setResource("FrontPage"); + request.setResource(WikiPageUtil.FRONT_PAGE); Responder responder = context.responderFactory.makeResponder(request); responder = context.authenticator.authenticate(context, request, responder); return responder.makeResponse(context, request); diff --git a/src/fitnesse/responders/ImportAndViewResponder.java b/src/fitnesse/responders/ImportAndViewResponder.java index 03c6e4bd0e..1b31669638 100644 --- a/src/fitnesse/responders/ImportAndViewResponder.java +++ b/src/fitnesse/responders/ImportAndViewResponder.java @@ -19,6 +19,7 @@ import fitnesse.wiki.WikiImportProperty; import fitnesse.wiki.WikiPage; import fitnesse.wiki.WikiPagePath; +import fitnesse.wiki.WikiPageUtil; public class ImportAndViewResponder implements SecureResponder, WikiImporterClient { private static final Logger LOG = Logger.getLogger(ImportAndViewResponder.class.getName()); @@ -30,7 +31,7 @@ public Response makeResponse(FitNesseContext context, Request request) throws Ex String resource = request.getResource(); if ("".equals(resource)) - resource = "FrontPage"; + resource = WikiPageUtil.FRONT_PAGE; loadPage(resource, context); if (page == null) diff --git a/src/fitnesse/responders/files/Publisher.java b/src/fitnesse/responders/files/Publisher.java index 4d8d18a5c1..92598b4637 100644 --- a/src/fitnesse/responders/files/Publisher.java +++ b/src/fitnesse/responders/files/Publisher.java @@ -32,7 +32,11 @@ public String traverse(WikiPage page) { String path = destinationPath(page); result.append(path).append("
"); try { - writer.accept(pageContent(page), path); + String content = pageContent(page); + writer.accept(content, path); + if (page.getFullPath().toString().equals(WikiPageUtil.FRONT_PAGE)) { + writer.accept(content, destinationPath("index")); + } } catch (Exception e) { e.printStackTrace(); @@ -117,6 +121,10 @@ private void fixFiles(StringTransform transform, long depth) { private String destinationPath(WikiPage page) { String pagePath = page.getFullPath().toString().replace(".", File.separator); + return destinationPath(pagePath); + } + + private String destinationPath(String pagePath) { return destination + File.separator + (pagePath.length() > 0 ? pagePath : "root") + ".html"; } diff --git a/src/fitnesse/responders/refactoring/DeletePageResponder.java b/src/fitnesse/responders/refactoring/DeletePageResponder.java index 6d9fafb437..029bc9afea 100644 --- a/src/fitnesse/responders/refactoring/DeletePageResponder.java +++ b/src/fitnesse/responders/refactoring/DeletePageResponder.java @@ -16,6 +16,8 @@ import fitnesse.wiki.PathParser; import fitnesse.wiki.WikiPage; import fitnesse.wiki.WikiPagePath; +import fitnesse.wiki.WikiPageProperty; +import fitnesse.wiki.WikiPageUtil; import java.io.UnsupportedEncodingException; import java.util.List; @@ -32,7 +34,7 @@ public Response makeResponse(final FitNesseContext context, final Request reques intializeResponse(request); if (shouldNotDelete()) - response.redirect(context.contextRoot, "FrontPage"); + response.redirect(context.contextRoot, WikiPageUtil.FRONT_PAGE); else tryToDeletePage(request); @@ -54,7 +56,7 @@ private void tryToDeletePage(Request request) throws UnsupportedEncodingExceptio } private boolean shouldNotDelete() { - return "FrontPage".equals(qualifiedPageName); + return WikiPageUtil.FRONT_PAGE.equals(qualifiedPageName); } private void intializeResponse(Request request) { @@ -82,7 +84,7 @@ private String buildConfirmationHtml(final WikiPage root, final String qualified WikiPage wikiPage = crawler.getPage(path); if(wikiPage != null) { PageData pageData = wikiPage.getData(); - tags = pageData.getAttribute(PageData.PropertySUITES); + tags = pageData.getAttribute(WikiPageProperty.SUITES); } html.setTitle("Delete Confirmation"); diff --git a/src/fitnesse/responders/refactoring/RenamePageResponder.java b/src/fitnesse/responders/refactoring/RenamePageResponder.java index ae01d01d24..7434fabf78 100644 --- a/src/fitnesse/responders/refactoring/RenamePageResponder.java +++ b/src/fitnesse/responders/refactoring/RenamePageResponder.java @@ -3,6 +3,7 @@ package fitnesse.responders.refactoring; import fitnesse.FitNesseContext; +import fitnesse.wiki.WikiPageUtil; import fitnesse.wiki.refactoring.ChangeReference; import fitnesse.wiki.refactoring.PageReferenceRenamer; import fitnesse.http.Request; @@ -22,7 +23,7 @@ protected boolean getAndValidateNewParentPage(FitNesseContext context, Request r @Override protected boolean getAndValidateRefactoringParameters(Request request) { newName = request.getInput("newName"); - return (newName != null && PathParser.isSingleWikiWord(newName) && !"FrontPage".equals(oldNameOfPageToBeMoved)); + return (newName != null && PathParser.isSingleWikiWord(newName) && !WikiPageUtil.FRONT_PAGE.equals(oldNameOfPageToBeMoved)); } @Override diff --git a/src/fitnesse/wiki/WikiPageUtil.java b/src/fitnesse/wiki/WikiPageUtil.java index 824c3a2262..a3a6675c4b 100644 --- a/src/fitnesse/wiki/WikiPageUtil.java +++ b/src/fitnesse/wiki/WikiPageUtil.java @@ -12,6 +12,7 @@ public class WikiPageUtil { public static final String PAGE_HEADER = "PageHeader"; public static final String PAGE_FOOTER = "PageFooter"; + public static final String FRONT_PAGE = "FrontPage"; public static void setPageContents(WikiPage page, String pageContents) { PageData pageData = page.getData(); diff --git a/test/fitnesse/responders/files/PublisherTest.java b/test/fitnesse/responders/files/PublisherTest.java index a1b43449f3..f5744b9cea 100644 --- a/test/fitnesse/responders/files/PublisherTest.java +++ b/test/fitnesse/responders/files/PublisherTest.java @@ -83,6 +83,13 @@ public class PublisherTest { assertPublishes(">SymPage", "PageOne", "", pageOne); } + @Test public void frontPageCopiedToIndex() { + WikiPageUtil.addPage(root, PathParser.parse("FrontPage"), "stuff"); + Publisher publisher = new Publisher(TEMPLATE, "out", root.getPageCrawler(), this::writer); + publisher.traverse(root); + Assert.assertEquals("out/root.htmlout/FrontPage.htmlout/index.html", paths); + } + private void assertChildPage(String expected, String pageContent) { WikiPage parent = WikiPageUtil.addPage(root, PathParser.parse("TestParent"), ""); WikiPageUtil.addPage(parent, PathParser.parse("TestSibling"), "");