Skip to content

Commit

Permalink
Avoid warning about legacy for default tags
Browse files Browse the repository at this point in the history
fix #74
  • Loading branch information
slawekjaranowski committed Jun 29, 2024
1 parent 295c644 commit 19aa03b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
35 changes: 19 additions & 16 deletions src/main/java/org/codehaus/mojo/taglist/TagListReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,6 @@ public class TagListReport extends AbstractMavenReport {
protected void executeReport(Locale locale) throws MavenReportException {
this.currentLocale = locale;

// User entered no tags and no tagOptions, then default tags
if ((tags == null || tags.length == 0)
&& (tagListOptions == null || tagListOptions.getTagClasses().isEmpty())) {
tags = new String[] {"@todo", "TODO", "FIXME"};
}

if (StringUtils.isEmpty(getInputEncoding())) {
getLog().warn("File encoding has not been set, using platform encoding "
+ Charset.defaultCharset().displayName() + ", i.e. build is platform dependent!");
Expand All @@ -219,16 +213,7 @@ protected void executeReport(Locale locale) throws MavenReportException {
if (tags != null && tags.length > 0) {
getLog().warn("Using legacy tag format. This is not recommended.");
for (String tag : tags) {
TagClass tc = new TagClass(tag);
try {
AbsTag newTag = TagFactory.createTag("exact", tag);
tc.addTag(newTag);

tagClasses.add(tc);
} catch (InvalidTagException e) {
// This should be impossible since exact is supported.
getLog().error("Invalid tag type used. tag type: exact");
}
tagClasses.add(createTagClass(tag));
}
}

Expand Down Expand Up @@ -262,6 +247,13 @@ protected void executeReport(Locale locale) throws MavenReportException {
}
}

// default tags
if (tagClasses.isEmpty()) {
tagClasses.add(createTagClass("@todo"));
tagClasses.add(createTagClass("TODO"));
tagClasses.add(createTagClass("FIXME"));
}

// let's proceed to the analysis
FileAnalyser fileAnalyser = new FileAnalyser(this, tagClasses);
Collection<TagReport> tagReports = fileAnalyser.execute();
Expand Down Expand Up @@ -297,6 +289,17 @@ protected void executeReport(Locale locale) throws MavenReportException {
generateXmlReport(tagReports);
}

private TagClass createTagClass(String tag) {
TagClass tc = new TagClass(tag);
try {
AbsTag newTag = TagFactory.createTag("exact", tag);
tc.addTag(newTag);
} catch (InvalidTagException e) {
// This should be impossible since exact is supported.
}
return tc;
}

/**
* Generate an XML report that can be used by other plugins like the dashboard plugin.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public void testDefaultTags() throws Exception {
// Check to see that @todo has one occurance.
expected = "\">TODO</a></td><td>1</td>";
assertTrue("Incorrect default TODO tag result.", htmlString.contains(expected));

// Check to see that @FIXME has one occurance.
expected = "\">FIXME</a></td><td>1</td>";
assertTrue("Incorrect default FIXME tag result.", htmlString.contains(expected));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/unit/tag-test/java-sources/com/Tags.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*
* @todo: This is the default tag #1.
* TODO: This is the default tag #2.
*
* FIXME: This is the default tag #3.
*
*/
class Tags
{
Expand Down

0 comments on commit 19aa03b

Please sign in to comment.