Skip to content

Commit

Permalink
Replace deprecated methods (#198)
Browse files Browse the repository at this point in the history
* Replace deprecated methods
  • Loading branch information
elharo authored and michael-o committed Jul 28, 2024
1 parent cf5c504 commit 73b57d3
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -57,6 +57,7 @@ public class EffectiveSiteMojo extends AbstractSiteDescriptorMojo {
/**
* {@inheritDoc}
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
SiteModel siteModel = prepareSiteModel(getLocales().get(0));

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
}
Expand All @@ -61,43 +63,50 @@ private String getFilename() {
return getArtifactId() + "-" + artifact.getVersion() + "-" + file.getName();
}

@Override
public void storeInLocalRepository(ArtifactRepository localRepository, ArtifactRepository remoteRepository)
throws RepositoryMetadataStoreException {
File destination = new File(
localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata(this, remoteRepository));

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)) {
throw new IllegalStateException("Cannot add two different pieces of metadata for: " + getKey());
}
}

@Override
public void merge(org.apache.maven.repository.legacy.metadata.ArtifactMetadata metadata) {
// FIXME what todo here ?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -195,7 +194,7 @@ protected String getInputEncoding() {
* @return The effective reporting output file encoding, never <code>null</code>.
*/
protected String getOutputEncoding() {
return (outputEncoding == null) ? WriterFactory.UTF_8 : outputEncoding;
return outputEncoding == null ? "UTF-8" : outputEncoding;
}

/**
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public CategorySummaryDocumentRenderer(
this.log = log;
}

@Override
public void renderDocument(Writer writer, SiteRenderer siteRenderer, SiteRenderingContext siteRenderingContext)
throws RendererException, IOException {
String msg = "Generating \"" + buffer().strong(title) + "\" report";
Expand Down Expand Up @@ -177,18 +178,22 @@ public void renderDocument(Writer writer, SiteRenderer siteRenderer, SiteRenderi
siteRenderer.mergeDocumentIntoSite(writer, sink, siteRenderingContext);
}

@Override
public String getOutputName() {
return docRenderingContext.getOutputName();
}

@Override
public DocumentRenderingContext getRenderingContext() {
return docRenderingContext;
}

@Override
public boolean isOverwrite() {
return true;
}

@Override
public boolean isExternalReport() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
Expand All @@ -41,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;

Expand Down Expand Up @@ -229,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<MultiPageSubSink> 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
Expand All @@ -245,14 +245,11 @@ public void renderDocument(Writer writer, SiteRenderer siteRenderer, SiteRenderi

File outputFile = new File(mySink.getOutputDirectory(), outputName);

try (Writer out = WriterFactory.newWriter(outputFile, siteRenderingContext.getOutputEncoding())) {
try (Writer out = new OutputStreamWriter(
Files.newOutputStream(outputFile.toPath()), siteRenderingContext.getOutputEncoding())) {
siteRenderer.mergeDocumentIntoSite(out, mySink, siteRenderingContext);
mySink.close();
mySink = null;
} finally {
if (mySink != null) {
mySink.close();
}
mySink.close();
}
}
}
Expand All @@ -262,6 +259,11 @@ public String getOutputName() {
return docRenderingContext.getOutputName();
}

@Override
public String getOutputPath() {
return getOutputName();
}

@Override
public DocumentRenderingContext getRenderingContext() {
return docRenderingContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class SiteMojo extends AbstractSiteRenderingMojo {
/**
* {@inheritDoc}
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().info("maven.site.skip = true: Skipping site generation");
Expand All @@ -104,7 +105,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
(!locale.equals(SiteTool.DEFAULT_LOCALE)
? "locale '" + locale + "'"
: "default locale"))
.toString());
.build());
File outputDirectory = getOutputDirectory(locale);
List<MavenReportExecution> reports =
generateReports ? getReports(outputDirectory) : Collections.emptyList();
Expand Down Expand Up @@ -209,7 +210,7 @@ private List<DocumentRenderer> renderDoxiaDocuments(
mb.strong(entry.getValue() + " " + entry.getKey());
}

getLog().info(mb.toString());
getLog().info(mb.build());

siteRenderer.render(doxiaDocuments, context, outputDirectory);
}
Expand All @@ -231,7 +232,7 @@ private List<DocumentRenderer> renderDoxiaDocuments(
mb.strong(entry.getValue() + " " + entry.getKey());
}

getLog().info(mb.toString());
getLog().info(mb.build());

siteRenderer.render(generatedDoxiaDocuments, context, outputDirectory);
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -162,18 +163,27 @@ private static String relativePath(String href) {
return href.startsWith("/") ? "." + href : href;
}

@Override
public String getOutputName() {
return docRenderingContext.getOutputName();
}

@Override
public String getOutputPath() {
return getOutputName();
}

@Override
public DocumentRenderingContext getRenderingContext() {
return docRenderingContext;
}

@Override
public boolean isOverwrite() {
return true;
}

@Override
public boolean isExternalReport() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
Expand Down Expand Up @@ -194,5 +196,6 @@ private void logDocumentRenderer(String path, String locale, DocumentRenderer do
/**
* @see javax.servlet.Filter#destroy()
*/
@Override
public void destroy() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class SiteRunMojo extends AbstractSiteRenderingMojo {
/**
* @see org.apache.maven.plugin.AbstractMojo#execute()
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
checkInputEncoding();

Expand All @@ -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 {
Expand Down

0 comments on commit 73b57d3

Please sign in to comment.