From ab4ffee40214ff6276ec4b8ee05fc77c08c727c8 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Thu, 3 Oct 2024 20:39:26 +0200 Subject: [PATCH] Upgrade Doxia to 2.x stack - fix 2 --- pom.xml | 7 +- .../codehaus/mojo/taglist/FileAnalyser.java | 8 +- .../codehaus/mojo/taglist/TagListReport.java | 43 +----- ...Render.java => TaglistReportRenderer.java} | 133 ++++++------------ .../taglist/AbstractTaglistMojoTestCase.java | 9 +- .../taglist/TaglistMojoBasicConfigTest.java | 8 +- 6 files changed, 70 insertions(+), 138 deletions(-) rename src/main/java/org/codehaus/mojo/taglist/{ReportRender.java => TaglistReportRenderer.java} (67%) diff --git a/pom.xml b/pom.xml index 51bd547..45991a8 100644 --- a/pom.xml +++ b/pom.xml @@ -105,7 +105,7 @@ 2024-07-03T21:22:33Z - 2.0.0-M12 + 2.0.0 4.0.0-M12 4.0.0-M15 1.4.1 @@ -335,9 +335,14 @@ + + org.apache.maven.plugins + maven-jxr-plugin + org.codehaus.mojo taglist-maven-plugin + ${project.version} diff --git a/src/main/java/org/codehaus/mojo/taglist/FileAnalyser.java b/src/main/java/org/codehaus/mojo/taglist/FileAnalyser.java index 8ebea9e..4e5804c 100644 --- a/src/main/java/org/codehaus/mojo/taglist/FileAnalyser.java +++ b/src/main/java/org/codehaus/mojo/taglist/FileAnalyser.java @@ -72,7 +72,7 @@ public class FileAnalyser { /** * The Locale of the files to analyze. */ - private final Locale soucreFileLocale; + private final Locale sourceFileLocale; /** * The directories to analyze. @@ -121,7 +121,7 @@ public FileAnalyser(TagListReport report, List tagClasses) { log = report.getLog(); sourceDirs = report.getSourceDirs(); encoding = report.getInputEncoding(); - soucreFileLocale = report.getSourceFileLocale(); + sourceFileLocale = report.getSourceFileLocale(); this.tagClasses = tagClasses; this.includes = report.getIncludesCommaSeparated(); this.excludes = report.getExcludesCommaSeparated(); @@ -188,7 +188,7 @@ public void scanFile(File file) { int index; // look for a tag on this line for (TagClass tagClass : tagClasses) { - index = tagClass.tagMatchContains(currentLine, soucreFileLocale); + index = tagClass.tagMatchContains(currentLine, sourceFileLocale); if (index != TagClass.NO_MATCH) { // there's a tag on this line String commentType = extractCommentType(currentLine, index); @@ -241,7 +241,7 @@ public void scanFile(File file) { // try to look if the next line is not a new tag boolean newTagFound = false; for (TagClass tc : tagClasses) { - if (tc.tagMatchStartsWith(currentComment, soucreFileLocale)) { + if (tc.tagMatchStartsWith(currentComment, sourceFileLocale)) { newTagFound = true; break; } diff --git a/src/main/java/org/codehaus/mojo/taglist/TagListReport.java b/src/main/java/org/codehaus/mojo/taglist/TagListReport.java index 69674ce..907ca5c 100644 --- a/src/main/java/org/codehaus/mojo/taglist/TagListReport.java +++ b/src/main/java/org/codehaus/mojo/taglist/TagListReport.java @@ -71,11 +71,6 @@ public class TagListReport extends AbstractMavenReport { @Parameter(property = "sourceFileLocale", defaultValue = "en") private String sourceFileLocale; - /** - * Default locale used if the source file locale is null. - */ - private static final String DEFAULT_SOURCE_FILE_LOCALE = "en"; - /** * List of files to include. Specified as fileset patterns which are relative to the source directory. * @@ -144,11 +139,6 @@ public class TagListReport extends AbstractMavenReport { @Parameter(defaultValue = "false", property = "taglists.aggregate") private boolean aggregate; - /** - * The locale used for rendering the page. - */ - private Locale currentLocale; - /** * This parameter indicates whether to generate details for tags with zero occurrences. * @@ -211,7 +201,6 @@ public class TagListReport extends AbstractMavenReport { */ @Override protected void executeReport(Locale locale) throws MavenReportException { - this.currentLocale = locale; if (StringUtils.isEmpty(getInputEncoding())) { getLog().warn("File encoding has not been set, using platform encoding " @@ -221,10 +210,11 @@ protected void executeReport(Locale locale) throws MavenReportException { executeAnalysis(); // Renders the report - ReportRender generator = new ReportRender(this, tagReportsResult); - generator.setXrefLocation(constructXrefLocation(false)); - generator.setTestXrefLocation(constructXrefLocation(true)); - generator.render(); + TaglistReportRenderer renderer = new TaglistReportRenderer(this, tagReportsResult); + renderer.setXrefLocation(constructXrefLocation(false)); + renderer.setTestXrefLocation(constructXrefLocation(true)); + renderer.setBundle(getBundle(locale)); + renderer.render(); // Generate the XML report generateXmlReport(tagReportsResult); @@ -544,10 +534,6 @@ String getExcludesCommaSeparated() { * @return The Locale of the source files. */ public Locale getSourceFileLocale() { - // The locale string should never be null. - if (sourceFileLocale == null) { - sourceFileLocale = DEFAULT_SOURCE_FILE_LOCALE; - } return new Locale(sourceFileLocale); } @@ -578,16 +564,6 @@ public boolean isShowEmptyDetails() { return showEmptyDetails; } - /** - * {@inheritDoc} - * - * @see org.apache.maven.reporting.AbstractMavenReport#getOutputDirectory() - */ - @Override - protected String getOutputDirectory() { - return super.getOutputDirectory(); - } - /** * Get the absolute path to the XML output directory. * @@ -627,15 +603,6 @@ public String getOutputName() { return "taglist"; } - /** - * Returns the correct resource bundle according to the locale. - * - * @return the bundle corresponding to the locale used for rendering the report. - */ - public ResourceBundle getBundle() { - return getBundle(currentLocale); - } - /** * Returns the correct resource bundle according to the locale. * diff --git a/src/main/java/org/codehaus/mojo/taglist/ReportRender.java b/src/main/java/org/codehaus/mojo/taglist/TaglistReportRenderer.java similarity index 67% rename from src/main/java/org/codehaus/mojo/taglist/ReportRender.java rename to src/main/java/org/codehaus/mojo/taglist/TaglistReportRenderer.java index 8bc53d5..c8934a4 100644 --- a/src/main/java/org/codehaus/mojo/taglist/ReportRender.java +++ b/src/main/java/org/codehaus/mojo/taglist/TaglistReportRenderer.java @@ -34,7 +34,7 @@ * * @author Fabrice Bellingard */ -public class ReportRender extends AbstractMavenReportRenderer { +public class TaglistReportRenderer extends AbstractMavenReportRenderer { /** * The source code cross reference path. */ @@ -48,7 +48,7 @@ public class ReportRender extends AbstractMavenReportRenderer { /** * The resource bundle used in this Maven build. */ - private final ResourceBundle bundle; + private ResourceBundle bundle; /** * The output path of the site. @@ -71,14 +71,17 @@ public class ReportRender extends AbstractMavenReportRenderer { * @param report the TagListReport object used in this build. * @param tagReports a collection of tagReports to output. */ - public ReportRender(TagListReport report, Collection tagReports) { + public TaglistReportRenderer(TagListReport report, Collection tagReports) { super(report.getSink()); this.sortedTagReports = new TreeSet<>(tagReports); - this.bundle = report.getBundle(); this.siteOutputDirectory = report.getReportOutputDirectory(); this.showEmptyDetails = report.isShowEmptyDetails(); } + public void setBundle(ResourceBundle bundle) { + this.bundle = bundle; + } + @Override public String getTitle() { return bundle.getString("report.taglist.header"); @@ -101,73 +104,49 @@ protected void renderBody() { * @param tagReports a collection of tagReports to summarize. */ private void doSummarySection(Collection tagReports) { - sink.paragraph(); - sink.text(bundle.getString("report.taglist.summary.description")); - sink.paragraph_(); - sink.table(); - sink.tableRows(null, false); - - sink.tableRow(); - sink.tableHeaderCell(); - sink.text(bundle.getString("report.taglist.summary.tag")); - sink.tableHeaderCell_(); - sink.tableHeaderCell(); - sink.text(bundle.getString("report.taglist.summary.occurrences")); - sink.tableHeaderCell_(); - sink.tableHeaderCell(); - sink.text(bundle.getString("report.taglist.summary.tagstrings")); - sink.tableHeaderCell_(); - sink.tableRow_(); + paragraph(bundle.getString("report.taglist.summary.description")); + + startTable(); + + tableHeader(new String[] { + bundle.getString("report.taglist.summary.tag"), + bundle.getString("report.taglist.summary.occurrences"), + bundle.getString("report.taglist.summary.tagstrings") + }); for (TagReport tagReport : tagReports) { doTagSummary(tagReport); } - sink.tableRows_(); - sink.table_(); + + endTable(); } /** * @param tagReport the tagReport to summarize. */ private void doTagSummary(TagReport tagReport) { - sink.tableRow(); - sink.tableCell(); - // Create a hyperlink if the "showEmptyTags" flag is set or the tag contains 1 or more occurrences. - if (showEmptyDetails || tagReport.getTagCount() > 0) { - sink.link("#" + tagReport.getHTMLSafeLinkName()); - sink.text(tagReport.getTagName()); - sink.link_(); - } else { - sink.text(tagReport.getTagName()); - } - sink.tableCell_(); - sink.tableCell(); - sink.text(String.valueOf(tagReport.getTagCount())); - sink.tableCell_(); - sink.tableCell(); + String[] tags = tagReport.getTagStrings(); + String tagsAsString = null; if (tags != null) { - // Output each tag string - for (int i = 0; i < tags.length; ++i) { - if (i > 0) { - // Insert comma before each tag except for the first one. - sink.text(", "); - } - sink.text(tags[i]); - } + tagsAsString = String.join(", ", tags); } - sink.tableCell_(); - sink.tableRow_(); + + tableRow(new String[] { + createLinkPatternedText( + tagReport.getTagName(), + showEmptyDetails || tagReport.getTagCount() > 0 ? "#" + tagReport.getHTMLSafeLinkName() : null), + String.valueOf(tagReport.getTagCount()), + tagsAsString + }); } /** * @param tagReports a collection of tagReports to be detailed in this section. */ private void doDetailSection(Collection tagReports) { - sink.paragraph(); - sink.text(bundle.getString("report.taglist.detail.description")); - sink.paragraph_(); + paragraph(bundle.getString("report.taglist.detail.description")); for (TagReport tagReport : tagReports) { doTagDetailedPart(tagReport); @@ -183,12 +162,8 @@ private void doTagDetailedPart(TagReport tagReport) { return; } - sink.section2(); - sink.sectionTitle2(); - sink.anchor(tagReport.getHTMLSafeLinkName()); - sink.text(tagReport.getTagName()); - sink.anchor_(); - sink.sectionTitle2_(); + startSection(tagReport.getTagName(), tagReport.getHTMLSafeLinkName()); + sink.paragraph(); sink.bold(); sink.text(bundle.getString("report.taglist.detail.numberOfOccurrences") + ' ' + tagReport.getTagCount()); @@ -200,31 +175,24 @@ private void doTagDetailedPart(TagReport tagReport) { // MTAGLIST-38 - sink table before generating each file report in order // to align the columns correctly. - sink.table(); - sink.tableRows(null, false); + startTable(); for (FileReport sortedFileReport : sortedFileReports) { doFileDetailedPart(sortedFileReport); } - sink.tableRows_(); - sink.table_(); + endTable(); - sink.section2_(); + endSection(); } /** * @param fileReport the FileReport to output for this detailed tag report. */ private void doFileDetailedPart(FileReport fileReport) { - sink.tableRow(); - sink.tableHeaderCell(); - sink.text(fileReport.getClassName()); - sink.tableHeaderCell_(); - sink.tableHeaderCell(); - sink.text(bundle.getString("report.taglist.detail.line")); - sink.tableHeaderCell_(); - sink.tableRow_(); + + tableHeader(new String[] {fileReport.getClassName(), bundle.getString("report.taglist.detail.line")}); + for (Integer integer : fileReport.getLineIndexes()) { doCommentLine(fileReport, integer); } @@ -235,47 +203,34 @@ private void doFileDetailedPart(FileReport fileReport) { * @param lineNumber the line number of the current tag's comment. */ private void doCommentLine(FileReport fileReport, Integer lineNumber) { - boolean linked = false; String comment = fileReport.getComment(lineNumber); if (comment == null || comment.isEmpty()) { comment = "--" + bundle.getString("report.taglist.nocomment") + "--"; } - sink.tableRow(); - sink.tableCell(); - sink.text(comment); - sink.tableCell_(); - sink.tableCell(); + + String link = null; if (xrefLocation != null) { String fileLink = xrefLocation + "/" + fileReport.getClassNameWithSlash() + ".html"; File xrefFile = new File(siteOutputDirectory, fileLink.substring(2)); // Link only if file exists in xref if (xrefFile.exists()) { - sink.link(fileLink + "#L" + lineNumber); - linked = true; + link = fileLink + "#L" + lineNumber; } } // If the file was not linked to xref and there is a test xref location check it - if (!linked && testXrefLocation != null) { + if (link == null && testXrefLocation != null) { String testFileLink = testXrefLocation + "/" + fileReport.getClassNameWithSlash() + ".html"; File testXrefFile = new File(siteOutputDirectory, testFileLink.substring(2)); // Link only if file exists in test xref if (testXrefFile.exists()) { - sink.link(testFileLink + "#L" + lineNumber); - linked = true; + link = testFileLink + "#L" + lineNumber; } } - sink.text(String.valueOf(lineNumber)); - - // Was a xref or test-xref link created? - if (linked) { - sink.link_(); - } - sink.tableCell_(); - sink.tableRow_(); + tableRow(new String[] {comment, createLinkPatternedText(String.valueOf(lineNumber), link)}); } /** diff --git a/src/test/java/org/codehaus/mojo/taglist/AbstractTaglistMojoTestCase.java b/src/test/java/org/codehaus/mojo/taglist/AbstractTaglistMojoTestCase.java index 687f6a0..237a23e 100644 --- a/src/test/java/org/codehaus/mojo/taglist/AbstractTaglistMojoTestCase.java +++ b/src/test/java/org/codehaus/mojo/taglist/AbstractTaglistMojoTestCase.java @@ -42,10 +42,11 @@ protected TagListReport getTagListReport(File pluginXmlFile) throws Exception { TagListReport mojo = (TagListReport) lookupMojo("taglist", pluginXmlFile); assertNotNull("Mojo not found.", mojo); + File outputDirectory = (File) getVariableValueFromObject(mojo, "outputDirectory"); setVariableValueToObject(mojo, "inputEncoding", TEST_ENCODING); setVariableValueToObject(mojo, "includes", new String[] {"**/*.java"}); - setVariableValueToObject(mojo, "xmlOutputDirectory", new File(mojo.getOutputDirectory(), "taglist")); - setVariableValueToObject(mojo, "siteDirectory", new File(mojo.getOutputDirectory(), "non-existing")); + setVariableValueToObject(mojo, "xmlOutputDirectory", new File(outputDirectory, "taglist")); + setVariableValueToObject(mojo, "siteDirectory", new File(outputDirectory, "non-existing")); setVariableValueToObject(mojo, "reactorProjects", singletonList(getVariableValueFromObject(mojo, "project"))); setVariableValueToObject(mojo, "repoSession", repositorySystemSession); setVariableValueToObject( @@ -55,6 +56,10 @@ protected TagListReport getTagListReport(File pluginXmlFile) throws Exception { repositorySystemSession, Collections.singletonList(remoteRepository))); setVariableValueToObject(mojo, "mojoExecution", new MojoExecution(new Plugin(), "taglist", "default")); + if (getVariableValueFromObject(mojo, "sourceFileLocale") == null) { + setVariableValueToObject(mojo, "sourceFileLocale", "en"); + } + return mojo; } diff --git a/src/test/java/org/codehaus/mojo/taglist/TaglistMojoBasicConfigTest.java b/src/test/java/org/codehaus/mojo/taglist/TaglistMojoBasicConfigTest.java index 518681f..745573b 100644 --- a/src/test/java/org/codehaus/mojo/taglist/TaglistMojoBasicConfigTest.java +++ b/src/test/java/org/codehaus/mojo/taglist/TaglistMojoBasicConfigTest.java @@ -213,11 +213,11 @@ public void testShowEmptyDetailsEnabled() throws Exception { assertTrue("Incorrect count for the not in code tag.", htmlString.contains(expected)); // Check to see show empty tags in code section details exist (they should). - expected = "\">@show_empty_details_tag_in_code"; + expected = "

@show_empty_details_tag_not_in_code

"; assertTrue("Missing tag details for the in code tag.", htmlString.contains(expected)); // Check to see show empty tags not in code section details exist (they should). - expected = "\">@show_empty_details_tag_not_in_code"; + expected = "

@show_empty_details_tag_not_in_code

"; assertTrue("Missing tag details for the not in code tag.", htmlString.contains(expected)); } @@ -245,11 +245,11 @@ public void testShowEmptyDetailsDisabled() throws Exception { assertTrue("Incorrect count for the not in code tag.", htmlString.contains(expected)); // Check to see show empty tags in code section details exist (they should). - expected = "\">@show_empty_details_tag_in_code"; + expected = "

@show_empty_details_tag_in_code

"; assertTrue("Missing tag details for the in code tag.", htmlString.contains(expected)); // Check to see show empty tags not in code section details do NOT exist (they should not). - expected = "\">@show_empty_details_tag_not_in_code"; + expected = "

@show_empty_details_tag_not_in_code

"; assertFalse("Unexpected tag details for the not in code tag.", htmlString.contains(expected)); }