Permalink
Switch branches/tags
v0.91.43 v0.91.37 v0.91.28 v0.91.27 v0.9.281 v0.9.275 v0.9.273 thucydides-0.9.275 thucydides-0.9.264 thucydides-0.9.230 thucydides-0.9.220-RC3 thucydides-0.9.220-RC2 thucydides-0.9.220-RC1 thucydides-0.9.131-NS thucydides-0.9.2 thucydides-0.9.0 thucydides-0.9.0-beta-4 thucydides-0.9.0-beta-2 thucydides-0.9.0-beta-1 thucydides-0.9.0-alpha-6 thucydides-0.9.0-alpha-4 thucydides-0.9.0-alpha-3 thucydides-0.9.0-RC6 thucydides-0.9.0-RC4 thucydides-0.9.0-RC3 thucydides-0.9.0-RC2 thucydides-0.9.0-RC1 thucydides-0.8.31 thucydides-0.8.30 thucydides-0.8.29 thucydides-0.8.27 thucydides-0.8.26 thucydides-0.8.25 thucydides-0.8.24 thucydides-0.8.23 thucydides-0.8.22 thucydides-0.8.21 thucydides-0.8.20 thucydides-0.8.19 thucydides-0.8.18 thucydides-0.8.17 thucydides-0.8.16 thucydides-0.8.15 thucydides-0.8.14 thucydides-0.8.13 thucydides-0.8.12 thucydides-0.8.10 thucydides-0.8.8 thucydides-0.8.7 thucydides-0.8.6 thucydides-0.8.5 thucydides-0.8.4 thucydides-0.8.3 thucydides-0.8.0 thucydides-0.7.11 thucydides-0.7.10 thucydides-0.7.9 thucydides-0.7.8 thucydides-0.7.6 thucydides-0.7.4 thucydides-0.7.3 thucydides-0.7.2 thucydides-0.7.1 thucydides-0.7.0 thucydides-0.6.9 thucydides-0.6.8 thucydides-0.6.7 thucydides-0.6.5 thucydides-0.6.4 thucydides-0.6.3 thucydides-0.6.2 thucydides-0.6.1 thucydides-0.6.0 thucydides-0.5.0 thucydides-0.4.34 thucydides-0.4.33 thucydides-0.4.32 thucydides-0.4.31 thucydides-0.4.30 thucydides-0.4.29 thucydides-0.4.28 thucydides-0.4.27 thucydides-0.4.26 thucydides-0.4.25 thucydides-0.4.24 thucydides-0.4.23 thucydides-0.4.22 thucydides-0.4.21 thucydides-0.4.19 thucydides-0.4.18 thucydides-0.4.17 thucydides-0.4.16 thucydides-0.4.15 thucydides-0.4.14 thucydides-0.4.13 thucydides-0.4.12 thucydides-0.4.11 thucydides-0.4.10 thucydides-0.4.9 thucydides-0.4.8
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
137 lines (110 sloc) 4.03 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
}