Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

Commit

Permalink
Issue #18: Fix evaluation ordering issue for POM modification.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmuschko committed Dec 28, 2013
1 parent c0a8759 commit ea989d4
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ example on how to retrieve it from Bintray:
}

dependencies {
classpath 'org.gradle.api.plugins:gradle-nexus-plugin:0.6'
classpath 'org.gradle.api.plugins:gradle-nexus-plugin:0.6.1'
}
}

Expand Down
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Version 0.6.1 (December 28, 2013)

* Could not find method modifyPom - [Issue 18](https://github.com/bmuschko/gradle-nexus-plugin/issues/18).

### Version 0.6 (December 15, 2013)

* Allow publishing using a custom configuration - [Issue 1](https://github.com/bmuschko/gradle-nexus-plugin/issues/1).
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def compatibilityVersion = 1.5
sourceCompatibility = compatibilityVersion
targetCompatibility = compatibilityVersion
group = 'org.gradle.api.plugins'
version = '0.6'
version = '0.6.1'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ apply plugin: org.gradle.api.plugins.nexus.NexusPlugin
}
}

protected void assertCorrectPomXml(File pomFile) {
println pomFile.text
def pomXml = new XmlSlurper().parse(pomFile)
assert pomXml.name.text() == 'myapp'
assert pomXml.description.text() == 'My application'
assert pomXml.inceptionYear.text() == '2012'
def developer = pomXml.developers.developer[0]
assert developer.id.text() == 'bmuschko'
assert developer.name.text() == 'Benjamin Muschko'
assert developer.email.text() == '[email protected]'
}

protected GradleProject runTasks(File projectDir, String... tasks) {
ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(projectDir).connect()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,54 @@ nexus {
assertExistingFiles(installationDir, expectedFilenames)
}

def "Installs all configured JARs, customized metadata and signature artifacts with default configuration"() {
setup:
def projectCoordinates = [group: 'org.gradle.mygroup', name: 'integTest', version: '1.0']
File installationDir = new File(M2_HOME_DIR, createInstallationDir(projectCoordinates))
deleteMavenLocalInstallationDir(installationDir)

when:
buildFile << """
version = '$projectCoordinates.version'
group = '$projectCoordinates.group'
nexus {
attachTests = true
}
modifyPom {
project {
name 'myapp'
description 'My application'
inceptionYear '2012'
developers {
developer {
id 'bmuschko'
name 'Benjamin Muschko'
email '[email protected]'
}
}
}
}
"""
runTasks(integTestDir, MavenPlugin.INSTALL_TASK_NAME)

then:
def expectedFilenames = ["${projectCoordinates.name}-${projectCoordinates.version}.jar",
"${projectCoordinates.name}-${projectCoordinates.version}.jar.asc",
"${projectCoordinates.name}-${projectCoordinates.version}.pom",
"${projectCoordinates.name}-${projectCoordinates.version}.pom.asc",
"${projectCoordinates.name}-${projectCoordinates.version}-javadoc.jar",
"${projectCoordinates.name}-${projectCoordinates.version}-javadoc.jar.asc",
"${projectCoordinates.name}-${projectCoordinates.version}-sources.jar",
"${projectCoordinates.name}-${projectCoordinates.version}-sources.jar.asc",
"${projectCoordinates.name}-${projectCoordinates.version}-tests.jar",
"${projectCoordinates.name}-${projectCoordinates.version}-tests.jar.asc"]
assertExistingFiles(installationDir, expectedFilenames)
assertCorrectPomXml(new File(installationDir, "${projectCoordinates.name}-${projectCoordinates.version}.pom"))
}

def "Installs all configured JARs, metadata and signature artifacts for release version with custom configuration"() {
setup:
def projectCoordinates = [group: 'org.gradle.mygroup', name: 'integTest', version: '1.0']
Expand Down Expand Up @@ -98,6 +146,63 @@ nexus {
assertExistingFiles(installationDir, expectedFilenames)
}

def "Installs all configured JARs, customized metadata and signature artifacts with custom configuration"() {
setup:
def projectCoordinates = [group: 'org.gradle.mygroup', name: 'integTest', version: '1.0']
File installationDir = new File(M2_HOME_DIR, createInstallationDir(projectCoordinates))
deleteMavenLocalInstallationDir(installationDir)

when:
buildFile << """
version = '$projectCoordinates.version'
group = '$projectCoordinates.group'
configurations {
myConfig.extendsFrom signatures
}
artifacts {
myConfig jar
}
nexus {
attachTests = true
configuration = configurations.myConfig
}
modifyPom {
project {
name 'myapp'
description 'My application'
inceptionYear '2012'
developers {
developer {
id 'bmuschko'
name 'Benjamin Muschko'
email '[email protected]'
}
}
}
}
"""
runTasks(integTestDir, MavenPlugin.INSTALL_TASK_NAME)

then:
def expectedFilenames = ["${projectCoordinates.name}-${projectCoordinates.version}.jar",
"${projectCoordinates.name}-${projectCoordinates.version}.jar.asc",
"${projectCoordinates.name}-${projectCoordinates.version}.pom",
"${projectCoordinates.name}-${projectCoordinates.version}.pom.asc",
"${projectCoordinates.name}-${projectCoordinates.version}-javadoc.jar",
"${projectCoordinates.name}-${projectCoordinates.version}-javadoc.jar.asc",
"${projectCoordinates.name}-${projectCoordinates.version}-sources.jar",
"${projectCoordinates.name}-${projectCoordinates.version}-sources.jar.asc",
"${projectCoordinates.name}-${projectCoordinates.version}-tests.jar",
"${projectCoordinates.name}-${projectCoordinates.version}-tests.jar.asc"]
assertExistingFiles(installationDir, expectedFilenames)
assertCorrectPomXml(new File(installationDir, "${projectCoordinates.name}-${projectCoordinates.version}.pom"))
}

def "Installs all configured JARs, metadata and signature artifacts for snapshot version with default configuration"() {
setup:
def projectCoordinates = [group: 'org.gradle.mygroup', name: 'integTest', version: '1.0-SNAPSHOT']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,45 @@ nexus {
assertExistingFiles(repoDir, expectedFilenames)
}

def "Uploads all configured JARs, customized metadata and signature artifacts with default configuration"() {
when:
buildFile << """
version = '1.0'
group = 'org.gradle.mygroup'
nexus {
attachTests = true
repositoryUrl = 'file://$integTestDir.canonicalPath/repo'
}
modifyPom {
project {
name 'myapp'
description 'My application'
inceptionYear '2012'
developers {
developer {
id 'bmuschko'
name 'Benjamin Muschko'
email '[email protected]'
}
}
}
}
"""
GradleProject project = runTasks(integTestDir, 'uploadArchives')

then:
File repoDir = new File(integTestDir, 'repo/org/gradle/mygroup/integTest/1.0')
def expectedFilenames = ["${project.name}-1.0.jar", "${project.name}-1.0.jar.asc", "${project.name}-1.0.pom",
"${project.name}-1.0.pom.asc", "${project.name}-1.0-javadoc.jar", "${project.name}-1.0-javadoc.jar.asc",
"${project.name}-1.0-sources.jar", "${project.name}-1.0-sources.jar.asc", "${project.name}-1.0-tests.jar",
"${project.name}-1.0-tests.jar.asc"]
assertExistingFiles(repoDir, expectedFilenames)
assertCorrectPomXml(new File(repoDir, "${project.name}-1.0.pom"))
}

def "Uploads all configured JARs, metadata and signature artifacts for release version with custom configuration"() {
when:
buildFile << """
Expand Down Expand Up @@ -76,6 +115,54 @@ nexus {
assertExistingFiles(repoDir, expectedFilenames)
}

def "Uploads all configured JARs, customized metadata and signature artifacts with custom configuration"() {
when:
buildFile << """
version = '1.0'
group = 'org.gradle.mygroup'
configurations {
myConfig.extendsFrom signatures
}
artifacts {
myConfig jar
}
nexus {
attachTests = true
repositoryUrl = 'file://$integTestDir.canonicalPath/repo'
configuration = configurations.myConfig
}
modifyPom {
project {
name 'myapp'
description 'My application'
inceptionYear '2012'
developers {
developer {
id 'bmuschko'
name 'Benjamin Muschko'
email '[email protected]'
}
}
}
}
"""
GradleProject project = runTasks(integTestDir, 'uploadMyConfig')

then:
File repoDir = new File(integTestDir, 'repo/org/gradle/mygroup/integTest/1.0')
def expectedFilenames = ["${project.name}-1.0.jar", "${project.name}-1.0.jar.asc", "${project.name}-1.0.pom",
"${project.name}-1.0.pom.asc", "${project.name}-1.0-javadoc.jar", "${project.name}-1.0-javadoc.jar.asc",
"${project.name}-1.0-sources.jar", "${project.name}-1.0-sources.jar.asc", "${project.name}-1.0-tests.jar",
"${project.name}-1.0-tests.jar.asc"]
assertExistingFiles(repoDir, expectedFilenames)
assertCorrectPomXml(new File(repoDir, "${project.name}-1.0.pom"))
}

def "Uploads all configured JARs and metadata without signature artifacts for release version with default configuration"() {
when:
buildFile << """
Expand Down
96 changes: 53 additions & 43 deletions src/main/groovy/org/gradle/api/plugins/nexus/NexusPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ class NexusPlugin implements Plugin<Project> {

NexusPluginExtension extension = project.extensions.create('nexus', NexusPluginExtension)

project.afterEvaluate {
configureTasks(project, extension)
configureSigning(project, extension)
configurePom(project)
configureUpload(project, extension)
}
configureTasks(project, extension)
configureSigning(project, extension)
configurePom(project, extension)
configureUpload(project, extension)
}

private void configureTasks(Project project, NexusPluginExtension extension) {
changeInstallTaskConfiguration(project, extension)
configureSourcesJarTask(project, extension)
configureTestsJarTask(project, extension)
configureJavadocJarTask(project, extension)
project.afterEvaluate {
changeInstallTaskConfiguration(project, extension)
configureSourcesJarTask(project, extension)
configureTestsJarTask(project, extension)
configureJavadocJarTask(project, extension)
}
}

private void changeInstallTaskConfiguration(Project project, NexusPluginExtension extension) {
Expand Down Expand Up @@ -110,18 +110,19 @@ class NexusPlugin implements Plugin<Project> {
}

private void configureSigning(Project project, NexusPluginExtension extension) {
if(extension.sign) {
project.signing {
required {
project.gradle.taskGraph.hasTask(extension.uploadTaskPath) && !project.version.endsWith('SNAPSHOT')
}

sign project.configurations[extension.configuration]
project.afterEvaluate {
if(extension.sign) {
project.signing {
required {
project.gradle.taskGraph.hasTask(extension.uploadTaskPath) && !project.version.endsWith('SNAPSHOT')
}

sign project.configurations[extension.configuration]

project.gradle.taskGraph.whenReady {
signPomForUpload(project, extension)
signInstallPom(project)
project.gradle.taskGraph.whenReady {
signPomForUpload(project, extension)
signInstallPom(project)
}
}
}
}
Expand Down Expand Up @@ -151,37 +152,46 @@ class NexusPlugin implements Plugin<Project> {
}
}

private void configurePom(Project project) {
private void configurePom(Project project, NexusPluginExtension extension) {
project.ext.modifyPom = { Closure modification ->
project.poms.each {
it.whenConfigured { project.configure(it, modification) }
project.afterEvaluate {
project.poms.each {
it.whenConfigured { project.configure(it, modification) }
}
}
}

project.afterEvaluate {
project.ext.poms = [project.tasks.getByName(MavenPlugin.INSTALL_TASK_NAME).repositories.mavenInstaller(),
project.tasks.getByName(extension.uploadTaskName).repositories.mavenDeployer()]*.pom
}
}

private void configureUpload(Project project, NexusPluginExtension extension) {
project.tasks.getByName(extension.uploadTaskName).repositories.mavenDeployer() {
project.gradle.taskGraph.whenReady { TaskExecutionGraph taskGraph ->
if(taskGraph.hasTask(extension.uploadTaskPath)) {
Console console = System.console()

String nexusUsername = project.hasProperty(NEXUS_USERNAME) ?
project.property(NEXUS_USERNAME) :
console.readLine('\nPlease specify username: ')

String nexusPassword = project.hasProperty(NEXUS_PASSWORD) ?
project.property(NEXUS_PASSWORD) :
new String(console.readPassword('\nPlease specify password: '))

if(extension.repositoryUrl) {
repository(url: extension.repositoryUrl) {
authentication(userName: nexusUsername, password: nexusPassword)
project.afterEvaluate {
project.tasks.getByName(extension.uploadTaskName).repositories.mavenDeployer() {
project.gradle.taskGraph.whenReady { TaskExecutionGraph taskGraph ->
if(taskGraph.hasTask(extension.uploadTaskPath)) {
Console console = System.console()

String nexusUsername = project.hasProperty(NEXUS_USERNAME) ?
project.property(NEXUS_USERNAME) :
console.readLine('\nPlease specify username: ')

String nexusPassword = project.hasProperty(NEXUS_PASSWORD) ?
project.property(NEXUS_PASSWORD) :
new String(console.readPassword('\nPlease specify password: '))

if(extension.repositoryUrl) {
repository(url: extension.repositoryUrl) {
authentication(userName: nexusUsername, password: nexusPassword)
}
}
}

if(extension.snapshotRepositoryUrl) {
snapshotRepository(url: extension.snapshotRepositoryUrl) {
authentication(userName: nexusUsername, password: nexusPassword)
if(extension.snapshotRepositoryUrl) {
snapshotRepository(url: extension.snapshotRepositoryUrl) {
authentication(userName: nexusUsername, password: nexusPassword)
}
}
}
}
Expand Down

0 comments on commit ea989d4

Please sign in to comment.