Skip to content

Commit

Permalink
https://github.com/bintray/gradle-bintray-plugin/issues/81
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalbe4 committed Feb 1, 2016
1 parent e935a50 commit f7e7279
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 40 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.1.1')
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.3"
}
}
Expand All @@ -27,6 +27,7 @@ dependencies {
compile('org.codehaus.groovy.modules.http-builder:http-builder:0.7.2') {
exclude(module: 'groovy')
}
compile('org.apache.maven:maven-ant-tasks:2.1.3')
testCompile('org.spockframework:spock-core:0.7-groovy-2.0') {
exclude(module: 'groovy-all')
}
Expand Down
39 changes: 28 additions & 11 deletions src/main/groovy/com/jfrog/bintray/gradle/BintrayUploadTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class BintrayUploadTask extends DefaultTask {
RecordingCopyTask recordingCopyTask = getDependsOn().find { it instanceof RecordingCopyTask }
fileUploads = (recordingCopyTask ? recordingCopyTask.fileUploads : []) as Artifact[]

//Upload the files
// Upload the files
HTTPBuilder http = BintrayHttpClientFactory.create(apiUrl, user, apiKey)
def repoPath = "${userOrg ?: user}/$repoName"
def packagePath = "$repoPath/$packageName"
Expand Down Expand Up @@ -576,14 +576,21 @@ class BintrayUploadTask extends DefaultTask {
)
}.unique();

//Add pom file per config
// Add pom file per config
Upload installTask = project.tasks.withType(Upload).findByName('install');
if (!installTask) {
logger.info "maven plugin was not applied, no pom will be uploaded."
} else if (!pomArtifact) {
artifacts << new Artifact(name: project.name, groupId: project.group, version: project.version,
extension: 'pom', type: 'pom',
file: new File(getProject().convention.plugins['maven'].mavenPomDir, "pom-default.xml"))
File pom = new File(getProject().convention.plugins['maven'].mavenPomDir, "pom-default.xml")
String artifactId = Utils.readArtifactIdFromPom(pom)
artifacts << new Artifact(
name: artifactId,
groupId: project.group,
version: project.version,
extension: 'pom',
type: 'pom',
file: pom
)
}
artifacts
}
Expand All @@ -598,16 +605,26 @@ class BintrayUploadTask extends DefaultTask {
boolean signedArtifact = (it instanceof org.gradle.plugins.signing.Signature)
def signedExtenstion = signedArtifact ? it.toSignArtifact.getExtension() : null
new Artifact(
name: identity.artifactId, groupId: identity.groupId, version: identity.version,
extension: it.extension, type: it.extension, classifier: it.classifier, file: it.file,
signedExtenstion: signedExtenstion
name: identity.artifactId,
groupId: identity.groupId,
version: identity.version,
extension: it.extension,
type: it.extension,
classifier: it.classifier,
file: it.file,
signedExtenstion: signedExtenstion
)
}

//Add the pom
// Add the pom file
artifacts << new Artifact(
name: identity.artifactId, groupId: identity.groupId, version: identity.version,
extension: 'pom', type: 'pom', file: publication.asNormalisedPublication().pomFile)
name: identity.artifactId,
groupId: identity.groupId,
version: identity.version,
extension: 'pom',
type: 'pom',
file: publication.asNormalisedPublication().pomFile
)
artifacts
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/groovy/com/jfrog/bintray/gradle/Utils.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.jfrog.bintray.gradle

import org.apache.maven.model.Model
import org.apache.maven.model.io.xpp3.MavenXpp3Reader
import org.apache.maven.project.MavenProject
import java.text.DateFormat
import java.text.ParseException
import java.text.SimpleDateFormat
Expand All @@ -25,4 +28,12 @@ class Utils {
DateFormat dateToStringFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy")
return isoFormat.format(dateToStringFormat.parse(dateString))
}

public static String readArtifactIdFromPom(File pom) {
FileReader reader = new FileReader(pom);
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
Model model = mavenreader.read(reader);
MavenProject project = new MavenProject(model);
return project.getArtifactId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,40 @@ class GradleBintrayPluginSpec extends Specification {
}
}

def "[configuration]create package and version with configuration"() {
when:
String version = PluginSpecUtils.createVersion()
String[] tasks = ["clean", "install", "bintrayUpload"]
def exitCode = PluginSpecUtils.launchGradle(testName.methodName, tasks, version)

then:
// Gradle build finished successfully:
exitCode == 0

// Package was created:
bintray.currentSubject().repository(config.repo)
.pkg(config.pkgName).exists()

// Version was created:
bintray.currentSubject().repository(config.repo)
.pkg(config.pkgName).version(version).exists()

when:
// Get the created package:
Pkg pkg = bintray.currentSubject().repository(config.repo)
.pkg(config.pkgName).get()

then:
pkg.name() == config.pkgName
pkg.description() == config.pkgDesc
pkg.labels().sort() == config.pkgLabels.sort()
}

def "[fileSpec]create package and version with fileSpec"() {
when:
String version = PluginSpecUtils.createVersion()
def exitCode = PluginSpecUtils.launchGradle(testName.methodName, version)
String[] tasks = ["clean", "build", "bintrayUpload"]
def exitCode = PluginSpecUtils.launchGradle(testName.methodName, tasks, version)

then:
// Gradle build finished successfully:
Expand Down Expand Up @@ -87,7 +117,8 @@ class GradleBintrayPluginSpec extends Specification {
when:
String version = PluginSpecUtils.createVersion()
versionForMavenCentralSync = version
def exitCode = PluginSpecUtils.launchGradle(testName.methodName, version)
String[] tasks = ["clean", "build", "bintrayUpload"]
def exitCode = PluginSpecUtils.launchGradle(testName.methodName, tasks, version)

then:
// Gradle build finished successfully:
Expand Down Expand Up @@ -117,7 +148,9 @@ class GradleBintrayPluginSpec extends Specification {
println("Waiting 60 seconds before linking the package to jcenter...")
Thread.sleep(60000)
PluginSpecUtils.linkPackageToJCenter()
def exitCode = PluginSpecUtils.launchGradle(testName.methodName, versionForMavenCentralSync)
String[] tasks = ["clean", "build", "bintrayUpload"]
def exitCode = PluginSpecUtils.launchGradle(testName.methodName, tasks,
versionForMavenCentralSync)

then:
// Gradle build finished successfully:
Expand Down
36 changes: 19 additions & 17 deletions src/test/groovy/com/jfrog/bintray/gradle/PluginSpecUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,24 @@ class PluginSpecUtils {
new File(resource.toURI())
}

def static GradleLauncher createGradleLauncher(String projectName) {
def static GradleLauncher createGradleLauncher(String projectName, String[] tasks) {
File projectFile = getGradleProjectFile(projectName)
GradleLauncher launcher = new GradleLauncher(
getGradleCommandPath(), projectFile.getCanonicalPath())
.addTask("clean")
.addTask("build")
.addTask("bintrayUpload")
.addEnvVar("bintrayApiUrl", config.url)
.addEnvVar("bintrayUser", config.bintrayUser)
.addEnvVar("bintrayKey", config.bintrayKey)
.addEnvVar("repoName", config.repo)
.addEnvVar("pkgName", config.pkgName)
.addEnvVar("pkgDesc", config.pkgDesc)
.addEnvVar("mavenCentralUser", config.mavenCentralUser)
.addEnvVar("mavenCentralPassword", config.mavenCentralPassword)
.addSwitch("info")
.addSwitch("stacktrace")
getGradleCommandPath(), projectFile.getCanonicalPath())
.addEnvVar("bintrayApiUrl", config.url)
.addEnvVar("bintrayUser", config.bintrayUser)
.addEnvVar("bintrayKey", config.bintrayKey)
.addEnvVar("repoName", config.repo)
.addEnvVar("pkgName", config.pkgName)
.addEnvVar("pkgDesc", config.pkgDesc)
.addEnvVar("mavenCentralUser", config.mavenCentralUser)
.addEnvVar("mavenCentralPassword", config.mavenCentralPassword)
.addSwitch("info")
.addSwitch("stacktrace")

for (String task : tasks) {
launcher.addTask(task)
}

config.pkgLabels.eachWithIndex { label, index ->
launcher.addEnvVar("label${index+1}", label)
Expand All @@ -61,12 +62,13 @@ class PluginSpecUtils {
launcher
}

def static launchGradle(String testMethodName, String version = null) {
def static launchGradle(String testMethodName, String[] tasks, String version = null) {
String[] projectAndMethod = extractFromTestMethodName(testMethodName)
String projectName = projectAndMethod[0]
String testFileName = projectAndMethod[1].replaceAll(" ", "_")

GradleLauncher launcher = createGradleLauncher(projectName).addEnvVar("testName", testFileName)
GradleLauncher launcher = createGradleLauncher(projectName, tasks)
.addEnvVar("testName", testFileName)
if (version) {
launcher.addEnvVar("versionName", version)
}
Expand Down
5 changes: 1 addition & 4 deletions src/test/resources/gradle/projects/fileSpec/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
buildscript {
repositories {
mavenLocal()
// maven {
// url 'https://oss.jfrog.org/oss-release-local'
// }
jcenter()
}

dependencies {
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.5"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6-SNAPSHOT"
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/test/resources/gradle/projects/publication/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
buildscript {
repositories {
mavenLocal()
// maven {
// url 'https://oss.jfrog.org/oss-release-local'
// }
jcenter()
}

dependencies {
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.5"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6-SNAPSHOT"
}
}

Expand Down

0 comments on commit f7e7279

Please sign in to comment.