Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish Kuksa SDK Snapshot Builds to MavenLocal #13

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ android {
applicationId = "org.eclipse.kuksa.testapp"
wba2hi marked this conversation as resolved.
Show resolved Hide resolved
minSdk = 27
targetSdk = 34
versionCode = 1
versionName = "1.0"
versionCode = rootProject.extra["projectVersionCode"].toString().toInt()
versionName = rootProject.extra["projectVersion"].toString()
vectorDrawables {
useSupportLibrary = true
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.incremental.createDirectory
plugins {
base
detekt
version
}

subprojects {
Expand Down
3 changes: 1 addition & 2 deletions buildSrc/src/main/kotlin/detekt.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.withType
import org.eclipse.kuksa.extension.lib

val baselineFile = project.file("$rootDir/config/detekt/baseline.xml")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*
*/

package org.eclipse.kuksa.extension

import org.gradle.api.Project
import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.artifacts.VersionCatalogsExtension
Expand Down
102 changes: 102 additions & 0 deletions buildSrc/src/main/kotlin/org/eclipse/kuksa/util/VersionProperties.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.eclipse.kuksa.util

import java.io.File
import java.io.FileWriter
import java.io.IOException
import java.util.Locale
import java.util.Properties

class VersionProperties(private val filePath: String) {
private val properties: Properties = Properties()

var major: Int
get() = properties.getProperty(KEY_MAJOR).toInt()
set(value) {
properties.put(KEY_MAJOR, value.toString())
}

var minor: Int
get() = properties.getProperty(KEY_MINOR).toInt()
set(value) {
properties.put(KEY_MINOR, value.toString())
}

var patch: Int
get() = properties.getProperty(KEY_PATCH).toInt()
set(value) {
properties.put(KEY_PATCH, value.toString())
}

var suffix: String
get() = properties.getProperty(KEY_SUFFIX)
set(value) {
properties.put(KEY_SUFFIX, value)
}

val version: String
get() {
var version = "$major.$minor.$patch"
if (suffix.isNotEmpty()) {
version += "-$suffix"
}
return version
}

val versionCode: Int
wba2hi marked this conversation as resolved.
Show resolved Hide resolved
get() {
val decorator = "10"
val paddedMajorVersion = String.format(Locale.ROOT, "%02d", major)
val paddedMinorVersion = String.format(Locale.ROOT, "%02d", minor)
val paddedPatchVersion = String.format(Locale.ROOT, "%02d", patch)

return "$decorator$paddedMajorVersion$paddedMinorVersion$paddedPatchVersion".toInt()
}

fun load() {
try {
val file = File(filePath)
val inputStream = file.inputStream()

properties.load(inputStream)
} catch (e: IOException) {
System.err.println("Could not load file $filePath: ${e.message}")
}
}

fun store() {
try {
val file = File(filePath)
val fileWriter = FileWriter(file)

properties.store(fileWriter, "Generated by 'store' in VersionProperties.kt")
} catch (e: IOException) {
System.err.print("Could not write file $filePath: ${e.message}")
}
}

private companion object {
private const val KEY_MAJOR = "MAJOR"
private const val KEY_MINOR = "MINOR"
private const val KEY_PATCH = "PATCH"
private const val KEY_SUFFIX = "SUFFIX"
}
}
35 changes: 35 additions & 0 deletions buildSrc/src/main/kotlin/publish.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

plugins {
`maven-publish`
}

afterEvaluate {
publishing {
repositories {
// to be defined
}
publications {
register<MavenPublication>("release") {
from(components["release"])
}
}
}
}
68 changes: 68 additions & 0 deletions buildSrc/src/main/kotlin/version.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import org.eclipse.kuksa.util.VersionProperties

val properties = VersionProperties("$rootDir/version.properties")
properties.load()

rootProject.extra["projectVersion"] = properties.version
rootProject.extra["projectVersionCode"] = properties.versionCode

tasks.register("increaseMajorVersion") {
group = "version"
doLast {
properties.major += 1
wba2hi marked this conversation as resolved.
Show resolved Hide resolved
properties.minor = 0
properties.patch = 0
properties.store()
}
}

tasks.register("increaseMinorVersion") {
group = "version"
doLast {
properties.minor += 1
wba2hi marked this conversation as resolved.
Show resolved Hide resolved
properties.patch = 0
properties.store()
}
}

tasks.register("increasePatchVersion") {
group = "version"
doLast {
properties.patch += 1
properties.store()
}
}

tasks.register("setReleaseVersion") {
group = "version"
doLast {
properties.suffix = ""
properties.store()
}
}

tasks.register("setSnapshotVersion") {
group = "version"
doLast {
properties.suffix = "SNAPSHOT"
properties.store()
}
}

tasks.register("printVersion") {
group = "version"
doLast {
val version = properties.version

println("VERSION=$version")
}
}

tasks.register("printVersionCode") {
group = "version"
doLast {
val versionCode = properties.versionCode

println("VERSION_CODE=$versionCode")
}
}
6 changes: 5 additions & 1 deletion kuksa-sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ plugins {
id("org.jetbrains.kotlin.android")

id("com.google.protobuf")
publish
}

group = "org.eclipse.kuksa"
version = rootProject.extra["projectVersion"].toString()

android {
namespace = "com.etas.kuksa.sdk"
namespace = "org.eclipse.kuksa"
compileSdk = 33

defaultConfig {
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pluginManagement {
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenLocal()
google()
mavenCentral()
}
Expand Down
6 changes: 6 additions & 0 deletions version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Generated by 'storeVersionProperties' in version.gradle.kts
#Thu Sep 14 08:52:28 CEST 2023
MAJOR=0
MINOR=1
PATCH=0
SUFFIX=SNAPSHOT