Skip to content

Commit

Permalink
don't write null values to pom (#89)
Browse files Browse the repository at this point in the history
* add integration tests with minimal set of pom values

* move setting test values to fixture setup

* don't write null values to pom
  • Loading branch information
gabrielittner authored Jan 25, 2020
1 parent eb962d7 commit feaaa27
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 21 deletions.
10 changes: 10 additions & 0 deletions src/integrationTest/fixtures/minimal_pom_project/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id "java"
id "com.vanniktech.maven.publish"
}

repositories {
mavenCentral()
}

apply from: "maven-publish.gradle"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>test-artifact</artifactId>
<version>1.0.0</version>
<licenses>
<license />
</licenses>
<developers>
<developer />
</developers>
<scm />
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
signing.keyId=B89C4055
signing.password=test
signing.secretKeyRingFile=test-secring.gpg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.vanniktech.maven.publish.test;

/**
* Just a test class with Javadoc.
*/
public class TestClass {
/**
* Main method which does something.
*
* @param args Command-line arguments passed to the program.
*/
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ class MavenPublishPluginIntegrationTest(
repoFolder = testProjectDir.newFolder("repo")

File("$FIXTURES/common").listFiles()?.forEach { it.copyRecursively(testProjectDir.root.resolve(it.name)) }
testProjectDir.root.resolve("gradle.properties").appendText("""
GROUP=$TEST_GROUP
VERSION_NAME=$TEST_VERSION_NAME
POM_ARTIFACT_ID=$TEST_POM_ARTIFACT_ID
test.releaseRepository=$repoFolder
test.useLegacyMode=$useLegacyMode
""")

val group = TEST_GROUP.replace(".", "/")
val artifactId = TEST_POM_ARTIFACT_ID
Expand Down Expand Up @@ -128,11 +120,29 @@ class MavenPublishPluginIntegrationTest(
assertExpectedCommonArtifactsGenerated("aar")
}

@Test fun generatesArtifactsAndDocumentationOnMinimalPomProject() {
setupFixture("minimal_pom_project")

val result = executeGradleCommands(uploadArchivesTargetTaskName, "--info")

assertExpectedTasksRanSuccessfully(result)
assertExpectedCommonArtifactsGenerated("jar")
}

/**
* Copies test fixture into temp directory under test.
*/
private fun setupFixture(fixtureName: String) {
File("$FIXTURES/$fixtureName").copyRecursively(testProjectDir.root, overwrite = true)

testProjectDir.root.resolve("gradle.properties").appendText("""
GROUP=$TEST_GROUP
VERSION_NAME=$TEST_VERSION_NAME
POM_ARTIFACT_ID=$TEST_POM_ARTIFACT_ID
test.releaseRepository=$repoFolder
test.useLegacyMode=$useLegacyMode
""")
}

private fun assertExpectedTasksRanSuccessfully(result: BuildResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,30 +164,56 @@ class MavenPublishPlugin extends BaseMavenPublishPlugin {
pom.version = publishPom.version

pom.project {
name publishPom.name
packaging publishPom.packaging
description publishPom.description
url publishPom.url
if (publishPom.name != null) {
name publishPom.name
}
if (publishPom.packaging != null) {
packaging publishPom.packaging
}
if (publishPom.description != null) {
description publishPom.description
}
if (publishPom.url != null) {
url publishPom.url
}

scm {
url publishPom.scmUrl
connection publishPom.scmConnection
developerConnection publishPom.scmDeveloperConnection
if (publishPom.scmUrl != null) {
url publishPom.scmUrl
}
if (publishPom.scmConnection != null) {
connection publishPom.scmConnection
}
if (publishPom.scmDeveloperConnection != null) {
developerConnection publishPom.scmDeveloperConnection
}
}

licenses {
license {
name publishPom.licenseName
url publishPom.licenseUrl
distribution publishPom.licenseDistribution
if (publishPom.licenseName != null) {
name publishPom.licenseName
}
if (publishPom.licenseUrl != null) {
url publishPom.licenseUrl
}
if (publishPom.licenseDistribution != null) {
distribution publishPom.licenseDistribution
}
}
}

developers {
developer {
id publishPom.developerId
name publishPom.developerName
url publishPom.developerUrl
if (publishPom.developerId != null) {
id publishPom.developerId
}
if (publishPom.developerName != null) {
name publishPom.developerName
}
if (publishPom.developerUrl != null) {
url publishPom.developerUrl
}
}
}
}
Expand Down

0 comments on commit feaaa27

Please sign in to comment.