Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/main/java/org/codehaus/mojo/taglist/FileAnalyser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
*/

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.Reader;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -184,7 +184,7 @@ private List<File> findFilesToScan() throws MavenReportException {
* @return a reader with the current file encoding.
*/
private Reader getReader(File file) throws IOException {
InputStream in = new FileInputStream(file);
InputStream in = Files.newInputStream(file.toPath());
return (encoding == null) ? new InputStreamReader(in) : new InputStreamReader(in, encoding);
}

Expand All @@ -198,15 +198,13 @@ public void scanFile(File file) {

String currentLine = reader.readLine();
while (currentLine != null) {
int index = -1;
int index;
// look for a tag on this line
for (TagClass tagClass : tagClasses) {
index = tagClass.tagMatchContains(currentLine, locale);
if (index != TagClass.NO_MATCH) {
// there's a tag on this line
String commentType = null;
commentType = extractCommentType(currentLine, index);

String commentType = extractCommentType(currentLine, index);
if (commentType == null) {
// this is not a valid comment tag: skip other tag classes and
// go to the next line
Expand All @@ -215,11 +213,11 @@ public void scanFile(File file) {

int tagLength = tagClass.getLastTagMatchStringLength();
int commentStartIndex = reader.getLineNumber();
StringBuffer comment = new StringBuffer();
StringBuilder comment = new StringBuilder();

String firstLine = StringUtils.strip(currentLine.substring(index + tagLength));
firstLine = StringUtils.removeEnd(firstLine, "*/"); // MTAGLIST-35
if (firstLine.length() == 0 || ":".equals(firstLine)) {
if (firstLine.isEmpty() || ":".equals(firstLine)) {
// this is not a valid comment tag: nothing is written there
if (emptyCommentsOn) {
comment.append("--");
Expand Down Expand Up @@ -247,12 +245,12 @@ public void scanFile(File file) {
// we're looking for multiple line comments
while (futureLine != null
&& futureLine.trim().startsWith(commentType)
&& futureLine.indexOf(tagClass.getLastTagMatchString()) < 0) {
&& !futureLine.contains(tagClass.getLastTagMatchString())) {
String currentComment = futureLine
.substring(futureLine.indexOf(commentType) + commentType.length())
.trim();
if (currentComment.startsWith("@")
|| "".equals(currentComment)
|| currentComment.isEmpty()
|| "/".equals(currentComment)) {
// the comment is finished
break;
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/codehaus/mojo/taglist/TagListReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -202,13 +203,13 @@ protected void executeReport(Locale locale) throws MavenReportException {

// User entered no tags and no tagOptions, then default tags
if ((tags == null || tags.length == 0)
&& (tagListOptions == null || tagListOptions.getTagClasses().size() == 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 "
+ System.getProperty("file.encoding") + ", i.e. build is platform dependent!");
+ Charset.defaultCharset().displayName() + ", i.e. build is platform dependent!");
}

// Create the tag classes
Expand All @@ -232,7 +233,7 @@ protected void executeReport(Locale locale) throws MavenReportException {
}

// If the new style of tag options were used, add them
if (tagListOptions != null && tagListOptions.getTagClasses().size() > 0) {
if (tagListOptions != null && !tagListOptions.getTagClasses().isEmpty()) {
// Scan each tag class
for (org.codehaus.mojo.taglist.options.TagClass tcOption : tagListOptions.getTagClasses()) {
// Store the tag class display name.
Expand All @@ -242,7 +243,7 @@ protected void executeReport(Locale locale) throws MavenReportException {
for (Tag tagOption : tcOption.getTags()) {
// If a match type is not specified use default.
String matchType = tagOption.getMatchType();
if (matchType == null || matchType.length() == 0) {
if (matchType == null || matchType.isEmpty()) {
matchType = TagFactory.getDefaultTagType();
}

Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/codehaus/mojo/taglist/beans/FileReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.file.Files;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;

/**
Expand Down Expand Up @@ -104,7 +103,7 @@ public String getClassNameWithSlash() {
* @return a reader with the current file encoding.
*/
private Reader getReader(File fileToRead) throws IOException {
InputStream in = new FileInputStream(fileToRead);
InputStream in = Files.newInputStream(fileToRead.toPath());
return (encoding == null) ? new InputStreamReader(in) : new InputStreamReader(in, encoding);
}

Expand Down Expand Up @@ -155,9 +154,7 @@ public String getClassName() {
* @return Collection of Integer.
*/
public Collection<Integer> getLineIndexes() {
SortedSet<Integer> lineIndexes = new TreeSet<>();
lineIndexes.addAll(tagListing.keySet());
return lineIndexes;
return new TreeSet<>(tagListing.keySet());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/codehaus/mojo/taglist/beans/TagReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ public void addTagString(final String tagString) {

/** Get a list of tag strings used by this tag report.
*
* @return a list of tag strings.
* @return an array of tag strings.
*/
public String[] getTagStrings() {

String[] strings = null;

if (tagStrings.size() > 0) {
if (!tagStrings.isEmpty()) {
strings = new String[tagStrings.size()];

for (int i = 0; i < tagStrings.size(); ++i) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/codehaus/mojo/taglist/tags/AbsTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import java.util.Locale;

/** The abstract base class for tags.
*
* <p>
* This class defines the required functions that each type of
* tag must implement. The goal here is to allow different types
* of tags to be created by the user, but the call processing
* for each tag can be generic.
*
* <p>
* For example, a generic tag might search files for an exact string
* match of the tag, but a regex tag will use regular expressions in
* its searching. Either way, the processing classes call each tag
Expand Down Expand Up @@ -66,11 +66,11 @@ public abstract class AbsTag {
public abstract boolean startsWith(final String currentLine, final Locale locale);

/** Return the length of the last matched tag.
*
* <p>
* Normally this is the length of the tag; however, some tags
* are dynamic. For example a regular expression tag might be
* 10 characters; however, the matched string may only be 5.
*
* <p>
* Calling this function allows the tag object to return the
* correct length for the last matched tag.
*
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/codehaus/mojo/taglist/tags/GenericTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import java.util.Locale;

/** The generic tag class.
*
* <p>
* This class defines a generic "case sensitive" exact match tag. This tag
* will only match if the exact string listed is found within
* the scanned lines.
*
* <p>
* Example POM:
* <pre>
* &lt;project &gt;
Expand Down Expand Up @@ -85,7 +85,7 @@ public boolean startsWith(final String currentLine, final Locale locale) {
}

/** Return the length of the last matched tag.
*
* <p>
* In the case of a generic tag, this is always the length of the tag.
*
* @return the length of the last matched tag.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import java.util.Locale;

/** The ignore case tag class.
*
* <p>
* This class defines a "case insensitive" match tag. This tag
* will match if the characters (upper or lower case) in the string listed is found within
* the scanned lines.
*
* <p>
* Example POM:
* <pre>
* &lt;project&gt;
Expand Down Expand Up @@ -90,7 +90,7 @@ public boolean startsWith(final String currentLine, final Locale locale) {
}

/** Return the length of the last matched tag.
*
* <p>
* In the case of a ignore case tag, this is always the length of the tag.
*
* @return the length of the last matched tag.
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/codehaus/mojo/taglist/tags/RegExTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import java.util.regex.Pattern;

/** The regular expression tag class.
*
* <p>
* This class defines a regular express tag search. This tag
* will match if the regular express string listed is found within
* the scanned lines.
*
* <p>
* Example POM:
* <pre>
* &lt;project&gt;
Expand Down Expand Up @@ -106,15 +106,15 @@ public boolean startsWith(final String currentLine, final Locale locale) {
}

/** Return the length of the last matched tag.
*
* <p>
* A regular expression tag might be 10 characters; however,
* the matched string may only be 5.
*
* <p>
* Example:
* regEx tag: a*b (tag length = 3)
*
* <p>
* matched comment: aaabbb (comment length = 6)
*
* <p>
* In the above example, this function will return 6.
*
* @return the length of the last matched tag.
Expand Down
19 changes: 7 additions & 12 deletions src/main/java/org/codehaus/mojo/taglist/tags/TagClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@

/**
* Class that define a classification of tags.
*
* <p>
* Each tag class contains 1 or more tags. This allows a user to define
* one tag "name" for display purposes, while still checking the files for
* multiple tag rules.
*
* <p>
* Example
* <pre>
* &lt;tagClass&gt;
Expand Down Expand Up @@ -77,11 +77,6 @@ public class TagClass {
*/
private static int uniqueTcCounter = 1;

/**
* The unique id for this tag class.
*/
private final int uniqueId;

/**
* Constructor.
*
Expand All @@ -91,7 +86,7 @@ public TagClass(final String displayName) {
classDisplayName = displayName;

// Assign a unique ID for this tag class and update the global counter.
uniqueId = uniqueTcCounter++;
int uniqueId = uniqueTcCounter++;

classTagReport = new TagReport(displayName, "tag_class_" + uniqueId);
}
Expand All @@ -117,7 +112,7 @@ public void addTag(AbsTag tag) {
}

/** Get the index of the first tag contained from within a string.
*
* <p>
* The tag class will check each for its tags until a match is found
* within the specified string. If no match is found, this function will
* return TagClass.NO_MATCH for the index.
Expand Down Expand Up @@ -150,7 +145,7 @@ public int tagMatchContains(final String currentLine, final Locale locale) {
}

/** Check if a string starts with a tag from this tag class.
*
* <p>
* The tag class will check each of its tags until the start of the string
* matched one of the tags. If not match if found, false is returned.
*
Expand Down Expand Up @@ -188,11 +183,11 @@ public String getLastTagMatchString() {
}

/** Return the length of the last matched tag.
*
* <p>
* Normally this is the length of the tag; however, some tags
* are dynamic. For example a regular expression tag might be
* 10 characters; however, the matched string may only be 5.
*
* <p>
* Calling this function allows the tag object to return the
* correct length for the last matched tag.
*
Expand Down
Loading