Skip to content

Sonotype integration #10

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
158 changes: 105 additions & 53 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,51 @@ import java.util.regex.Pattern
buildscript {
repositories {
mavenLocal()
jcenter()
maven { url "https://dl.bintray.com/stroom/stroom" }
mavenCentral()
}
dependencies {
// A fork of https://github.com/wfhartford/gradle-dependency-analyze that works with Java 10
//classpath 'stroom:gradle-dependency-analyze:v2.2.2'
classpath 'ca.cutterslade.gradle:gradle-dependency-analyze:1.2.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
//classpath "org.javamodularity:moduleplugin:1.6.0"
classpath group: 'ca.cutterslade.gradle', name: 'gradle-dependency-analyze', version: '1.5.2'
}
}

plugins {
//plugin for downloading content from the 'net
id "de.undercouch.download" version "3.4.3"

id "io.github.gradle-nexus.publish-plugin" version "1.0.0"
//plugin for producing a tree of task dependencies, run task 'taskTree'
//id "com.dorongold.task-tree" version "1.3"
id "signing"
id "maven-publish"
}

//must be applied to all projects including root
apply plugin: 'ca.cutterslade.analyze'
apply plugin: 'io.github.gradle-nexus.publish-plugin'
apply plugin: 'maven-publish'

ext.isPropertySet = { propName ->
if (!project.hasProperty(propName)) {
return false
} else {
def prop = project.getProperty(propName)
return (prop != "unspecified" && (prop != "" || prop != null))
}
}

ext.ensurePropertyIsSet = { propName ->
if (!isPropertySet(propName)) {
throw new GradleException(
"Expecting project property [${propName}] or env var [ORG_GRADLE_PROJECT_${propName}] to be set.")
}
}

//if the project has a value for the passed property (i.e from the cmd line via -PpropName=xxx)
//use that, else use a default value
ext.getPropertyOrDefault = { propName, defaultValue ->
ext.getPropertyOrDefault = { propName, defaultValue ->
def val;
if (project.hasProperty(propName) && project.getProperty(propName) != "unspecified" && project.getProperty(propName) != "") {
if (isPropertySet(propName)) {
val = project.getProperty(propName)
println "Using property [$propName] with value [$val]"
println "Getting property [$propName] with value [$val]"
} else {
val = defaultValue
println "Property [$propName] has no value, using default value [$val]"
Expand All @@ -55,20 +70,39 @@ def eventLoggingSchemaVer = "v4.0-beta.3"


// Set this to the last release of this repo on this branch, or earlier branches
// It is used to diff the current jaxb code against the last release
// It is used to diff the current jaxb code against the last release so you can
// see if/how the java model has changed following schema changes or changes
// to the jaxb code generation.
// *****************************************************************************
ext.previousReleaseVersion = "v5.0-beta.13_schema-v4.0-beta.1"
ext.previousReleaseVersion = "v5.0-beta.15_schema-v4.0-beta.3"
// *****************************************************************************




def VERSION_PATTERN = /^v[0-9a-zA-Z\.-]+_schema-(v[0-9a-zA-Z\.-]+)$/
def VERSION_PATTERN = /^(?:v[0-9.]+(?:-(?:beta|alpha)[0-9.]+)_)?schema-(v[0-9.]+(?:-(?:beta|alpha)[0-9.]+))(-SNAPSHOT)?$/
def CHANGE_LOG_FILENAME = "CHANGELOG.md"
def projectGroup = "event-logging"
def projectVersion = getPropertyOrDefault('version', "SNAPSHOT_schema-${eventLoggingSchemaVer}")
def projectGroup = "eventlogging"
def projectVersion = getPropertyOrDefault('version', "schema-${eventLoggingSchemaVer}-SNAPSHOT")
def eventLoggingSchemaMajorVer = getMajorVersion(eventLoggingSchemaVer)
def combinedVersion = "${projectVersion}"

ext.isReleaseBuild = !projectVersion.endsWith("SNAPSHOT")

// We don't want the 'v' prefix on version numbers in maven
ext.projectVersionForMaven = projectVersion.replaceFirst(/^v/, "")

if (isReleaseBuild) {
println "This is a release build for maven version [${projectVersionForMaven}]"
// Ensure the various props are set for signing and publishing to sonatype

// The username for Sonatype OSSRH Jira account
ensurePropertyIsSet("sonatypeUsername")
// The password for Sonatype OSSRH Jira account
ensurePropertyIsSet("sonatypePassword")
// The GPG2 secret key in ascii armour format, base64 encoded
ensurePropertyIsSet("signingKey")
// The password for the GPG2 secret key
ensurePropertyIsSet("signingPassword")
}

if (!(projectVersion =~ /^SNAPSHOT\.*/)) {
//Ensure the version string looks a bit like v1.2.3_schema-v4.5.6
Expand All @@ -78,19 +112,20 @@ if (!(projectVersion =~ /^SNAPSHOT\.*/)) {

//Ensure the schema part of the combined version string matches eventLoggingSchemaVer
//This makes sure we don't tag as schema vX when the jar is built with schema vY
def matcher = (combinedVersion =~ VERSION_PATTERN)
def matcher = (projectVersion =~ VERSION_PATTERN)
def schemaVerFromProjectVer = matcher[0][1]
if (schemaVerFromProjectVer != eventLoggingSchemaVer) {
throw new GradleException("eventLoggingSchemaVer [${eventLoggingSchemaVer}] does not match schema version part [${schemaVerFromProjectVer}] of [${combinedVersion}]")
throw new GradleException("eventLoggingSchemaVer [${eventLoggingSchemaVer}] does not match schema version part [${schemaVerFromProjectVer}] of [${projectVersion}]")
}

//This is versioned build so ensure the version is in the CHANGELOG
def changeLogFile = new File(CHANGE_LOG_FILENAME)
def pattern = Pattern.compile(combinedVersion, Pattern.LITERAL)
def pattern = Pattern.compile(projectVersion, Pattern.LITERAL)

if (!changeLogFile.getText("UTF-8").find(pattern)) {
throw new GradleException("This is a versioned build, cannot find string \"${pattern.toString()}\" in file ${CHANGE_LOG_FILENAME}, add the new version to the change log")
}
// TODO commented for testing
//if (!changeLogFile.getText("UTF-8").find(pattern)) {
//throw new GradleException("This is a versioned build, cannot find string \"${pattern.toString()}\" in file ${CHANGE_LOG_FILENAME}, add the new version to the change log")
//}
}

//The XML Schema to use as the basis for generating the event-logging jaxb library code
Expand All @@ -109,17 +144,22 @@ if (!eventLoggingSchemaFilePath.isEmpty()) {
println "Setting eventLoggingSchemaFilePath to ${ext.eventLoggingSchemaFilePath}"
}

println "Using project version: $projectVersion"
println "Using schema version: $eventLoggingSchemaVer"
println "Using combined version: $combinedVersion"
println "Using namespace version: $eventLoggingSchemaMajorVer"
println "Using schema url: $eventLoggingSchemaUrl"
println "Using schema file path: $eventLoggingSchemaFilePath"

// maven stuff
//group "$projectGroup"
////archivesBaseName = "eventlogging"
//version "$projectVersion"

println "Using project version: ${projectVersion}"
println "Using project version (maven): ${projectVersionForMaven}"
println "Using schema version: ${eventLoggingSchemaVer}"
println "Using namespace version: ${eventLoggingSchemaMajorVer}"
println "Using schema url: ${eventLoggingSchemaUrl}"
println "Using schema file path: ${eventLoggingSchemaFilePath}"

ext.versions = [
//------event-logging--------------
eventLogging : projectVersion,
eventLoggingAndSchema: combinedVersion,
eventLogging : projectVersionForMaven,

//------------3rd-party------------
assertj : '3.10.0',
Expand All @@ -136,14 +176,12 @@ ext.versions = [
]

allprojects {
apply plugin: 'maven'

group "$projectGroup"
version "$projectVersion"
group "uk.gov.gchq.eventlogging" // no spaces as java pkg name convention
version projectVersionForMaven
}

subprojects {
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'ca.cutterslade.analyze'
apply plugin: 'idea'
//apply plugin: "org.javamodularity.moduleplugin"
Expand All @@ -153,26 +191,27 @@ subprojects {

repositories {
mavenLocal()
jcenter()
mavenCentral()
}

configurations {
// TODO at055612 pretty sure this is not needed
//configurations {

all {
exclude group: "org.slf4j", module: "slf4j-log4j12"
exclude group: "log4j", module: "log4j"
//all {
//exclude group: "org.slf4j", module: "slf4j-log4j12"
//exclude group: "log4j", module: "log4j"

resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.name == 'log4j') {
details.useTarget "org.slf4j:log4j-over-slf4j:$versions.slf4j"
}
}
resolutionStrategy {
forcedModules = [
]
}
}
}
//resolutionStrategy.eachDependency { DependencyResolveDetails details ->
//if (details.requested.name == 'log4j') {
//details.useTarget "org.slf4j:log4j-over-slf4j:$versions.slf4j"
//}
//}
//resolutionStrategy {
//forcedModules = [
//]
//}
//}
//}

test {
// Needed for junit 5
Expand Down Expand Up @@ -247,4 +286,17 @@ subprojects {
}


// Uses sonotypeUsername and sonotypePassword
// This needs to be in the root project
// See https://github.com/rwinch/gradle-publish-ossrh-sample
// Also https://github.com/kit-data-manager/nexus-publish-example
nexusPublishing {
repositories {
sonatype() //sonatypeUsername and sonatypePassword properties are used automatically
}
// these are not strictly required. The default timeouts are set to 1 minute. But Sonatype can be really slow.
// If you get the error "java.net.SocketTimeoutException: timeout", these lines will help.
connectTimeout = Duration.ofMinutes(3)
clientTimeout = Duration.ofMinutes(3)
}

22 changes: 12 additions & 10 deletions diffAgainstLatestRelease.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ popd() {
main() {
#Check script arguments
if [ "$#" -ne 2 ] || ! [ -d "$1" ]; then
echo "${RED}INVALID ARGS!${NC}"
echo "${GREEN}Usage: $0 workingDir previousVersionTag${NC}"
echo "${GREEN}e.g : $0 event-logging-api/build v3.2.3_schema-v3.2.4${NC}"
echo -e "${RED}INVALID ARGS!${NC}"
echo -e "${GREEN}Usage: $0 workingDir previousVersionTag${NC}"
echo -e "${GREEN}e.g : $0 event-logging-api/build v3.2.3_schema-v3.2.4${NC}"

echo "Where workingDir normally event-logging-api/build"
echo -e "Where workingDir normally event-logging-api/build"
exit 1
fi

local workingDir=${1}
local prevVersionTag="${2}"
echo "workingDir=${workingDir}"
echo -e "${BLUE}Working directory: ${YELLOW}${workingDir}${NC}"

echo "Comparing current JAXB code to release ${prevVersionTag}"
echo -e "${BLUE}Comparing current JAXB code to release:" \
"${YELLOW}${prevVersionTag}${NC}"

# GITHUB_TOKEN decalred in travis settings UI
# DO NOT echo the token!
Expand All @@ -47,8 +48,8 @@ main() {
local apiUrl="${API_URL_BASE}/${prevVersionTag}"
local prevVersionJar="event-logging-${prevVersionTag}-sources.jar"

echo "Using API URL: ${apiUrl}"
echo "Searching for file: ${prevVersionJar}"
echo -e "${BLUE}Using API URL: ${YELLOW}${apiUrl}${NC}"
echo -e "${BLUE}Searching for file: ${YELLOW}${prevVersionJar}${NC}"

local jqScript=".assets[]
| select( .name
Expand Down Expand Up @@ -95,7 +96,8 @@ main() {
rm event-logging*.jar
popd

echo -e "${BLUE}Comparing the source to the latested released version${NC}"
echo -e "${BLUE}Comparing the source to version" \
"${YELLOW}${prevVersionTag}${NC}"

diff -r old/ new/ > source.diff || true

Expand All @@ -109,7 +111,7 @@ main() {
echo
echo -e "${BLUE}$PWD/source.diff${NC}"

echo "The nature of the changes will determine whether the next release" \
echo -e "The nature of the changes will determine whether the next release" \
"is major/minor/patch or may indicate a bad change to the schema"
else
echo -e "\n${GREEN}Source is identical to ${YELLOW}${sourcesJarUrl}${NC}"
Expand Down
Loading