-
Notifications
You must be signed in to change notification settings - Fork 1
multiproject setup testing and fixes #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -18,13 +18,16 @@ package nebula.plugin.publishing | |
| import org.gradle.api.Plugin | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.provider.ProviderFactory | ||
| import org.gradle.api.publish.maven.tasks.PublishToMavenRepository | ||
| import org.gradle.kotlin.dsl.apply | ||
| import org.gradle.kotlin.dsl.withType | ||
| import javax.inject.Inject | ||
|
|
||
| /** | ||
| * Configures artifact signing and publication to NetflixOSS and Maven Central | ||
| */ | ||
| open class NebulaOssPublishingPlugin @Inject constructor(private val providerFactory: ProviderFactory): Plugin<Project> { | ||
| open class NebulaOssPublishingPlugin @Inject constructor(private val providerFactory: ProviderFactory) : | ||
| Plugin<Project> { | ||
| companion object { | ||
| const val netflixOssDefaultRepositoryBaseUrl = "https://artifacts-oss.netflix.net/artifactory" | ||
| const val netflixOssGradlePluginsRepository = "gradle-plugins" | ||
|
|
@@ -43,6 +46,16 @@ open class NebulaOssPublishingPlugin @Inject constructor(private val providerFac | |
| project.pluginManager.apply(MavenCentralPublishingPlugin::class) | ||
| project.pluginManager.apply(NebulaOssRepositoriesPlugin::class) | ||
|
|
||
| project.plugins.withId("com.netflix.nebula.release") { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think plugins we have built on top of this accounted for this, but including this logic here make this plugin a lot more usable on its own and testable |
||
| project.afterEvaluate { | ||
| project.tasks.withType<PublishToMavenRepository> { | ||
| mustRunAfter(project.rootProject.tasks.named("release")) | ||
| } | ||
| project.rootProject.tasks.named("postRelease") { | ||
| dependsOn(project.tasks.withType<PublishToMavenRepository>()) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun setExtensionDefaults(nebulaOssPublishingExtension: NebulaOssPublishingExtension, project: Project) { | ||
|
|
@@ -64,7 +77,7 @@ open class NebulaOssPublishingPlugin @Inject constructor(private val providerFac | |
| "sonatypeStagingProfileId" | ||
| ) ?: netflixDefaultStagingProfile | ||
|
|
||
| if(!stagingProfileId.isNotBlank()) { | ||
| if (!stagingProfileId.isNotBlank()) { | ||
| extension.stagingProfileId.convention(stagingProfileId) | ||
| } | ||
| } | ||
|
|
@@ -77,14 +90,14 @@ open class NebulaOssPublishingPlugin @Inject constructor(private val providerFac | |
| "sonatypePackageGroup" | ||
| ) ?: project.group.toString().split(".").take(2).joinToString(".") | ||
|
|
||
| if(packageGroup.isNotBlank()) { | ||
| if (packageGroup.isNotBlank()) { | ||
| extension.packageGroup.convention(packageGroup) | ||
| } | ||
| } | ||
|
|
||
| private fun setSigningKey(extension: NebulaOssPublishingExtension, project: Project) { | ||
| val signingKeyFile = project.rootProject.file(signingKeyFileLocation) | ||
| if(signingKeyFile.exists()) { | ||
| if (signingKeyFile.exists()) { | ||
| extension.signingKey.convention(signingKeyFile.readText()) | ||
| } else { | ||
| val signingKey = findPropertyValue( | ||
|
|
@@ -93,54 +106,64 @@ open class NebulaOssPublishingPlugin @Inject constructor(private val providerFac | |
| "sonatype.signingKey", | ||
| "netflixOssSigningKey" | ||
| ) | ||
| if(!signingKey.isNullOrBlank()) { | ||
| if (!signingKey.isNullOrBlank()) { | ||
| extension.signingKey.convention(signingKey) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun setSigningPassword(extension: NebulaOssPublishingExtension, project: Project) { | ||
| val signingPassword = findPropertyValue(project, | ||
| val signingPassword = findPropertyValue( | ||
| project, | ||
| "NETFLIX_OSS_SIGNING_PASSWORD", | ||
| "sonatype.signingPassword", | ||
| "netflixOssSigningPassword") | ||
| if(!signingPassword.isNullOrBlank()) { | ||
| "netflixOssSigningPassword" | ||
| ) | ||
| if (!signingPassword.isNullOrBlank()) { | ||
| extension.signingPassword.convention(signingPassword) | ||
| } | ||
| } | ||
|
|
||
| private fun setNetflixOssCredentials(extension: NebulaOssPublishingExtension, project: Project) { | ||
| val netflixOssUsername = findPropertyValue(project, | ||
| val netflixOssUsername = findPropertyValue( | ||
| project, | ||
| "NETFLIX_OSS_REPO_USERNAME", | ||
| "netflixOss.username", | ||
| "netflixOssUsername") | ||
| if(!netflixOssUsername.isNullOrBlank()) { | ||
| "netflixOssUsername" | ||
| ) | ||
| if (!netflixOssUsername.isNullOrBlank()) { | ||
| extension.netflixOssUsername.convention(netflixOssUsername) | ||
| } | ||
|
|
||
| val netflixOssPassword = findPropertyValue(project, | ||
| val netflixOssPassword = findPropertyValue( | ||
| project, | ||
| "NETFLIX_OSS_REPO_PASSWORD", | ||
| "netflixOss.password", | ||
| "netflixOssPassword") | ||
| if(!netflixOssPassword.isNullOrBlank()) { | ||
| "netflixOssPassword" | ||
| ) | ||
| if (!netflixOssPassword.isNullOrBlank()) { | ||
| extension.netflixOssPassword.convention(netflixOssPassword) | ||
| } | ||
| } | ||
|
|
||
| private fun setMavenCentralCredentials(extension: NebulaOssPublishingExtension, project: Project) { | ||
| val sonatypeUsername = findPropertyValue(project, | ||
| val sonatypeUsername = findPropertyValue( | ||
| project, | ||
| "NETFLIX_OSS_SONATYPE_USERNAME", | ||
| "sonatype.username", | ||
| "sonatypeUsername") | ||
| if(!sonatypeUsername.isNullOrBlank()) { | ||
| "sonatypeUsername" | ||
| ) | ||
| if (!sonatypeUsername.isNullOrBlank()) { | ||
| extension.sonatypeUsername.convention(sonatypeUsername) | ||
| } | ||
|
|
||
| val sonatypePassword = findPropertyValue(project, | ||
| val sonatypePassword = findPropertyValue( | ||
| project, | ||
| "NETFLIX_OSS_SONATYPE_PASSWORD", | ||
| "sonatype.password", | ||
| "sonatypePassword") | ||
| if(!sonatypePassword.isNullOrBlank()) { | ||
| "sonatypePassword" | ||
| ) | ||
| if (!sonatypePassword.isNullOrBlank()) { | ||
| extension.sonatypePassword.convention(sonatypePassword) | ||
| } | ||
| } | ||
|
|
@@ -152,7 +175,7 @@ open class NebulaOssPublishingPlugin @Inject constructor(private val providerFac | |
| "netflixOss.repositoryBaseUrl", | ||
| "netflixOssRepositoryBaseUrl" | ||
| ) | ||
| if(!repositoryBaseUrl.isNullOrBlank()) { | ||
| if (!repositoryBaseUrl.isNullOrBlank()) { | ||
| extension.netflixOssRepositoryBaseUrl.convention(repositoryBaseUrl) | ||
| } else { | ||
| extension.netflixOssRepositoryBaseUrl.convention(netflixOssDefaultRepositoryBaseUrl) | ||
|
|
@@ -195,32 +218,38 @@ open class NebulaOssPublishingPlugin @Inject constructor(private val providerFac | |
| } | ||
|
|
||
| private fun projectExecutionHasTask(project: Project, task: String): Boolean { | ||
| return project.gradle.startParameter.taskNames.contains(task) || project.gradle.startParameter.taskNames.contains(":${task}") | ||
| return project.gradle.startParameter.taskNames.contains(task) || project.gradle.startParameter.taskNames.contains( | ||
| ":${task}" | ||
| ) | ||
| } | ||
|
|
||
| private fun findPropertyValue(project: Project, | ||
| envVariableName: String, | ||
| namespacedPropertyName: String, | ||
| propertyName: String | ||
| ) : String? { | ||
| private fun findPropertyValue( | ||
| project: Project, | ||
| envVariableName: String, | ||
| namespacedPropertyName: String, | ||
| propertyName: String | ||
| ): String? { | ||
| val propertyValueFromEnv = readEnvVariable(envVariableName) | ||
| return when { | ||
| propertyValueFromEnv != null -> { | ||
| propertyValueFromEnv | ||
| } | ||
|
|
||
| project.hasProperty(propertyName) -> { | ||
| project.prop(propertyName) | ||
| } | ||
|
|
||
| project.hasProperty(namespacedPropertyName) -> { | ||
| project.prop(namespacedPropertyName) | ||
| } | ||
|
|
||
| else -> null | ||
| } | ||
| } | ||
|
|
||
| private fun readEnvVariable(envVariableName: String) : String? { | ||
| private fun readEnvVariable(envVariableName: String): String? { | ||
| val envVariable = providerFactory.environmentVariable(envVariableName) | ||
| return if(envVariable.isPresent) envVariable.get() else null | ||
| return if (envVariable.isPresent) envVariable.get() else null | ||
| } | ||
|
|
||
| private fun Project.prop(s: String): String? = project.findProperty(s) as String? | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package nebula.plugin.publishing | ||
|
|
||
| import nebula.test.dsl.TestProjectRunner | ||
| import org.ajoberstar.grgit.Grgit | ||
| import java.io.File | ||
|
|
||
| fun withGitTag( | ||
| projectDir: File, | ||
| remoteGitDir: File, | ||
| tag: String, | ||
| block: () -> TestProjectRunner | ||
| ): TestProjectRunner { | ||
| Grgit.init { | ||
| dir = remoteGitDir | ||
| } | ||
| val localCopy = Grgit.clone { | ||
| dir = projectDir | ||
| uri = remoteGitDir.toURI().toString() | ||
| } | ||
| projectDir.resolve(".gitignore").writeText( | ||
| """ | ||
| .gradle/ | ||
| """ | ||
| ) | ||
| val runner = block() | ||
| localCopy.add { | ||
| this.patterns = setOf(".") | ||
| } | ||
| localCopy.commit { | ||
| message = "Initial" | ||
| } | ||
| localCopy.tag.add { | ||
| name = tag | ||
| } | ||
| return runner | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep it lazy