Skip to content

Commit

Permalink
Merge pull request #236 from AlexeiVainshtein/master
Browse files Browse the repository at this point in the history
Adjustment to make tests public, create final task for publishing,
  • Loading branch information
eyalbe4 authored Jun 10, 2018
2 parents d60ffcc + 8fc0bc9 commit 3b8766c
Show file tree
Hide file tree
Showing 30 changed files with 1,618 additions and 1,014 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,30 @@ bintray {
}
```

# Tests

#### Pre condition
The profile that performs the tests (user or organization) must have the following two repositories:
1. maven - For performing the java tests
2. debian - For performing the debian tests

#### Running the tests
To run the tests, we need to provide a few variables. Those variables can be created as environment variables:

| Environment variable | Description
| --- | --- |
| `BINTRAY_USER` | [Mandatory] Bintray user name. |
| `BINTRAY_KEY` | [Mandatory] Bintray API key. |
| `BINTRAY_ORG` | [Optional] Bintray organization. |

To run the tests, please perform the following:

````
1. Clone the project
2. Configure the environment variables or configure within the build.gradle file.
3. Run the following: gradle test
````

# Release Notes
The release notes are available on [Bintray](https://bintray.com/jfrog/jfrog-jars/gradle-bintray-plugin#release).

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jfrog.bintray.gradle

import com.jfrog.bintray.gradle.tasks.RecordingCopyTask
import org.gradle.api.Project
import org.gradle.util.ConfigureUtil

Expand Down
156 changes: 47 additions & 109 deletions src/main/groovy/com/jfrog/bintray/gradle/BintrayPlugin.groovy
Original file line number Diff line number Diff line change
@@ -1,125 +1,63 @@
package com.jfrog.bintray.gradle

import com.jfrog.bintray.gradle.tasks.BintrayPublishTask
import com.jfrog.bintray.gradle.tasks.BintrayUploadTask
import org.gradle.api.*
import org.gradle.api.publish.Publication
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.Upload

class BintrayPlugin implements Plugin<Project> {

private Project project

public void apply(Project project) {
this.project = project;
if (project.getTasks().findByName(BintrayUploadTask.TASK_NAME) == null) {
//Create and configure the task
BintrayUploadTask bintrayUpload = project.task(type: BintrayUploadTask, BintrayUploadTask.TASK_NAME)
project.gradle.addListener(new ProjectsEvaluatedBuildListener(project, bintrayUpload))
}

//Create and configure the task
BintrayUploadTask bintrayUpload = project.task(type: BintrayUploadTask, BintrayUploadTask.NAME)
addBintrayUploadTask(project)
if (isRootProject(project)) {
addBintrayPublishTask(project)
} else {
if (!project.getRootProject().getPluginManager().hasPlugin("com.jfrog.bintray")) {
// Reached this state means that the plugin is not enabled on the root project
BintrayUploadTask bintrayUploadRoot = project.getRootProject().task(type: BintrayUploadTask, BintrayUploadTask.TASK_NAME)
bintrayUploadRoot.setEnabled(false)
project.getRootProject().gradle.addListener(new ProjectsEvaluatedBuildListener(project.getRootProject(), bintrayUploadRoot))
project.getRootProject().getPluginManager().apply(BintrayPlugin.class)
}
}
}

def extension = project.extensions.create("bintray", BintrayExtension, project)
extension.with {
apiUrl = BintrayUploadTask.API_URL_DEFAULT
private BintrayUploadTask addBintrayUploadTask(Project project) {
BintrayUploadTask bintrayUploadTask = project.tasks.findByName(BintrayUploadTask.TASK_NAME)
if (bintrayUploadTask == null) {
bintrayUploadTask = createBintrayUploadTask(project)
bintrayUploadTask.setGroup(BintrayUploadTask.GROUP)
}
return bintrayUploadTask
}

project.gradle.addListener(new ProjectEvaluationListener() {
@Override
void beforeEvaluate(Project proj) {
BintrayUploadTask createBintrayUploadTask(Project project) {
def result = project.getTasks().create(BintrayUploadTask.TASK_NAME, BintrayUploadTask.class)
result.setDescription('''AddS bintray closure''')
return result
}

}
private static boolean isRootProject(Project project) {
project.equals(project.getRootProject())
}

@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
}
if (extension.configurations?.length) {
extension.configurations.each {
def configuration = project.configurations.findByName(it)
if (!configuration) {
project.logger.warn "Configuration ${it} specified but does not exist in project {}.",
project.path
} else {
bintrayUpload.dependsOn(configuration.allArtifacts)
}
}
Upload installTask = project.tasks.withType(Upload)?.findByName('install')
if (installTask) {
bintrayUpload.dependsOn(installTask)
} else {
project.logger.warn "Configuration(s) specified but the install task does not exist in project {}.",
project.path
}
}
if (extension.publications?.length) {
def publicationExt = project.extensions.findByType(PublishingExtension)
if (!publicationExt) {
project.logger.warn "Publications(s) specified but no publications exist in project {}.",
project.path
} else {
extension.publications.each {
Publication publication = publicationExt?.publications?.findByName(it)
if (!publication) {
project.logger.warn 'Publication {} not found in project {}.', it, project.path
} else if (publication instanceof MavenPublication) {
def taskName =
"publish${it[0].toUpperCase()}${it.substring(1)}PublicationToMavenLocal"
bintrayUpload.dependsOn(taskName)
/*bintrayUpload.dependsOn(publication.publishableFiles)*/
} else {
project.logger.warn "{} can only use maven publications - skipping {}.",
bintrayUpload.path, publication.name
}
}
}
}
// Depend on tasks in sub-projects
project.subprojects.each {
Task subTask = it.tasks.findByName(BintrayUploadTask.NAME)
if (subTask) {
bintrayUpload.dependsOn(subTask)
}
}
if (extension.filesSpec) {
bintrayUpload.dependsOn(extension.filesSpec)
}
}
})
private BintrayPublishTask addBintrayPublishTask(Project project) {
Task signAndPublish = project.tasks.findByName(BintrayPublishTask.TASK_NAME)
if (signAndPublish == null) {
project.getLogger().info("Configuring signAndPublish task for project ${project.path}")
signAndPublish = createBintraySignAndPublishTask(project)
signAndPublish.setGroup(BintrayUploadTask.GROUP)
}
}

protected BintrayPublishTask createBintraySignAndPublishTask(Project project) {
def result = project.getTasks().create(BintrayPublishTask.TASK_NAME, BintrayPublishTask.class)
result.setDescription('''Bintray Sign, publish and Maven central sync task''')
return result
}
}
Loading

0 comments on commit 3b8766c

Please sign in to comment.