From 9ae3703c535e34d328fd60758f85a8ee358224ca Mon Sep 17 00:00:00 2001 From: Vincent Massol <vincent@massol.net> Date: Mon, 3 Jan 2022 15:27:45 +0100 Subject: [PATCH] XWIKI-19288: Plain Text Mentions 1.0 syntax doesn't have a nice friendly name --- .../xwiki-platform-mentions-default/pom.xml | 2 +- .../rendering/MentionsSyntaxProvider.java | 59 +++++++++++++++++++ .../PlainTextMentionsBlockRenderer.java | 2 +- .../rendering/PlainTextMentionsRenderer.java | 2 +- .../PlainTextMentionsRendererFactory.java | 4 +- .../main/resources/META-INF/components.txt | 1 + .../rendering/MentionsSyntaxProviderTest.java | 50 ++++++++++++++++ 7 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/MentionsSyntaxProvider.java create mode 100644 xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/test/java/org/xwiki/mentions/internal/rendering/MentionsSyntaxProviderTest.java diff --git a/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/pom.xml b/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/pom.xml index 7ac18837c01..25c2b28f8e0 100644 --- a/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/pom.xml +++ b/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/pom.xml @@ -32,7 +32,7 @@ <packaging>jar</packaging> <description>Default implementation of the Mentions components.</description> <properties> - <xwiki.jacoco.instructionRatio>0.85</xwiki.jacoco.instructionRatio> + <xwiki.jacoco.instructionRatio>0.86</xwiki.jacoco.instructionRatio> <!-- This component must be installed at the farm level because org.xwiki.eventstream.store.internal.RecordableEventListener.convertEvent uses org.xwiki.component.manager.ComponentManager. To be removed once XWIKI-17359 is fixed. --> diff --git a/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/MentionsSyntaxProvider.java b/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/MentionsSyntaxProvider.java new file mode 100644 index 00000000000..dbba9803f17 --- /dev/null +++ b/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/MentionsSyntaxProvider.java @@ -0,0 +1,59 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.mentions.internal.rendering; + +import java.util.Collections; +import java.util.List; + +import javax.inject.Named; +import javax.inject.Provider; +import javax.inject.Singleton; + +import org.xwiki.component.annotation.Component; +import org.xwiki.rendering.syntax.Syntax; +import org.xwiki.rendering.syntax.SyntaxType; + +/** + * Register the {@code plainmentions/1.0} Syntax supported by this module. + * + * @version $Id$ + * @since 14.0RC1 + */ +@Component +@Named("plainmentions/1.0") +@Singleton +public class MentionsSyntaxProvider implements Provider<List<Syntax>> +{ + /** + * Plain Mentions syntax. + */ + public static final SyntaxType PLAINMENTIONS = new SyntaxType("plainmentions", "Plain Text Mentions"); + + /** + * Plain Mentions 1.0 syntax. + */ + public static final Syntax PLAINMENTIONS_1_0 = new Syntax(PLAINMENTIONS, "1.0"); + + @Override + public List<Syntax> get() + { + return Collections.singletonList(PLAINMENTIONS_1_0); + } +} diff --git a/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/PlainTextMentionsBlockRenderer.java b/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/PlainTextMentionsBlockRenderer.java index 17fd87425fe..880025ae65e 100644 --- a/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/PlainTextMentionsBlockRenderer.java +++ b/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/PlainTextMentionsBlockRenderer.java @@ -39,7 +39,7 @@ public class PlainTextMentionsBlockRenderer extends PlainTextBlockRenderer { /** - * Used to create new plain/1.0 {@link org.xwiki.rendering.renderer.PrintRenderer}s. + * Used to create new {@code plain/1.0} {@link org.xwiki.rendering.renderer.PrintRenderer}s. */ @Inject @Named("plainmentions/1.0") diff --git a/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/PlainTextMentionsRenderer.java b/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/PlainTextMentionsRenderer.java index 6d94bad5d1c..0e9989cac39 100644 --- a/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/PlainTextMentionsRenderer.java +++ b/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/PlainTextMentionsRenderer.java @@ -36,7 +36,7 @@ import org.xwiki.rendering.internal.renderer.plain.PlainTextRenderer; /** - * Plain text rendered with a specialization to display well formatted user mentions. + * Plain text rendered with a specialization to display well-formatted user mentions. * * @version $Id$ * @since 12.6 diff --git a/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/PlainTextMentionsRendererFactory.java b/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/PlainTextMentionsRendererFactory.java index 4a4ca7981b8..6561b7afd84 100644 --- a/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/PlainTextMentionsRendererFactory.java +++ b/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/java/org/xwiki/mentions/internal/rendering/PlainTextMentionsRendererFactory.java @@ -25,7 +25,6 @@ import org.xwiki.component.annotation.Component; import org.xwiki.rendering.internal.renderer.AbstractPrintRendererFactory; import org.xwiki.rendering.syntax.Syntax; -import org.xwiki.rendering.syntax.SyntaxType; /** * Mentions specific plain text renderer factory. @@ -41,7 +40,6 @@ public class PlainTextMentionsRendererFactory extends AbstractPrintRendererFacto @Override public Syntax getSyntax() { - String plainmentions = "plainmentions"; - return new Syntax(new SyntaxType(plainmentions, plainmentions), "1.0"); + return MentionsSyntaxProvider.PLAINMENTIONS_1_0; } } diff --git a/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/resources/META-INF/components.txt b/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/resources/META-INF/components.txt index 028a6c98a45..21d67d8798c 100644 --- a/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/resources/META-INF/components.txt +++ b/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/main/resources/META-INF/components.txt @@ -15,6 +15,7 @@ org.xwiki.mentions.internal.MentionsConfigurationSource org.xwiki.mentions.internal.rendering.PlainTextMentionsBlockRenderer org.xwiki.mentions.internal.rendering.PlainTextMentionsRenderer org.xwiki.mentions.internal.rendering.PlainTextMentionsRendererFactory +org.xwiki.mentions.internal.rendering.MentionsSyntaxProvider org.xwiki.mentions.internal.DefaultMentionsFormatterProvider org.xwiki.mentions.internal.analyzer.CreatedDocumentMentionsAnalyzer org.xwiki.mentions.internal.analyzer.UpdatedDocumentMentionsAnalyzer diff --git a/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/test/java/org/xwiki/mentions/internal/rendering/MentionsSyntaxProviderTest.java b/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/test/java/org/xwiki/mentions/internal/rendering/MentionsSyntaxProviderTest.java new file mode 100644 index 00000000000..09d71509509 --- /dev/null +++ b/xwiki-platform-core/xwiki-platform-mentions/xwiki-platform-mentions-default/src/test/java/org/xwiki/mentions/internal/rendering/MentionsSyntaxProviderTest.java @@ -0,0 +1,50 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.mentions.internal.rendering; + +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.xwiki.rendering.syntax.Syntax; +import org.xwiki.test.junit5.mockito.ComponentTest; +import org.xwiki.test.junit5.mockito.InjectMockComponents; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Unit tests for {@link MentionsSyntaxProvider}. + * + * @version $Id$ + */ +@ComponentTest +class MentionsSyntaxProviderTest +{ + @InjectMockComponents + private MentionsSyntaxProvider provider; + + @Test + void get() + { + List<Syntax> syntaxes = this.provider.get(); + assertEquals(1, syntaxes.size()); + assertEquals("plainmentions/1.0", syntaxes.get(0).toIdString()); + assertEquals("Plain Text Mentions 1.0", syntaxes.get(0).toString()); + } +} -- GitLab