diff --git a/pom.xml b/pom.xml index fc2e6ca..b452003 100644 --- a/pom.xml +++ b/pom.xml @@ -105,8 +105,10 @@ 2024-07-03T21:22:33Z - 1.12.0 - 1.11.1 + 2.0.0 + 4.0.0 + 4.0.0-M15 + 1.4.1 ${project.version} @@ -161,60 +163,21 @@ org.apache.maven.reporting maven-reporting-api - 3.1.1 + ${reportingApiVersion} org.apache.maven.reporting maven-reporting-impl - 3.1.0 - - - org.apache.maven - maven-core - - - org.apache.maven - maven-plugin-api - - + ${reportingImplVersion} - - org.apache.maven.doxia - doxia-core - ${doxiaVersion} - runtime - - - org.codehaus.plexus - plexus-container-default - - - org.apache.maven.doxia doxia-sink-api ${doxiaVersion} - - - org.apache.maven.doxia - doxia-site-renderer - ${doxia-sitetoolsVersion} - - - org.apache.maven - maven-artifact - - - org.codehaus.plexus - plexus-container-default - - - - org.apache.commons @@ -233,11 +196,28 @@ 3.3.0 test + + org.apache.maven.resolver + maven-resolver-connector-basic + ${mavenResolverVersion} + test + + + org.apache.maven.resolver + maven-resolver-transport-http + ${mavenResolverVersion} + test + org.junit.jupiter junit-jupiter-api test + + org.junit.jupiter + junit-jupiter-params + test + org.junit.vintage junit-vintage-engine @@ -303,6 +283,9 @@ maven-surefire-plugin -Duser.language=en + + ${settings.localRepository} + @@ -357,6 +340,10 @@ + + org.apache.maven.plugins + maven-jxr-plugin + org.codehaus.mojo taglist-maven-plugin diff --git a/src/main/java/org/codehaus/mojo/taglist/FileAnalyser.java b/src/main/java/org/codehaus/mojo/taglist/FileAnalyser.java index 9d9c2d2..5515828 100644 --- a/src/main/java/org/codehaus/mojo/taglist/FileAnalyser.java +++ b/src/main/java/org/codehaus/mojo/taglist/FileAnalyser.java @@ -25,7 +25,6 @@ import java.io.InputStreamReader; import java.io.LineNumberReader; import java.io.Reader; -import java.io.UncheckedIOException; import java.nio.file.Files; import java.util.ArrayList; import java.util.Collection; @@ -73,7 +72,7 @@ public class FileAnalyser { /** * The Locale of the files to analyze. */ - private final Locale locale; + private final Locale sourceFileLocale; /** * The directories to analyze. @@ -117,12 +116,14 @@ public class FileAnalyser { * @param tagClasses the array of tag classes to use for searching */ public FileAnalyser(TagListReport report, List tagClasses) { + // TODO - direct class TagListReport should not be used, + // we can add a separate args or new class/interface for group of args multipleLineCommentsOn = report.isMultipleLineComments(); emptyCommentsOn = report.isEmptyComments(); log = report.getLog(); sourceDirs = report.getSourceDirs(); encoding = report.getInputEncoding(); - locale = report.getLocale(); + sourceFileLocale = report.getSourceFileLocale(); this.tagClasses = tagClasses; this.includes = report.getIncludesCommaSeparated(); this.excludes = report.getExcludesCommaSeparated(); @@ -133,7 +134,7 @@ public FileAnalyser(TagListReport report, List tagClasses) { * * @return a collection of TagReport objects. */ - public Collection execute() { + public Collection execute() throws IOException { List fileList = findFilesToScan(); for (File file : fileList) { @@ -156,15 +157,10 @@ public Collection execute() { * * @return a List of File objects. */ - private List findFilesToScan() { + private List findFilesToScan() throws IOException { List filesList = new ArrayList<>(); - try { - for (String sourceDir : sourceDirs) { - filesList.addAll(FileUtils.getFiles(new File(sourceDir), includes, excludes)); - } - } catch (IOException e) { - // TODO - fix with Doxia 2.x - canGenerateReport will have a checked exception - throw new UncheckedIOException("Error while trying to find the files to scan.", e); + for (String sourceDir : sourceDirs) { + filesList.addAll(FileUtils.getFiles(new File(sourceDir), includes, excludes)); } return filesList; } @@ -173,8 +169,8 @@ private List findFilesToScan() { * Access an input reader that uses the current file encoding. * * @param file the file to open in the reader. - * @throws IOException the IO exception. * @return a reader with the current file encoding. + * @throws IOException the IO exception. */ private Reader getReader(File file) throws IOException { InputStream in = Files.newInputStream(file.toPath()); @@ -194,7 +190,7 @@ public void scanFile(File file) { int index; // look for a tag on this line for (TagClass tagClass : tagClasses) { - index = tagClass.tagMatchContains(currentLine, locale); + index = tagClass.tagMatchContains(currentLine, sourceFileLocale); if (index != TagClass.NO_MATCH) { // there's a tag on this line String commentType = extractCommentType(currentLine, index); @@ -247,7 +243,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, locale)) { + 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 d8a65a8..f03b99b 100644 --- a/src/main/java/org/codehaus/mojo/taglist/TagListReport.java +++ b/src/main/java/org/codehaus/mojo/taglist/TagListReport.java @@ -26,12 +26,14 @@ import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; import java.util.concurrent.atomic.AtomicReference; import org.apache.maven.model.ReportPlugin; +import org.apache.maven.model.Reporting; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; @@ -62,19 +64,14 @@ @Mojo(name = "taglist", requiresDependencyResolution = ResolutionScope.COMPILE) public class TagListReport extends AbstractMavenReport { /** - * Specifies the Locale of the source files. + * Specifies the Locale of the source files. Syntax is like "en", "en_US" or "en_US_win". * * @since 2.4 */ + // TODO rename to sourceFilesLocale @Parameter(property = "sourceFileLocale", defaultValue = "en") private String sourceFileLocale; - /** - * Default locale used if the source file locale is null. - */ - // TODO - please review default locale with Doxia 2.x - private static final String DEFAULT_LOCALE = "en"; - /** * List of files to include. Specified as fileset patterns which are relative to the source directory. * @@ -122,34 +119,27 @@ public class TagListReport extends AbstractMavenReport { private boolean linkXRef; /** - * Location of the Xrefs to link to. + * Location where Source XRef is generated for this project. + *
+ * Default: {@link #getReportOutputDirectory()} + {@code /xref} */ - @Parameter(defaultValue = "${project.reporting.outputDirectory}/xref", property = "taglists.xrefLocation") + @Parameter private File xrefLocation; /** - * Location of the Test Xrefs to link to. + * Location where Test Source XRef is generated for this project. + *
+ * Default: {@link #getReportOutputDirectory()} + {@code /xref-test} */ - @Parameter(defaultValue = "${project.reporting.outputDirectory}/xref-test", property = "taglists.testXrefLocation") + @Parameter private File testXrefLocation; - /** - * The projects in the reactor for aggregation report. - */ - @Parameter(readonly = true, defaultValue = "${reactorProjects}") - private List reactorProjects; - /** * Whether to build an aggregated report at the root, or build individual reports. */ @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. * @@ -212,7 +202,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 " @@ -222,39 +211,55 @@ protected void executeReport(Locale locale) throws MavenReportException { executeAnalysis(); // Renders the report - ReportGenerator generator = new ReportGenerator(this, tagReportsResult); + 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); + } + + protected String constructXrefLocation(boolean test) { + String location = null; if (linkXRef) { - String relativePath = getRelativePath(xrefLocation); + File xrefLocation = getXrefLocation(test); + + String relativePath = PathTool.getRelativePath( + getReportOutputDirectory().getAbsolutePath(), xrefLocation.getAbsolutePath()); + if (relativePath == null || relativePath.isEmpty()) { + relativePath = "."; + } + relativePath = relativePath + "/" + xrefLocation.getName(); if (xrefLocation.exists()) { // XRef was already generated by manual execution of a lifecycle binding - generator.setXrefLocation(relativePath); - generator.setTestXrefLocation(getRelativePath(testXrefLocation)); + location = relativePath; } else { // Not yet generated - check if the report is on its way - - for (ReportPlugin report : - getProject().getModel().getReporting().getPlugins()) { - String artifactId = report.getArtifactId(); - if ("maven-jxr-plugin".equals(artifactId) || "jxr-maven-plugin".equals(artifactId)) { - getLog().error("Taglist plugin MUST be executed after the JXR plugin." - + " No links to xref were generated."); + Reporting reporting = project.getModel().getReporting(); + List reportPlugins = reporting != null ? reporting.getPlugins() : Collections.emptyList(); + for (ReportPlugin plugin : reportPlugins) { + String artifactId = plugin.getArtifactId(); + if ("maven-jxr-plugin".equals(artifactId)) { + location = relativePath; } } } - // TODO we have similar code in many plugins to generate xref links - // we can externalize it to one place - if (generator.getXrefLocation() == null) { - getLog().warn("Unable to locate Source XRef to link to - DISABLED"); + if (location == null) { + getLog().warn("Unable to locate" + (test ? " Test" : "") + " Source XRef to link to - DISABLED"); } } - generator.generateReport(); + return location; + } - // Generate the XML report - generateXmlReport(tagReportsResult); + protected File getXrefLocation(boolean test) { + File location = test ? testXrefLocation : xrefLocation; + return location != null ? location : new File(getReportOutputDirectory(), test ? "xref-test" : "xref"); } - private void executeAnalysis() { + private void executeAnalysis() throws MavenReportException { if (tagReportsResult != null) { // already analyzed return; @@ -302,7 +307,11 @@ private void executeAnalysis() { // let's proceed to the analysis FileAnalyser fileAnalyser = new FileAnalyser(this, tagClasses); - tagReportsResult = fileAnalyser.execute(); + try { + tagReportsResult = fileAnalyser.execute(); + } catch (IOException e) { + throw new MavenReportException(e.getMessage(), e); + } } private TagClass createTagClass(String tag) { @@ -389,7 +398,7 @@ private String getRelativePath(File location) { * @see org.apache.maven.reporting.MavenReport#canGenerateReport() */ @Override - public boolean canGenerateReport() { + public boolean canGenerateReport() throws MavenReportException { boolean canGenerate = !getSourceDirs().isEmpty(); if (aggregate && !getProject().isExecutionRoot()) { canGenerate = false; @@ -520,17 +529,39 @@ String getExcludesCommaSeparated() { } } + void setSourceFileLocale(String sourceFileLocale) { + this.sourceFileLocale = sourceFileLocale; + } + /** * Returns the Locale of the source files. * * @return The Locale of the source files. */ - public Locale getLocale() { - // The locale string should never be null. - if (sourceFileLocale == null) { - sourceFileLocale = DEFAULT_LOCALE; + public Locale getSourceFileLocale() { + String[] items = sourceFileLocale.split("_"); + if (sourceFileLocale.isEmpty() || items.length > 3) { + getLog().warn("Invalid java.util.Locale format '" + sourceFileLocale + + "' for 'sourceFileLocale' using 'ENGLISH' locale"); + return Locale.ENGLISH; + } + + String language = ""; + String country = ""; + String variant = ""; + + if (items.length > 0) { + language = items[0]; + } + + if (items.length > 1) { + country = items[1]; } - return new Locale(sourceFileLocale); + + if (items.length > 2) { + variant = items[2]; + } + return new Locale(language, country, variant); } /** @@ -560,16 +591,6 @@ public boolean isShowEmptyDetails() { return showEmptyDetails; } - /** - * {@inheritDoc} - * - * @see org.apache.maven.reporting.AbstractMavenReport#getOutputDirectory() - */ - @Override - protected String getOutputDirectory() { - return outputDirectory.getAbsolutePath(); - } - /** * Get the absolute path to the XML output directory. * @@ -609,15 +630,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/ReportGenerator.java b/src/main/java/org/codehaus/mojo/taglist/TaglistReportRenderer.java similarity index 57% rename from src/main/java/org/codehaus/mojo/taglist/ReportGenerator.java rename to src/main/java/org/codehaus/mojo/taglist/TaglistReportRenderer.java index 7a65703..9985de4 100644 --- a/src/main/java/org/codehaus/mojo/taglist/ReportGenerator.java +++ b/src/main/java/org/codehaus/mojo/taglist/TaglistReportRenderer.java @@ -25,7 +25,7 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.apache.maven.doxia.sink.Sink; +import org.apache.maven.reporting.AbstractMavenReportRenderer; import org.codehaus.mojo.taglist.beans.FileReport; import org.codehaus.mojo.taglist.beans.TagReport; @@ -34,7 +34,7 @@ * * @author Fabrice Bellingard */ -public class ReportGenerator { +public class TaglistReportRenderer extends AbstractMavenReportRenderer { /** * The source code cross reference path. */ @@ -45,20 +45,15 @@ public class ReportGenerator { */ private String testXrefLocation; - /** - * The sink used in this Maven build to generated the tag list page. - */ - private final Sink sink; - /** * The resource bundle used in this Maven build. */ - private final ResourceBundle bundle; + private ResourceBundle bundle; /** - * The output path of the site. + * The output path of the report. */ - private final File siteOutputDirectory; + private final File reportOutputDirectory; /** * A list of sorted tag reports. @@ -76,30 +71,25 @@ public class ReportGenerator { * @param report the TagListReport object used in this build. * @param tagReports a collection of tagReports to output. */ - public ReportGenerator(TagListReport report, Collection tagReports) { - sortedTagReports = new TreeSet<>(tagReports); - this.bundle = report.getBundle(); - this.sink = report.getSink(); - this.siteOutputDirectory = report.getReportOutputDirectory(); + public TaglistReportRenderer(TagListReport report, Collection tagReports) { + super(report.getSink()); + this.sortedTagReports = new TreeSet<>(tagReports); + this.reportOutputDirectory = report.getReportOutputDirectory(); this.showEmptyDetails = report.isShowEmptyDetails(); } - /** - * Generates the whole report using each tag reports made during the analysis. - */ - public void generateReport() { - sink.head(); - sink.title(); - sink.text(bundle.getString("report.taglist.header")); - sink.title_(); - sink.head_(); + public void setBundle(ResourceBundle bundle) { + this.bundle = bundle; + } - sink.body(); - sink.section1(); + @Override + public String getTitle() { + return bundle.getString("report.taglist.header"); + } - sink.sectionTitle1(); - sink.text(bundle.getString("report.taglist.mainTitle")); - sink.sectionTitle1_(); + @Override + protected void renderBody() { + startSection(bundle.getString("report.taglist.mainTitle")); // Summary section doSummarySection(sortedTagReports); @@ -107,83 +97,56 @@ public void generateReport() { // Detail section doDetailSection(sortedTagReports); - sink.section1_(); - sink.body_(); - sink.flush(); - sink.close(); + endSection(); } /** * @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); @@ -199,48 +162,33 @@ private void doTagDetailedPart(TagReport tagReport) { return; } - sink.section2(); - sink.sectionTitle2(); - sink.anchor(tagReport.getHTMLSafeLinkName()); - sink.text(tagReport.getTagName()); - sink.anchor_(); - sink.sectionTitle2_(); - sink.paragraph(); - sink.bold(); - sink.text(bundle.getString("report.taglist.detail.numberOfOccurrences") + ' ' + tagReport.getTagCount()); - sink.bold_(); - sink.paragraph_(); + startSection(tagReport.getTagName(), tagReport.getHTMLSafeLinkName()); + + paragraph(bundle.getString("report.taglist.detail.numberOfOccurrences") + ' ' + tagReport.getTagCount()); Collection fileReports = tagReport.getFileReports(); SortedSet sortedFileReports = new TreeSet<>(fileReports); // 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); } @@ -251,47 +199,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)); + File xrefFile = new File(reportOutputDirectory, 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)); + File testXrefFile = new File(reportOutputDirectory, 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 c8bd5af..237a23e 100644 --- a/src/test/java/org/codehaus/mojo/taglist/AbstractTaglistMojoTestCase.java +++ b/src/test/java/org/codehaus/mojo/taglist/AbstractTaglistMojoTestCase.java @@ -4,9 +4,18 @@ import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; +import java.util.Collections; import java.util.stream.Collectors; +import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.eclipse.aether.DefaultRepositorySystemSession; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.repository.LocalRepository; +import org.eclipse.aether.repository.RemoteRepository; + +import static java.util.Collections.singletonList; public abstract class AbstractTaglistMojoTestCase extends AbstractMojoTestCase { public static final String TEST_ENCODING = "UTF-8"; @@ -20,17 +29,43 @@ public abstract class AbstractTaglistMojoTestCase extends AbstractMojoTestCase { */ protected TagListReport getTagListReport(File pluginXmlFile) throws Exception { assertTrue("Cannot find plugin file.", pluginXmlFile.exists()); + + DefaultRepositorySystemSession repositorySystemSession = new DefaultRepositorySystemSession(); + RepositorySystem repositorySystem = lookup(RepositorySystem.class); + + repositorySystemSession.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager( + repositorySystemSession, new LocalRepository(System.getProperty("localRepository")))); + + // Test need to download a maven-fluido-skin if not present in local repo + RemoteRepository remoteRepository = + new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2").build(); + 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, "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( + mojo, + "remoteProjectRepositories", + repositorySystem.newResolutionRepositories( + repositorySystemSession, Collections.singletonList(remoteRepository))); + setVariableValueToObject(mojo, "mojoExecution", new MojoExecution(new Plugin(), "taglist", "default")); + + if (getVariableValueFromObject(mojo, "sourceFileLocale") == null) { + setVariableValueToObject(mojo, "sourceFileLocale", "en"); + } return mojo; } /** * Reads the generated taglist report into a String. + * * @param mojo to use as source * @return a String containing the contents. * @throws IOException in case of generic I/O errors. @@ -46,6 +81,7 @@ protected String getGeneratedOutput(TagListReport mojo) throws IOException { /** * Reads the generated taglist XML report into a String. + * * @param mojo to use as source * @return a String containing the contents. * @throws IOException in case of generic I/O errors. diff --git a/src/test/java/org/codehaus/mojo/taglist/TagListReportSourceFileLocaleTest.java b/src/test/java/org/codehaus/mojo/taglist/TagListReportSourceFileLocaleTest.java new file mode 100644 index 0000000..5b345c0 --- /dev/null +++ b/src/test/java/org/codehaus/mojo/taglist/TagListReportSourceFileLocaleTest.java @@ -0,0 +1,31 @@ +package org.codehaus.mojo.taglist; + +import java.util.Locale; +import java.util.stream.Stream; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.params.provider.Arguments.of; + +class TagListReportSourceFileLocaleTest { + + static Stream sourceFileLocaleParserTest() { + return Stream.of( + of("en", new Locale("en")), + of("en_US", new Locale("en", "US")), + of("en_US_win", new Locale("en", "US", "win")), + of("en_US_win_XX", Locale.ENGLISH), + of("", Locale.ENGLISH)); + } + + @ParameterizedTest + @MethodSource + void sourceFileLocaleParserTest(String inputLocale, Locale expectedLocale) { + TagListReport tagListReport = new TagListReport(); + tagListReport.setSourceFileLocale(inputLocale); + assertEquals(expectedLocale, tagListReport.getSourceFileLocale()); + } +} diff --git a/src/test/java/org/codehaus/mojo/taglist/TaglistMojoBasicConfigTest.java b/src/test/java/org/codehaus/mojo/taglist/TaglistMojoBasicConfigTest.java index 0b2616b..9dc270d 100644 --- a/src/test/java/org/codehaus/mojo/taglist/TaglistMojoBasicConfigTest.java +++ b/src/test/java/org/codehaus/mojo/taglist/TaglistMojoBasicConfigTest.java @@ -102,7 +102,7 @@ public void testEmptyCommentsEnabled() throws Exception { String htmlString = super.getGeneratedOutput(mojo); // Check to see that there was only one occurrence. - String expected = "Number of occurrences found in the code: 1"; + String expected = "Number of occurrences found in the code: 1"; assertTrue("Missing tag result.", htmlString.contains(expected)); // Use the resource bundle to determine what the no comment string @@ -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)); }