diff --git a/README.md b/README.md index 0cfae88e..220079f0 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,16 @@ A Vertx framework for microservice +![build](https://github.com/zero88/msa-blueprint/workflows/build/badge.svg?branch=master) +![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/zero88/msa-blueprint?sort=semver) +![Sonatype Nexus (Releases)](https://img.shields.io/nexus/r/io.github.zero88/msa-blueprint?server=https%3A%2F%2Foss.sonatype.org%2F) +![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/io.github.zero88/msa-blueprint?server=https%3A%2F%2Foss.sonatype.org%2F) + +[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=zero88_msa-blueprint&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=zero88_msa-blueprint) +[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=zero88_msa-blueprint&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=zero88_msa-blueprint) +[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=zero88_msa-blueprint&metric=security_rating)](https://sonarcloud.io/dashboard?id=zero88_msa-blueprint) +[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=zero88_msa-blueprint&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=zero88_msa-blueprint) +[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=zero88_msa-blueprint&metric=coverage)](https://sonarcloud.io/dashboard?id=zero88_msa-blueprint) + + ## Overview diff --git a/base/gradle.properties b/base/gradle.properties new file mode 100644 index 00000000..7d469325 --- /dev/null +++ b/base/gradle.properties @@ -0,0 +1,2 @@ +title=MSA BP Base +description=This module declares and defines core functionality microservices diff --git a/build.gradle.kts b/build.gradle.kts index 2b524d6c..9f46a187 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,9 +13,10 @@ plugins { } val jacocoHtml: String? by project val semanticVersion: String by project +val buildHash: String by project allprojects { - group = "io.github.zero88" + group = "io.github.zero88.msa.bp" repositories { mavenLocal() @@ -34,6 +35,10 @@ subprojects { apply(plugin = "signing") apply(plugin = "maven-publish") project.version = "$version$semanticVersion" + project.group = ProjectUtils.computeGroup(project) + project.ext.set("title", findProperty("title") ?: project.name) + project.ext.set("baseName", ProjectUtils.computeBaseName(project)) + project.ext.set("description", findProperty("description") ?: "A Vertx framework for microservice: ${project.name}") java { sourceCompatibility = JavaVersion.VERSION_1_8 @@ -54,9 +59,19 @@ subprojects { tasks { jar { + doFirst { + println("- Project Name: ${project.ext.get("baseName")}") + println("- Project Title: ${project.ext.get("title")}") + println("- Project Group: ${project.group}") + println("- Project Artifact: ${project.name}") + println("- Project Version: ${project.version}") + } + + archiveBaseName.set(project.ext.get("baseName") as String) manifest { attributes( - mapOf(Name.IMPLEMENTATION_TITLE.toString() to project.name, + mapOf(Name.MANIFEST_VERSION.toString() to "1.0", + Name.IMPLEMENTATION_TITLE.toString() to archiveBaseName, Name.IMPLEMENTATION_VERSION.toString() to project.version, "Created-By" to GradleVersion.current(), "Build-Jdk" to Jvm.current(), @@ -67,6 +82,7 @@ subprojects { } } javadoc { + title = "${project.ext.get("title")} ${project.version} API" options { this as StandardJavadocDocletOptions tags = mutableListOf("apiNote:a:API Note:", "implSpec:a:Implementation Requirements:", @@ -76,6 +92,10 @@ subprojects { test { useJUnitPlatform() } + + withType().configureEach { + onlyIf { project.hasProperty("release") } + } } publishing { @@ -96,12 +116,12 @@ subprojects { } pom { name.set(project.name) - description.set("A Vertx framework for microservice") - url.set("https://github.com/zero88/blueprint") + description.set(project.ext.get("description") as String) + url.set("https://github.com/zero88/msa-blueprint") licenses { license { name.set("The Apache License, Version 2.0") - url.set("https://github.com/zero88/blueprint/blob/master/LICENSE") + url.set("https://github.com/zero88/msa-blueprint/blob/master/LICENSE") } } developers { @@ -111,9 +131,9 @@ subprojects { } } scm { - connection.set("scm:git:git://git@github.com:zero88/blueprint.git") - developerConnection.set("scm:git:ssh://git@github.com:zero88/blueprint.git") - url.set("https://github.com/zero88/blueprint") + connection.set("scm:git:git://git@github.com:zero88/msa-blueprint.git") + developerConnection.set("scm:git:ssh://git@github.com:zero88/msa-blueprint.git") + url.set("https://github.com/zero88/msa-blueprint") } } } @@ -170,10 +190,6 @@ sonarqube { } } -tasks.withType().configureEach { - onlyIf { project.hasProperty("release") } -} - task("sign") { dependsOn(subprojects.map { it.tasks.withType() }) } diff --git a/buildSrc/src/main/groovy/ProjectUtils.groovy b/buildSrc/src/main/groovy/ProjectUtils.groovy new file mode 100644 index 00000000..8308e6be --- /dev/null +++ b/buildSrc/src/main/groovy/ProjectUtils.groovy @@ -0,0 +1,54 @@ +import org.gradle.api.Project + +class ProjectUtils { + + static boolean isSubProject(Project project, String projectName) { + if (project.parent == null) { + return project.name == projectName + } + return project.parent.name == projectName || isSubProject(project.parent, projectName) + } + + static String computeGroup(Project project) { + if (project.parent == null) { + return project.group + } + def suffix = project.parent == project.rootProject ? "" : ("." + project.parent.name) + return computeGroup(project.parent) + suffix + } + + static String computeBaseName(Project project) { + return computeProjectName(project, "-") + } + + static String computeDockerName(Project project) { + return computeProjectName(project, "-", "/") + } + + def static loadSecretProps(Project project, secretFile) { + def sf = new File(secretFile.toString()) + if (sf.exists()) { + def props = new Properties() + sf.withInputStream { props.load(it) } + props.findAll { Strings.isBlank(extraProp(project, it.key.toString())) } + .each { k, v -> project.ext.set(k, v) } + } + } + + static String extraProp(Project project, String key) { + return extraProp(project, key, null) + } + + static String extraProp(Project project, String key, String fallback) { + return project.ext.has(key) && !Strings.isBlank((String) project.ext.get(key)) ? (String) project.ext.get(key) : + fallback + } + + private static String computeProjectName(Project project, String sep, String firstSep = null) { + if (project.parent == null) { + return extraProp(project, "baseName", project.name) + } + final def s = project.parent.parent == null && firstSep ? firstSep : sep + return computeProjectName(project.parent, sep, firstSep) + s + project.name + } +} diff --git a/buildSrc/src/main/groovy/Strings.groovy b/buildSrc/src/main/groovy/Strings.groovy new file mode 100644 index 00000000..a049bbfc --- /dev/null +++ b/buildSrc/src/main/groovy/Strings.groovy @@ -0,0 +1,39 @@ + + +class Strings { + + static boolean isBlank(String text) { + return text == null || "" == text.trim() + } + + static String requireNotBlank(String text) { + return requireNotBlank(text, "Not blank") + } + + static String requireNotBlank(String text, String message) { + if (isBlank(text)) { + throw new IllegalArgumentException(message) + } + return text.trim() + } + + static String toSnakeCase(String text, boolean upper = true) { + if (upper && text == text.toUpperCase()) { + return text + } + if (!upper && text == text.toLowerCase()) { + return text + } + def regex = upper ? "A-Z" : "a-z" + def t = text.replaceAll(/([$regex])/, /_$1/).replaceAll(/^_/, '') + return upper ? t.toUpperCase() : t.toLowerCase() + } + + static String replaceJsonSuffix(String name) { + return name.replaceAll(toRegexIgnoreCase("_JSON(_ARRAY)?|_ARRAY\$"), "") + } + + static String toRegexIgnoreCase(String name) { + return "(?i:${name})" + } +} diff --git a/cache/gradle.properties b/cache/gradle.properties new file mode 100644 index 00000000..18443d1e --- /dev/null +++ b/cache/gradle.properties @@ -0,0 +1,2 @@ +title=MSA BP Cache +description=This module declares and defines microservice cache diff --git a/gradle.properties b/gradle.properties index ad86b8f6..a164a247 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.parallel=true # Project properties -------------------------- version=0.5.1 -semanticVersion=-SNAPSHOT +semanticVersion= buildBy=local buildHash= diff --git a/http/client/gradle.properties b/http/client/gradle.properties new file mode 100644 index 00000000..2ecc6c39 --- /dev/null +++ b/http/client/gradle.properties @@ -0,0 +1,2 @@ +title=MSA BP HTTP Client +description=This module declares and defines microservice HTTP Client diff --git a/http/gradle.properties b/http/gradle.properties new file mode 100644 index 00000000..beaa0211 --- /dev/null +++ b/http/gradle.properties @@ -0,0 +1,2 @@ +title=MSA BP HTTP +description=This module declares and defines microservice base HTTP functional diff --git a/http/server/gradle.properties b/http/server/gradle.properties new file mode 100644 index 00000000..4a0be787 --- /dev/null +++ b/http/server/gradle.properties @@ -0,0 +1,2 @@ +title=MSA BP HTTP Server +description=This module declares and defines microservice HTTP server diff --git a/micro/gradle.properties b/micro/gradle.properties new file mode 100644 index 00000000..2923ded5 --- /dev/null +++ b/micro/gradle.properties @@ -0,0 +1,2 @@ +title=MSA BP Micro +description=This module declares and defines microservice service discovery