From 778e9381fd42023747ac2e5498492aea58a76d9b Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sun, 21 Jul 2024 08:48:34 -0400 Subject: [PATCH 1/6] Replace deprecated methods --- .../site/render/AbstractSiteRenderingMojo.java | 15 +++++++-------- .../render/CategorySummaryDocumentRenderer.java | 9 +++++++-- .../site/render/ReportDocumentRenderer.java | 2 +- .../maven/plugins/site/render/SiteMojo.java | 9 +++++---- .../site/render/SitemapDocumentRenderer.java | 7 ++++++- .../maven/plugins/site/run/DoxiaFilter.java | 5 ++++- .../maven/plugins/site/run/SiteRunMojo.java | 3 ++- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java b/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java index c74ab234..f5b4d2f9 100644 --- a/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java +++ b/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java @@ -57,7 +57,6 @@ import org.apache.maven.reporting.exec.MavenReportExecution; import org.apache.maven.reporting.exec.MavenReportExecutor; import org.apache.maven.reporting.exec.MavenReportExecutorRequest; -import org.apache.maven.shared.utils.WriterFactory; import org.codehaus.plexus.util.ReaderFactory; import static org.apache.maven.shared.utils.logging.MessageUtils.buffer; @@ -195,7 +194,7 @@ protected String getInputEncoding() { * @return The effective reporting output file encoding, never null. */ protected String getOutputEncoding() { - return (outputEncoding == null) ? WriterFactory.UTF_8 : outputEncoding; + return outputEncoding == null ? "UTF-8" : outputEncoding; } /** @@ -295,7 +294,7 @@ protected SiteRenderingContext createSiteRenderingContext(Locale locale) getLog().info(buffer().a("Rendering content with ") .strong(skinArtifact.getId() + " skin") - .toString()); + .build()); context = siteRenderer.createContextForSkin( skinArtifact, templateProperties, siteModel, project.getName(), locale); @@ -355,7 +354,7 @@ protected Map locateReports( for (MavenReportExecution mavenReportExecution : reports) { MavenReport report = mavenReportExecution.getMavenReport(); - String outputName = report.getOutputName(); + String outputName = report.getOutputPath(); String filename = outputName + ".html"; // Always add the report to the menu, see MSITE-150 @@ -460,7 +459,7 @@ protected Map locateDocuments( DocumentRenderer docRenderer = new CategorySummaryDocumentRenderer( subMojoExecution, docRenderingContext, title, desc1, desc2, i18n, categoryReports, getLog()); - String filename = docRenderer.getOutputName(); + String filename = docRenderer.getOutputPath(); if (!documents.containsKey(filename)) { documents.put(filename, docRenderer); } else { @@ -483,7 +482,7 @@ protected Map locateDocuments( DocumentRenderer docRenderer = new CategorySummaryDocumentRenderer( subMojoExecution, docRenderingContext, title, desc1, desc2, i18n, categoryReports, getLog()); - String filename = docRenderer.getOutputName(); + String filename = docRenderer.getOutputPath(); if (!documents.containsKey(filename)) { documents.put(filename, docRenderer); } else { @@ -502,7 +501,7 @@ protected Map locateDocuments( DocumentRenderer docRenderer = new SitemapDocumentRenderer( subMojoExecution, docRenderingContext, title, context.getSiteModel(), i18n, getLog()); - String filename = docRenderer.getOutputName(); + String filename = docRenderer.getOutputPath(); if (!documents.containsKey(filename)) { documents.put(filename, docRenderer); } else { @@ -533,7 +532,7 @@ private void populateItemRefs(List items, Locale locale, Map reports = generateReports ? getReports(outputDirectory) : Collections.emptyList(); @@ -209,7 +210,7 @@ private List renderDoxiaDocuments( mb.strong(entry.getValue() + " " + entry.getKey()); } - getLog().info(mb.toString()); + getLog().info(mb.build()); siteRenderer.render(doxiaDocuments, context, outputDirectory); } @@ -231,7 +232,7 @@ private List renderDoxiaDocuments( mb.strong(entry.getValue() + " " + entry.getKey()); } - getLog().info(mb.toString()); + getLog().info(mb.build()); siteRenderer.render(generatedDoxiaDocuments, context, outputDirectory); } @@ -275,7 +276,7 @@ private void renderNonDoxiaDocuments( mb.a("Rendering "); mb.strong(count + " " + type + " document" + (count > 1 ? "s" : "")); - getLog().info(mb.toString()); + getLog().info(mb.build()); } siteRenderer.render(documents, context, outputDirectory); diff --git a/src/main/java/org/apache/maven/plugins/site/render/SitemapDocumentRenderer.java b/src/main/java/org/apache/maven/plugins/site/render/SitemapDocumentRenderer.java index 1536d234..90fa68e4 100644 --- a/src/main/java/org/apache/maven/plugins/site/render/SitemapDocumentRenderer.java +++ b/src/main/java/org/apache/maven/plugins/site/render/SitemapDocumentRenderer.java @@ -78,6 +78,7 @@ public SitemapDocumentRenderer( this.log = log; } + @Override public void renderDocument(Writer writer, SiteRenderer siteRenderer, SiteRenderingContext siteRenderingContext) throws RendererException, IOException { Locale locale = siteRenderingContext.getLocale(); @@ -162,18 +163,22 @@ private static String relativePath(String href) { return href.startsWith("/") ? "." + href : href; } + @Override public String getOutputName() { - return docRenderingContext.getOutputName(); + return docRenderingContext.getOutputPath(); } + @Override public DocumentRenderingContext getRenderingContext() { return docRenderingContext; } + @Override public boolean isOverwrite() { return true; } + @Override public boolean isExternalReport() { return false; } diff --git a/src/main/java/org/apache/maven/plugins/site/run/DoxiaFilter.java b/src/main/java/org/apache/maven/plugins/site/run/DoxiaFilter.java index 9fce1cc3..d363da5e 100644 --- a/src/main/java/org/apache/maven/plugins/site/run/DoxiaFilter.java +++ b/src/main/java/org/apache/maven/plugins/site/run/DoxiaFilter.java @@ -74,6 +74,7 @@ public class DoxiaFilter implements Filter { /** * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) */ + @Override public void init(FilterConfig filterConfig) throws ServletException { servletContext = filterConfig.getServletContext(); @@ -89,6 +90,7 @@ public void init(FilterConfig filterConfig) throws ServletException { /** * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) */ + @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) servletRequest; @@ -139,7 +141,7 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo try { DocumentRenderer docRenderer = documents.get(path); logDocumentRenderer(path, localeWanted, docRenderer); - String outputName = docRenderer.getOutputName(); + String outputName = docRenderer.getOutputPath(); String contentType = MimeTypes.getDefaultMimeByExtension(outputName); if (contentType != null) { servletResponse.setContentType(contentType); @@ -194,5 +196,6 @@ private void logDocumentRenderer(String path, String locale, DocumentRenderer do /** * @see javax.servlet.Filter#destroy() */ + @Override public void destroy() {} } diff --git a/src/main/java/org/apache/maven/plugins/site/run/SiteRunMojo.java b/src/main/java/org/apache/maven/plugins/site/run/SiteRunMojo.java index 266909c4..eb2ad981 100644 --- a/src/main/java/org/apache/maven/plugins/site/run/SiteRunMojo.java +++ b/src/main/java/org/apache/maven/plugins/site/run/SiteRunMojo.java @@ -74,6 +74,7 @@ public class SiteRunMojo extends AbstractSiteRenderingMojo { /** * @see org.apache.maven.plugin.AbstractMojo#execute() */ + @Override public void execute() throws MojoExecutionException, MojoFailureException { checkInputEncoding(); @@ -91,7 +92,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { throw new MojoExecutionException("Error executing Jetty", e); } - getLog().info(buffer().a("Started Jetty on ").strong(server.getURI()).toString()); + getLog().info(buffer().a("Started Jetty on ").strong(server.getURI()).build()); // Watch it try { From 0de418d1e07a46bf1e8ed43375e597105c757261 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sun, 21 Jul 2024 08:50:25 -0400 Subject: [PATCH 2/6] spotless --- .../maven/plugins/site/render/AbstractSiteRenderingMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java b/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java index f5b4d2f9..1537eb90 100644 --- a/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java +++ b/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java @@ -194,7 +194,7 @@ protected String getInputEncoding() { * @return The effective reporting output file encoding, never null. */ protected String getOutputEncoding() { - return outputEncoding == null ? "UTF-8" : outputEncoding; + return outputEncoding == null ? "UTF-8" : outputEncoding; } /** From 24c93a8f934029c68f0316d580d83caf8e8714e4 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Wed, 24 Jul 2024 07:22:26 -0400 Subject: [PATCH 3/6] Restore getOutputName --- .../site/descriptor/EffectiveSiteMojo.java | 5 +++-- .../site/render/AbstractSiteRenderingMojo.java | 10 +++++----- .../render/CategorySummaryDocumentRenderer.java | 4 ++-- .../site/render/ReportDocumentRenderer.java | 17 ++++++++++------- .../site/render/SitemapDocumentRenderer.java | 7 ++++++- .../maven/plugins/site/run/DoxiaFilter.java | 2 +- 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/site/descriptor/EffectiveSiteMojo.java b/src/main/java/org/apache/maven/plugins/site/descriptor/EffectiveSiteMojo.java index 5566b837..e4c0046a 100644 --- a/src/main/java/org/apache/maven/plugins/site/descriptor/EffectiveSiteMojo.java +++ b/src/main/java/org/apache/maven/plugins/site/descriptor/EffectiveSiteMojo.java @@ -30,9 +30,9 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import org.codehaus.plexus.util.WriterFactory; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.XMLWriter; +import org.codehaus.plexus.util.xml.XmlStreamWriter; import org.codehaus.plexus.util.xml.XmlWriterUtil; /** @@ -57,6 +57,7 @@ public class EffectiveSiteMojo extends AbstractSiteDescriptorMojo { /** * {@inheritDoc} */ + @Override public void execute() throws MojoExecutionException, MojoFailureException { SiteModel siteModel = prepareSiteModel(getLocales().get(0)); @@ -148,7 +149,7 @@ private void writeEffectiveSite(SiteModel siteModel, XMLWriter writer) throws Mo } protected static void writeXmlFile(File output, String content) throws IOException { - try (Writer out = WriterFactory.newXmlWriter(output)) { + try (Writer out = new XmlStreamWriter(output)) { output.getParentFile().mkdirs(); out.write(content); diff --git a/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java b/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java index 1537eb90..1030d63c 100644 --- a/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java +++ b/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java @@ -354,7 +354,7 @@ protected Map locateReports( for (MavenReportExecution mavenReportExecution : reports) { MavenReport report = mavenReportExecution.getMavenReport(); - String outputName = report.getOutputPath(); + String outputName = report.getOutputName(); String filename = outputName + ".html"; // Always add the report to the menu, see MSITE-150 @@ -459,7 +459,7 @@ protected Map locateDocuments( DocumentRenderer docRenderer = new CategorySummaryDocumentRenderer( subMojoExecution, docRenderingContext, title, desc1, desc2, i18n, categoryReports, getLog()); - String filename = docRenderer.getOutputPath(); + String filename = docRenderer.getOutputName(); if (!documents.containsKey(filename)) { documents.put(filename, docRenderer); } else { @@ -482,7 +482,7 @@ protected Map locateDocuments( DocumentRenderer docRenderer = new CategorySummaryDocumentRenderer( subMojoExecution, docRenderingContext, title, desc1, desc2, i18n, categoryReports, getLog()); - String filename = docRenderer.getOutputPath(); + String filename = docRenderer.getOutputName(); if (!documents.containsKey(filename)) { documents.put(filename, docRenderer); } else { @@ -501,7 +501,7 @@ protected Map locateDocuments( DocumentRenderer docRenderer = new SitemapDocumentRenderer( subMojoExecution, docRenderingContext, title, context.getSiteModel(), i18n, getLog()); - String filename = docRenderer.getOutputPath(); + String filename = docRenderer.getOutputName(); if (!documents.containsKey(filename)) { documents.put(filename, docRenderer); } else { @@ -532,7 +532,7 @@ private void populateItemRefs(List items, Locale locale, Map Date: Wed, 24 Jul 2024 07:27:41 -0400 Subject: [PATCH 4/6] spotless --- .../descriptor/SiteDescriptorArtifactMetadata.java | 13 +++++++++++-- .../plugins/site/render/ReportDocumentRenderer.java | 4 ++-- .../plugins/site/stubs/SiteMavenProjectStub.java | 12 ++++-------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/site/descriptor/SiteDescriptorArtifactMetadata.java b/src/main/java/org/apache/maven/plugins/site/descriptor/SiteDescriptorArtifactMetadata.java index ebb23fa1..bd36b376 100644 --- a/src/main/java/org/apache/maven/plugins/site/descriptor/SiteDescriptorArtifactMetadata.java +++ b/src/main/java/org/apache/maven/plugins/site/descriptor/SiteDescriptorArtifactMetadata.java @@ -29,7 +29,7 @@ import org.apache.maven.artifact.repository.metadata.RepositoryMetadataStoreException; import org.apache.maven.doxia.site.SiteModel; import org.apache.maven.doxia.site.io.xpp3.SiteXpp3Writer; -import org.codehaus.plexus.util.WriterFactory; +import org.codehaus.plexus.util.xml.XmlStreamWriter; /** * Attach a POM to an artifact. @@ -49,10 +49,12 @@ public SiteDescriptorArtifactMetadata(Artifact artifact, SiteModel siteModel, Fi this.siteModel = siteModel; } + @Override public String getRemoteFilename() { return getFilename(); } + @Override public String getLocalFilename(ArtifactRepository repository) { return getFilename(); } @@ -61,6 +63,7 @@ private String getFilename() { return getArtifactId() + "-" + artifact.getVersion() + "-" + file.getName(); } + @Override public void storeInLocalRepository(ArtifactRepository localRepository, ArtifactRepository remoteRepository) throws RepositoryMetadataStoreException { File destination = new File( @@ -68,29 +71,34 @@ public void storeInLocalRepository(ArtifactRepository localRepository, ArtifactR destination.getParentFile().mkdirs(); - try (Writer writer = WriterFactory.newXmlWriter(destination)) { + try (Writer writer = new XmlStreamWriter(destination)) { new SiteXpp3Writer().write(writer, siteModel); } catch (IOException e) { throw new RepositoryMetadataStoreException("Error saving in local repository", e); } } + @Override public String toString() { return "site descriptor for " + artifact.getArtifactId() + " " + artifact.getVersion() + " " + file.getName(); } + @Override public boolean storedInArtifactVersionDirectory() { return true; } + @Override public String getBaseVersion() { return artifact.getBaseVersion(); } + @Override public Object getKey() { return "site descriptor " + artifact.getGroupId() + ":" + artifact.getArtifactId() + " " + file.getName(); } + @Override public void merge(ArtifactMetadata metadata) { SiteDescriptorArtifactMetadata m = (SiteDescriptorArtifactMetadata) metadata; if (!m.file.equals(file)) { @@ -98,6 +106,7 @@ public void merge(ArtifactMetadata metadata) { } } + @Override public void merge(org.apache.maven.repository.legacy.metadata.ArtifactMetadata metadata) { // FIXME what todo here ? } diff --git a/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java b/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java index 86e5eb6b..18e40380 100644 --- a/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java +++ b/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java @@ -43,7 +43,6 @@ import org.apache.maven.reporting.MavenReportException; import org.apache.maven.reporting.exec.MavenReportExecution; import org.codehaus.plexus.util.PathTool; -import org.codehaus.plexus.util.WriterFactory; import static org.apache.maven.shared.utils.logging.MessageUtils.buffer; @@ -247,7 +246,8 @@ public void renderDocument(Writer writer, SiteRenderer siteRenderer, SiteRenderi File outputFile = new File(mySink.getOutputDirectory(), outputName); - try (Writer out = new OutputStreamWriter(Files.newOutputStream(outputFile.toPath()), siteRenderingContext.getOutputEncoding())) { + try (Writer out = new OutputStreamWriter( + Files.newOutputStream(outputFile.toPath()), siteRenderingContext.getOutputEncoding())) { siteRenderer.mergeDocumentIntoSite(out, mySink, siteRenderingContext); } finally { mySink.close(); diff --git a/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java b/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java index f624b2ce..1140d22f 100644 --- a/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java +++ b/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java @@ -25,8 +25,6 @@ import org.apache.maven.model.Site; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.xml.XmlStreamReader; /** @@ -41,15 +39,10 @@ public class SiteMavenProjectStub extends MavenProjectStub { public SiteMavenProjectStub(String projectName) { basedir = new File(super.getBasedir() + "/src/test/resources/unit/" + projectName); - XmlStreamReader reader = null; - try { - reader = ReaderFactory.newXmlReader(new File(getBasedir(), "pom.xml")); + try (XmlStreamReader reader = new XmlStreamReader(new File(getBasedir(), "pom.xml"))) { setModel(new MavenXpp3Reader().read(reader)); - reader.close(); } catch (Exception e) { throw new RuntimeException(e); - } finally { - IOUtil.close(reader); } Site site = new Site(); site.setId("localhost"); @@ -59,6 +52,7 @@ public SiteMavenProjectStub(String projectName) { /** * @see org.apache.maven.project.MavenProject#getName() */ + @Override public String getName() { return getModel().getName(); } @@ -66,6 +60,7 @@ public String getName() { /** * @see org.apache.maven.project.MavenProject#getProperties() */ + @Override public Properties getProperties() { return new Properties(); } @@ -76,6 +71,7 @@ public DistributionManagement getDistributionManagement() { } /** {@inheritDoc} */ + @Override public File getBasedir() { return basedir; } From 2f0d3ec92bfbda449b390b749540ba556509872c Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Wed, 24 Jul 2024 07:33:10 -0400 Subject: [PATCH 5/6] format --- .../maven/plugins/site/render/ReportDocumentRenderer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java b/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java index 18e40380..93c540e2 100644 --- a/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java +++ b/src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java @@ -230,13 +230,12 @@ public void renderDocument(Writer writer, SiteRenderer siteRenderer, SiteRenderi siteRenderer.mergeDocumentIntoSite(writer, mainSink, siteRenderingContext); // render sub-sinks, eventually created by multi-page reports - String outputName = ""; List sinks = multiPageSinkFactory.sinks(); log.debug("Multipage report: " + sinks.size() + " subreports"); for (MultiPageSubSink mySink : sinks) { - outputName = mySink.getOutputName(); + String outputName = mySink.getOutputName(); log.debug(" Rendering " + outputName); // Create directories if necessary From 9b735980040db150a2401820450c7a02fe6538eb Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sat, 27 Jul 2024 08:38:10 -0400 Subject: [PATCH 6/6] imports --- .../apache/maven/plugins/site/stubs/SiteMavenProjectStub.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java b/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java index c52e37f5..2e229cd7 100644 --- a/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java +++ b/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java @@ -28,11 +28,7 @@ import org.apache.maven.model.Site; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; -<<<<<<< HEAD -import org.codehaus.plexus.util.xml.XmlStreamReader; -======= import org.codehaus.plexus.util.xml.pull.XmlPullParserException; ->>>>>>> master /** * @author Vincent Siveton