Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

137 lines (110 sloc) 4.123 kb
project.ext {
currentBranch = getCurrentBranch()
releaseBranch = "release-${versionNumber}"
workDirectory = createWorkDirectory()
project = 'thucydides'
artifacts = ['thucydides-report-resources','thucydides-core', 'thucydides-junit',
'maven-thucydides-plugin','thucydides-ant-task',
'thuydides-browsermob-plugin']
mavenRepo = "~/.m2/repository"
}
task buildArtifacts {
executeOnShell "mvn javadoc:jar source:jar"
}
task deployCurrentBuildArtifacts {
dependsOn buildArtifacts
def parentPomFile = findParentArtifact()
def jarFiles = findChildArtifacts()
def javadocFiles = findJavadocArtifacts()
def sourceJarFiles = findSourceArtifacts()
deployFile(parentPomFile, parentPomFile)
jarFiles.each { jarFile ->
def artifactName = new File(jarFile).name.replace(".jar","")
def pomFile = jarFile.replace(".jar",".pom")
def sourceFile = sourceJarFiles.find { it.contains(artifactName)}
def javadocFile = javadocFiles.find { it.contains(artifactName)}
deployFiles(pomFile, jarFile, sourceFile, javadocFile)
}
}
def deployFile(pomFilePath, artifactFilePath) {
deployFiles(pomFilePath, artifactFilePath, null, null)
}
def deployFiles(pomFilePath, artifactFilePath, sourceFile, javadocFile) {
println "Deploying $artifactFilePath"
def tempDirectory = project.ext.workDirectory
def toSonatypeStagingRepo = "-Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=sonatype-nexus-staging"
def pomFile = new File(pomFilePath)
def artifactFile = new File(artifactFilePath)
def tempPom = new File(tempDirectory, pomFile.getName())
def tempArtifact = new File(tempDirectory, artifactFile.getName())
executeOnShell "cp ${pomFilePath.trim()} ${tempDirectory.path}"
executeOnShell "cp ${artifactFilePath.trim()} ${tempDirectory.path}"
deployCmd = "mvn gpg:sign-and-deploy-file $toSonatypeStagingRepo -DpomFile=${tempPom.path} -Dfile=${tempArtifact.path}"
if (sourceFile) {
deployCmd += " -Dsources=$sourceFile"
}
if (javadocFile) {
deployCmd += " -Djavadoc=$javadocFile"
}
executeOnShell deployCmd
}
def getCurrentBranch() {
def branches = executeOnShell('git branch',true)
def branch = branches.readLines().find { it.startsWith('*') }
branch.stripIndent(2)
}
def findParentArtifact() {
def parentPom = executeOnShell "find ~/.m2/repository -name '*.pom' | grep ${project.ext.project}-${versionNumber}.pom"
parentPom.trim()
}
def findChildArtifacts() {
findJarsWithQualifier(versionNumber, "~/.m2/repository")
}
def findJavadocArtifacts() {
findJarsWithQualifier("javadoc")
}
def findSourceArtifacts() {
findJarsWithQualifier("sources")
}
def findJarsWithQualifier(qualifier) {
findJarsWithQualifier(qualifier,".")
}
def findJarsWithQualifier(qualifier, directory) {
def artifactPaths = []
project.ext.artifacts.each {
def jarFile = executeOnShell "find ${directory} -name '*.jar' | grep ${it} | grep ${qualifier}.jar"
if (jarFile) {
artifactPaths.add jarFile.trim()
}
}
return artifactPaths
}
def executeOnShell(String command) {
return executeOnShell(command, false)
}
def createWorkDirectory() {
File dir = File.createTempFile( 'artifacts', '.dir' )
dir.delete()
dir.mkdir()
return dir
}
def executeOnShell(String command, boolean failOnError) {
println "EXECUTING $command"
def output = new StringBuffer();
def process = new ProcessBuilder(addShellPrefix(command))
.redirectErrorStream(true)
.start()
process.inputStream.eachLine {println it; output.append(it).append("\n")}
process.waitFor();
if (failOnError && process.exitValue() != 0) {
throw new GradleException("$command failed to execute")
}
return output.toString()
}
private def addShellPrefix(String command) {
commandArray = new String[3]
commandArray[0] = "sh"
commandArray[1] = "-c"
commandArray[2] = command
return commandArray
}
Jump to Line
Something went wrong with that request. Please try again.