Skip to content

Commit

Permalink
XWIKI-22211: Deprecate NotificationFilterPreferenceProvider
Browse files Browse the repository at this point in the history
  * Deprecate and legacify NotificationFilterPreferenceProvider and
    NotificationFilterPreference#getProviderHint
  * Clean up all code relying on it simplifying a lot the implem of
    NotificationFilterPreference
  * Only valid usage of the providerHint was for checking if a filter
    preference was stored or not: replaced it with checking the ID of
the filter
  • Loading branch information
surli committed Jun 4, 2024
1 parent 0487a59 commit 670780f
Show file tree
Hide file tree
Showing 30 changed files with 288 additions and 452 deletions.
12 changes: 12 additions & 0 deletions xwiki-platform-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@
Single justification example:
-->
<revapi.differences>
<justification>Deprecated method available through legacy but breakage triggered by a
dependant module.</justification>
<criticality>allowed</criticality>
<differences>
<item>
<ignore>true</ignore>
<code>java.method.removed</code>
<old>method java.lang.String org.xwiki.notifications.filters.NotificationFilterPreference::getProviderHint()</old>
</item>
</differences>
</revapi.differences>


</analysisConfiguration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@
By setting this property, we make sure this application would be automatically uninstalled if the administrator
installs the old Activity Stream Application. -->
<xwiki.extension.features>org.xwiki.platform:xwiki-platform-notifications-filters-api</xwiki.extension.features>
<xwiki.jacoco.instructionRatio>0.63</xwiki.jacoco.instructionRatio>
<xwiki.jacoco.instructionRatio>0.08</xwiki.jacoco.instructionRatio>
</properties>
<dependencies>
<!-- Trigger xwiki-platform-notifications-fomters-api dependencies (but without
xwiki-platform-notifications-filters-api jar itself) -->
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-notifications-filters-api</artifactId>
<version>${project.version}</version>
<type>pom</type>
<exclusions>
<!-- We want the legacy dependency of notification-api -->
<exclusion>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-notifications-api</artifactId>
Expand All @@ -56,6 +60,27 @@
<artifactId>xwiki-platform-legacy-notifications-api</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Aspectified dependency -->
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-notifications-filters-api</artifactId>
<version>${project.version}</version>
<!-- We don't want to draw this dependency since we're wrapping it -->
<scope>provided</scope>
<exclusions>
<!-- We want the legacy dependency of notification-api -->
<exclusion>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-notifications-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Build tools -->
<!-- Needed for backward compatibility Aspects -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.xwiki.commons</groupId>
Expand All @@ -64,4 +89,111 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Apply Backward compatibility Aspects using the strategy described at
http://blogs.sonatype.com/john/2007/11/09/1194630418546.html -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<executions>
<execution>
<id>backward-compatibility-aspects</id>
<configuration>
<weaveDependencies>
<weaveDependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-notifications-filters-api</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>
</execution>
</executions>
</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>
<!-- Merge components.txt files -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<configuration>
<target>
<!-- Add a line separator before appending the legacy components.
NOTE: The following solutions didn't work:
* the fixlastline parameter of the concat task affects only the appended files, NOT the destination
file; we need the new line at the end of the destination file!
* the text content of the header element inside the concat task is trimmed when the POM is parsed.
See http://jira.codehaus.org/browse/PLX-461 -->
<echo message="${line.separator}" file="${project.build.directory}/classes/META-INF/components.txt" append="true" />
<concat destfile="${project.build.directory}/classes/META-INF/components.txt" append="true">
<filelist dir="${basedir}/src/main/resources/META-INF/" files="components.txt" />
</concat>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Make sure we run the tests only with the aspectified JARs since otherwise components will be registered
twice for example. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<classpathDependencyExcludes>
<classpathDependencyExcludes>org.xwiki.platform:xwiki-platform-notifications-filters-api:jar</classpathDependencyExcludes>
</classpathDependencyExcludes>
</configuration>
</plugin>
<plugin>
<groupId>fr.inria.gforge.spoon</groupId>
<artifactId>spoon-maven-plugin</artifactId>
<executions>
<execution>
<id>spoon-main</id>
<configuration>
<processorProperties combine.children="append">
<processorProperty>
<name>org.xwiki.tool.spoon.ComponentAnnotationProcessor</name>
<properties>
<property>
<!-- Skip foreign declaration checks since we merge the components.txt -->
<name>skipForeignDeclarations</name>
<value>true</value>
</property>
<!-- TODO: Ideally inherit this from the top level pom but I couldn't find how to do it, or remove
it when spoon is fixed, see https://github.com/INRIA/spoon/issues/3339 -->
<property>
<name>componentsTxtPath</name>
<value>target/classes/META-INF/components.txt</value>
</property>
</properties>
</processorProperty>
</processorProperties>
</configuration>
</execution>
<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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.notifications.filters;

/**
* Add a backward compatibility layer to {@link NotificationFilterPreference}.
*
* @version $Id$
* @since 16.5.0RC1
*/
public privileged aspect NotificationFilterPreferenceCompatibilityAspect
{
declare parents : NotificationFilterPreference implements CompatibilityNotificationFilterPreference;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.notifications.filters;

/**
* Deprecated methods of {@link NotificationFilterPreference}.
*
* @version $Id$
* @since 16.5.0RC1
*/
public interface CompatibilityNotificationFilterPreference
{
/**
* @return the name of the provider hint associated with this preference.
* @deprecated this information is now useless with support of a single location for storing preferences
*/
@Deprecated(since = "16.5.0RC1")
default String getProviderHint()
{
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
*
* @version $Id$
* @since 9.8RC1
* @deprecated this interface is not used anywhere anymore in XWiki Standard.
*/
@Role
@Deprecated(since = "16.5.0RC1")
public interface NotificationFilterPreferenceProvider
{
/**
Expand Down Expand Up @@ -73,7 +75,7 @@ default Set<NotificationFilterPreference> getFilterPreferences(WikiReference wik
* @since 9.11.9
*/
void saveFilterPreferences(DocumentReference user, Set<NotificationFilterPreference> filterPreferences)
throws NotificationException;
throws NotificationException;

/**
* Delete a filter preference.
Expand Down Expand Up @@ -129,7 +131,7 @@ default void deleteFilterPreference(WikiReference wikiReference, String filterPr
* @since 9.11.9
*/
void setFilterPreferenceEnabled(DocumentReference user, String filterPreferenceId, boolean enabled)
throws NotificationException;
throws NotificationException;

/**
* Enable or disable a filter preference.
Expand Down Expand Up @@ -158,4 +160,4 @@ default void setFilterPreferenceEnabled(WikiReference wikiReference, String filt
* @since 9.11.5
*/
void setStartDateForUser(DocumentReference user, Date startDate) throws NotificationException;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ private DefaultNotificationFilterPreference getFilterPreference(String property,
filterPreference.setFilterName(ScopeNotificationFilter.FILTER_NAME);
filterPreference.setFilterType(NotificationFilterType.INCLUSIVE);
filterPreference.setNotificationFormats(Collections.singleton(NotificationFormat.ALERT));
filterPreference.setProviderHint("FACTORY");
return filterPreference;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<!-- Name to display by the Extension Manager -->
<xwiki.extension.name>Notifications Filters API</xwiki.extension.name>
<checkstyle.suppressions.location>${basedir}/src/checkstyle/checkstyle-suppressions.xml</checkstyle.suppressions.location>
<!-- Skip revapi since it's handled by the legacy module -->
<xwiki.revapi.skip>true</xwiki.revapi.skip>
</properties>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.apache.commons.lang3.StringUtils;
import org.xwiki.notifications.NotificationFormat;
import org.xwiki.stability.Unstable;

import static com.xpn.xwiki.doc.XWikiDocument.DB_SPACE_SEP;

Expand All @@ -47,6 +48,13 @@
*/
public interface NotificationFilterPreference
{
/**
* Prefix to be used for the ID only when the preference is stored in database.
* @since 16.5.0RC1
*/
@Unstable
String DB_STORED_FILTER_PREFIX = "NFP_";

/**
* @return the unique identifier of the filter preference.
* @since 10.8RC1
Expand All @@ -59,11 +67,6 @@ public interface NotificationFilterPreference
*/
String getFilterName();

/**
* @return the name of the {@link NotificationFilterPreferenceProvider} associated with this preference.
*/
String getProviderHint();

/**
* @return true if the current notification preference is enabled.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ Stream<NotificationFilterPreference> getFilterPreferences(
* @since 10.8.3
* @since 9.11.9
*/
void saveFilterPreferences(DocumentReference user, Set<NotificationFilterPreference> notificationFilterPreferences);
void saveFilterPreferences(DocumentReference user, Set<NotificationFilterPreference> notificationFilterPreferences)
throws NotificationException;

/**
* Delete a filter preference.
Expand Down
Loading

0 comments on commit 670780f

Please sign in to comment.