Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
astrapi69 committed Feb 20, 2023
2 parents 68c9e49 + baa0095 commit 9205901
Show file tree
Hide file tree
Showing 14 changed files with 250 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ your project `build.gradle` if you want to import the core functionality of prop
define version in file gradle.properties

```
propToYamlVersion=2
propToYamlVersion=2.1
```

or in build.gradle ext area

```
propToYamlVersion = "2"
propToYamlVersion = "2.1"
```

then add the dependency to the dependencies area
Expand All @@ -68,7 +68,7 @@ Than you can add the dependency to your dependencies:
<properties>
...
<!-- prop-to-yaml version -->
<prop-to-yaml.version>2</prop-to-yaml.version>
<prop-to-yaml.version>2.1</prop-to-yaml.version>
...
</properties>
...
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
######################
# project properties #
######################
projectVersion=2
projectVersion=2.1
groupPackage=io.github.astrapi69
projectSourceCompatibility=11
projectInceptionYear=2015
Expand Down Expand Up @@ -35,7 +35,7 @@ spotlessGradlePluginVersion=6.15.0
#########################
# dependencies versions #
#########################
kotlinVersion=1.8.20-Beta
kotlinVersion=1.8.10
snakeyamlVersion=1.33
sillyCollectionVersion=21
##############################
Expand Down
8 changes: 8 additions & 0 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.yaml:snakeyaml:$snakeyamlVersion")
implementation("io.github.astrapi69:silly-collection:$sillyCollectionVersion")
testImplementation("io.github.astrapi69:file-worker:$fileWorkerVersion")
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion")
}
17 changes: 17 additions & 0 deletions gradle/formatting.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
spotless {

format "misc", {
// define the files to apply `misc` to
target "*.gradle", "*.md", ".gitignore"

// define the steps to apply to those files
trimTrailingWhitespace()
indentWithSpaces() // or spaces. Takes an integer argument if you don"t like 4
endWithNewline()
}
java {
// export config file: https://github.com/diffplug/spotless/blob/main/ECLIPSE_SCREENSHOTS.md#creating-spotlessimportorder
importOrderFile('src/test/resources/spotless/importorder.properties') // import order file as exported from eclipse
eclipse("4.21.0").configFile("src/test/resources/spotless/alpharo-formatter.xml")
}
}
9 changes: 9 additions & 0 deletions gradle/grgit.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
task tagRelease {
description = "Tags the current head with the project\'s version."
doLast {
grgit.tag.add {
name = "RELEASE-${project.version.toString()}"
message = "New release in version ${version}"
}
}
}
37 changes: 37 additions & 0 deletions gradle/licensing.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
license {
ext.year="$projectInceptionYear"
ext.owner="$projectLeaderName"
ignoreFailures = true
header rootProject.file("src/main/resources/LICENSE.txt")
excludes(["**/README",
"**/README.md",
"**/LICENSE",
"**/NOTICE",
"**/*.xml",
"**/*.xsl",
"**/*.xsd",
"**/*.dtd",
"**/*.html",
"**/*.jsp",
"**/*.jpa",
"**/*.sql",
"**/*.properties",
"**/*.bat",
"**/*.gradle",
"**/*.MF",
"**/*.txt",
"**/*.vm",
"**/*.log",
"**/*.map",
"**/*.js.map",
"**/*.tmpl",
"**/*.js.tmpl",
"**/*.editorconfig",
"src/test/resources/**",
"src/main/resources/**",
"out/**",
"build/**"])
}
// workhack for license issue #76
gradle.startParameter.excludedTaskNames += "licenseMain"
gradle.startParameter.excludedTaskNames += "licenseTest"
18 changes: 18 additions & 0 deletions gradle/packaging.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.text.SimpleDateFormat

jar {
dependsOn(test)
manifest {
attributes(
"Name": project.name,
"Manifest-Version": project.version,
"Implementation-Title": "$groupPackage" + "." + "$rootProject.name",
"Implementation-Version": project.version,
"Implementation-Vendor": "$projectLeaderName",
"Created-By": "Gradle ${gradle.gradleVersion}",
"Built-By": "$projectLeaderName",
"Build-Timestamp": new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
"Build-Jdk": "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
"Build-OS": "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}")
}
}
82 changes: 82 additions & 0 deletions gradle/publishing.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
def releaseVersion = !version.endsWith("SNAPSHOT")

tasks.withType(GenerateModuleMetadata) {
enabled = false
}

task sourcesJar(type: Jar) {
archiveClassifier.set("sources")
from(sourceSets.main.allJava)
}

task javadocJar(type: Jar) {
from javadoc
archiveClassifier.set("javadoc")
javadoc.properties.failOnError = true
}

javadoc {
failOnError = false
if (JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption("html5", true)
}
}

publishing {
publications {
mavenJava(MavenPublication) {
artifactId = "$rootProject.name"
from components.java
artifact sourcesJar
artifact javadocJar
pom {
name = "$rootProject.name"
description = "$projectDescription"
url = "$projectScmProviderUrl" + "$projectHolderUsername" + "$slash" + "$rootProject.name"
organization {
name = "$projectOrganizationName"
url = "$projectOrganizationUrl"
}
issueManagement {
system = "$projectIssueManagementSystem"
url = "$projectScmProviderUrl" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$issuesPath"
}
licenses {
license {
name = "$projectLicenseName"
url = "$projectLicenseUrl"
distribution = "$projectLicenseDistribution"
}
}
developers {
developer {
id = "$projectHolderUsername"
name = "$projectLeaderName"
}
}
scm {
connection = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix"
developerConnection = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix"
url = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix"
}
}
}
}
repositories {
maven {
credentials {
username System.getenv("$projectRepositoriesUserNameKey") ?: project.property("$projectRepositoriesUserNameKey")
password System.getenv("$projectRepositoriesPasswordKey") ?: project.property("$projectRepositoriesPasswordKey")
}
def releasesRepoUrl = "$projectRepositoriesReleasesRepoUrl"
def snapshotsRepoUrl = "$projectRepositoriesSnapshotsRepoUrl"
url = releaseVersion ? releasesRepoUrl : snapshotsRepoUrl
}
}
}

signing {
if (releaseVersion) {
sign publishing.publications.mavenJava
}
}
18 changes: 18 additions & 0 deletions gradle/repositories.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repositories {
mavenLocal()
mavenCentral()
maven {
name "Sonatype Nexus Releases"
url "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
mavenContent {
releasesOnly()
}
}
maven {
name "Sonatype Nexus Snapshots"
url "https://oss.sonatype.org/content/repositories/snapshots"
mavenContent {
snapshotsOnly()
}
}
}
12 changes: 12 additions & 0 deletions gradle/testing.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test {
useJUnitPlatform()
}

jacocoTestReport {
reports {
xml.required.set(true)
html.required.set(true)
}
}

check.dependsOn jacocoTestReport
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ import java.util.*

object PropertiesToYamlConverter {
@JvmStatic
fun convert(file: File): String {
fun convert(content: String): String {
val p = Properties()
val content = String(Files.readAllBytes(Paths.get(file.toURI())))
p.load(StringReader(content))
return convert(p)
}
@JvmStatic
fun convert(file: File): String {
val content = String(Files.readAllBytes(Paths.get(file.toURI())))
return convert(content)
}
@JvmStatic
fun convert(p: Properties): String {
val propertiesMap: MutableMap<String, Collection<String>> = HashMap()
for ((key, value) in p) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import io.github.astrapi69.prop.to.yaml.PropertiesToYamlConverter.convert
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths

class PropertiesToYamlConverterTest {
@Test
Expand Down Expand Up @@ -48,4 +50,35 @@ class PropertiesToYamlConverterTest {
" type: DEVELOPMENT\n"
assertEquals(actual, expected)
}

@Test
fun testConvertPropertiesAsString() {
var expected: String
var actual: String
var propertiesFile = File(PathFinder.getSrcTestResourcesDir(), "config.properties")
var content = String(Files.readAllBytes(Paths.get(propertiesFile.toURI())))
actual = convert(content)
expected = "application:\n" +
" http:\n" +
" port: '18080'\n" +
" https:\n" +
" port: '18443'\n" +
"configuration:\n" +
" type: DEVELOPMENT\n"
assertEquals(actual, expected)

propertiesFile = File(PathFinder.getSrcTestResourcesDir(), "list-or-array.properties")
content = String(Files.readAllBytes(Paths.get(propertiesFile.toURI())))
actual = convert(content)
expected = "application:\n" +
" property:\n" +
" - first\n" +
" - second\n" +
" public-paths:\n" +
" - first: /v1/first\n" +
" second: /v1/second\n" +
" - first: /v1/public/first\n" +
" second: /v1/public/second\n"
assertEquals(actual, expected)
}
}

0 comments on commit 9205901

Please sign in to comment.