100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
import java.security.MessageDigest
import javax.annotation.processing.Processor
import javax.tools.ToolProvider
plugins {
id 'java'
id 'maven-publish'
id 'signing'
}
sourceSets {
main {
output.dir(layout.buildDirectory.dir("classes/main"), builtBy: "generateSources")
}
}
base {
archivesName = "openremote-${project.name}"
}
java {
withJavadocJar()
withSourcesJar()
}
publishing {
publications {
maven(MavenPublication) {
group = "io.openremote.ui"
artifactId = "openremote-${project.name}"
from components.java
pom {
name = 'OpenRemote Shared UI Files'
description = 'Provides the files shared between OpenRemote UIs'
url = 'https://github.com/openremote/core'
licenses {
license {
name = 'GNU Affero General Public License v3.0'
url = 'https://www.gnu.org/licenses/agpl-3.0.en.html'
}
}
developers {
developer {
id = 'developers'
name = 'Developers'
email = '[email protected]'
organization = 'OpenRemote'
organizationUrl = 'https://openremote.io'
}
}
scm {
connection = 'scm:git:git://github.com/openremote/core.git'
developerConnection = 'scm:git:ssh://github.com:openremote/core.git'
url = 'https://github.com/openremote/core/tree/main'
}
}
}
}
repositories {
maven {
if (!version.endsWith('-LOCAL')) {
credentials {
username = findProperty("publishUsername")
password = findProperty("publishPassword")
}
}
url = version.endsWith('-LOCAL') ? layout.buildDirectory.dir('repo') : version.endsWith('-SNAPSHOT') ? findProperty("snapshotsRepoUrl") : findProperty("releasesRepoUrl")
}
}
}
signing {
def signingKey = findProperty("signingKey")
def signingPassword = findProperty("signingPassword")
if (signingKey && signingPassword) {
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.maven
}
}
def cacheDir = layout.projectDirectory.dir("cache").asFile
def openMapTilesFontsVersion = "v2.0"
def openMapTilesFontsZip = new File(cacheDir, "openmaptiles-fonts-${openMapTilesFontsVersion}.zip")
def openMapTilesFontsZipSha256 = "3a7a6c2dcd940a840aa6ffac8f39758252a667a0b329945b071fb44bf00e7f47"
tasks.register('downloadOpenMapTilesFontsZip') {
// Mark the downloaded file as the output (for Gradle caching)
outputs.file openMapTilesFontsZip
// Mark version and package name as inputs (if they change, redownload)
inputs.property("openMapTilesFontsVersion", openMapTilesFontsVersion)
inputs.property("openMapTilesFontsZipSha256", openMapTilesFontsZipSha256)
doLast {
def verifyChecksum = { file, expectedSha256 ->
if (!file.exists()) {
return false
}
def digest = MessageDigest.getInstance("SHA-256")
file.withInputStream { is ->
byte[] buffer = new byte[8192]
int read = 0
while ((read = is.read(buffer)) > 0) {
digest.update(buffer, 0, read)
}
}
def actual = digest.digest().collect { String.format("%02x", it) }.join()
return actual.equalsIgnoreCase(expectedSha256)
}
def needDownload = !verifyChecksum(openMapTilesFontsZip, openMapTilesFontsZipSha256)
def url = "https://github.com/openmaptiles/fonts/releases/download/${openMapTilesFontsVersion}/${openMapTilesFontsVersion}.zip"
if (needDownload) {
cacheDir.mkdirs()
logger.lifecycle("Downloading OpenMapTiles Fonts ${openMapTilesFontsVersion} ...")
try {
new URI(url).toURL().openStream().withCloseable { is ->
openMapTilesFontsZip.withOutputStream { os ->
is.transferTo(os)
}
}
} catch (Exception e) {
throw new GradleException("Failed to download OpenMapTiles Fonts from ${url}", e)
}
} else {
logger.lifecycle("Using cached ${openMapTilesFontsZip.name}")
}
}
}
tasks.register('extractOpenMapTilesFontsZip', Copy) {
dependsOn downloadOpenMapTilesFontsZip
def fontNames = ["Open Sans Bold", "Open Sans Italic", "Open Sans Regular", "Open Sans Semibold"]
from(zipTree(openMapTilesFontsZip)) {
include fontNames.collect(({ "${it}/**" } as Closure<String>))
}
def outputDir = layout.projectDirectory.dir("fonts").asFile
into outputDir
doLast {
def missingFonts = fontNames.findAll { fontDir -> !new File(outputDir, fontDir).exists() }
if (!missingFonts.isEmpty()) {
throw new GradleException("Font extraction failed: missing font directories: ${missingFonts.join(', ')}")
} else {
logger.lifecycle("All expected font directories extracted: ${fontNames.join(', ')}")
}
// Gzip PBF font files
outputDir.eachFileRecurse { file ->
if (file.isFile()) {
def tempGz = new File(file.parentFile, file.name + ".gz")
ant.gzip(src: file, destfile: tempGz)
file.delete()
tempGz.renameTo(file)
}
}
}
}
tasks.register('generateSources', Copy) {
dependsOn extractOpenMapTilesFontsZip
from fileTree(projectDir) {
exclude 'build.gradle'
exclude 'build/**'
exclude 'cache/**'
}
into layout.buildDirectory.dir("classes/main/org/openremote/web/${project.name}")
}
tasks.register('installDist', Copy) {
dependsOn generateSources
mustRunAfter ":manager:installDist"
from layout.buildDirectory.dir("classes/main/org/openremote/web/${project.name}")
into project(':manager').layout.buildDirectory.dir("install/manager/web/${project.name}")
}
tasks.register('processTranslations', JavaCompile) {
dependsOn(":agent:classes")
dependsOn(":model:classes")
outputs.upToDateWhen { false } // Always invalidate
def agentSourceSet = project(":agent").sourceSets.main
def modelSourceSet = project(":model").sourceSets.main
source = files(agentSourceSet.allJava, modelSourceSet.allJava)
classpath = files(agentSourceSet.compileClasspath, modelSourceSet.compileClasspath)
destinationDirectory = layout.buildDirectory.dir("generated/i18n") // unused
options.compilerArgs += [
"-proc:only",
// Only run the processor
"-processor",
"org.openremote.model.util.I18nAnnotationProcessor",
"-Ashared=${project.getProjectDir()}".toString()
]
// Pass classpath to compiler
options.annotationProcessorPath = modelSourceSet.output + modelSourceSet.compileClasspath
}
jar.dependsOn(generateSources)
gradle.startParameter.excludedTaskNames += ["${project.path}:test".toString()]