Skip to content

Commit

Permalink
Merge pull request #113 from chali/PomAndIvyContentIsNotMissing
Browse files Browse the repository at this point in the history
Pom and ivy files have the right content when STABLE_PUBLISHING is enabled
  • Loading branch information
chali authored Aug 16, 2018
2 parents 835a432 + c82a9f7 commit c313bb7
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ class IvyBasePublishPlugin implements Plugin<Project> {
project.publishing {
publications {
withType(IvyPublication) {
descriptor.status = project.status
descriptor.description {
text = project.description ?: ''
if (! project.state.executed) {
project.afterEvaluate { p ->
configureDescription(it, p)
}
} else {
configureDescription(it, project)
}

descriptor.withXml { XmlProvider xml ->
def root = xml.asNode()
def configurationsNode = root?.configurations
Expand Down Expand Up @@ -85,4 +89,11 @@ class IvyBasePublishPlugin implements Plugin<Project> {
}
}
}

private void configureDescription(IvyPublication publication, Project p) {
publication.descriptor.status = p.status
publication.descriptor.description {
text = p.description ?: ''
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,22 @@ class MavenBasePublishPlugin implements Plugin<Project> {
project.publishing {
publications {
withType(MavenPublication) {
pom {
name = project.name
description = project.description
if (! project.state.executed) {
project.afterEvaluate { p ->
configureDescription(it, p)
}
} else {
configureDescription(it, project)
}
}
}
}
}

private void configureDescription(MavenPublication publication, Project p) {
publication.pom {
name = p.name
description = p.description
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import nebula.plugin.contacts.BaseContactsPlugin
import nebula.plugin.contacts.Contact
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.XmlProvider
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin

class MavenDeveloperPlugin implements Plugin<Project> {
@Override
Expand All @@ -38,30 +36,40 @@ class MavenDeveloperPlugin implements Plugin<Project> {
project.plugins.withType(BaseContactsPlugin) { BaseContactsPlugin contactsPlugin ->
project.publishing {
publications {
withType(MavenPublication) {
pom.developers {
def myContacts = contactsPlugin.getAllContacts()
myContacts.each { Contact contact ->
developer {
if (contact.github) {
id = contact.github
} else if (contact.twitter) {
id = contact.twitter
}
if (contact.moniker) {
name = contact.moniker
}

email = contact.email
if (contact.roles) {
roles = contact.roles
}
}
withType(MavenPublication) { publication ->
if (! project.state.executed) {
project.afterEvaluate {
configureContacts(contactsPlugin, publication)
}
} else {
configureContacts(contactsPlugin, publication)
}
}
}
}
}
}

private void configureContacts(BaseContactsPlugin contactsPlugin, MavenPublication publication) {
publication.pom.developers {
def myContacts = contactsPlugin.getAllContacts()
myContacts.each { Contact contact ->
developer {
if (contact.github) {
id = contact.github
} else if (contact.twitter) {
id = contact.twitter
}
if (contact.moniker) {
name = contact.moniker
}

email = contact.email
if (contact.roles) {
roles = contact.roles
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package nebula.plugin.publishing.ivy
import nebula.test.IntegrationTestKitSpec
import nebula.test.dependencies.DependencyGraphBuilder
import nebula.test.dependencies.GradleDependencyGenerator
import spock.lang.Unroll

class IvyBasePublishPluginIntegrationSpec extends IntegrationTestKitSpec {
File publishDir
Expand Down Expand Up @@ -78,13 +79,18 @@ class IvyBasePublishPluginIntegrationSpec extends IntegrationTestKitSpec {
confs.size() == expectedConfs.size()
}

def 'verify ivy.xml is correct'() {
@Unroll
def 'verify ivy.xml is correct with #publishingType'() {
buildFile << '''\
apply plugin: 'java'
description = 'test description'
'''.stripIndent()

settingsFile << """
$settingsUpdate
"""

when:
runTasks('publishNebulaIvyPublicationToTestLocalRepository')

Expand All @@ -101,6 +107,11 @@ class IvyBasePublishPluginIntegrationSpec extends IntegrationTestKitSpec {
artifact.@type == 'jar'
artifact.@ext == 'jar'
artifact.@conf == 'compile'

where:
publishingType | settingsUpdate
"STABLE_PUBLISHING" | "enableFeaturePreview(\"STABLE_PUBLISHING\")"
"default publishing"| ""
}

def 'status changes when set'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package nebula.plugin.publishing.maven
import nebula.test.IntegrationTestKitSpec
import nebula.test.dependencies.DependencyGraphBuilder
import nebula.test.dependencies.GradleDependencyGenerator
import spock.lang.Unroll

class MavenBasePublishPluginIntegrationSpec extends IntegrationTestKitSpec {
File publishDir
Expand Down Expand Up @@ -60,12 +61,17 @@ class MavenBasePublishPluginIntegrationSpec extends IntegrationTestKitSpec {
pom.name == 'maventest'
}

def 'description appears in pom'() {
@Unroll
def 'description appears in pom with #publishingType'() {
given:
buildFile << '''\
description = 'Test description'
'''.stripIndent()

settingsFile << """
$settingsUpdate
"""

when:
runTasks('generatePomFileForNebulaPublication')

Expand All @@ -74,6 +80,11 @@ class MavenBasePublishPluginIntegrationSpec extends IntegrationTestKitSpec {
def pom = new XmlSlurper().parse(pomFile)

pom.description == 'Test description'

where:
publishingType | settingsUpdate
"STABLE_PUBLISHING" | "enableFeaturePreview(\"STABLE_PUBLISHING\")"
"default publishing"| ""
}

def 'creates a jar publication'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package nebula.plugin.publishing.maven

import nebula.test.IntegrationTestKitSpec
import spock.lang.Unroll

class MavenDeveloperPluginIntegrationSpec extends IntegrationTestKitSpec {
def setup() {
Expand All @@ -34,7 +35,8 @@ class MavenDeveloperPluginIntegrationSpec extends IntegrationTestKitSpec {
'''.stripIndent()
}

def 'take info from contacts plugin and place in pom'() {
@Unroll
def 'take info from contacts plugin and place in pom with #publishingType'() {
buildFile << '''\
apply plugin: 'nebula.contacts'
Expand All @@ -46,6 +48,10 @@ class MavenDeveloperPluginIntegrationSpec extends IntegrationTestKitSpec {
}
'''.stripIndent()

settingsFile << """
$settingsUpdate
"""

when:
runTasks('generatePomFileForNebulaPublication')

Expand All @@ -60,6 +66,12 @@ class MavenDeveloperPluginIntegrationSpec extends IntegrationTestKitSpec {
devs[0].name.text() == 'Example Nebula'
devs[0].email.text() == '[email protected]'
devs[0].id.text() == 'nebula-plugins'

where:
publishingType | settingsUpdate
"STABLE_PUBLISHING" | "enableFeaturePreview(\"STABLE_PUBLISHING\")"
"default publishing"| ""

}

def 'multiple contacts'() {
Expand Down

0 comments on commit c313bb7

Please sign in to comment.