Skip to content

Commit

Permalink
issue 240 - Prevent publish task operations run multiple time for the…
Browse files Browse the repository at this point in the history
… same values (#248)
  • Loading branch information
AlexeiVainshtein authored and eyalbe4 committed Jul 8, 2018
1 parent 3fe02df commit 476b2c5
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.3"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
currentVersion=1.8.3
currentVersion=1.8.4
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.jfrog.bintray.gradle.tasks

import com.jfrog.bintray.gradle.Utils
import com.jfrog.bintray.gradle.tasks.entities.Repository
import com.jfrog.bintray.gradle.tasks.entities.Package
import com.jfrog.bintray.gradle.tasks.entities.Version
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.tasks.TaskAction
Expand All @@ -15,6 +18,7 @@ import static groovyx.net.http.Method.POST
*/
class BintrayPublishTask extends DefaultTask {
static final String TASK_NAME = "bintrayPublish"
private HashMap<String, Repository> repositories = new HashMap<>()

@TaskAction
void taskAction() throws IOException {
Expand All @@ -25,14 +29,36 @@ class BintrayPublishTask extends DefaultTask {
HashSet<BintrayUploadTask> tasks = project.getTasksByName(BintrayUploadTask.TASK_NAME, true)
for (BintrayUploadTask task : tasks) {
if (task.getEnabled() && task.getDidWork()) {
if (task.getSignVersion()) {
gpgSignVersion(task.repoName, task.packageName, task.versionName, task)
Package pkg = new Package(task.packageName)
Repository repository = new Repository(task.repoName)
Repository existingRepo = repositories.putIfAbsent(task.repoName, repository)
if (!existingRepo) {
existingRepo = repository
}
if (task.publish) {
publishVersion(task.repoName, task.packageName, task.versionName, task)

Package existingPackage = existingRepo.packages.putIfAbsent(task.packageName, pkg)
if (!existingPackage) {
existingPackage = pkg
}

Version v = new Version(
task.versionName, task.signVersion, task.gpgPassphrase, task.publish, task.shouldSyncToMavenCentral())
Version existingVersion = existingPackage.getVersionIfExists(v)

if (existingVersion == null) {
existingPackage.addVersionIfAbsent(v)
existingVersion = new Version(v.name, false, v.gpgPassphrase, false, false)
}
if (task.shouldSyncToMavenCentral()) {
mavenCentralSync(task.repoName, task.packageName, task.versionName, task)
if (existingVersion.shouldGpgSign(v.gpgSign)) {
gpgSignVersion(existingRepo.name, existingPackage.name, existingVersion.name, task)
}

if (existingVersion.shouldPerformPublish(v.publish)) {
publishVersion(existingRepo.name, existingPackage.name, existingVersion.name, task)
}

if (existingVersion.shouldPerformMavenSync(v.mavenCentralSync)) {
mavenCentralSync(existingRepo.name, existingPackage.name, existingVersion.name, task)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class Package {
return v
}

// Returns the version of the Map if exists
// Null if there is no such version in the map
Version getVersionIfExists(Version v) {
return versions.get(v)
}

boolean equals(o) {
if (this.is(o)) {
return true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.jfrog.bintray.gradle.tasks.entities

import org.apache.commons.lang.StringUtils

class Version {
private String name
private boolean created
private boolean gpgSign
private String gpgPassphrase
private boolean publish
private boolean mavenCentralSync
private boolean mavenCentralSync

Version(String name, boolean gpgSign, String gpgPassphrase, boolean publish, boolean mavenCentralSync) {
this.name = name
Expand Down Expand Up @@ -49,16 +51,51 @@ class Version {
}
}

boolean equals(o) {
if (this.is(o)) {
return true
boolean shouldPerformPublish(boolean publish) {
// If publish already occurred for this version
// Or
// If no publish is needed
// don't perform publishing
if (this.publish || !publish) {
return false
}
this.publish = publish
return true
}

boolean shouldPerformMavenSync(boolean mavenCentralSync) {
// If maven Central Sync already occurred for this version
// Or
// If mavenCentralSync is false
// don't perform maven central sync
if (this.mavenCentralSync || !mavenCentralSync) {
return false
}
if (getClass() != o.class || name != ((Version) o).name) {
this.mavenCentralSync = mavenCentralSync
return true
}

boolean shouldGpgSign(boolean gpgSign) {
// If signing of the version already occurred
// Or
// If no signing is required
// return false
if (this.gpgSign || !gpgSign) {
return false
}
this.gpgSign = gpgSign
return true
}

boolean equals(o) {
if (!(o instanceof String)) {
return false
}

String name = (String) o
return StringUtils.equals(this.name, name)
}

int hashCode() {
name != null ? name.hashCode() : 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.3"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.3"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/gradle/projects/fileSpec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.3"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.3"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.3"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
}
}

Expand Down

0 comments on commit 476b2c5

Please sign in to comment.