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

[WIP]Mechanism to push zip plugins. #167

Closed
wants to merge 11 commits into from
11 changes: 11 additions & 0 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
- [Build](#build)
- [Building from the command line](#building-from-the-command-line)
- [Debugging](#debugging)
- [Publish zips to maven](#to-publish-generated-plugin-zips-to-maven-repo)
- [Using IntelliJ IDEA](#using-intellij-idea)
- [Submitting Changes](#submitting-changes)

@@ -53,6 +54,16 @@ opensearch-plugin install file:///path/to/target/releases/opensearch-job-schedul
```
to install the JobScheduler plugin to your OpenSearch.

## To Publish generated plugin zips to maven repo
The generated plugin zip `opensearch-job-scheduler-<version>.zip` after the build, inside the folder `build/distributions` can be published to maven repo. This can be done by including the project `pluginZips` inside `settings.gradle` file. Once added the generated plugin zip will be published to maven repo with following maven coordinates
```
<groupId>org.opensearch.plugin</groupId>
<artifactId>opensearch-security</artifactId>
Copy link
Member

Choose a reason for hiding this comment

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

This should be job scheduler not security, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks I have updated in my latest commit.

<version><version></version>
<packaging>zip</packaging>
```
To skip the publish, while this sub-project is still included, pass the flag as ` ext.publish = 'skip'` to file `build.gradle` inside `maven/plugin-zips/` folder.

## Develop a plugin that extends JobScheduler
JobScheduler plugin provides a SPI for other plugins to implement. Essentially, you need to
1. Define your *JobParameter* type by implementing `ScheduledJobParameter` interface
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -184,4 +184,4 @@ afterEvaluate {
doLast { delete file("$buildDir/distributions/$archiveName") }
}
}
}
}
102 changes: 102 additions & 0 deletions maven/plugin-zips/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
plugins {
id 'maven-publish'
}

ext {
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
opensearch_version = System.getProperty("opensearch.version", "2.0.0-alpha1-SNAPSHOT")
buildVersionQualifier = System.getProperty("build.version_qualifier", "alpha1")
// 2.0.0-alpha1-SNAPSHOT -> 2.0.0.0-alpha1-SNAPSHOT
version_tokens = opensearch_version.tokenize('-')
opensearch_build = version_tokens[0] + '.0'
if (buildVersionQualifier) {
opensearch_build += "-${buildVersionQualifier}"
opensearch_build_nosnapshot = opensearch_build
}
if (isSnapshot) {
opensearch_build += "-SNAPSHOT"
}
}


allprojects {
// Default to the apache license
project.ext.licenseName = 'The Apache Software License, Version 2.0'
project.ext.licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
publishing {
repositories {
maven {
name = 'staging'
url = "${rootProject.buildDir}/local-staging-repo"
}
}
publications {
// add license information to generated poms
all {
pom.withXml { XmlProvider xml ->
Node node = xml.asNode()
node.appendNode('inceptionYear', '2021')

Node license = node.appendNode('licenses').appendNode('license')
license.appendNode('name', project.licenseName)
license.appendNode('url', project.licenseUrl)

Node developer = node.appendNode('developers').appendNode('developer')
developer.appendNode('name', 'OpenSearch')
developer.appendNode('url', 'https://github.com/opensearch-project/job-scheduler')
}
}
}
}
}

def group = "org.opensearch.plugin"
def pluginversion = opensearch_build
def component = "opensearch-job-scheduler"
def description = "OpenSearch Job Scheduler Zip"
def zipFile = "${component}-${pluginversion}.zip"
def zipArtifact = "${rootProject.buildDir}/distributions/${zipFile}"


publishing {
publications {
maven(MavenPublication) {
//Add ext.publish = 'skip' to skip publishing skip to maven staging repo
groupId = "${group}"
artifactId = "${component}"
version = "${pluginversion}"
// Add extension, to get <packaging>zip</packaging> as in pom file
artifact(zipArtifact) {
extension 'zip'
}
pom {
name = "${component}"
description = "${description}"
}
}
}
}

task printZipsPublishProperty {
doLast {
tasks.withType(PublishToMavenRepository).all { publishTask ->
if (publication.hasProperty('publish')) {
println(publication.publish)
}else {
println("null")
}
}
}
}

afterEvaluate {
tasks.withType(PublishToMavenRepository).all { publishTask ->
publishTask.onlyIf { task ->
if (publication.hasProperty('publish') && publication.publish == 'skip') {
return false
}
return true
}
}
}

10 changes: 5 additions & 5 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -67,12 +67,12 @@ fi
[[ "$SNAPSHOT" == "true" ]] && VERSION=$VERSION-SNAPSHOT
[ -z "$OUTPUT" ] && OUTPUT=artifacts

./gradlew publishToMavenLocal -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER
./gradlew publishAllPublicationsToStagingRepository -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER
mkdir -p $OUTPUT/maven/org/opensearch
cp -r ./build/local-staging-repo/org/opensearch/. $OUTPUT/maven/org/opensearch

./gradlew assemble --no-daemon --refresh-dependencies -DskipTests=true -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER
[ -z "$OUTPUT" ] && OUTPUT=artifacts
mkdir -p $OUTPUT/plugins
cp ./build/distributions/*.zip $OUTPUT/plugins

./gradlew publishToMavenLocal -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER
./gradlew publishAllPublicationsToStagingRepository -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER
mkdir -p $OUTPUT/maven/org/opensearch
cp -r ./build/local-staging-repo/org/opensearch/. $OUTPUT/maven/org/opensearch
6 changes: 5 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -9,4 +9,8 @@ include "spi"
project(":spi").name = rootProject.name + "-spi"

include "sample-extension-plugin"
project(":sample-extension-plugin").name = rootProject.name + "-sample-extension"
project(":sample-extension-plugin").name = rootProject.name + "-sample-extension"

//Adding pluginZips project under maven folder, this is to publish generated plugin zips to maven repo
include 'pluginZips'
project(':pluginZips').projectDir = file('maven/plugin-zips')