Skip to content

Commit

Permalink
Enable Explicit API mode (#1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler authored Nov 20, 2024
1 parent 4cf33b1 commit 4397a27
Show file tree
Hide file tree
Showing 39 changed files with 209 additions and 210 deletions.
1 change: 1 addition & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ java {
}

kotlin {
explicitApi()
compilerOptions {
// https://docs.gradle.org/current/userguide/compatibility.html#kotlin
apiVersion = KotlinVersion.KOTLIN_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.gradle.api.tasks.application.CreateStartScripts
import org.gradle.jvm.application.scripts.TemplateBasedScriptGenerator
import org.gradle.jvm.toolchain.JavaToolchainService

abstract class ShadowApplicationPlugin : Plugin<Project> {
public abstract class ShadowApplicationPlugin : Plugin<Project> {
private lateinit var project: Project
private lateinit var javaApplication: JavaApplication

Expand Down Expand Up @@ -127,9 +127,9 @@ abstract class ShadowApplicationPlugin : Plugin<Project> {
protected val shadowJar: TaskProvider<ShadowJar>
get() = project.tasks.named(ShadowJavaPlugin.SHADOW_JAR_TASK_NAME, ShadowJar::class.java)

companion object {
const val SHADOW_RUN_TASK_NAME: String = "runShadow"
const val SHADOW_SCRIPTS_TASK_NAME: String = "startShadowScripts"
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 @@ -6,7 +6,7 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.util.GradleVersion

abstract class ShadowBasePlugin : Plugin<Project> {
public abstract class ShadowBasePlugin : Plugin<Project> {

override fun apply(project: Project) {
if (GradleVersion.current() < GradleVersion.version("8.3")) {
Expand All @@ -20,12 +20,12 @@ abstract class ShadowBasePlugin : Plugin<Project> {
}
}

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

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

@Deprecated("configure publication using component.shadow directly.")
fun component(publication: MavenPublication) {
public fun component(publication: MavenPublication) {
publication.from(components.findByName(ShadowBasePlugin.COMPONENT_NAME))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.gradle.api.tasks.TaskProvider
import org.gradle.jvm.tasks.Jar
import org.gradle.plugin.devel.plugins.JavaGradlePluginPlugin

abstract class ShadowJavaPlugin @Inject constructor(
public abstract class ShadowJavaPlugin @Inject constructor(
private val softwareComponentFactory: SoftwareComponentFactory,
) : Plugin<Project> {

Expand Down Expand Up @@ -104,8 +104,8 @@ abstract class ShadowJavaPlugin @Inject constructor(
return taskProvider
}

companion object {
const val SHADOW_JAR_TASK_NAME: String = "shadowJar"
const val SHADOW_RUNTIME_ELEMENTS_CONFIGURATION_NAME: String = "shadowRuntimeElements"
public companion object {
public const val SHADOW_JAR_TASK_NAME: String = "shadowJar"
public const val SHADOW_RUNTIME_ELEMENTS_CONFIGURATION_NAME: String = "shadowRuntimeElements"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.gradle.api.Project
import org.gradle.api.plugins.ApplicationPlugin
import org.gradle.api.plugins.JavaPlugin

abstract class ShadowPlugin : Plugin<Project> {
public abstract class ShadowPlugin : Plugin<Project> {

override fun apply(project: Project) {
project.run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,50 @@ package com.github.jengelman.gradle.plugins.shadow

import org.gradle.api.GradleException

open class ShadowStats {
open var totalTime: Long = 0
open var jarStartTime: Long = 0
open var jarEndTime: Long = 0
open var jarCount: Int = 1
open var processingJar: Boolean = false
open val relocations: MutableMap<String, String> = mutableMapOf()
public open class ShadowStats {
public open var totalTime: Long = 0
public open var jarStartTime: Long = 0
public open var jarEndTime: Long = 0
public open var jarCount: Int = 1
public open var processingJar: Boolean = false
public open val relocations: MutableMap<String, String> = mutableMapOf()

open val relocationString: String
public open val relocationString: String
get() {
return relocations.map { (k, v) -> "$k$v" }
.sorted()
.joinToString("\n")
}

open val jarTiming: Long
public open val jarTiming: Long
get() = jarEndTime - jarStartTime

open val totalTimeSecs: Double
public open val totalTimeSecs: Double
get() = totalTime / 1000.0

open val averageTimePerJar: Double
public open val averageTimePerJar: Double
get() = totalTime / jarCount.toDouble()

open val averageTimeSecsPerJar: Double
public open val averageTimeSecsPerJar: Double
get() = averageTimePerJar / 1000.0

open val buildScanData: Map<String, String>
public open val buildScanData: Map<String, String>
get() = mapOf(
"dependencies" to jarCount.toString(),
"relocations" to relocationString,
)

open fun relocate(src: String, dst: String) {
public open fun relocate(src: String, dst: String) {
relocations[src] = dst
}

open fun startJar() {
public open fun startJar() {
if (processingJar) throw GradleException("Can only time one entry at a time")
processingJar = true
jarStartTime = System.currentTimeMillis()
}

open fun finishJar() {
public open fun finishJar() {
if (processingJar) {
jarEndTime = System.currentTimeMillis()
jarCount++
Expand All @@ -54,7 +54,7 @@ open class ShadowStats {
}
}

open fun printStats() {
public open fun printStats() {
println(this)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import org.objectweb.asm.commons.Remapper
*
* @author John Engelman
*/
open class RelocatorRemapper(
public open class RelocatorRemapper(
private val relocators: List<Relocator>,
private val stats: ShadowStats,
) : Remapper() {
private val classPattern: Pattern = Pattern.compile("(\\[*)?L(.+)")

open fun hasRelocators(): Boolean = relocators.isNotEmpty()
public open fun hasRelocators(): Boolean = relocators.isNotEmpty()

override fun mapValue(value: Any): Any {
return if (value is String) {
Expand Down Expand Up @@ -54,11 +54,11 @@ open class RelocatorRemapper(
return name
}

open fun mapPath(path: String): String {
public open fun mapPath(path: String): String {
return map(path.substring(0, path.indexOf('.')))
}

open fun mapPath(path: ShadowCopyAction.RelativeArchivePath): String {
public open fun mapPath(path: ShadowCopyAction.RelativeArchivePath): String {
return mapPath(path.pathString)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,49 @@ import org.gradle.api.artifacts.ResolvedDependency
import org.gradle.api.file.FileCollection
import org.gradle.api.specs.Spec

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

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

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

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

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

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

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

/**
* Create a spec that matches the provided closure.
*/
fun dependency(closure: Closure<*>): Spec<ResolvedDependency>
public fun dependency(closure: Closure<*>): Spec<ResolvedDependency>
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ internal class UnusedTracker private constructor(
}

companion object {
@JvmStatic
fun forProject(
apiJars: FileCollection,
sourceSetsClassesDirs: Iterable<File>,
Expand All @@ -52,7 +51,6 @@ internal class UnusedTracker private constructor(
return UnusedTracker(sourceSetsClassesDirs, apiJars, toMinimize)
}

@JvmStatic
fun getApiJarsFromProject(project: Project): FileCollection {
val apiDependencies = project.configurations.findByName("api")?.dependencies
?: return project.files()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import org.gradle.api.Project
*
* This allows older build logic to keep on working as if that old plugin ID was applied.
*/
abstract class LegacyShadowPlugin : Plugin<Project> {
public abstract class LegacyShadowPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ package com.github.jengelman.gradle.plugins.shadow.relocation
*/
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
annotation class CacheableRelocator
public annotation class CacheableRelocator
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ package com.github.jengelman.gradle.plugins.shadow.relocation

import com.github.jengelman.gradle.plugins.shadow.ShadowStats

data class RelocateClassContext(
public data class RelocateClassContext(
val className: String,
val stats: ShadowStats,
) {
class Builder {
public class Builder {
private var className = ""
private var stats = ShadowStats()

fun className(className: String): Builder = apply { this.className = className }
fun stats(stats: ShadowStats): Builder = apply { this.stats = stats }
fun build(): RelocateClassContext = RelocateClassContext(className, stats)
public fun className(className: String): Builder = apply { this.className = className }
public fun stats(stats: ShadowStats): Builder = apply { this.stats = stats }
public fun build(): RelocateClassContext = RelocateClassContext(className, stats)
}

companion object {
public companion object {
@JvmStatic
fun builder(): Builder = Builder()
public fun builder(): Builder = Builder()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ package com.github.jengelman.gradle.plugins.shadow.relocation

import com.github.jengelman.gradle.plugins.shadow.ShadowStats

data class RelocatePathContext(
public data class RelocatePathContext(
val path: String,
val stats: ShadowStats,
) {
class Builder {
public class Builder {
private var path = ""
private var stats = ShadowStats()

fun path(path: String): Builder = apply { this.path = path }
fun stats(stats: ShadowStats): Builder = apply { this.stats = stats }
fun build(): RelocatePathContext = RelocatePathContext(path, stats)
public fun path(path: String): Builder = apply { this.path = path }
public fun stats(stats: ShadowStats): Builder = apply { this.stats = stats }
public fun build(): RelocatePathContext = RelocatePathContext(path, stats)
}

companion object {
public companion object {
@JvmStatic
fun builder(): Builder = Builder()
public fun builder(): Builder = Builder()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ package com.github.jengelman.gradle.plugins.shadow.relocation
* @author Jason van Zyl
* @author John Engelman
*/
interface Relocator {
fun canRelocatePath(path: String): Boolean
public interface Relocator {
public fun canRelocatePath(path: String): Boolean

fun relocatePath(context: RelocatePathContext): String
public fun relocatePath(context: RelocatePathContext): String

fun canRelocateClass(className: String): Boolean
public fun canRelocateClass(className: String): Boolean

fun relocateClass(context: RelocateClassContext): String
public fun relocateClass(context: RelocateClassContext): String

fun applyToSourceContent(sourceContent: String): String
public fun applyToSourceContent(sourceContent: String): String

companion object {
val ROLE: String = Relocator::class.java.name
public companion object {
public val ROLE: String = Relocator::class.java.name
}
}
Loading

0 comments on commit 4397a27

Please sign in to comment.