This is an automated email from the ASF dual-hosted git repository. diru pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-sitemap.git
commit 6f7191f3ddb040a1b717ce4301ab327c6b4c0159 Author: Dirk Rudolph <[email protected]> AuthorDate: Tue Jun 29 16:35:02 2021 +0200 SLING-10573: rename SitemapGenerator.GenerationContext to SitemapGenerator.Context --- .../sitemap/impl/SitemapGeneratorExecutor.java | 24 +++++++++++----------- .../apache/sling/sitemap/impl/SitemapServlet.java | 2 +- .../generator/ResourceTreeSitemapGenerator.java | 4 ++-- .../sitemap/spi/generator/SitemapGenerator.java | 16 +++++++-------- .../org/apache/sling/sitemap/TestGenerator.java | 2 +- .../sitemap/impl/SitemapGeneratorExecutorTest.java | 6 +++--- .../impl/SitemapServiceImplSchedulingTest.java | 4 ++-- .../ResourceTreeSitemapGeneratorTest.java | 11 +++++----- 8 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/apache/sling/sitemap/impl/SitemapGeneratorExecutor.java b/src/main/java/org/apache/sling/sitemap/impl/SitemapGeneratorExecutor.java index a1c0e39..2364c2c 100644 --- a/src/main/java/org/apache/sling/sitemap/impl/SitemapGeneratorExecutor.java +++ b/src/main/java/org/apache/sling/sitemap/impl/SitemapGeneratorExecutor.java @@ -134,7 +134,7 @@ public class SitemapGeneratorExecutor implements JobExecutor { throws SitemapException, IOException { try { CopyableByteArrayOutputStream buffer = new CopyableByteArrayOutputStream(); - GenerationContextImpl genCtxt = new GenerationContextImpl(); + Context genCtxt = new Context(); // prefill the buffer with existing data from storage ValueMap state = storage.getState(res, name); @@ -266,7 +266,7 @@ public class SitemapGeneratorExecutor implements JobExecutor { private final Resource sitemapRoot; private final String name; private final JobExecutionContext jobContext; - private final GenerationContextImpl generationContext; + private final Context generatorContext; private final List<String> files = new ArrayList<>(1); private final CopyableByteArrayOutputStream buffer; private final CopyableByteArrayOutputStream overflowBuffer = new CopyableByteArrayOutputStream(); @@ -275,13 +275,13 @@ public class SitemapGeneratorExecutor implements JobExecutor { private StatefulSitemap currentSitemap; MultiFileSitemap(Resource sitemapRoot, String name, int fileIndex, CopyableByteArrayOutputStream buffer, - GenerationContextImpl generationContext, JobExecutionContext jobContext) throws IOException { + Context generatorContext, JobExecutionContext jobContext) throws IOException { this.sitemapRoot = sitemapRoot; this.name = name; this.fileIndex = fileIndex; this.buffer = buffer; this.jobContext = jobContext; - this.generationContext = generationContext; + this.generatorContext = generatorContext; this.currentSitemap = newSitemap(); } @@ -304,7 +304,7 @@ public class SitemapGeneratorExecutor implements JobExecutor { } private StatefulSitemap newSitemap() throws IOException { - return new StatefulSitemap(sitemapRoot, name, buffer, jobContext, generationContext); + return new StatefulSitemap(sitemapRoot, name, buffer, jobContext, generatorContext); } private void closeSitemap() throws IOException { @@ -316,7 +316,7 @@ public class SitemapGeneratorExecutor implements JobExecutor { } String path = storage.writeSitemap(sitemapRoot, name, buffer.copy(), fileIndex, buffer.size(), urlCount); // increment the file index for the next sitemap and store it in the context - generationContext.data.put(SitemapStorage.PN_SITEMAP_FILE_INDEX, ++fileIndex); + generatorContext.data.put(SitemapStorage.PN_SITEMAP_FILE_INDEX, ++fileIndex); files.add(path); } @@ -364,19 +364,19 @@ public class SitemapGeneratorExecutor implements JobExecutor { private final String name; private final CopyableByteArrayOutputStream buffer; private final JobExecutionContext jobContext; - private final GenerationContextImpl generationContext; + private final Context generatorContext; private int urlCount = 0; private int writtenUrls = 0; StatefulSitemap(Resource sitemapRoot, String name, CopyableByteArrayOutputStream buffer, - JobExecutionContext jobContext, GenerationContextImpl generationContext) throws IOException { + JobExecutionContext jobContext, Context generatorContext) throws IOException { super(new OutputStreamWriter(buffer, StandardCharsets.UTF_8), extensionProviderManager, buffer.size() == 0); this.sitemapRoot = sitemapRoot; this.name = name; this.buffer = buffer; this.jobContext = jobContext; - this.generationContext = generationContext; + this.generatorContext = generatorContext; } @NotNull @@ -398,8 +398,8 @@ public class SitemapGeneratorExecutor implements JobExecutor { // make sure the buffer has all data from the writer out.flush(); // copy the state and add the buffer's data - Map<String, Object> copy = new HashMap<>(generationContext.data.size() + 1); - copy.putAll(generationContext.data); + Map<String, Object> copy = new HashMap<>(generatorContext.data.size() + 1); + copy.putAll(generatorContext.data); copy.put(SitemapStorage.PN_SITEMAP_ENTRIES, urlCount); copy.put(JcrConstants.JCR_DATA, buffer.copy()); // write the state and reset the counter for the next iteration @@ -413,7 +413,7 @@ public class SitemapGeneratorExecutor implements JobExecutor { } } - private class GenerationContextImpl implements SitemapGenerator.GenerationContext { + private static class Context implements SitemapGenerator.Context { private final ValueMap data = new ValueMapDecorator(new HashMap<>()); diff --git a/src/main/java/org/apache/sling/sitemap/impl/SitemapServlet.java b/src/main/java/org/apache/sling/sitemap/impl/SitemapServlet.java index 2ed67fb..35f23ae 100644 --- a/src/main/java/org/apache/sling/sitemap/impl/SitemapServlet.java +++ b/src/main/java/org/apache/sling/sitemap/impl/SitemapServlet.java @@ -61,7 +61,7 @@ public class SitemapServlet extends SlingSafeMethodsServlet { static final String SITEMAP_EXTENSION = "xml"; private static final Logger LOG = LoggerFactory.getLogger(SitemapServlet.class); - private static SitemapGenerator.GenerationContext NOOP_CONTEXT = new SitemapGenerator.GenerationContext() { + private static SitemapGenerator.Context NOOP_CONTEXT = new SitemapGenerator.Context() { @Nullable @Override public <T> T getProperty(@NotNull String name, @NotNull Class<T> cls) { diff --git a/src/main/java/org/apache/sling/sitemap/spi/generator/ResourceTreeSitemapGenerator.java b/src/main/java/org/apache/sling/sitemap/spi/generator/ResourceTreeSitemapGenerator.java index 73acb70..5bc8c80 100644 --- a/src/main/java/org/apache/sling/sitemap/spi/generator/ResourceTreeSitemapGenerator.java +++ b/src/main/java/org/apache/sling/sitemap/spi/generator/ResourceTreeSitemapGenerator.java @@ -42,7 +42,7 @@ import static org.apache.sling.sitemap.SitemapUtil.isSitemapRoot; * follows through only on content that is not below the "jcr:content" or any other sitemap root. * <p> * This implementation keeps track of the traversal's state in the - * {@link SitemapGenerator.GenerationContext}. It is capable to continue from a previous + * {@link Context}. It is capable to continue from a previous * persisted state, when the generation got aborted. */ @ConsumerType @@ -52,7 +52,7 @@ public abstract class ResourceTreeSitemapGenerator implements SitemapGenerator { @Override public final void generate(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull Sitemap sitemap, - @NotNull GenerationContext context) throws SitemapException { + @NotNull SitemapGenerator.Context context) throws SitemapException { String lastPath = context.getProperty(PROPERTY_LAST_PATH, String.class); for (Resource descendant : (Iterable<? extends Resource>) traverse(sitemapRoot, lastPath)::iterator) { addResource(name, sitemap, descendant); diff --git a/src/main/java/org/apache/sling/sitemap/spi/generator/SitemapGenerator.java b/src/main/java/org/apache/sling/sitemap/spi/generator/SitemapGenerator.java index 155bdaf..8707c09 100644 --- a/src/main/java/org/apache/sling/sitemap/spi/generator/SitemapGenerator.java +++ b/src/main/java/org/apache/sling/sitemap/spi/generator/SitemapGenerator.java @@ -18,6 +18,9 @@ */ package org.apache.sling.sitemap.spi.generator; +import java.util.Collections; +import java.util.Set; + import org.apache.sling.api.resource.Resource; import org.apache.sling.sitemap.SitemapException; import org.apache.sling.sitemap.SitemapService; @@ -26,9 +29,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.osgi.annotation.versioning.ConsumerType; -import java.util.Collections; -import java.util.Set; - /** * {@link SitemapGenerator} implementations are responsible to generate one or many sitemaps for a given sitemap root * {@link Resource}. When a {@link SitemapGenerator} generates multiple sitemaps for a given {@link Resource} it has to @@ -36,7 +36,7 @@ import java.util.Set; * that any of those names should be served on-demand by returning a subset of names for * {@link SitemapGenerator#getOnDemandNames(Resource)}. * <p> - * {@link SitemapGenerator#generate(Resource, String, Sitemap, GenerationContext)} may be called for each name and + * {@link SitemapGenerator#generate(Resource, String, Sitemap, Context)} may be called for each name and * each sitemap root {@link Resource}, the implementation returned an non-empty {@link Set} of names for. * <p> * It is possible to register multiple {@link SitemapGenerator}s for a single name. In this case the one with the @@ -106,7 +106,7 @@ public interface SitemapGenerator { /** * Generates a {@link Sitemap} with the given name at the given {@link Resource}. * <p> - * This process may be stateful and the given {@link GenerationContext} can be used to keep track of the state. For + * This process may be stateful and the given {@link Context} can be used to keep track of the state. For * example a traversal that keeps track on the last {@link Resource} added to the {@link Sitemap}. * * @param sitemapRoot the root at which the sitemap should be created @@ -116,14 +116,14 @@ public interface SitemapGenerator { * @param context the context under which the sitemap is generated * @throws SitemapException may be thrown in unrecoverable exceptional cases */ - void generate(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull Sitemap sitemap, - @NotNull GenerationContext context) throws SitemapException; + void generate(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull Sitemap sitemap, @NotNull SitemapGenerator.Context context) + throws SitemapException; /** * A context object that gives the {@link SitemapGenerator} access to additional configurations and methods to * track state. */ - interface GenerationContext { + interface Context { @Nullable <T> T getProperty(@NotNull String name, @NotNull Class<T> cls); diff --git a/src/test/java/org/apache/sling/sitemap/TestGenerator.java b/src/test/java/org/apache/sling/sitemap/TestGenerator.java index d051a3d..1d031db 100644 --- a/src/test/java/org/apache/sling/sitemap/TestGenerator.java +++ b/src/test/java/org/apache/sling/sitemap/TestGenerator.java @@ -69,7 +69,7 @@ public abstract class TestGenerator implements SitemapGenerator { } @Override - public void generate(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull Sitemap sitemap, @NotNull GenerationContext context) throws SitemapException { + public void generate(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull Sitemap sitemap, @NotNull SitemapGenerator.Context context) throws SitemapException { fail(); } } diff --git a/src/test/java/org/apache/sling/sitemap/impl/SitemapGeneratorExecutorTest.java b/src/test/java/org/apache/sling/sitemap/impl/SitemapGeneratorExecutorTest.java index 91caba8..ac147c5 100644 --- a/src/test/java/org/apache/sling/sitemap/impl/SitemapGeneratorExecutorTest.java +++ b/src/test/java/org/apache/sling/sitemap/impl/SitemapGeneratorExecutorTest.java @@ -393,7 +393,7 @@ public class SitemapGeneratorExecutorTest { "http://example.com/page2.html" ) { @Override - public void generate(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull Sitemap sitemap, @NotNull GenerationContext context) throws SitemapException { + public void generate(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull Sitemap sitemap, @NotNull SitemapGenerator.Context context) throws SitemapException { try { super.generate(sitemapRoot, name, sitemap, context); } finally { @@ -437,7 +437,7 @@ public class SitemapGeneratorExecutorTest { private SitemapException ex; @Override - public void generate(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull Sitemap sitemap, @NotNull GenerationContext context) throws SitemapException { + public void generate(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull Sitemap sitemap, @NotNull SitemapGenerator.Context context) throws SitemapException { throw ex; } } @@ -467,7 +467,7 @@ public class SitemapGeneratorExecutorTest { @Override public void generate(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull Sitemap sitemap, - @NotNull GenerationContext context) throws SitemapException { + @NotNull SitemapGenerator.Context context) throws SitemapException { int i = context.getProperty("i", 0); for (; i < locations.length; i++) { context.setProperty("i", i); diff --git a/src/test/java/org/apache/sling/sitemap/impl/SitemapServiceImplSchedulingTest.java b/src/test/java/org/apache/sling/sitemap/impl/SitemapServiceImplSchedulingTest.java index de184ef..a0ae4a6 100644 --- a/src/test/java/org/apache/sling/sitemap/impl/SitemapServiceImplSchedulingTest.java +++ b/src/test/java/org/apache/sling/sitemap/impl/SitemapServiceImplSchedulingTest.java @@ -70,7 +70,7 @@ public class SitemapServiceImplSchedulingTest { } @Override - public void generate(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull Sitemap sitemap, @NotNull GenerationContext context) throws SitemapException { + public void generate(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull Sitemap sitemap, @NotNull SitemapGenerator.Context context) throws SitemapException { fail(); } }; @@ -81,7 +81,7 @@ public class SitemapServiceImplSchedulingTest { } @Override - public void generate(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull Sitemap sitemap, @NotNull GenerationContext context) throws SitemapException { + public void generate(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull Sitemap sitemap, @NotNull SitemapGenerator.Context context) throws SitemapException { fail(); } }; diff --git a/src/test/java/org/apache/sling/sitemap/spi/generator/ResourceTreeSitemapGeneratorTest.java b/src/test/java/org/apache/sling/sitemap/spi/generator/ResourceTreeSitemapGeneratorTest.java index d87f975..f6be78e 100644 --- a/src/test/java/org/apache/sling/sitemap/spi/generator/ResourceTreeSitemapGeneratorTest.java +++ b/src/test/java/org/apache/sling/sitemap/spi/generator/ResourceTreeSitemapGeneratorTest.java @@ -24,7 +24,6 @@ import org.apache.sling.sitemap.SitemapService; import org.apache.sling.sitemap.TestResourceTreeSitemapGenerator; import org.apache.sling.sitemap.impl.builder.extensions.ExtensionProviderManager; import org.apache.sling.sitemap.impl.builder.SitemapImpl; -import org.apache.sling.sitemap.spi.generator.SitemapGenerator; import org.apache.sling.testing.mock.sling.junit5.SlingContext; import org.apache.sling.testing.mock.sling.junit5.SlingContextExtension; import org.junit.jupiter.api.BeforeEach; @@ -49,7 +48,7 @@ public class ResourceTreeSitemapGeneratorTest { private final ExtensionProviderManager extensionProviderManager = new ExtensionProviderManager(); @Mock - private SitemapGenerator.GenerationContext generationContext; + private SitemapGenerator.Context generatorContext; private Resource sitemapRoot; @BeforeEach @@ -67,7 +66,7 @@ public class ResourceTreeSitemapGeneratorTest { SitemapImpl sitemap = new SitemapImpl(writer, extensionProviderManager); // when - subject.generate(sitemapRoot, SitemapService.DEFAULT_SITEMAP_NAME, sitemap, generationContext); + subject.generate(sitemapRoot, SitemapService.DEFAULT_SITEMAP_NAME, sitemap, generatorContext); sitemap.close(); // then @@ -90,7 +89,7 @@ public class ResourceTreeSitemapGeneratorTest { context.create().resource("/content/site/de/child3"); // when - subject.generate(sitemapRoot, SitemapService.DEFAULT_SITEMAP_NAME, sitemap, generationContext); + subject.generate(sitemapRoot, SitemapService.DEFAULT_SITEMAP_NAME, sitemap, generatorContext); sitemap.close(); // then @@ -110,7 +109,7 @@ public class ResourceTreeSitemapGeneratorTest { // given StringWriter writer = new StringWriter(); SitemapImpl sitemap = new SitemapImpl(writer, extensionProviderManager); - when(generationContext.getProperty("lastPath", String.class)).thenReturn("/content/site/de/child2/grandchild21"); + when(generatorContext.getProperty("lastPath", String.class)).thenReturn("/content/site/de/child2/grandchild21"); context.create().resource("/content/site/de/child2/grandchild21"); context.create().resource("/content/site/de/child2/grandchild21/jcr:content"); context.create().resource("/content/site/de/child2/grandchild22"); @@ -121,7 +120,7 @@ public class ResourceTreeSitemapGeneratorTest { context.create().resource("/content/site/de/child3/grandchild31/jcr:content"); // when - subject.generate(sitemapRoot, SitemapService.DEFAULT_SITEMAP_NAME, sitemap, generationContext); + subject.generate(sitemapRoot, SitemapService.DEFAULT_SITEMAP_NAME, sitemap, generatorContext); sitemap.close(); // then
