Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

Commit

Permalink
feature/AOS-5131 Added support for building python leveransepakker (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikand13 committed Nov 20, 2020
1 parent 401ecd0 commit 4063878
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 15 deletions.
3 changes: 0 additions & 3 deletions Jenkinsfile
Expand Up @@ -23,10 +23,7 @@ fileLoader.withGit(overrides.pipelineScript,, overrides.scriptVersion) {
}

jenkinsfile.gradle(overrides.scriptVersion, overrides, {

if(it.isSnapshotVersion) {
//it.version="2.2.3-rc4"
error("Cannot publish snapshot version to gradle plugin portal")
}

})
17 changes: 16 additions & 1 deletion README.md
Expand Up @@ -169,7 +169,13 @@ You can disable this with;
deliveryBundle = false
}
}


If you are building a python app your delivery bundle will have this format:

<artifactiId>-<version>-Leveransepakke/
<artifactiId>-<version>-Leveransepakke/metadata/<all contents of src/main/dist/metadata>
<artifactiId>-<version>-Leveransepakke/src/<all app source from src/main/resources and all deps exploded>

### Configuration of defaultTasks

defaultTasks will be set to `clean install` if this property has not already been set.
Expand Down Expand Up @@ -337,6 +343,13 @@ in your `~/.gradle/gradle.properties` file and be turned of in ci server. They c
}
}

### Python
If python is enabled the jython plugin will be added if missing, and a python leveransepakke will be built, with exploded source:

aurora {
usePython
}

### Kotlin
The Aurora plugin will react to Kotlin plugin and add dependencies on kotlin-reflect, stdlib-jdk8 and add
kotlinLogging (wrapper for Logback) with the version of. Kotlin will be configured to target
Expand Down Expand Up @@ -373,6 +386,7 @@ All configuration options and their default values are shown by running `:aurora
Complete configuration options for the `aurora` block looks like this:

aurora {
usePython
useGitProperties
useLatestVersions
useAsciiDoctor
Expand Down Expand Up @@ -416,6 +430,7 @@ Complete configuration options for the `aurora` block looks like this:
mavenDeployer = '<enabled>'
junit5Support = '<enabled>'
springDevTools = '<enabled>'
python = '<enabled>'
}
}

Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Expand Up @@ -41,6 +41,7 @@ object Features {
const val applyJunit5Support: Boolean = true
const val springDevTools: Boolean = false
const val useWebFlux: Boolean = false
const val usePython: Boolean = false
const val useBootJar: Boolean = false
const val useAuroraStarters: Boolean = true
}
Expand Up @@ -16,6 +16,7 @@ class Aurora(
if (config.applyDeliveryBundleConfig) {
add(
tools.applyDeliveryBundleConfig(
python = config.usePython,
bootJar = config.useBootJar
)
)
Expand Down
Expand Up @@ -18,7 +18,7 @@ class Maven(
if (config.applyMavenDeployer) {
project.logger.lifecycle("Apply maven deployer")

add(tools.addMavenDeployer())
add(tools.addMavenDeployer(python = config.usePython))
}
}
}
Expand Up @@ -43,6 +43,21 @@ open class AuroraExtension(private val project: Project) {
return this
}

val usePython: AuroraExtension
get() = configurePython()

fun usePython(): AuroraExtension = configurePython()

private fun configurePython(): AuroraExtension {
features {
with(it) {
python = true
}
}

return this
}

val useLatestVersions: AuroraExtension
get() = configureLatestVersions()

Expand Down
Expand Up @@ -11,4 +11,5 @@ open class Features {
var junit5Support: Boolean? = null
var springDevTools: Boolean? = null
var auroraStarters: Boolean? = null
var python: Boolean? = null
}
Expand Up @@ -30,6 +30,7 @@ data class AuroraConfiguration(
val applyJunit5Support: Boolean = Features.applyJunit5Support,
val springDevTools: Boolean = Features.springDevTools,
val useWebFlux: Boolean = Features.useWebFlux,
val usePython: Boolean = Features.usePython,
val useBootJar: Boolean = Features.useBootJar,
val useAuroraStarters: Boolean = Features.useAuroraStarters
) {
Expand Down Expand Up @@ -57,6 +58,7 @@ data class AuroraConfiguration(
"applyJunit5Support=$applyJunit5Support,\n" +
"springDevTools=$springDevTools,\n" +
"useWebFlux=$useWebFlux,\n" +
"usePython=$usePython,\n" +
"useBootJar=$useBootJar,\n" +
"useAuroraStarters=$useAuroraStarters)"
}
Expand Down Expand Up @@ -98,6 +100,7 @@ fun Project.getConfig(): AuroraConfiguration {
applyJunit5Support = features.junit5Support ?: props.asBoolean("applyJunit5Support") ?: Features.applyJunit5Support,
springDevTools = features.springDevTools ?: props.asBoolean("springDevTools") ?: Features.springDevTools,
useWebFlux = spring.webFluxEnabled ?: props.asBoolean("useWebFlux") ?: Features.useWebFlux,
usePython = features.python ?: props.asBoolean("usePython") ?: Features.usePython,
useBootJar = spring.bootJarEnabled ?: props.asBoolean("useBootJar") ?: Features.useBootJar,
useAuroraStarters = features.auroraStarters ?: props.asBoolean("useAuroraStarters") ?: Features.useAuroraStarters
)
Expand Down
Expand Up @@ -7,7 +7,43 @@ import org.gradle.api.tasks.bundling.Tar
import org.gradle.kotlin.dsl.named

class AuroraTools(private val project: Project) {
fun applyDeliveryBundleConfig(bootJar: Boolean): AuroraReport = when {
fun applyDeliveryBundleConfig(python: Boolean, bootJar: Boolean): AuroraReport = when {
python -> {
project.logger.lifecycle("Apply python delivery bundle")

with(project) {
plugins.apply("distribution")

with(extensions.getByName("distributions") as DistributionContainer) {
with(getByName("main")) {
with(contents) {
from("${project.buildDir}/resources/main") {
it.into("src")
}

from("${project.projectDir}/src/main/dist/metadata") {
it.into("metadata")
}
}
}
}

with(tasks.named("distZip", org.gradle.api.tasks.bundling.Zip::class).get()) {
archiveClassifier.set("Leveransepakke")
duplicatesStrategy = org.gradle.api.file.DuplicatesStrategy.EXCLUDE

dependsOn("processResources")
}

disableSuperfluousArtifacts()
}

AuroraReport(
name = "aurora.applyDeliveryBundleConfig",
pluginsApplied = listOf("distribution"),
description = "Configure Leveransepakke for python"
)
}
bootJar -> {
project.logger.lifecycle("Apply bootjar delivery bundle")

Expand Down Expand Up @@ -52,6 +88,8 @@ class AuroraTools(private val project: Project) {

with(tasks.named("distZip", org.gradle.api.tasks.bundling.Zip::class).get()) {
archiveClassifier.set("Leveransepakke")

dependsOn("jar")
}

disableSuperfluousArtifacts()
Expand Down
Expand Up @@ -9,7 +9,7 @@ import org.gradle.kotlin.dsl.withConvention
import org.gradle.kotlin.dsl.withGroovyBuilder

class MavenTools(private val project: Project) {
fun addMavenDeployer(): AuroraReport = when {
fun addMavenDeployer(python: Boolean = false): AuroraReport = when {
missingRepositoryConfiguration() -> AuroraReport(
name = "aurora.applyMavenDeployer",
description = MISSING_REPO_CREDS_MESSAGE
Expand All @@ -26,6 +26,7 @@ class MavenTools(private val project: Project) {
with(project) {
with(tasks) {
configureDeployer(
python,
repositoryReleaseUrl,
repositoryUsername,
repositoryPassword,
Expand Down Expand Up @@ -53,12 +54,17 @@ class MavenTools(private val project: Project) {
}

private fun TaskContainer.configureDeployer(
python: Boolean,
repositoryReleaseUrl: String,
repositoryUsername: String,
repositoryPassword: String,
repositorySnapshotUrl: String
) = named("uploadArchives", Upload::class.java) {
with(it) {
if (python) {
isUploadDescriptor = false
}

with(repositories) {
withConvention(MavenRepositoryHandlerConvention::class) {
with(mavenDeployer()) {
Expand Down
Expand Up @@ -105,9 +105,9 @@ class AuroraToolsTest {
val metaEntryCount = zipEntries.filter { it.name.contains("Leveransepakke/metadata") }
val distDir = testProjectDir.resolve("build/distributions")

assertThat(libEntry?.isDirectory ?: false).isTrue()
assertThat(libEntry?.isDirectory).isNotNull().isTrue()
assertThat(libEntryCount.size).isEqualTo(2)
assertThat(metaEntry?.isDirectory ?: false).isTrue()
assertThat(metaEntry?.isDirectory).isNotNull().isTrue()
assertThat(metaEntryCount.size).isEqualTo(2)
assertThat(distDir.listFiles().size).isEqualTo(1)
assertThat(distDir.listFiles().first().name).contains("Leveransepakke")
Expand Down Expand Up @@ -170,14 +170,91 @@ class AuroraToolsTest {
val distDir = testProjectDir.resolve("build/distributions")

assertThat(libEntry).isNotNull()
assertThat(libEntry?.isDirectory ?: false).isTrue()
assertThat(libEntry?.isDirectory).isNotNull().isTrue()
assertThat(metaEntry).isNotNull()
assertThat(metaEntry?.isDirectory ?: false).isTrue()
assertThat(metaEntry?.isDirectory).isNotNull().isTrue()
assertThat(result.taskOutcome()).isSuccessOrEqualTo()
assertThat(distDir.listFiles()).hasSize(1)
assertThat(distDir.listFiles().first().name).contains("Leveransepakke")
}

@Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
@Test
fun `deliveryBundleConfig built correctly for python`() {
testProjectDir.resolve("src/main/resources").mkdirs()
testProjectDir.resolve("src/main/dist/metadata").mkdirs()
val openshiftMeta = testProjectDir.resolve("src/main/dist/metadata/openshift.json")
openshiftMeta.createNewFile()
openshiftMeta.writeText(
"""
{}
""".trimIndent()
)
val application = testProjectDir.resolve("src/main/resources/__run__.py")
application.createNewFile()
application.writeText(
"""
print("Hello world!")
""".trimIndent()
)
val requirements = testProjectDir.resolve("src/main/resources/req.txt")
requirements.createNewFile()
requirements.writeText(
"""
certifi==2020.6.20
chardet==3.0.4
docopt==0.6.2
idna==2.10
numpy==1.19.2
pandas==1.1.3
psycopg2-binary==2.8.6
python-dateutil==2.8.1
pytz==2020.1
requests==2.24.0
six==1.15.0
urllib3==1.25.11
yarg==0.1.9
""".trimIndent()
)
buildFile.writeText(
"""
plugins {
id 'no.skatteetaten.gradle.aurora'
}
repositories {
mavenCentral()
}
aurora {
usePython
}
""".trimIndent()
)
val result = GradleRunner.create()
.withProjectDir(testProjectDir)
.withArguments("build")
.withPluginClasspath()
.build()
val jar = testProjectDir.resolve("build/distributions").listFiles()
?.find { it.path.contains("Leveransepakke") }
val jarAsZip = ZipFile(jar)
val zipEntries = jarAsZip.entries().toList()
val libEntry = zipEntries.find { it.name.endsWith("src/") }
val libEntryCount = zipEntries.filter { it.name.contains("Leveransepakke/src") }
val metaEntry = zipEntries.find { it.name.endsWith("metadata/") }
val metaEntryCount = zipEntries.filter { it.name.contains("Leveransepakke/metadata") }
val distDir = testProjectDir.resolve("build/distributions")

assertThat(libEntry?.isDirectory).isNotNull().isTrue()
assertThat(libEntryCount.size).isEqualTo(3)
assertThat(metaEntry?.isDirectory).isNotNull().isTrue()
assertThat(metaEntryCount.size).isEqualTo(2)
assertThat(distDir.listFiles().size).isEqualTo(1)
assertThat(distDir.listFiles().first().name).contains("Leveransepakke")
assertThat(result.taskOutcome()).isSuccessOrEqualTo()
}

@Test
fun `java defaults configure version and group correctly`() {
val gradleProps = testProjectDir.resolve("gradle.properties")
Expand Down
Expand Up @@ -128,9 +128,9 @@ class JavaToolsTest {
val metaEntry = zipEntries.find { it.name.endsWith("metadata/") }
val metaEntryCount = zipEntries.filter { it.name.contains("Leveransepakke/metadata") }

assertThat(libEntry?.isDirectory ?: false).isTrue()
assertThat(libEntry?.isDirectory).isNotNull().isTrue()
assertThat(libEntryCount.size).isEqualTo(2)
assertThat(metaEntry?.isDirectory ?: false).isTrue()
assertThat(metaEntry?.isDirectory).isNotNull().isTrue()
assertThat(metaEntryCount.size).isEqualTo(2)
assertThat(result.taskOutcome()).isSuccessOrEqualTo()
}
Expand Down Expand Up @@ -189,9 +189,9 @@ class JavaToolsTest {
val metaEntry = jarAsZip.entries().toList().find { it.name.endsWith("metadata/") }

assertThat(libEntry).isNotNull()
assertThat(libEntry?.isDirectory ?: false).isTrue()
assertThat(libEntry?.isDirectory).isNotNull().isTrue()
assertThat(metaEntry).isNotNull()
assertThat(metaEntry?.isDirectory ?: false).isTrue()
assertThat(metaEntry?.isDirectory).isNotNull().isTrue()
assertThat(result.taskOutcome()).isSuccessOrEqualTo()
}

Expand Down

0 comments on commit 4063878

Please sign in to comment.