-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support to automatic apply application framework support for Spri…
…ng and Micronaut
- Loading branch information
Showing
21 changed files
with
295 additions
and
52 deletions.
There are no files selected for viewing
This file contains 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 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 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
24 changes: 24 additions & 0 deletions
24
...otlin/io/cloudflight/gradle/autoconfigure/application/development/DevelopmentExtension.kt
This file contains 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,24 @@ | ||
package io.cloudflight.gradle.autoconfigure.application.development | ||
|
||
import io.cloudflight.gradle.autoconfigure.AutoConfigureGradlePlugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.plugins.JavaPlugin | ||
import org.gradle.api.tasks.WriteProperties | ||
import org.gradle.language.jvm.tasks.ProcessResources | ||
|
||
object DevelopmentExtension { | ||
|
||
fun create(project: Project) { | ||
val propertiesTask = | ||
project.tasks.create("clfDevelopmentProperties", WriteProperties::class.java) { | ||
it.property("development.name", project.name) | ||
it.property("development.group", project.group.toString()) | ||
it.property("development.version", project.version.toString()) | ||
it.encoding = "UTF-8" | ||
it.group = AutoConfigureGradlePlugin.TASK_GROUP | ||
it.setOutputFile(project.layout.buildDirectory.file("generated/resources/development/development.properties")) | ||
} | ||
project.tasks.named(JavaPlugin.PROCESS_RESOURCES_TASK_NAME, ProcessResources::class.java).get() | ||
.from(propertiesTask) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/io/cloudflight/gradle/autoconfigure/application/shadow/ShadowExtension.kt
This file contains 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,21 @@ | ||
package io.cloudflight.gradle.autoconfigure.application.shadow | ||
|
||
import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin | ||
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin | ||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar | ||
import org.gradle.api.Project | ||
import org.gradle.api.plugins.ApplicationPlugin | ||
|
||
object ShadowExtension { | ||
|
||
fun create(project: Project) { | ||
project.plugins.apply(ShadowPlugin::class.java) | ||
project.plugins.apply(ApplicationPlugin::class.java) | ||
} | ||
|
||
fun configure(project: Project) { | ||
val shadowJar = project.tasks.getByName(ShadowJavaPlugin.SHADOW_JAR_TASK_NAME) as ShadowJar | ||
shadowJar.mergeServiceFiles() | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
.../kotlin/io/cloudflight/gradle/autoconfigure/application/springboot/SpringBootExtension.kt
This file contains 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,28 @@ | ||
package io.cloudflight.gradle.autoconfigure.application.springboot | ||
|
||
import io.cloudflight.gradle.autoconfigure.java.PopulateManifestAction | ||
import org.gradle.api.Project | ||
import org.gradle.api.plugins.JavaPlugin | ||
import org.springframework.boot.gradle.plugin.SpringBootPlugin | ||
import org.springframework.boot.gradle.tasks.bundling.BootJar | ||
|
||
object SpringBootExtension { | ||
fun create(project: Project) { | ||
project.plugins.apply(SpringBootPlugin::class.java) | ||
} | ||
|
||
fun configure(project: Project) { | ||
val boot = project.tasks.getByName(SpringBootPlugin.BOOT_JAR_TASK_NAME) as BootJar | ||
boot.archiveBaseName.set(project.name) | ||
boot.archiveFileName.set("${project.name}.jar") | ||
boot.doFirst(PopulateManifestAction) | ||
|
||
val springBoot = project.extensions.getByType(org.springframework.boot.gradle.dsl.SpringBootExtension::class.java) | ||
springBoot.buildInfo() | ||
|
||
// we don't need the plain archive, see https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#packaging-executable.and-plain-archives | ||
project.tasks.named(JavaPlugin.JAR_TASK_NAME) { | ||
it.enabled = false | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...in/kotlin/io/cloudflight/gradle/autoconfigure/extentions/gradle/api/project/ProjectExt.kt
This file contains 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,12 @@ | ||
package io.cloudflight.gradle.autoconfigure.extentions.gradle.api.project | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
|
||
fun Project.withPlugin(plugin: Class<out Plugin<*>>, callable: () -> Any) { | ||
if (plugins.hasPlugin(plugin)) { | ||
callable.invoke() | ||
} else { | ||
plugins.withType(plugin).whenPluginAdded { callable.invoke() } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/io/cloudflight/gradle/autoconfigure/git/GitExtension.kt
This file contains 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,17 @@ | ||
package io.cloudflight.gradle.autoconfigure.git | ||
|
||
import com.gorylenko.GitPropertiesPlugin | ||
import com.gorylenko.GitPropertiesPluginExtension | ||
import org.gradle.api.Project | ||
|
||
object GitExtension { | ||
|
||
fun create(project:Project) { | ||
project.plugins.apply(GitPropertiesPlugin::class.java) | ||
} | ||
|
||
fun configure(project:Project) { | ||
val gitProperties = project.extensions.getByType(GitPropertiesPluginExtension::class.java) | ||
gitProperties.customProperty("gradle.version", project.gradle.gradleVersion) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/io/cloudflight/gradle/autoconfigure/java/ApplicationFramework.kt
This file contains 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,7 @@ | ||
package io.cloudflight.gradle.autoconfigure.java | ||
|
||
enum class ApplicationFramework { | ||
SpringBoot, | ||
Micronaut, | ||
Other | ||
} |
This file contains 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 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
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/io/cloudflight/gradle/autoconfigure/java/PopulateManifestAction.kt
This file contains 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 io.cloudflight.gradle.autoconfigure.java | ||
|
||
import io.cloudflight.gradle.autoconfigure.extentions.gradle.api.java.archives.attributes | ||
import io.cloudflight.gradle.autoconfigure.extentions.gradle.api.plugins.getByType | ||
import org.gradle.api.Action | ||
import org.gradle.api.Task | ||
import org.gradle.api.plugins.JavaPlugin | ||
import org.gradle.api.plugins.JavaPluginExtension | ||
import org.gradle.jvm.tasks.Jar | ||
import org.gradle.jvm.toolchain.JavaToolchainService | ||
|
||
internal object PopulateManifestAction : Action<Task> { | ||
override fun execute(t: Task) { | ||
val jar = t as Jar | ||
val project = t.project | ||
val javaConfigureExtension = project.extensions.getByType(JavaConfigurePluginExtension::class) | ||
val javaPluginExtension = project.extensions.getByType(JavaPluginExtension::class) | ||
val configuration = | ||
project.configurations.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME) | ||
val classpath = configuration.files.joinToString(" ") { it.name } | ||
val javaToolChains = project.extensions.getByType(JavaToolchainService::class.java) | ||
val compiler = javaToolChains.compilerFor(javaPluginExtension.toolchain).get().metadata | ||
val createdBy = compiler.javaRuntimeVersion + " (" + compiler.vendor + ")" | ||
|
||
jar.manifest.attributes( | ||
"Class-Path" to classpath, | ||
"Created-By" to createdBy, | ||
"Implementation-Vendor" to javaConfigureExtension.vendorName.get(), | ||
"Implementation-Title" to project.name, | ||
"Implementation-Version" to project.version, | ||
GRADLE_VERSION to project.gradle.gradleVersion | ||
) | ||
} | ||
|
||
private const val GRADLE_VERSION = "Gradle-Version" | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/io/cloudflight/gradle/autoconfigure/util/BuildUtils.kt
This file contains 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,9 @@ | ||
package io.cloudflight.gradle.autoconfigure.util | ||
|
||
object BuildUtils { | ||
|
||
fun isIntegrationBuild(): Boolean { | ||
return EnvironmentUtils.isDefaultBuild() || EnvironmentUtils.isVerifyBuild() || EnvironmentUtils.isPublishBuild() | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/io/cloudflight/gradle/autoconfigure/util/EnvironmentUtils.kt
This file contains 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,23 @@ | ||
package io.cloudflight.gradle.autoconfigure.util | ||
|
||
object EnvironmentUtils { | ||
fun isDefaultBuild(): Boolean { | ||
return getBoolean(ENV_DEFAULT_BUILD) | ||
} | ||
|
||
fun isVerifyBuild(): Boolean { | ||
return getBoolean(ENV_VERIFY_BUILD) | ||
} | ||
|
||
fun isPublishBuild(): Boolean { | ||
return getBoolean(ENV_PUBLISH_BUILD) | ||
} | ||
|
||
private fun getBoolean(name: String): Boolean { | ||
return System.getenv(name).toBoolean() | ||
} | ||
|
||
const val ENV_DEFAULT_BUILD = "DEFAULT_BUILD" | ||
const val ENV_VERIFY_BUILD = "VERIFY_BUILD" | ||
const val ENV_PUBLISH_BUILD = "PUBLISH_BUILD" | ||
} |
4 changes: 4 additions & 0 deletions
4
...fixtures/java/single-java-module-application/src/main/java/io/cloudflight/gradle/Foo.java
This file contains 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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
package io.cloudflight.gradle; | ||
|
||
public class Foo { | ||
|
||
public static void main(String[] args) { | ||
|
||
} | ||
} |
This file contains 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 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
Oops, something went wrong.