Skip to content
Open
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
48 changes: 48 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.gradle
**/build/
!**/src/**/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Avoid ignore Gradle wrappper properties
!gradle-wrapper.properties

# Cache of project
.gradletasknamecache

# Eclipse Gradle plugin generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

.idea
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# OSH Gradle Plugins

Project containing common build files for osh projects, as well as a plugin containing common build tasks

## Usage instructions

### Common Build Files

Include this repository as a git submodule, and use
```
apply from: 'path_to_submodules/osh-gradle-plugins/common/common.gradle'
apply from: 'path_to_submodules/osh-gradle-plugins/common/release.gradle'
```

### Plugin

If pulling in as a submodule, then use `includeBuild path_to_submodules/osh-gradle-plugins` in your `settings.gradle` and declare plugin normally:

```
plugins {
id 'org.sensorhub.osh-plugin'
}
```
or
`apply plugin: 'org.sensorhub.osh-plugin'`

If not pulling in as a submodule, and this plugin is hosted on the gradle plugin repository, then a simple plugin declaration will suffice.
34 changes: 34 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
id 'com.gradle.plugin-publish' version '2.0.0'
id 'java-gradle-plugin'
id 'groovy'
}

group = 'org.sensorhub'
version = '1.0'

repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}

dependencies {
implementation localGroovy()
implementation 'biz.aQute.bnd:biz.aQute.bnd.gradle:6.1.0'
}

gradlePlugin {
website = 'https://opensensorhub.org/'
vcsUrl = 'https://github.com/opensensorhub/osh-gradle-plugins'
plugins {
register('osh-plugin') {
id = 'org.sensorhub.osh-plugin'
displayName = 'OSH Gradle Plugin'
description = 'Gradle tasks for building, publishing and releasing gradle based osh drivers'
tags.addAll('osh', 'opensensorhub')
implementationClass = 'org.sensorhub.OshPlugin'
}
}
}
239 changes: 239 additions & 0 deletions common/common.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
import java.nio.file.*;

ext.oshCoreVersion = '2.0.0'


buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:6.1.0"
}
}


allprojects {
group = 'org.sensorhub'

repositories {
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
}
ext.buildNumber = "$stdout".trim()

afterEvaluate { project ->
if (project.hasProperty('sourceCompatibility')) {
project.sourceCompatibility = 17
project.targetCompatibility = 17
}
}
}


subprojects {
apply plugin: 'java-library'
apply plugin: 'java-test-fixtures'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'org.sensorhub.osh-plugin'

ext.details = null
ext.pom = {} // pom data that subprojects can append to

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:-options"
}

tasks.withType(Javadoc) {
options.encoding = 'UTF-8'
options.addStringOption('Xdoclint:none', '-quiet')
}

eclipse {
classpath {
downloadJavadoc = true
file.whenMerged {
entries.each {
if (it.hasProperty('exported'))
it.exported = true
}
}
}
}

// custom dependency configurations for embedding jars in OSGi bundle
configurations {
embeddedApi
embeddedImpl
embedded
embedded.extendsFrom(embeddedApi, embeddedImpl)
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 {
events 'PASSED', 'FAILED'
showCauses true
showStackTraces true
exceptionFormat 'full'
}
}

assemble.dependsOn osgi

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

// set defaults for some OSGi manifest entries
project.osgi {
manifest {
// main info
attributes 'Bundle-SymbolicName': project.group + '.' + project.name
if (project.description != null && !attributes['Bundle-Name'])
attributes 'Bundle-Name': project.description
if (project.details != null && !attributes['Bundle-Description'])
attributes 'Bundle-Description': project.details
attributes 'Bundle-Version': project.version
if (project.buildNumber != null && !project.buildNumber.isEmpty())
attributes 'Bundle-BuildNumber': project.buildNumber
if (!attributes['Bundle-License'])
attributes 'Bundle-License': 'MPL 2.0 (http://mozilla.org/MPL/2.0)'
if (!attributes['Bundle-Copyright'] && attributes['Bundle-Vendor'])
attributes 'Bundle-Copyright': 'Copyright (c) ' + attributes['Bundle-Vendor'] + '. All Rights Reserved'
}
}

// also use osgi headers in JAR manifest
project.jar {
manifest {
from project.osgi.manifest
}
}

// maven artifact content
project.publishing {

publications {
mavenJava(MavenPublication) {
from components.java
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not seeing the publication of OSGi Bundles - in order to accomplish this automatically this needs to be added

          artifact(p.tasks.osgi) {
              classifier = 'bundle'
          }

pom.withXml {
asNode().get('version') + ({
resolveStrategy = Closure.DELEGATE_FIRST
name project.description
if (project.details != null)
description project.details
url 'http://www.opensensorhub.org'
licenses {
license {
name 'Mozilla Public License Version 2.0'
url 'http://www.mozilla.org/MPL/2.0'
distribution 'repo'
}
}
def repoName = projectDir.parentFile.name
scm {
url 'https://github.com/opensensorhub/' + repoName + '/tree/master/' + project.name
connection 'scm:git:git://github.com/opensensorhub/' + repoName + '.git'
}
issueManagement {
url 'https://github.com/opensensorhub/' + repoName + '/issues'
system 'GitHub Issues'
}
} >> 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")
}
}
}
}

project.tasks.named("generateMetadataFileForMavenJavaPublication") {
doFirst {
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")
}
}
}

project.tasks.named("publishMavenJavaPublicationToGitHubPackagesRepository") {
onlyIf {
//
MavenArtifactRepository repo = repository as MavenArtifactRepository;
MavenPublication pub = publication as MavenPublication;

HttpURLConnection connection = new URL("$repo.url/${pub.groupId.replace('.', '/')}/$pub.artifactId/$pub.version/$pub.artifactId-${pub.version}.jar").openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Authorization", "Basic ${new String(Base64.getEncoder().encode("$repo.credentials.username:$repo.credentials.password".bytes))}");
connection.connect();
return connection.responseCode == 404;
}
}
}

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

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


// distribution zip files
apply plugin: 'java-library'
apply plugin: 'distribution'

tasks.jar.enabled = false
afterEvaluate { // disable all distTar tasks
tasks.each {
if (it.name.endsWith('istTar'))
it.enabled = false
}
}


// collect all configured repositories in parent build
gradle.projectsEvaluated { g ->
if (gradle.parent != null) {
gradle.parent.rootProject {
repositories.addAll(g.rootProject.repositories)
}
}
}
Loading