Skip to content

Commit

Permalink
issue 241 - Check if the task did some work before performing final o…
Browse files Browse the repository at this point in the history
…perations (#246)

* issue 241 - Check if the task did some work before performing final operations

* issue 244 - Projects need to be evaluated in the projectsEvaluated
  • Loading branch information
AlexeiVainshtein authored and eyalbe4 committed Jun 21, 2018
1 parent 1e801c7 commit 3fe02df
Show file tree
Hide file tree
Showing 19 changed files with 275 additions and 138 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.2"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.3"
}
}

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.2
currentVersion=1.8.3
Original file line number Diff line number Diff line change
Expand Up @@ -33,49 +33,7 @@ class ProjectsEvaluatedBuildListener extends BuildAdapter implements ProjectEval

@Override
void afterEvaluate(Project proj, ProjectState state) {

bintrayUpload.with {
apiUrl = extension.apiUrl
user = extension.user
apiKey = extension.key
configurations = extension.configurations
publications = extension.publications
filesSpec = extension.filesSpec
publish = extension.publish
override = extension.override
dryRun = extension.dryRun
userOrg = extension.pkg.userOrg ?: extension.user
repoName = extension.pkg.repo
packageName = extension.pkg.name
packageDesc = extension.pkg.desc
packageWebsiteUrl = extension.pkg.websiteUrl
packageIssueTrackerUrl = extension.pkg.issueTrackerUrl
packageVcsUrl = extension.pkg.vcsUrl
packageGithubRepo = extension.pkg.githubRepo
packageGithubReleaseNotesFile = extension.pkg.githubReleaseNotesFile
packageLicenses = extension.pkg.licenses
packageLabels = extension.pkg.labels
packageAttributes = extension.pkg.attributes
packagePublicDownloadNumbers = extension.pkg.publicDownloadNumbers
debianDistribution = extension.pkg.debian.distribution
debianComponent = extension.pkg.debian.component
debianArchitecture = extension.pkg.debian.architecture
versionName = extension.pkg.version.name ?: project.version
versionDesc = extension.pkg.version.desc
versionReleased = extension.pkg.version.released
versionVcsTag = extension.pkg.version.vcsTag ?: project.version
versionAttributes = extension.pkg.version.attributes
signVersion = extension.pkg.version.gpg.sign
gpgPassphrase = extension.pkg.version.gpg.passphrase
syncToMavenCentral = extension.pkg.version.mavenCentralSync.sync == null ?
true : extension.pkg.version.mavenCentralSync.sync
ossUser = extension.pkg.version.mavenCentralSync.user
ossPassword = extension.pkg.version.mavenCentralSync.password
ossCloseRepo = extension.pkg.version.mavenCentralSync.close
}

bintrayUploadTasks.add(bintrayUpload)

Task bintrayPublish = bintrayUpload.project.getRootProject().getTasks().findByName(BintrayPublishTask.TASK_NAME)
if (bintrayPublish == null) {
throw new IllegalStateException(String.format("Could not find %s in the root project", BintrayPublishTask.TASK_NAME))
Expand All @@ -96,6 +54,46 @@ class ProjectsEvaluatedBuildListener extends BuildAdapter implements ProjectEval
@Override
void projectsEvaluated(Gradle gradle) {
for (BintrayUploadTask bintrayUpload : bintrayUploadTasks) {
bintrayUpload.with {
apiUrl = extension.apiUrl
user = extension.user
apiKey = extension.key
configurations = extension.configurations
publications = extension.publications
filesSpec = extension.filesSpec
publish = extension.publish
override = extension.override
dryRun = extension.dryRun
userOrg = extension.pkg.userOrg ?: extension.user
repoName = extension.pkg.repo
packageName = extension.pkg.name
packageDesc = extension.pkg.desc
packageWebsiteUrl = extension.pkg.websiteUrl
packageIssueTrackerUrl = extension.pkg.issueTrackerUrl
packageVcsUrl = extension.pkg.vcsUrl
packageGithubRepo = extension.pkg.githubRepo
packageGithubReleaseNotesFile = extension.pkg.githubReleaseNotesFile
packageLicenses = extension.pkg.licenses
packageLabels = extension.pkg.labels
packageAttributes = extension.pkg.attributes
packagePublicDownloadNumbers = extension.pkg.publicDownloadNumbers
debianDistribution = extension.pkg.debian.distribution
debianComponent = extension.pkg.debian.component
debianArchitecture = extension.pkg.debian.architecture
versionName = extension.pkg.version.name ?: project.version
versionDesc = extension.pkg.version.desc
versionReleased = extension.pkg.version.released
versionVcsTag = extension.pkg.version.vcsTag ?: project.version
versionAttributes = extension.pkg.version.attributes
signVersion = extension.pkg.version.gpg.sign
gpgPassphrase = extension.pkg.version.gpg.passphrase
syncToMavenCentral = extension.pkg.version.mavenCentralSync.sync == null ?
true : extension.pkg.version.mavenCentralSync.sync
ossUser = extension.pkg.version.mavenCentralSync.user
ossPassword = extension.pkg.version.mavenCentralSync.password
ossCloseRepo = extension.pkg.version.mavenCentralSync.close
}

if (bintrayUpload.extension.configurations?.length) {
bintrayUpload.extension.configurations.each {
def configuration = bintrayUpload.project.configurations.findByName(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BintrayPublishTask extends DefaultTask {
private void signPublishAndSync() {
HashSet<BintrayUploadTask> tasks = project.getTasksByName(BintrayUploadTask.TASK_NAME, true)
for (BintrayUploadTask task : tasks) {
if (task.getEnabled()) {
if (task.getEnabled() && task.getDidWork()) {
if (task.getSignVersion()) {
gpgSignVersion(task.repoName, task.packageName, task.versionName, task)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,41 +193,41 @@ class BintrayUploadTask extends DefaultTask {
logger.info("Gradle Bintray Plugin version: ${new Utils().pluginVersion}");
if (getEnabled()) {
validateDebianDefinition()
//TODO: [by yl] replace with findResults for Gradle 2.x
configurationUploads = configurations.collect {
if (it instanceof CharSequence) {
Configuration configuration = project.configurations.findByName(it)
if (configuration != null) {
return collectArtifacts(configuration)
//TODO: [by yl] replace with findResults for Gradle 2.x
configurationUploads = configurations.collect {
if (it instanceof CharSequence) {
Configuration configuration = project.configurations.findByName(it)
if (configuration != null) {
return collectArtifacts(configuration)
} else {
logger.error("{}: Could not find configuration: {}.", path, it)
}
} else if (conf instanceof Configuration) {
return collectArtifacts((Configuration) it)
} else {
logger.error("{}: Could not find configuration: {}.", path, it)
logger.error("{}: Unsupported configuration type: {}.", path, it.class)
}
} else if (conf instanceof Configuration) {
return collectArtifacts((Configuration) it)
} else {
logger.error("{}: Unsupported configuration type: {}.", path, it.class)
}
[]
}.flatten() as Artifact[]

publicationUploads = publications.collect {
if (it instanceof CharSequence) {
Publication publication = project.extensions.getByType(PublishingExtension).publications.findByName(it)
if (publication != null) {
return collectArtifacts(publication)
[]
}.flatten() as Artifact[]

publicationUploads = publications.collect {
if (it instanceof CharSequence) {
Publication publication = project.extensions.getByType(PublishingExtension).publications.findByName(it)
if (publication != null) {
return collectArtifacts(publication)
} else {
logger.error("{}: Could not find publication: {}.", path, it);
}
} else if (conf instanceof MavenPublication) {
return collectArtifacts((Configuration) it)
} else {
logger.error("{}: Could not find publication: {}.", path, it);
logger.error("{}: Unsupported publication type: {}.", path, it.class)
}
} else if (conf instanceof MavenPublication) {
return collectArtifacts((Configuration) it)
} else {
logger.error("{}: Unsupported publication type: {}.", path, it.class)
}
[]
}.flatten() as Artifact[]
[]
}.flatten() as Artifact[]

RecordingCopyTask recordingCopyTask = getDependsOn().find { it instanceof RecordingCopyTask }
fileUploads = (recordingCopyTask ? recordingCopyTask.fileUploads : []) as Artifact[]
RecordingCopyTask recordingCopyTask = getDependsOn().find { it instanceof RecordingCopyTask }
fileUploads = (recordingCopyTask ? recordingCopyTask.fileUploads : []) as Artifact[]

if (repoName == null || versionName == null || packageName == null) {
logger.warn("Repository name, package name or version name are null for project: " + project.getDisplayName())
Expand Down Expand Up @@ -399,10 +399,10 @@ class BintrayUploadTask extends DefaultTask {
Package pkg = getRepository().packages.get(packageName)
if (!pkg) {
throw new IllegalStateException(
"Attempted checking and creating version, before checking and creating the package.")
"Attempted checking and creating version, before checking and creating the package.")
}
Version v = new Version(
versionName, signVersion, gpgPassphrase, publish, shouldSyncToMavenCentral())
versionName, signVersion, gpgPassphrase, publish, shouldSyncToMavenCentral())
Version version = pkg.addVersionIfAbsent(v)
if (version && !version.created) {
synchronized (version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import com.jfrog.bintray.gradle.tasks.entities.Artifact
import org.gradle.api.internal.file.copy.CopyAction
import org.gradle.api.internal.file.copy.CopyActionProcessingStream
import org.gradle.api.internal.file.copy.FileCopyDetailsInternal
import org.gradle.api.internal.tasks.SimpleWorkResult
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.WorkResults

class RecordingCopyTask extends Copy {

Expand Down Expand Up @@ -37,7 +37,7 @@ class RecordingCopyTask extends Copy {
didWork = true
}
}
new SimpleWorkResult(true)
WorkResults.didWork(true)
}
}
}
Loading

0 comments on commit 3fe02df

Please sign in to comment.