Skip to content

Commit

Permalink
publish empty source and javadocs jars for plugin marker (#118)
Browse files Browse the repository at this point in the history
* make test helpers more reusable

* publish empty source and javadocs jars for plugin marker
  • Loading branch information
gabrielittner authored Feb 23, 2020
1 parent b77782a commit 9ef18be
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,21 @@ class MavenPublishPluginIntegrationTest(
assertPomContentMatches()

val metadataArtifactId = "$TEST_POM_ARTIFACT_ID-metadata"
assertExpectedCommonArtifactsGenerated(metadataArtifactId, "module")
assertArtifactGenerated(metadataArtifactId, "$metadataArtifactId-$TEST_VERSION_NAME.jar")
assertExpectedCommonArtifactsGenerated("module", metadataArtifactId)
assertArtifactGenerated("$metadataArtifactId-$TEST_VERSION_NAME.jar", metadataArtifactId)
assertPomContentMatches(metadataArtifactId)

val jvmArtifactId = "$TEST_POM_ARTIFACT_ID-jvm"
assertExpectedCommonArtifactsGenerated(jvmArtifactId, "module")
assertExpectedCommonArtifactsGenerated("module", jvmArtifactId)
assertPomContentMatches(jvmArtifactId)

val nodejsArtifactId = "$TEST_POM_ARTIFACT_ID-nodejs"
assertExpectedCommonArtifactsGenerated(nodejsArtifactId, "module")
assertExpectedCommonArtifactsGenerated("module", nodejsArtifactId)
assertPomContentMatches(nodejsArtifactId)

val linuxArtifactId = "$TEST_POM_ARTIFACT_ID-linux"
assertExpectedCommonArtifactsGenerated(linuxArtifactId, "module")
assertArtifactGenerated(linuxArtifactId, "$linuxArtifactId-$TEST_VERSION_NAME.klib")
assertExpectedCommonArtifactsGenerated("module", linuxArtifactId)
assertArtifactGenerated("$linuxArtifactId-$TEST_VERSION_NAME.klib", linuxArtifactId)
assertPomContentMatches(linuxArtifactId)
}

Expand All @@ -178,10 +178,9 @@ class MavenPublishPluginIntegrationTest(

if (!useLegacyMode) {
val pluginId = "com.example.test-plugin"
val markerArtifactFolder = repoFolder.resolve("${pluginId.replace(".", "/")}/$pluginId.gradle.plugin/$TEST_VERSION_NAME")
val pomFile = "$pluginId.gradle.plugin-$TEST_VERSION_NAME.pom"
assertArtifactGenerated(markerArtifactFolder, pomFile)
assertPomContentMatches(markerArtifactFolder, pomFile)
val artifactId = "$pluginId.gradle.plugin"
assertExpectedCommonArtifactsGenerated("pom", artifactId, pluginId)
assertPomContentMatches(artifactId, pluginId)
}
}

Expand Down Expand Up @@ -216,43 +215,38 @@ class MavenPublishPluginIntegrationTest(
* no matter what project type is and which plugins are applied.
*/
private fun assertExpectedCommonArtifactsGenerated(
artifactExtension: String = "jar",
artifactId: String = TEST_POM_ARTIFACT_ID,
artifactExtension: String = "jar"
groupId: String = TEST_GROUP
) {
val artifactFolder = artifactFolder(artifactId)
val artifactJar = "$artifactId-$TEST_VERSION_NAME.$artifactExtension"
val pomFile = "$artifactId-$TEST_VERSION_NAME.pom"
val javadocJar = "$artifactId-$TEST_VERSION_NAME-javadoc.jar"
val sourcesJar = "$artifactId-$TEST_VERSION_NAME-sources.jar"
assertArtifactGenerated(artifactFolder, artifactJar)
assertArtifactGenerated(artifactFolder, pomFile)
assertArtifactGenerated(artifactFolder, javadocJar)
assertArtifactGenerated(artifactFolder, sourcesJar)
assertArtifactGenerated(artifactJar, artifactId, groupId)
assertArtifactGenerated(pomFile, artifactId, groupId)
assertArtifactGenerated(javadocJar, artifactId, groupId)
assertArtifactGenerated(sourcesJar, artifactId, groupId)
}

private fun assertArtifactGenerated(
artifactFileNameWithExtension: String,
artifactId: String = TEST_POM_ARTIFACT_ID,
artifactFileNameWithExtension: String
groupId: String = TEST_GROUP
) {
assertArtifactGenerated(artifactFolder(artifactId), artifactFileNameWithExtension)
}
val artifactFolder = artifactFolder(artifactId, groupId)

private fun assertArtifactGenerated(
artifactFolder: File,
artifactFileNameWithExtension: String
) {
assertThat(artifactFolder.resolve(artifactFileNameWithExtension)).exists()
assertThat(artifactFolder.resolve("$artifactFileNameWithExtension.asc")).exists()
}

private fun assertPomContentMatches(artifactId: String = TEST_POM_ARTIFACT_ID) {
assertPomContentMatches(artifactFolder(artifactId), "$artifactId-$TEST_VERSION_NAME.pom")
}

private fun assertPomContentMatches(
artifactFolder: File,
pomFileName: String
artifactId: String = TEST_POM_ARTIFACT_ID,
groupId: String = TEST_GROUP
) {
val artifactFolder = artifactFolder(artifactId, groupId)
val pomFileName = "$artifactId-$TEST_VERSION_NAME.pom"

val resolvedPomFile = artifactFolder.resolve(pomFileName)
// in legacyMode for Android the packaging is written, for all other modes it's currently not written
// https://github.com/vanniktech/gradle-maven-publish-plugin/issues/82
Expand All @@ -275,9 +269,11 @@ class MavenPublishPluginIntegrationTest(
private fun assertSourceJarContainsFile(
file: String,
srcRoot: String,
artifactId: String = TEST_POM_ARTIFACT_ID
artifactId: String = TEST_POM_ARTIFACT_ID,
groupId: String = TEST_GROUP
) {
val sourcesJar = ZipFile(artifactFolder().resolve("$artifactId-$TEST_VERSION_NAME-sources.jar"))
val artifactFolder = artifactFolder(artifactId, groupId)
val sourcesJar = ZipFile(artifactFolder.resolve("$artifactId-$TEST_VERSION_NAME-sources.jar"))
val entry = sourcesJar.getEntry(file)
val content = sourcesJar.getInputStream(entry)?.reader()?.buffered()?.readText()

Expand All @@ -288,10 +284,10 @@ class MavenPublishPluginIntegrationTest(
assertThat(content).isEqualTo(expectedContent)
}

private fun artifactFolder(artifactId: String = TEST_POM_ARTIFACT_ID): File {
val group = TEST_GROUP.replace(".", "/")
private fun artifactFolder(artifactId: String, groupId: String): File {
val group = groupId.replace(".", "/")
val version = TEST_VERSION_NAME
return repoFolder.resolve("$group/$artifactId/$version")
return repoFolder.resolve(group).resolve(artifactId).resolve(version)
}

private fun executeGradleCommands(vararg commands: String) = GradleRunner.create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.vanniktech.maven.publish.MavenPublishPluginExtension.Companion.LOCAL_
import com.vanniktech.maven.publish.tasks.AndroidJavadocs
import com.vanniktech.maven.publish.tasks.AndroidJavadocsJar
import com.vanniktech.maven.publish.tasks.AndroidSourcesJar
import com.vanniktech.maven.publish.tasks.EmptyJavadocsJar
import com.vanniktech.maven.publish.tasks.EmptySourcesJar
import com.vanniktech.maven.publish.tasks.GroovydocsJar
import com.vanniktech.maven.publish.tasks.JavadocsJar
Expand Down Expand Up @@ -147,6 +148,10 @@ internal class MavenPublishConfigurer(
if (it.name == "${plugin.name}PluginMarkerMaven") {
// keep the current group and artifact ids, they are based on the gradle plugin id
configurePom(it, groupId = it.groupId, artifactId = it.artifactId)
val emptyJavadocsJar = project.tasks.register("emptyJavadocsJar", EmptyJavadocsJar::class.java)
it.addTaskOutput(emptyJavadocsJar)
val emptySourcesJar = project.tasks.register("emptySourcesJar", EmptySourcesJar::class.java)
it.addTaskOutput(emptySourcesJar)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.vanniktech.maven.publish.tasks

import org.gradle.jvm.tasks.Jar

@Suppress("UnstableApiUsage")
open class EmptyJavadocsJar : Jar() {

init {
archiveClassifier.set("javadoc")
}
}

0 comments on commit 9ef18be

Please sign in to comment.