Merge pull request #8 from Izakey/FINCN115

Migrate rhythm from MariaDB to PostgreSQL
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..a3b6dc5
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,7 @@
+LICENSE
+README.md
+docs/
+HEADER
+NOTICE.txt
+.git/
+.gitignore
diff --git a/.gitignore b/.gitignore
index cc730d5..7069aef 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,3 +18,5 @@
 *.log
 
 *.toDelete
+
+*.jar
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..758a6f7
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,33 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+#
+language: java
+sudo: false
+jdk:
+- openjdk8
+install: true
+script: "./travis.sh"
+env:
+  global:
+    - BUILD_SNAPSHOTS_BRANCH=develop
+    - ARTIFACTORY_URL=https://mifos.jfrog.io/mifos
+    - ARTIFACTORY_USER=travis-ci
+    - secure: "l1xWZsribnzO0EpD+RJre6pqujPZ4uq+jCzdz5HH9oWd9j7kAKVH/24Zferi+vUUnMYM+yjghZS3kn3fki0/cpTyD5SPfCMk0E7kJkMnMXoLYw/FqgHc00wciHZbd9FnoaUohI8rxWyW5SIJQSW9tEBGljKGIs+NxX/APEMZVAW6AaRDVw6vO9jL3t+fLi29AqX1lehGi3DiafSh2FrE04pP96L9A8kKsV3yg3jfPjDXWOfHipjJgl0epSP8UHwIEItsNb25m8TI61erj4HAERCwJFdlHrWPG+laTWapnPBUunCgqN49cowBmAy6Zi5e5FhvAI+mj1YjAP01gbpdFtCSEJDr0k0iZmmzwQvyf84sf883Jlw3XMUWy5RtTt0ZYyap3p1FPGYqfEyUYFexmKmIjJjVEg8apOSDcvdw/Fs+qEbDieg5ibGt7osD1j2M3kt5bilqdgjN+V4tdb3j4/C6TYTarvLXmKZKsZHjHuOa1n7A3KnJBk6ljlJyk3fVwLBnPDxtxxYfjlbRjoSNxYiIfAVFJpDHOdvUaW2HYKkpykDPiVA5j59TSm2LillzDzyuYko/sx1CzlHOdOH0qw1W2dIOvA6qPsZ0snOy4lKvnbn91rucBrEMGmJu+G6A5YIbNGsGX/r0c85KQ0F03jOOYVt+hlKfm57TfAr3HEc="
+after_failure:
+  - ./gradlew rat
+  - cat api/build/reports/rat/rat-report.txt
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..af26daa
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,39 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+#
+FROM openjdk:8-jdk-alpine AS builder
+RUN mkdir builddir
+COPY . builddir
+WORKDIR builddir
+RUN ./gradlew publishToMavenLocal
+
+
+FROM openjdk:8-jdk-alpine AS runner
+
+ARG rhythm_port=2022
+
+ENV server.max-http-header-size=16384 \
+    cassandra.clusterName="Test Cluster" \
+    rhythm.beatCheckRate=10 \
+    rhythm.user=imhotep \
+    server.port=$rhythm_port
+
+WORKDIR /tmp
+COPY --from=builder /builddir/service/build/libs/service-0.1.0-BUILD-SNAPSHOT-boot.jar ./rhythm-service-boot.jar
+
+CMD ["java", "-jar", "rhythm-service-boot.jar"]
diff --git a/README.md b/README.md
index 74b868a..fdc997a 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Apache Fineract CN Rhythm
+# Apache Fineract CN Rhythm [![Build Status](https://api.travis-ci.com/apache/fineract-cn-rhythm.svg?branch=develop)](https://travis-ci.com/apache/fineract-cn-rhythm)
 
 This project provides a heart beatPublish for other services which need to start jobs to be executed once and only once at a defined time.
 
diff --git a/api/build.gradle b/api/build.gradle
index 5b9924a..a11f487 100644
--- a/api/build.gradle
+++ b/api/build.gradle
@@ -28,6 +28,7 @@
 plugins {
     id "com.github.hierynomus.license" version "0.13.1"
     id("org.nosphere.apache.rat") version "0.3.1"
+    id "com.jfrog.artifactory" version "4.9.5"
 }
 
 apply from: '../shared.gradle'
@@ -51,7 +52,7 @@
             from components.java
             groupId project.group
             artifactId project.name
-            version project.version
+            version project.findProperty('externalVersion') ?: project.version
         }
     }
 }
diff --git a/build.gradle b/build.gradle
index fb912e0..362938b 100644
--- a/build.gradle
+++ b/build.gradle
@@ -46,6 +46,15 @@
     dependsOn publishComponentTestToMavenLocal
 }
 
+task artifactoryPublish {
+    group 'all'
+    dependsOn publishToMavenLocal
+    dependsOn gradle.includedBuild('api').task(':artifactoryPublish')
+    dependsOn gradle.includedBuild('spi').task(':artifactoryPublish')
+    dependsOn gradle.includedBuild('service').task(':artifactoryPublish')
+    dependsOn gradle.includedBuild('component-test').task(':artifactoryPublish')
+}
+
 task prepareForTest {
     group 'all'
     dependsOn publishToMavenLocal
diff --git a/component-test/build.gradle b/component-test/build.gradle
index 0f34ef6..1b76ae6 100644
--- a/component-test/build.gradle
+++ b/component-test/build.gradle
@@ -33,6 +33,7 @@
 plugins {
     id "com.github.hierynomus.license" version "0.13.1"
     id("org.nosphere.apache.rat") version "0.3.1"
+    id "com.jfrog.artifactory" version "4.9.5"
 }
 apply from: '../shared.gradle'
 apply plugin: 'org.asciidoctor.convert'
@@ -60,8 +61,9 @@
 
 publishing {
     publications {
-        mavenJava(MavenPublication) {
+        componentTest(MavenPublication) {
             from components.java
+            version project.findProperty('externalVersion') ?: project.version
         }
     }
 }
diff --git a/service/build.gradle b/service/build.gradle
index dc36627..d44e64a 100644
--- a/service/build.gradle
+++ b/service/build.gradle
@@ -32,6 +32,7 @@
 plugins {
     id "com.github.hierynomus.license" version "0.13.1"
     id("org.nosphere.apache.rat") version "0.3.1"
+    id "com.jfrog.artifactory" version "4.9.5"
 }
 
 apply from: '../shared.gradle'
@@ -71,14 +72,14 @@
             from components.java
             groupId project.group
             artifactId project.name
-            version project.version
+            version project.findProperty('externalVersion') ?: project.version
         }
         bootService(MavenPublication) {
             // "boot" jar
             artifact ("$buildDir/libs/$project.name-$version-boot.jar")
             groupId project.group
             artifactId ("$project.name-boot")
-            version project.version
+            version project.findProperty('externalVersion') ?: project.version
         }
     }
 }
diff --git a/shared.gradle b/shared.gradle
index 97d5baa..ab5ef82 100644
--- a/shared.gradle
+++ b/shared.gradle
@@ -45,6 +45,7 @@
 repositories {
     jcenter()
     mavenLocal()
+    maven { url 'https://mifos.jfrog.io/mifos/libs-snapshot/' }
 }
 
 dependencyManagement {
@@ -75,6 +76,22 @@
     from sourceSets.main.allSource
 }
 
+artifactory {
+    contextUrl = System.getenv("ARTIFACTORY_URL")
+    publish {
+        repository {
+            repoKey = project.findProperty('artifactoryRepoKey')
+            username = System.getenv("ARTIFACTORY_USER")
+            password = System.getenv("ARTIFACTORY_PASSWORD")
+        }
+
+        defaults {
+            publications ('api', 'componentTest', 'service', 'bootService', 'spi')
+        }
+    }
+}
+artifactoryPublish.dependsOn('clean','publishToMavenLocal')
+
 license {
     header rootProject.file('../HEADER')
     strictCheck true
@@ -90,12 +107,15 @@
 rat {
     // List of exclude directives, defaults to ['**/.gradle/**']
     excludes = [
+            "**/.dockerignore/**",
             "**/.idea/**",
             "**/.gradle/**",
             "**/gradle/**",
             "**/build/**",
             "gradlew",
             "gradlew.bat",
-            "README.md"
+            "README.md",
+            "**/.dockerignore/**"
     ]
+    plainOutput = true
 }
diff --git a/spi/build.gradle b/spi/build.gradle
index d271f63..aecd058 100644
--- a/spi/build.gradle
+++ b/spi/build.gradle
@@ -28,6 +28,7 @@
 plugins {
     id "com.github.hierynomus.license" version "0.13.1"
     id("org.nosphere.apache.rat") version "0.3.1"
+    id "com.jfrog.artifactory" version "4.9.5"
 }
 
 apply from: '../shared.gradle'
@@ -49,11 +50,11 @@
 
 publishing {
     publications {
-        api(MavenPublication) {
+        spi(MavenPublication) {
             from components.java
             groupId project.group
             artifactId project.name
-            version project.version
+            version project.findProperty('externalVersion') ?: project.version
         }
     }
 }
diff --git a/travis.sh b/travis.sh
new file mode 100755
index 0000000..03a75ee
--- /dev/null
+++ b/travis.sh
@@ -0,0 +1,71 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+#
+
+# Documentation: https://cwiki.apache.org/confluence/display/FINERACT/Fineract-CN+Artifactory
+
+#Exit immediately if a command exits with a non-zero status.
+set -e
+EXIT_STATUS=0
+
+# Builds and Publishes a SNAPSHOT
+function build_snapshot() {
+  echo -e "Building and publishing a snapshot out of branch [$TRAVIS_BRANCH]"
+  ./gradlew -PartifactoryRepoKey=libs-snapshot-local -DbuildInfo.build.number=${TRAVIS_COMMIT::7} artifactoryPublish --stacktrace || EXIT_STATUS=$?
+}
+
+# Builds a Pull Request
+function build_pullrequest() {
+  echo -e "Building pull request #$TRAVIS_PULL_REQUEST of branch [$TRAVIS_BRANCH]. Won't publish anything to Artifactory."
+  ./gradlew publishToMavenLocal rat || EXIT_STATUS=$?
+}
+
+# For other branches we need to add branch name as prefix
+function build_otherbranch() {
+  echo -e "Building a snapshot out of branch [$TRAVIS_BRANCH] and publishing it with prefix '${TRAVIS_BRANCH}-SNAPSHOT'"
+  ./gradlew -PartifactoryRepoKey=libs-snapshot-local -DbuildInfo.build.number=${TRAVIS_COMMIT::7} -PexternalVersion=${TRAVIS_BRANCH}-SNAPSHOT artifactoryPublish --stacktrace || EXIT_STATUS=$?
+}
+
+# Builds and Publishes a Tag
+function build_tag() {
+  echo -e "Building tag [$TRAVIS_TAG] and publishing it as a release"
+  ./gradlew -PartifactoryRepoKey=libs-release-local -PexternalVersion=$TRAVIS_TAG artifactoryPublish --stacktrace || EXIT_STATUS=$?
+
+}
+
+echo -e "TRAVIS_BRANCH=$TRAVIS_BRANCH"
+echo -e "TRAVIS_TAG=$TRAVIS_TAG"
+echo -e "TRAVIS_COMMIT=${TRAVIS_COMMIT::7}"
+echo -e "TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST"
+
+# Build Logic
+if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
+  build_pullrequest
+elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" != "$BUILD_SNAPSHOTS_BRANCH" ] && [ "$TRAVIS_TAG" == "" ]  ; then
+  build_otherbranch
+elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "$BUILD_SNAPSHOTS_BRANCH" ] && [ "$TRAVIS_TAG" == "" ] ; then
+  build_snapshot
+elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ]; then
+  build_tag
+else
+  echo -e "WARN: Unexpected env variable values => Branch [$TRAVIS_BRANCH], Tag [$TRAVIS_TAG], Pull Request [#$TRAVIS_PULL_REQUEST]"
+  ./gradlew clean build
+fi
+
+exit ${EXIT_STATUS}