Skip to content

Commit

Permalink
Make it uploadable to the Maven Central
Browse files Browse the repository at this point in the history
  • Loading branch information
new-mikha committed Dec 12, 2019
1 parent 1aa4cf2 commit d532027
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 29 deletions.
10 changes: 7 additions & 3 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
## The library contains ReplayRemoveSubject - an addition to RxJava 2 ##

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.new-mikha/rxhelpers/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.new-mikha/rxhelpers)

The subject works like a `ReplaySubject`, but it also allows to remove elements from the buffer so late observers do not see removed ones, and the buffer size can be limited manually.

It can be useful in scenarios where e.g. a cold observable of an updatable database is required. Notice that the buffer is distinct (see details below)


### Installation ###
Can be built by running `./gradlew` (`gradlew` on Windows) from the working directory. Result is a JAR file in build\libs directory, with POM and sources generated too, so it's easy to either use JAR directly or upload JAR's and POM to an organisation-specific repository first.
- Can be found in the [Maven Central, with groupId `io.github.new-mikha` and name `rxhelpers`](https://search.maven.org/artifact/io.github.new-mikha/rxhelpers)

- Can be built from sources by running `./gradlew` (`gradlew` on Windows) from the working directory. Result is a JAR file in `build\libs` directory

Or simply take the whole src/main/java/rxhelpers folder into your project - just don't forget to add a reference to your NOTICES file and keep the original license headers, in according to the Apache License used here.
- Or simply take the whole `src/main/java/rxhelpers` directory into your project - just don't forget to add a reference to your NOTICES file and keep the original license headers, in according to the Apache License used here

### Usage ###
The subject has a variety of methods to get combinations of snapshot, inserts, updates, and removal events, but in a simplest way it looks like this:
Expand All @@ -19,8 +23,8 @@ The subject has a variety of methods to get combinations of snapshot, inserts, u
subject.onNext(2);
subject.onNext(3);
subject.subscribe(x -> System.out.println("SubscrA: " + x));
// So far it's the same as ReplaySubject: output above is 1, 2, 3
System.out.println("(I) ----");
// So far it's the same as ReplaySubject: output above (I) is 1, 2, 3

subject.onRemove(2); // onRemove() is a new method
subject.subscribe(x -> System.out.println("SubscrB: " + x));
Expand Down
82 changes: 64 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ plugins {
id 'java'
id 'java-library'
id 'maven'
id 'signing'
}

project.version = '1.0.0'
group = 'org.flytrace'
def projectFileName = "${project.name}"

version = '1.0.0'
project.version = version
group = 'io.github.new-mikha'
archivesBaseName = projectFileName
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

defaultTasks 'clean', 'build'

Expand All @@ -20,28 +26,23 @@ repositories {
jcenter()
}

def projectFileName = "${project.name}-${project.version}"

jar {
archiveFileName = "${projectFileName}.jar"
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
}

task writePom {
doLast {
pom {
}.writeTo("$buildDir/libs/${projectFileName}.pom")
}
task javadocJar(type: Jar, dependsOn: classes) {
archiveClassifier.set('javadoc')
from sourceSets.main.allSource
}

build.dependsOn(writePom)

task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
artifacts {
archives javadocJar, sourcesJar
}

artifacts {
archives sourcesJar
signing {
required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}

dependencies {
Expand All @@ -53,3 +54,48 @@ dependencies {
testImplementation 'junit:junit:4.12'
testImplementation "org.mockito:mockito-core:2.1.0"
}

uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: project.findProperty("nexusUsername"), password: project.findProperty("nexusPassword"))
}

snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: project.findProperty("nexusUsername"), password: project.findProperty("nexusPassword"))
}

pom.project {
name 'rxhelpers'
packaging 'jar'
// optionally artifactId can be defined here
description 'Add-ons for RxJava2, currently contains ReplayRemoveSubject that allows to remove replayable items from the buffer'
url 'https://github.com/new-mikha/rxhelpers'

scm {
connection 'scm:git:https://github.com/new-mikha/rxhelpers'
developerConnection 'scm:git:https://github.com/new-mikha/rxhelpers'
url 'https://github.com/new-mikha/rxhelpers'
}

licenses {
license {
name 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}

developers {
developer {
id 'new-mikha'
name 'Michael Karmazin'
email 'm.karmazin@gmail.com'
}
}
}
}
}
}
6 changes: 4 additions & 2 deletions src/main/java/rxhelpers/ReplayRemoveSubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ public void onSubscribe(Disposable d) {


/**
* A thread-safety note - this method and {@link ##onRemove} can be called simultaneously from different threads.
* A thread-safety note - this method and {@link #onRemove} can be called simultaneously from different threads.
* @param t
*/
@Override
public void onNext(T t) {
Expand All @@ -243,7 +244,8 @@ public void onNext(T t) {


/**
* A thread-safety note - this method and {@link ##onNext(T)} can be called simultaneously from different threads.
* A thread-safety note - this method and {@link #onNext} can be called simultaneously from different threads.
* @param t
*/
@SuppressWarnings("unused")
public void onRemove(T t) {
Expand Down
13 changes: 7 additions & 6 deletions src/test/java/rxhelpers/Demo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@ public class Demo {

@Test
public void mainUseCaseDemo() {

ReplayRemoveSubject<Integer> subject = ReplayRemoveSubject.create();

subject.subscribe(x -> System.out.println("SubscrA: " + x));
subject.onNext(1);
subject.onNext(2);
subject.onNext(3);
// output: 1, 2, 3
subject.subscribe(x -> System.out.println("SubscrA: " + x));
System.out.println("(I) ----");
// So far it's the same as ReplaySubject: output above (I) is 1, 2, 3

subject.onRemove(2);
subject.subscribe(x -> System.out.println("SubscrB: " + x)); // output: 1, 3
subject.onRemove(2); // onRemove() is a new method
subject.subscribe(x -> System.out.println("SubscrB: " + x));
System.out.println("(II) ----");
// output between (I) and (II): 1, 3 (all from SubscrB)

subject.onNext(4);
// output: 4, 4
// output after (II): 4, 4 (one from SubscrA, other from SubscrB)
}


Expand Down

0 comments on commit d532027

Please sign in to comment.