Skip to content

Commit

Permalink
Revert "Apply indent_size 4"
Browse files Browse the repository at this point in the history
This reverts commit 7dc3429.
  • Loading branch information
Goooler committed Oct 2, 2024
1 parent 1da2c03 commit dbeaf6f
Show file tree
Hide file tree
Showing 44 changed files with 2,059 additions and 2,047 deletions.
4 changes: 0 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,5 @@ ij_kotlin_packages_to_use_import_on_demand = unset
ktlint_code_style = intellij_idea
ktlint_standard_function-expression-body = disabled

# TODO: this overriding will be removed in the next PR.
[*.kt]
indent_size = 4

[*.md]
trim_trailing_whitespace = false
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,48 @@ import org.gradle.api.file.FileCollection
import org.gradle.api.specs.Spec

public interface DependencyFilter {
/**
* Resolve a FileCollection against the include/exclude rules in the filter
*/
public fun resolve(configuration: FileCollection): FileCollection

/**
* Resolve all FileCollections against the include/exclude ruels in the filter and combine the results
*/
public fun resolve(configurations: Collection<FileCollection>): FileCollection

/**
* Exclude dependencies that match the provided spec.
*/
public fun exclude(spec: Spec<ResolvedDependency>): DependencyFilter

/**
* Include dependencies that match the provided spec.
*/
public fun include(spec: Spec<ResolvedDependency>): DependencyFilter

/**
* Create a spec that matches the provided project notation on group, name, and version
*/
public fun project(notation: Map<String, *>): Spec<ResolvedDependency>

/**
* Create a spec that matches the default configuration for the provided project path on group, name, and version
*/
public fun project(notation: String): Spec<ResolvedDependency>

/**
* Create a spec that matches dependencies using the provided notation on group, name, and version
*/
public fun dependency(notation: Any): Spec<ResolvedDependency>

/**
* Create a spec that matches the provided dependency on group, name, and version
*/
public fun dependency(dependency: Dependency): Spec<ResolvedDependency>

/**
* Create a spec that matches the provided closure
*/
public fun dependency(spec: Closure<*>): Spec<ResolvedDependency>
/**
* Resolve a FileCollection against the include/exclude rules in the filter
*/
public fun resolve(configuration: FileCollection): FileCollection

/**
* Resolve all FileCollections against the include/exclude ruels in the filter and combine the results
*/
public fun resolve(configurations: Collection<FileCollection>): FileCollection

/**
* Exclude dependencies that match the provided spec.
*/
public fun exclude(spec: Spec<ResolvedDependency>): DependencyFilter

/**
* Include dependencies that match the provided spec.
*/
public fun include(spec: Spec<ResolvedDependency>): DependencyFilter

/**
* Create a spec that matches the provided project notation on group, name, and version
*/
public fun project(notation: Map<String, *>): Spec<ResolvedDependency>

/**
* Create a spec that matches the default configuration for the provided project path on group, name, and version
*/
public fun project(notation: String): Spec<ResolvedDependency>

/**
* Create a spec that matches dependencies using the provided notation on group, name, and version
*/
public fun dependency(notation: Any): Spec<ResolvedDependency>

/**
* Create a spec that matches the provided dependency on group, name, and version
*/
public fun dependency(dependency: Dependency): Spec<ResolvedDependency>

/**
* Create a spec that matches the provided closure
*/
public fun dependency(spec: Closure<*>): Spec<ResolvedDependency>
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,124 +19,124 @@ import org.gradle.api.tasks.application.CreateStartScripts
import org.gradle.jvm.toolchain.JavaToolchainService

public class ShadowApplicationPlugin : Plugin<Project> {
private val shadowJar: TaskProvider<ShadowJar>
get() = project.tasks.named(ShadowJavaPlugin.SHADOW_JAR_TASK_NAME, ShadowJar::class.java)
private val shadowJar: TaskProvider<ShadowJar>
get() = project.tasks.named(ShadowJavaPlugin.SHADOW_JAR_TASK_NAME, ShadowJar::class.java)

private lateinit var project: Project
private lateinit var javaApplication: JavaApplication
private lateinit var project: Project
private lateinit var javaApplication: JavaApplication

override fun apply(project: Project) {
this.project = project
this.javaApplication = project.extensions.getByType(JavaApplication::class.java)
override fun apply(project: Project) {
this.project = project
this.javaApplication = project.extensions.getByType(JavaApplication::class.java)

val distributions = project.extensions.getByName("distributions") as DistributionContainer
val distribution = distributions.create("shadow")
val distributions = project.extensions.getByName("distributions") as DistributionContainer
val distribution = distributions.create("shadow")

addRunTask(project)
addCreateScriptsTask(project)
configureDistSpec(project, distribution.contents)
configureJarMainClass()
configureInstallTask(project)
}
addRunTask(project)
addCreateScriptsTask(project)
configureDistSpec(project, distribution.contents)
configureJarMainClass()
configureInstallTask(project)
}

private fun configureJarMainClass() {
val classNameProvider = javaApplication.mainClass
shadowJar.configure { jar ->
jar.inputs.property("mainClassName", classNameProvider)
jar.doFirst {
jar.manifest.attributes["Main-Class"] = classNameProvider.get()
}
}
private fun configureJarMainClass() {
val classNameProvider = javaApplication.mainClass
shadowJar.configure { jar ->
jar.inputs.property("mainClassName", classNameProvider)
jar.doFirst {
jar.manifest.attributes["Main-Class"] = classNameProvider.get()
}
}
}

private fun addRunTask(project: Project) {
project.tasks.register(SHADOW_RUN_TASK_NAME, JavaJarExec::class.java) { run ->
val install = project.tasks.named(SHADOW_INSTALL_TASK_NAME, Sync::class.java)
run.dependsOn(SHADOW_INSTALL_TASK_NAME)
run.mainClass.set("-jar")
run.description = "Runs this project as a JVM application using the shadow jar"
run.group = ApplicationPlugin.APPLICATION_GROUP
run.conventionMapping.map("jvmArgs") { javaApplication.applicationDefaultJvmArgs }
run.conventionMapping.map("jarFile") {
project.file("${install.get().destinationDir.path}/lib/${shadowJar.get().archiveFile.get().asFile.name}")
}
configureJavaLauncher(run)
}
private fun addRunTask(project: Project) {
project.tasks.register(SHADOW_RUN_TASK_NAME, JavaJarExec::class.java) { run ->
val install = project.tasks.named(SHADOW_INSTALL_TASK_NAME, Sync::class.java)
run.dependsOn(SHADOW_INSTALL_TASK_NAME)
run.mainClass.set("-jar")
run.description = "Runs this project as a JVM application using the shadow jar"
run.group = ApplicationPlugin.APPLICATION_GROUP
run.conventionMapping.map("jvmArgs") { javaApplication.applicationDefaultJvmArgs }
run.conventionMapping.map("jarFile") {
project.file("${install.get().destinationDir.path}/lib/${shadowJar.get().archiveFile.get().asFile.name}")
}
configureJavaLauncher(run)
}
}

private fun configureJavaLauncher(run: JavaJarExec) {
val toolchain = project.extensions.getByType(JavaPluginExtension::class.java).toolchain
val service = project.extensions.getByType(JavaToolchainService::class.java)
val defaultLauncher = service.launcherFor(toolchain)
run.javaLauncher.set(defaultLauncher)
}
private fun configureJavaLauncher(run: JavaJarExec) {
val toolchain = project.extensions.getByType(JavaPluginExtension::class.java).toolchain
val service = project.extensions.getByType(JavaToolchainService::class.java)
val defaultLauncher = service.launcherFor(toolchain)
run.javaLauncher.set(defaultLauncher)
}

private fun addCreateScriptsTask(project: Project) {
project.tasks.register(SHADOW_SCRIPTS_TASK_NAME, CreateStartScripts::class.java) { startScripts ->
(startScripts.unixStartScriptGenerator as DefaultTemplateBasedStartScriptGenerator).template =
project.resources.text.fromString(this::class.java.requireResourceAsText("internal/unixStartScript.txt"))
(startScripts.windowsStartScriptGenerator as DefaultTemplateBasedStartScriptGenerator).template =
project.resources.text.fromString(this::class.java.requireResourceAsText("internal/windowsStartScript.txt"))
startScripts.description =
"Creates OS specific scripts to run the project as a JVM application using the shadow jar"
startScripts.group = ApplicationPlugin.APPLICATION_GROUP
startScripts.classpath = project.files(shadowJar)
startScripts.conventionMapping.map("mainClassName") { javaApplication.mainClass.get() }
startScripts.conventionMapping.map("applicationName") { javaApplication.applicationName }
startScripts.conventionMapping.map("outputDir") {
project.layout.buildDirectory.dir("scriptsShadow").get().asFile
}
startScripts.conventionMapping.map("defaultJvmOpts") { javaApplication.applicationDefaultJvmArgs }
startScripts.inputs.files(project.objects.fileCollection().from(shadowJar))
}
private fun addCreateScriptsTask(project: Project) {
project.tasks.register(SHADOW_SCRIPTS_TASK_NAME, CreateStartScripts::class.java) { startScripts ->
(startScripts.unixStartScriptGenerator as DefaultTemplateBasedStartScriptGenerator).template =
project.resources.text.fromString(this::class.java.requireResourceAsText("internal/unixStartScript.txt"))
(startScripts.windowsStartScriptGenerator as DefaultTemplateBasedStartScriptGenerator).template =
project.resources.text.fromString(this::class.java.requireResourceAsText("internal/windowsStartScript.txt"))
startScripts.description =
"Creates OS specific scripts to run the project as a JVM application using the shadow jar"
startScripts.group = ApplicationPlugin.APPLICATION_GROUP
startScripts.classpath = project.files(shadowJar)
startScripts.conventionMapping.map("mainClassName") { javaApplication.mainClass.get() }
startScripts.conventionMapping.map("applicationName") { javaApplication.applicationName }
startScripts.conventionMapping.map("outputDir") {
project.layout.buildDirectory.dir("scriptsShadow").get().asFile
}
startScripts.conventionMapping.map("defaultJvmOpts") { javaApplication.applicationDefaultJvmArgs }
startScripts.inputs.files(project.objects.fileCollection().from(shadowJar))
}
}

private fun configureInstallTask(project: Project) {
project.tasks.named(SHADOW_INSTALL_TASK_NAME, Sync::class.java).configure { task ->
task.doFirst {
if (task.destinationDir.isDirectory) {
if (task.destinationDir.listFiles()?.isNotEmpty() == true &&
(!File(task.destinationDir, "lib").isDirectory || !File(task.destinationDir, "bin").isDirectory)
) {
throw GradleException(
"The specified installation directory '${task.destinationDir}' is neither empty nor does it contain an installation for '${javaApplication.applicationName}'.\n" +
"If you really want to install to this directory, delete it and run the install task again.\n" +
"Alternatively, choose a different installation directory.",
)
}
}
}
task.doLast {
task.eachFile { file ->
if (file.path == "bin/${javaApplication.applicationName}") {
file.permissions {
it.unix(0x755)
}
}
}
private fun configureInstallTask(project: Project) {
project.tasks.named(SHADOW_INSTALL_TASK_NAME, Sync::class.java).configure { task ->
task.doFirst {
if (task.destinationDir.isDirectory) {
if (task.destinationDir.listFiles()?.isNotEmpty() == true &&
(!File(task.destinationDir, "lib").isDirectory || !File(task.destinationDir, "bin").isDirectory)
) {
throw GradleException(
"The specified installation directory '${task.destinationDir}' is neither empty nor does it contain an installation for '${javaApplication.applicationName}'.\n" +
"If you really want to install to this directory, delete it and run the install task again.\n" +
"Alternatively, choose a different installation directory.",
)
}
}
}
task.doLast {
task.eachFile { file ->
if (file.path == "bin/${javaApplication.applicationName}") {
file.permissions {
it.unix(0x755)
}
}
}
}
}
}

private fun configureDistSpec(project: Project, distSpec: CopySpec): CopySpec {
val startScripts = project.tasks.named(SHADOW_SCRIPTS_TASK_NAME)
return distSpec.apply {
from(project.file("src/dist"))
private fun configureDistSpec(project: Project, distSpec: CopySpec): CopySpec {
val startScripts = project.tasks.named(SHADOW_SCRIPTS_TASK_NAME)
return distSpec.apply {
from(project.file("src/dist"))

into("lib") {
from(shadowJar)
from(project.configurations.getByName(ShadowBasePlugin.CONFIGURATION_NAME))
}
into("bin") {
from(startScripts)
filePermissions { it.unix(493) }
}
}
into("lib") {
from(shadowJar)
from(project.configurations.getByName(ShadowBasePlugin.CONFIGURATION_NAME))
}
into("bin") {
from(startScripts)
filePermissions { it.unix(493) }
}
}
}

public companion object {
public const val SHADOW_RUN_TASK_NAME: String = "runShadow"
public const val SHADOW_SCRIPTS_TASK_NAME: String = "startShadowScripts"
public const val SHADOW_INSTALL_TASK_NAME: String = "installShadowDist"
}
public companion object {
public const val SHADOW_RUN_TASK_NAME: String = "runShadow"
public const val SHADOW_SCRIPTS_TASK_NAME: String = "startShadowScripts"
public const val SHADOW_INSTALL_TASK_NAME: String = "installShadowDist"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import org.gradle.api.Project
import org.gradle.util.GradleVersion

public class ShadowBasePlugin : Plugin<Project> {
override fun apply(project: Project) {
if (GradleVersion.current() < GradleVersion.version("8.3")) {
throw GradleException("This version of Shadow supports Gradle 8.3+ only. Please upgrade.")
}
override fun apply(project: Project) {
if (GradleVersion.current() < GradleVersion.version("8.3")) {
throw GradleException("This version of Shadow supports Gradle 8.3+ only. Please upgrade.")
}

project.extensions.create(EXTENSION_NAME, ShadowExtension::class.java, project)
project.configurations.create(CONFIGURATION_NAME)
project.extensions.create(EXTENSION_NAME, ShadowExtension::class.java, project)
project.configurations.create(CONFIGURATION_NAME)

project.tasks.register(KnowsTask.NAME, KnowsTask::class.java) {
it.group = ShadowJavaPlugin.SHADOW_GROUP
it.description = KnowsTask.DESC
}
project.tasks.register(KnowsTask.NAME, KnowsTask::class.java) {
it.group = ShadowJavaPlugin.SHADOW_GROUP
it.description = KnowsTask.DESC
}
}

public companion object {
public const val EXTENSION_NAME: String = "shadow"
public const val CONFIGURATION_NAME: String = "shadow"
public const val COMPONENT_NAME: String = "shadow"
}
public companion object {
public const val EXTENSION_NAME: String = "shadow"
public const val CONFIGURATION_NAME: String = "shadow"
public const val COMPONENT_NAME: String = "shadow"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import org.gradle.api.publish.maven.MavenPublication

@Deprecated("This is deprecated since 8.3.2")
public abstract class ShadowExtension(project: Project) {
private val components = project.components
private val components = project.components

@Deprecated(
message = "configure publication using component.shadow directly.",
replaceWith = ReplaceWith("publication.from(components.getByName(\"shadow\"))"),
)
public fun component(publication: MavenPublication) {
publication.from(components.findByName("shadow"))
}
@Deprecated(
message = "configure publication using component.shadow directly.",
replaceWith = ReplaceWith("publication.from(components.getByName(\"shadow\"))"),
)
public fun component(publication: MavenPublication) {
publication.from(components.findByName("shadow"))
}
}
Loading

0 comments on commit dbeaf6f

Please sign in to comment.