Unverified Commit 40e5d953 authored by Manuel Leduc's avatar Manuel Leduc Committed by GitHub
Browse files

XRENDERING-664: Allow macros to have several categories (#216)

* Introduce the operations to set several macro categories
* Introduce xwiki-rendering-legacy-transformation-macro legacy module
* Move AbstractMacroDescriptor.setDefaultCategory to xwiki-rendering-legacy-transformation-macro
* Some deprecated methods are temporarily kept until their use is removed from xwiki-platform
parent 7b88f4d1
......@@ -37,6 +37,7 @@
</properties>
<modules>
<module>xwiki-rendering-legacy-api</module>
<module>xwiki-rendering-legacy-transformations</module>
</modules>
<dependencies>
<!-- Needed for backward compatibility Aspects -->
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
* 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.xwiki.rendering</groupId>
<artifactId>xwiki-rendering-legacy</artifactId>
<version>14.6-SNAPSHOT</version>
</parent>
<artifactId>xwiki-rendering-legacy-transformations</artifactId>
<name>XWiki Rendering - Legacy - Transformations - Parent POM</name>
<packaging>pom</packaging>
<description>XWiki Rendering - Legacy - Transformations - Parent POM</description>
<modules>
<module>xwiki-rendering-legacy-transformation-macro</module>
</modules>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
* 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.xwiki.rendering</groupId>
<artifactId>xwiki-rendering-legacy-transformations</artifactId>
<version>14.6-SNAPSHOT</version>
</parent>
<artifactId>xwiki-rendering-legacy-transformation-macro</artifactId>
<name>XWiki Rendering - Legacy - Transformation - Macro</name>
<packaging>jar</packaging>
<description>Legacy module for xwiki-rendering-transformation-macro</description>
<properties>
<xwiki.jacoco.instructionRatio>0.04</xwiki.jacoco.instructionRatio>
<!-- The features provided by this module so that it's found when resolving extension. -->
<xwiki.extension.features>org.xwiki.rendering:xwiki-rendering-transformation-macro</xwiki.extension.features>
</properties>
<dependencies>
<!-- Trigger xwiki-rendering-transformation-macro dependencies (but without xwiki-rendering-transformation-macro jar itself). -->
<dependency>
<groupId>org.xwiki.rendering</groupId>
<artifactId>xwiki-rendering-transformation-macro</artifactId>
<version>${project.version}</version>
<type>pom</type>
</dependency>
<!-- We need this dependency so that the wrapped module is built before this one. -->
<dependency>
<groupId>org.xwiki.rendering</groupId>
<artifactId>xwiki-rendering-transformation-macro</artifactId>
<version>${project.version}</version>
<!-- We don't want to draw this dependency since we're wrapping it. -->
<scope>provided</scope>
</dependency>
<!-- Testing Dependencies. -->
<dependency>
<groupId>org.xwiki.commons</groupId>
<artifactId>xwiki-commons-tool-test-component</artifactId>
<version>${commons.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Apply Compatibility Aspects. -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<executions>
<execution>
<id>backward-compatibility-aspects</id>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<weaveDependencies>
<weaveDependency>
<groupId>org.xwiki.rendering</groupId>
<artifactId>xwiki-rendering-transformation-macro</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>
</plugin>
<!-- Exclude AspectJ's builddef.lst file form the generated JAR since it's not useful there. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/builddef.lst</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<classpathDependencyExcludes>
<classpathDependencyExcludes>org.xwiki.rendering:xwiki-rendering-transformation-macro:jar</classpathDependencyExcludes>
</classpathDependencyExcludes>
</configuration>
</plugin>
<plugin>
<groupId>fr.inria.gforge.spoon</groupId>
<artifactId>spoon-maven-plugin</artifactId>
<executions>
<execution>
<id>spoon-test</id>
<configuration>
<!-- TODO: Remove once https://github.com/INRIA/spoon/issues/3583 is fixed -->
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package org.xwiki.rendering.macro.descriptor;
import java.util.Set;
/**
* Add a backward compatibility layer to the {@link AbstractMacroDescriptor} class.
*
* @version $Id$
* @since 14.6RC1
*/
public privileged aspect AbstractMacroDescriptorAspect
{
/**
* @param defaultCategory default category under which this macro should be listed
* @see MacroDescriptor#getDefaultCategories()
* @deprecated since 14.6RC1 use {@link AbstractMacroDescriptor#setDefaultCategories(Set)} instead
*/
@Deprecated(since = "14.6RC1")
public void AbstractMacroDescriptor.setDefaultCategory(String defaultCategory)
{
this.defaultCategories = Set.of(defaultCategory);
}
}
/*
* 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.rendering.macro.descriptor;
import org.junit.jupiter.api.Test;
import org.xwiki.properties.BeanDescriptor;
import org.xwiki.rendering.macro.MacroId;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.mockito.Mockito.mock;
/**
* Test of the deprecated methods of {@link AbstractMacroDescriptorAspect}.
*
* @version $Id$
* @since 14.6RC1
*/
class DeprecatedAbstractMacroDescriptorTest
{
@Test
void setDefaultCategory()
{
AbstractMacroDescriptor abstractMacroDescriptor = new AbstractMacroDescriptor(new MacroId("testmacro"),
"testmacro", "description", new DefaultContentDescriptor("description", false), mock(BeanDescriptor.class))
{
};
abstractMacroDescriptor.setDefaultCategory("testcategory");
assertThat(abstractMacroDescriptor.getDefaultCategories(), containsInAnyOrder("testcategory"));
}
}
......@@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.inject.Named;
import javax.inject.Singleton;
......@@ -63,7 +64,7 @@ public DefaultBoxMacro()
{
super("Box", DESCRIPTION, new DefaultContentDescriptor(CONTENT_DESCRIPTION, false,
Block.LIST_BLOCK_TYPE), BoxMacroParameters.class);
setDefaultCategory(DEFAULT_CATEGORY_FORMATTING);
setDefaultCategories(Set.of(DEFAULT_CATEGORY_FORMATTING));
}
@Override
......
......@@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.inject.Named;
import javax.inject.Singleton;
......@@ -60,7 +61,7 @@ public class CommentMacro extends AbstractNoParameterMacro
public CommentMacro()
{
super("Comment", DESCRIPTION, new DefaultContentDescriptor(CONTENT_DESCRIPTION));
setDefaultCategory(DEFAULT_CATEGORY_DEVELOPMENT);
setDefaultCategories(Set.of(DEFAULT_CATEGORY_DEVELOPMENT));
}
@Override
......
......@@ -22,6 +22,7 @@
import java.io.StringReader;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
......@@ -79,7 +80,7 @@ public ContentMacro()
{
super("Content", DESCRIPTION, new DefaultContentDescriptor(CONTENT_DESCRIPTION, true,
Block.LIST_BLOCK_TYPE), ContentMacroParameters.class);
setDefaultCategory(DEFAULT_CATEGORY_CONTENT);
setDefaultCategories(Set.of(DEFAULT_CATEGORY_CONTENT));
}
@Override
......
......@@ -95,7 +95,7 @@ public class CTSDataMacro extends AbstractNoParameterMacro
public CTSDataMacro()
{
super("CTS Data", DESCRIPTION, new DefaultContentDescriptor(CONTENT_DESCRIPTION));
setDefaultCategory(DEFAULT_CATEGORY_DEVELOPMENT);
setDefaultCategories(Set.of(DEFAULT_CATEGORY_DEVELOPMENT));
}
@Override
......
......@@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
......@@ -69,7 +70,7 @@ public FigureCaptionMacro()
{
super("Figure Caption", DESCRIPTION,
new DefaultContentDescriptor(CONTENT_DESCRIPTION, true, Block.LIST_BLOCK_TYPE));
setDefaultCategory(DEFAULT_CATEGORY_DEVELOPMENT);
setDefaultCategories(Set.of(DEFAULT_CATEGORY_DEVELOPMENT));
}
@Override
......
......@@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
......@@ -68,7 +69,7 @@ public FigureMacro()
{
super("Figure", DESCRIPTION,
new DefaultContentDescriptor(CONTENT_DESCRIPTION, false, Block.LIST_BLOCK_TYPE));
setDefaultCategory(DEFAULT_CATEGORY_DEVELOPMENT);
setDefaultCategories(Set.of(DEFAULT_CATEGORY_DEVELOPMENT));
}
@Override
......
......@@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.inject.Named;
import javax.inject.Singleton;
......@@ -87,7 +88,7 @@ public FootnoteMacro()
{
super("Footnote", DESCRIPTION, new DefaultContentDescriptor(CONTENT_DESCRIPTION),
FootnoteMacroParameters.class);
setDefaultCategory(DEFAULT_CATEGORY_CONTENT);
setDefaultCategories(Set.of(DEFAULT_CATEGORY_CONTENT));
// The putfootnote macro might already exist in some other macro but to find it the footnote macro need to be
// executed later
......
......@@ -22,6 +22,7 @@
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
......@@ -88,7 +89,7 @@ public class PutFootnotesMacro extends AbstractMacro<FootnoteMacroParameters>
public PutFootnotesMacro()
{
super("Put Footnote", DESCRIPTION, FootnoteMacroParameters.class);
setDefaultCategory(DEFAULT_CATEGORY_CONTENT);
setDefaultCategories(Set.of(DEFAULT_CATEGORY_CONTENT));
// Must be executed after footnote macro because it's injecting links in it
setPriority(FootnoteMacro.PRIORITY + 1);
......
......@@ -24,6 +24,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
......@@ -125,7 +126,7 @@ public class HTMLMacro extends AbstractMacro<HTMLMacroParameters>
public HTMLMacro()
{
super("HTML", DESCRIPTION, new DefaultContentDescriptor(CONTENT_DESCRIPTION), HTMLMacroParameters.class);
setDefaultCategory(DEFAULT_CATEGORY_DEVELOPMENT);
setDefaultCategories(Set.of(DEFAULT_CATEGORY_DEVELOPMENT));
}
@Override
......
......@@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.inject.Named;
import javax.inject.Singleton;
......@@ -61,7 +62,7 @@ public IdMacro()
// Set a high priority so that this macro executes before most others.
setPriority(20);
setDefaultCategory(DEFAULT_CATEGORY_NAVIGATION);
setDefaultCategories(Set.of(DEFAULT_CATEGORY_NAVIGATION));
}
@Override
......
......@@ -19,6 +19,8 @@
*/
package org.xwiki.rendering.internal.macro.message;
import java.util.Set;
import javax.inject.Named;
import javax.inject.Singleton;
......@@ -41,6 +43,6 @@ public class ErrorMessageMacro extends AbstractMessageMacro
public ErrorMessageMacro()
{
super("Error Message", "Displays an error message note.");
setDefaultCategory(DEFAULT_CATEGORY_FORMATTING);
setDefaultCategories(Set.of(DEFAULT_CATEGORY_FORMATTING));
}
}
......@@ -19,6 +19,8 @@
*/
package org.xwiki.rendering.internal.macro.message;
import java.util.Set;
import javax.inject.Named;
import javax.inject.Singleton;
......@@ -41,6 +43,6 @@ public class InfoMessageMacro extends AbstractMessageMacro
public InfoMessageMacro()
{
super("Info Message", "Displays an info message note.");
setDefaultCategory(DEFAULT_CATEGORY_FORMATTING);
setDefaultCategories(Set.of(DEFAULT_CATEGORY_FORMATTING));
}
}
......@@ -19,6 +19,8 @@
*/
package org.xwiki.rendering.internal.macro.message;
import java.util.Set;
import javax.inject.Named;
import javax.inject.Singleton;
......@@ -41,6 +43,6 @@ public class SuccessMessageMacro extends AbstractMessageMacro
public SuccessMessageMacro()
{
super("Success Message", "Displays a success message note.");
setDefaultCategory(DEFAULT_CATEGORY_FORMATTING);
setDefaultCategories(Set.of(DEFAULT_CATEGORY_FORMATTING));
}
}
......@@ -19,6 +19,8 @@
*/
package org.xwiki.rendering.internal.macro.message;
import java.util.Set;
import javax.inject.Named;
import javax.inject.Singleton;
......@@ -41,6 +43,6 @@ public class WarningMessageMacro extends AbstractMessageMacro
public WarningMessageMacro()
{
super("Warning Message", "Displays a warning message note.");
setDefaultCategory(DEFAULT_CATEGORY_FORMATTING);
setDefaultCategories(Set.of(DEFAULT_CATEGORY_FORMATTING));
}
}
......@@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.inject.Named;
import javax.inject.Singleton;
......@@ -63,7 +64,7 @@ public RawMacro()
{
super("Raw", DESCRIPTION, new DefaultContentDescriptor(CONTENT_DESCRIPTION, true, Block.LIST_BLOCK_TYPE),
RawMacroParameters.class);
setDefaultCategory(DEFAULT_CATEGORY_CONTENT);
setDefaultCategories(Set.of(DEFAULT_CATEGORY_CONTENT));
}
@Override
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment