Skip to content

Commit

Permalink
Revert removal of deprecated grails-events-compat (#69)
Browse files Browse the repository at this point in the history
* Revert "Remove deprecated grails-events-compat project."

This reverts commit f5e36db.

* build: Change groovy core library declaration name

It's name was previously a sub-path of other groovy modules

* build: Add dependency resolution of Groovy Snapshot versions
  • Loading branch information
matrei authored Dec 21, 2023
1 parent a8d1f22 commit 539bad0
Show file tree
Hide file tree
Showing 28 changed files with 531 additions and 11 deletions.
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ configurations {
}

dependencies {
documentation libs.groovy
documentation libs.groovy.core
documentation libs.groovy.templates
documentation libs.groovy.ant
documentation libs.groovy.dateutil
Expand Down Expand Up @@ -121,6 +121,13 @@ subprojects {
repositories {
mavenCentral()
maven { url 'https://repo.grails.org/grails/core' }
if (libs.versions.groovy.asProvider().get().endsWith('-SNAPSHOT')) {
maven {
name 'JFrog Groovy snapshot repo'
url 'https://groovy.jfrog.io/artifactory/libs-snapshot-local/'
}
}

}

tasks.withType(Test).configureEach {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ grails-docs = { module = "org.grails:grails-docs", version.ref = "grails" }
gpars = { module = 'org.codehaus.gpars:gpars', version.ref = 'gpars' }
gorm = { module = 'org.grails:grails-datastore-gorm', version.ref = 'gorm' }
gorm-test = { module = 'org.grails:grails-datastore-gorm-test', version.ref = 'gorm' }
groovy = { module = 'org.codehaus.groovy:groovy', version.ref = 'groovy' }
groovy-core = { module = 'org.codehaus.groovy:groovy', version.ref = 'groovy' }
groovy-templates = { module = 'org.codehaus.groovy:groovy-templates', version.ref = 'groovy' }
groovy-ant = { module = 'org.codehaus.groovy:groovy-ant', version.ref = 'groovy' }
groovy-dateutil = { module = 'org.codehaus.groovy:groovy-dateutil', version.ref = 'groovy' }
Expand Down
2 changes: 1 addition & 1 deletion grails-async-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
group = 'org.grails'

dependencies {
implementation libs.groovy
implementation libs.groovy.core
implementation libs.javax.annotation.api
implementation libs.slf4j.api
testImplementation libs.spock.core
Expand Down
2 changes: 1 addition & 1 deletion grails-async-gpars/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies {

implementation project(':grails-async-core')

implementation libs.groovy
implementation libs.groovy.core

implementation libs.gpars, {
exclude group: 'org.multiverse', module: 'multiverse-core'
Expand Down
2 changes: 1 addition & 1 deletion grails-async-rxjava/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies {

implementation project(':grails-async-core')

implementation libs.groovy
implementation libs.groovy.core

implementation libs.rxjava
implementation libs.slf4j.api
Expand Down
2 changes: 1 addition & 1 deletion grails-async-rxjava2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {

implementation project(':grails-async-core')

implementation libs.groovy
implementation libs.groovy.core

implementation libs.rxjava2
implementation libs.slf4j.api
Expand Down
3 changes: 3 additions & 0 deletions grails-events-compat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## grails-events-compat

This subproject established a compatibility layer for plugins built with older versions of Grails that worked with Reactor 2
26 changes: 26 additions & 0 deletions grails-events-compat/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
plugins {

id 'groovy'
id 'java-library'

id 'maven-publish'
id 'signing'

}

group = 'org.grails'

dependencies {

implementation project(':grails-events-core')
implementation project(':grails-events-transform')

implementation libs.groovy.core

implementation libs.slf4j.api
implementation libs.spring.tx

}

apply from: file("$rootProject.projectDir/gradle/java-config.gradle")
apply from: file("$rootProject.projectDir/gradle/publishing.gradle")
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2014 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package grails.artefact

import grails.events.Events


/**
* A trait implemented for services that implement events
*
* @author Graeme Rocher
* @since 3.0
* @deprecated Here for compatibility, do not use directly
*/
@Deprecated
trait Service extends Events {
}
181 changes: 181 additions & 0 deletions grails-events-compat/src/main/groovy/grails/events/Events.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
package grails.events

import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.slf4j.LoggerFactory
import reactor.bus.Bus
import reactor.bus.Event
import reactor.bus.EventBus
import reactor.bus.registry.Registration
import reactor.bus.registry.Subscription
import reactor.bus.selector.Selector
import reactor.fn.Consumer

/**
* Bridges the OLD API to the new
* @deprecated Here for compatibility only. Do not use directly
*/
@Deprecated
@CompileStatic
trait Events {

EventBus eventBus

/**
* @see #on(reactor.bus.selector.Selector, reactor.fn.Consumer)
*/
def <E extends Event<?>> Registration<Object, Consumer<E>> on(Class key, Closure consumer) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
on key.name, consumer
}

/**
* @see #on(reactor.bus.selector.Selector, reactor.fn.Consumer)
*/
def <E extends Event<?> > Registration<Object, Consumer<E>> on(Selector key, Closure consumer) {
throw new UnsupportedOperationException("Events of type [Selector] are no longer supported. Use string ids")
}

/**
* @see #on(reactor.bus.selector.Selector, reactor.fn.Consumer)
*/
def <E extends Event<?> > Registration<Object, Consumer<E>> on(key, Closure consumer) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")

eventBus.on(key.toString(), consumer) as Registration
}

/**
* @see #on(reactor.bus.selector.Selector, reactor.fn.Consumer)
*/
def <E extends Event<?> > Registration<Object, Consumer<E>> on(key, Consumer<E> consumer) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
if(key instanceof CharSequence) {
key = key.toString()
}
on(key) {
consumer.accept(it as E)
}
}

/**
* @see #on(reactor.bus.selector.Selector, reactor.fn.Consumer)
*/
def <E extends Event<?> > Registration<Object, Consumer<E>> on(Class type, Consumer<E> consumer) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
on(type.name, consumer)
}

/**
* Register a {@link reactor.fn.Consumer} to be triggered when a notification matches the given {@link
* Selector}.
*
* @param sel
* The {@literal Selector} to be used for matching
* @param consumer
* The {@literal Consumer} to be triggered
* @param <E>
* The type of the {@link Event}
*
* @return A {@link Subscription} object that allows the caller to interact with the given mapping
*/
def <E extends Event<?> > Registration<Object, Consumer<E>> on(Selector sel, Consumer<E> consumer) {
throw new UnsupportedOperationException("Events of type [Selector] are no longer supported. Use string ids")
}

/**
* @see reactor.bus.Bus#notify(java.lang.Object, java.lang.Object)
*/
@CompileDynamic
Bus notify(Object key, Event<?> ev) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
if(eventBus == null) throw new IllegalStateException("EventBus not present. Event notification attempted outside of application context.")
if(ev.replyTo) {
eventBus.sendAndReceive( ev ) {
eventBus.notify(ev.replyTo.toString(), it)
}
}
else {
eventBus.notify key, ev
}
return eventBus
}

/**
* @see reactor.bus.Bus#notify(java.lang.Object, reactor.bus.Event)
*/
Bus notify(Object key, data) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
eventBus.notify Event.from(key.toString(), data)
return eventBus
}

def <E extends Event<?>> Bus notify(Object key, Closure<E> supplier) {
if(eventBus == null) throw new IllegalStateException("EventBus not present. Event notification attempted outside of application context.")
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
eventBus.notify( (CharSequence)key.toString(), supplier.call() )
return eventBus
}

Bus sendAndReceive(Object key, data, Closure reply) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
eventBus.sendAndReceive(key.toString(), data, reply)
return eventBus
}

def <E extends Event<?>> Bus sendAndReceive(Object key, Closure reply) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
eventBus.sendAndReceive key.toString(), new grails.events.Event(key.toString(), new Object[0]), reply
return eventBus
}



/**
* Creates an {@link Event} for the given data
*
* @param data The data
* @return The event
*/
def <T> Event<T> eventFor(T data) {
throw new UnsupportedOperationException("Use [grails.events.Event] instead")
}

/**
* Creates an {@link Event} for the given headers and data
*
* @param headers The headers
* @param data The data
* @return The event
*/
def <T> Event<T> eventFor(Map<String, Object> headers, T data) {
throw new UnsupportedOperationException("Use [grails.events.Event] instead")
}

/**
* Creates an {@link Event} for the given headers, data and error consumer
*
* @param headers The headers
* @param data The data
* @param errorConsumer The errors consumer
* @return The event
*/
def <T> Event<T> eventFor(Map<String, Object> headers, T data, Closure<Throwable> errorConsumer) {
throw new UnsupportedOperationException("Use [grails.events.Event] instead")
}

/**
* Clears event consumers for the given key
* @param key The key
* @return True if modifications were made
*/
boolean clearEventConsumers(key) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
if(eventBus) {
eventBus.unsubscribeAll(key.toString())
return true
}
return false
}

}
46 changes: 46 additions & 0 deletions grails-events-compat/src/main/groovy/reactor/bus/Bus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package reactor.bus;

import reactor.bus.registry.Subscription;
import reactor.bus.selector.Selector;
import reactor.fn.Consumer;

/**
* Basic unit of event handling in Reactor.
*
* @author Jon Brisbin
* @author Stephane Maldini
* @author Andy Wilkinson
* @deprecated Here for compatibility only. Do not use directly
*/
@Deprecated
public interface Bus<T> {

/**
* Are there any {@link Subscription}s with {@link Selector Selectors} that match the given {@code key}.
*
* @param key The key to be matched by {@link Selector Selectors}
* @return {@literal true} if there are any matching {@literal Subscription}s, {@literal false} otherwise
*/
boolean respondsToKey(Object key);

/**
* Register a {@link reactor.fn.Consumer} to be triggered when a notification matches the given {@link
* Selector}.
*
* @param selector The {@literal Selector} to be used for matching
* @param consumer The {@literal Consumer} to be triggered
* @return A {@link Subscription} object that allows the caller to interact with the given mapping
*/
<V extends T> Subscription<Object, Consumer<? extends T>> on(final Selector selector,
final Consumer<V> consumer);


/**
* Notify this component that an {@link Event} is ready to be processed.
*
* @param key The key to be matched by {@link Selector Selectors}
* @param ev The {@literal Event}
* @return {@literal this}
*/
Bus notify(Object key, T ev);
}
Loading

0 comments on commit 539bad0

Please sign in to comment.