From 64eeb7e56f114eebaf4e6fd4aa4c971a7a8c93a1 Mon Sep 17 00:00:00 2001 From: jk1 Date: Mon, 23 Feb 2015 19:40:54 +0300 Subject: [PATCH] basic feature branches support --- README.md | 12 +++++++++++- build.gradle | 2 +- consumer/build.gradle | 4 +++- .../model/ArtifactVersion.groovy | 2 +- .../model/BranchScopedArtifactVersion.groovy | 13 +++++++------ 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5066faa..a20a6a9 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,16 @@ configurations.all { } ``` +Changing dependencies may be also resolved against particular [feature branches](https://confluence.jetbrains.com/display/TCD8/Working+with+Feature+Branches): + +```groovy +dependencies { + compile tc(buildTypeId: 'bt345', version: 'lastSuccessful', artifactPath: 'testng-6.8.8.jar', branch: 'master') +} +``` + +Default branch will be used if branch value is not specified explicitly. + ###Pinning the build By default, TeamCity does not store artifacts indefinitely, deleting them after some time. To avoid dependency loss one may choose to [pin the build](https://confluence.jetbrains.com/display/TCD8/Pinned+Build) as follows: @@ -70,7 +80,7 @@ repositories{ teamcityServer{ url = 'http://teamcity.jetbrains.com' pin { - // pinning usually requires authnetication + // pinning usually requires authentication username = "name" password = "secret" stopBuildOnFail = true // not mandatory, default to 'false' diff --git a/build.gradle b/build.gradle index 4ae1c2d..aea7927 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'maven' group = 'com.github.jk1' description = 'TeamCity dependencies plugin resolves project dependencies via local TeamCity server' -version = '0.5' +version = '0.6' repositories { mavenCentral() diff --git a/consumer/build.gradle b/consumer/build.gradle index 4ac3439..507ad79 100644 --- a/consumer/build.gradle +++ b/consumer/build.gradle @@ -5,7 +5,7 @@ version = '1.0' repositories { teamcityServer { - url = 'http://teamcity.jetbrains.com' + url = 'https://teamcity.jetbrains.com' } } @@ -27,6 +27,8 @@ dependencies { compile tc('bt131:lastPinned:javadocs/index.html') compile tc('bt337:lastSuccessful:odata4j.zip') compile tc('bt132:sameChainOrLastFinished:index.html') + // with feature branches supported + compile tc(buildTypeId: 'bt345', version: 'lastSuccessful', artifactPath: 'testng-6.8.8.jar', branch: 'master') } defaultTasks 'listdeps' diff --git a/src/main/groovy/com.github.jk1.tcdeps/model/ArtifactVersion.groovy b/src/main/groovy/com.github.jk1.tcdeps/model/ArtifactVersion.groovy index 9b80e60..43937e6 100644 --- a/src/main/groovy/com.github.jk1.tcdeps/model/ArtifactVersion.groovy +++ b/src/main/groovy/com.github.jk1.tcdeps/model/ArtifactVersion.groovy @@ -8,7 +8,7 @@ import org.gradle.api.Project class ArtifactVersion { def versionPlaceholders = ['lastFinished':'', - 'lastPinned': 'pinned:true', + 'lastPinned': ',pinned:true', 'lastSuccessful':',status:SUCCESS', 'sameChainOrLastFinished':''] diff --git a/src/main/groovy/com.github.jk1.tcdeps/model/BranchScopedArtifactVersion.groovy b/src/main/groovy/com.github.jk1.tcdeps/model/BranchScopedArtifactVersion.groovy index 645f581..208fa9e 100644 --- a/src/main/groovy/com.github.jk1.tcdeps/model/BranchScopedArtifactVersion.groovy +++ b/src/main/groovy/com.github.jk1.tcdeps/model/BranchScopedArtifactVersion.groovy @@ -21,26 +21,27 @@ class BranchScopedArtifactVersion extends ArtifactVersion { @Override def resolve(Project project, String btid) { + String request = url(project.teamcityServer.url, btid) String response = "" try { - HttpURLConnection connection = url(project.teamcityServer.url, btid).toURL().openConnection() + HttpURLConnection connection = request.toURL().openConnection() response = connection.inputStream.withReader { Reader reader -> reader.text } - if (connection.getResponseCode() == 200) { + if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { project.logger.info("$version has been resolved as $response in $branch") version = response changing = false } else { - String message = "Unable to resolve $version in $branch. Server response: \n $response" - throw new GradleException(message, e) + String message = "Unable to resolve $version in $branch.\nRequest: GET $request \nServer response: \n $response" + throw new GradleException(message) } } catch (Exception e) { - String message = "Unable to resolve $version in $branch. Server response: \n $response" + String message = "Unable to resolve $version in $branch.\nRequest: GET $request \nServer response: \n $response" throw new GradleException(message, e) } } private def url(String server, String btid) { - def query = "buildType:$btid,branch:$branch,${versionPlaceholders[version]}/number" + def query = "buildType:$btid,branch:$branch${versionPlaceholders[version]}/number" return "${server}/guestAuth/app/rest/builds/$query" } }