Skip to content

Commit

Permalink
Upgrade Doxia to 2.x stack - fix 2
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Oct 3, 2024
1 parent 305f364 commit ab4ffee
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 138 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@

<properties>
<project.build.outputTimestamp>2024-07-03T21:22:33Z</project.build.outputTimestamp>
<doxiaVersion>2.0.0-M12</doxiaVersion>
<doxiaVersion>2.0.0</doxiaVersion>
<reportingApiVersion>4.0.0-M12</reportingApiVersion>
<reportingImplVersion>4.0.0-M15</reportingImplVersion>
<mavenResolverVersion>1.4.1</mavenResolverVersion>
Expand Down Expand Up @@ -335,9 +335,14 @@

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>taglist-maven-plugin</artifactId>
<!-- <version>3.1.0</version>-->
<version>${project.version}</version>
<configuration>
<tagListOptions>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/codehaus/mojo/taglist/FileAnalyser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -121,7 +121,7 @@ public FileAnalyser(TagListReport report, List<TagClass> 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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
43 changes: 5 additions & 38 deletions src/main/java/org/codehaus/mojo/taglist/TagListReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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 "
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* @author <a href="mailto:bellingard.NO-SPAM@gmail.com">Fabrice Bellingard </a>
*/
public class ReportRender extends AbstractMavenReportRenderer {
public class TaglistReportRenderer extends AbstractMavenReportRenderer {
/**
* The source code cross reference path.
*/
Expand All @@ -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.
Expand All @@ -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<TagReport> tagReports) {
public TaglistReportRenderer(TagListReport report, Collection<TagReport> 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");
Expand All @@ -101,73 +104,49 @@ protected void renderBody() {
* @param tagReports a collection of tagReports to summarize.
*/
private void doSummarySection(Collection<TagReport> 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<TagReport> 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);
Expand All @@ -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());
Expand All @@ -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);
}
Expand All @@ -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)});
}

/**
Expand Down
Loading

0 comments on commit ab4ffee

Please sign in to comment.