Skip to content
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
21 changes: 21 additions & 0 deletions .github/workflows/gradle_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish package to GitHub Packages
on: workflow_dispatch
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v5
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@017a9effdb900e5b5b2fddfb590a105619dca3c3 # v4.4.2

- name: Publish package
run: ./gradlew publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,45 @@ You can also go to this [Demo Page](http://opensensorhub.github.io/osh-js/latest

This other [Technical Page](http://sensiasoft.net:8181/demo.html) contains example SWE service calls for you to see the standard compliant XML and data that OSH generates.

If using a build system, binaries for osh-core are stored in GitHub Packages. Use the following repository setup to resolve dependencies:

### Gradle

```groovy
//build.gradle
repositories {
maven {
url = uri("https://maven.pkg.github.com/opensensorhub/osh-core")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
```
### Maven
```xml
<!--pom.xml-->
<repositories>
<repository>
<id>osh-core</id>
<name>osh-core</name>
<url>https://maven.pkg.github.com/opensensorhub/osh-core</url>
</repository>
</repositories>
```
```xml
<!--~/.m2/settings.xml-->
<servers>
<server>
<id>osh-core</id>
<username>${env.GITHUB_ACTOR}</username>
<password>${env.GITHUB_TOKEN}</password>
</server>
</servers>
```
Where environment variables `GITHUB_ACTOR` and `GITHUB_TOKEN` are your GitHub username and PAT respectively.<br>
[Instructions on how to generate PATs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)

## Building

Expand Down
87 changes: 57 additions & 30 deletions common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ buildscript {
}
}

allprojects {

allprojects {
group = 'org.sensorhub'

repositories {
maven { url "https://repo.maven.apache.org/maven2" }
mavenCentral()
}

// set build number to HEAD SHA-1
def stdout = new ByteArrayOutputStream()
exec {
commandLine('git','rev-parse','--short','HEAD')
standardOutput = stdout
// hide errors and don't throw exception if not a git repo
errorOutput = new ByteArrayOutputStream()
ignoreExitValue = true
commandLine('git', 'rev-parse', '--short', 'HEAD')
standardOutput = stdout
// hide errors and don't throw exception if not a git repo
errorOutput = new ByteArrayOutputStream()
ignoreExitValue = true
}
ext.buildNumber = "$stdout".trim()

Expand Down Expand Up @@ -64,15 +64,15 @@ subprojects {
eclipse {
classpath {
downloadJavadoc = true
file.whenMerged {
file.whenMerged {
entries.each {
if (it.hasProperty('exported'))
it.exported = true
}
}
}
}

// custom dependency configurations for embedding jars in OSGi bundle
configurations {
embeddedApi
Expand All @@ -82,13 +82,13 @@ subprojects {
api.extendsFrom(embeddedApi)
implementation.extendsFrom(embeddedImpl)
}

// default test dependencies
dependencies {
testImplementation 'junit:junit:4.13'
testImplementation 'xmlunit:xmlunit:1.6'
}

// print test names
test {
testLogging {
Expand Down Expand Up @@ -118,8 +118,8 @@ subprojects {
ext.getPackagesFromJar = { jarFile, packageSet ->
//println jarFile
FileSystems.newFileSystem(jarFile.toPath(), ClassLoader.getSystemClassLoader()).withCloseable { fs ->
def rootDir = fs.getPath('/')
getPackagesFromDir(rootDir, packageSet)
def rootDir = fs.getPath('/')
getPackagesFromDir(rootDir, packageSet)
}
}

Expand All @@ -141,24 +141,26 @@ subprojects {
// of the manifest files
if (rootDir.relativize(dir).toString().contains('\\')) {
packageSet.add(rootDir.relativize(dir).toString()
.replace('\\', '.') + '.*')
.replace('\\', '.') + '.*')
} else {
packageSet.add(rootDir.relativize(dir).toString()
.replace('/', '.') + '.*')
.replace('/', '.') + '.*')
}
}
}
}

// help method to automatically find osgi activator class
ext.findActivator = {
for (def classDir: sourceSets.main.output.classesDirs) {
for (def classDir : sourceSets.main.output.classesDirs) {
def rootDir = classDir.toPath()
def activatorClass = Files.walk(rootDir)
.filter { it.toString().endsWith('Activator.class') }
.map { rootDir.relativize(it).toString()
.replace(java.io.File.separatorChar, (char)'.')
.replaceAll('.class$', '') }
.map {
rootDir.relativize(it).toString()
.replace(java.io.File.separatorChar, (char) '.')
.replaceAll('.class$', '')
}
.findAny()
.orElse(null)
if (activatorClass)
Expand All @@ -176,10 +178,10 @@ subprojects {

// ignore some common errors
attributes '-fixupmessages': 'Classes found in the wrong directory; is:=ignore,' +
'Unused Import-Package instructions; is:=ignore,' +
'The default package \'.\' is not permitted by the Import-Package syntax; is:=ignore,' +
'Unused Export-Package instructions; is:=ignore,'
'Unused Import-Package instructions; is:=ignore,' +
'The default package \'.\' is not permitted by the Import-Package syntax; is:=ignore,' +
'Unused Export-Package instructions; is:=ignore,'

// disable DS annotation processing
if (!attributes['-dsannotations'])
attributes '-dsannotations': '!*'
Expand Down Expand Up @@ -292,9 +294,23 @@ subprojects {

assemble.dependsOn osgi

tasks.register('prePublish') {
if (System.getenv("GITHUB_ACTOR") == null) {
throw new Exception("Environment variable GITHUB_ACTOR not set. Please set to your github username.")
}

if (System.getenv("GITHUB_TOKEN") == null) {
throw new Exception("Environment variable GITHUB_TOKEN not set. Please generate and set to your personal access token: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens")
}
}

tasks.named('publish') { // This is a lifecycle task that runs all publish tasks
dependsOn 'prePublish'
}

// do stuff at the end in case subprojects add extra info
afterEvaluate { project ->

// set defaults for some OSGi manifest entries
project.osgi {
manifest {
Expand All @@ -320,9 +336,10 @@ subprojects {
from project.osgi.manifest
}
}

// maven artifact content
project.publishing {

publications {
mavenJava(MavenPublication) {
from components.java
Expand Down Expand Up @@ -352,20 +369,30 @@ subprojects {
} >> project.pom)
}
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/opensensorhub/osh-core"
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
}

// disable jar task if no source is included
if (!new File(project.projectDir, 'src').exists()) {
tasks.osgi.enabled = false
tasks.osgi.enabled = false
tasks.jar.enabled = false
}

// custom task to install in local maven repo
task install
install.dependsOn(build)
install.dependsOn(publishToMavenLocal)
install.dependsOn(publishToMavenLocal)
}


Expand Down
Loading