-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from AlexeiVainshtein/master
Adjustment to make tests public, create final task for publishing,
- Loading branch information
Showing
30 changed files
with
1,618 additions
and
1,014 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/groovy/com/jfrog/bintray/gradle/BintrayExtension.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 47 additions & 109 deletions
156
src/main/groovy/com/jfrog/bintray/gradle/BintrayPlugin.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.