Skip to content
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

Removes all Gradle internal APIs #3286

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions wire-gradle-plugin-playground/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import com.squareup.wire.schema.EventListener
import org.gradle.api.internal.file.FileOperations

plugins {
id("java-library")
Expand All @@ -16,7 +15,6 @@ class MyEventListenerFactory : EventListener.Factory {
@CacheableTask
abstract class ProtoWritingTask @Inject constructor(
objects: ObjectFactory,
private val fileOperations: FileOperations,
) : DefaultTask() {

@get:OutputDirectory
Expand Down
3 changes: 1 addition & 2 deletions wire-gradle-plugin/api/wire-gradle-plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ public final class com/squareup/wire/gradle/WireExtension$ProtoRootSet {
public final fun srcJar (Lorg/gradle/api/provider/ProviderConvertible;)V
public final fun srcProject (Ljava/lang/String;)V
public final fun srcProject (Lorg/gradle/api/artifacts/ProjectDependency;)V
public final synthetic fun srcProject (Lorg/gradle/api/internal/catalog/DelegatingProjectDependency;)V
}

public abstract class com/squareup/wire/gradle/WireOutput {
Expand All @@ -170,7 +169,7 @@ public final class com/squareup/wire/gradle/WirePlugin : org/gradle/api/Plugin {
}

public abstract class com/squareup/wire/gradle/WireTask : org/gradle/api/tasks/SourceTask {
public fun <init> (Lorg/gradle/api/model/ObjectFactory;Lorg/gradle/api/internal/file/FileOperations;)V
public fun <init> (Lorg/gradle/api/model/ObjectFactory;)V
public final fun generateWireFiles ()V
public abstract fun getBuildDirProperty ()Lorg/gradle/api/file/DirectoryProperty;
public final fun getDryRun ()Lorg/gradle/api/provider/Property;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ package com.squareup.wire.gradle

import com.squareup.wire.schema.EventListener
import java.io.File
import java.lang.IllegalArgumentException
import java.net.URI
import java.net.URISyntaxException
import kotlin.LazyThreadSafetyMode.NONE
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.internal.catalog.DelegatingProjectDependency
import org.gradle.api.internal.file.FileOrUriNotationConverter
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderConvertible

Expand Down Expand Up @@ -338,11 +339,38 @@ open class WireExtension(

private fun srcFileOrConfiguration(jar: String) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method goes with our public API

    /** Sets a local or a remote jar. Examples: "libs/protos.jar", or "com.example:protos:1.0.0". */
    fun srcJar(jar: String) {
      srcFileOrConfiguration(jar)
    }

isEmpty = false
val parser = FileOrUriNotationConverter.parser()
val converted = parser.parseNotation(jar)
when (converted) {
is File -> sourceDirectoriesAndLocalJars += project.file(jar)
else -> addDependency(jar)
try {
val uri = URI.create(jar)
if (uri.scheme != null) {
// If the URI has a scheme, it's likely a URI notation.
addDependency(jar)
} else {
// If the URI has no scheme, it's likely a file path.
val file = try {
File(uri)
} catch (e: IllegalArgumentException) {
// File creation would fail if `url` happened to be relative.
File(project.projectDir, uri.path)
}
if (file.exists()) {
sourceDirectoriesAndLocalJars += project.file(jar)
} else {
addDependency(jar)
}
}
} catch (e: URISyntaxException) {
// If creating a URI fails, treat it as a file path.
val file = try {
File(jar)
} catch (e: IllegalArgumentException) {
// File creation would fail if `url` happened to be relative.
File(project.projectDir, jar)
}
if (file.exists()) {
sourceDirectoriesAndLocalJars += project.file(jar)
} else {
addDependency(jar)
}
}
}

Expand All @@ -361,15 +389,6 @@ open class WireExtension(
addDependency(project.project(projectPath))
}

/** Sets a project. */
@Deprecated(
message = "Use srcProject(ProjectDependency) instead. This method will be removed in a future version of Wire.",
level = DeprecationLevel.HIDDEN,
)
fun srcProject(project: DelegatingProjectDependency) {
addDependency(project)
}

/** Sets a project. */
fun srcProject(project: ProjectDependency) {
addDependency(project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.squareup.wire.schema.Location
import java.io.EOFException
import java.io.File
import java.io.RandomAccessFile
import org.gradle.api.internal.file.FileOperations
import org.gradle.api.Project

internal val List<ProtoRootSet>.inputLocations: List<InputLocation>
get() = flatMap { rootSet ->
Expand Down Expand Up @@ -48,7 +48,7 @@ private fun ProtoRootSet.inputLocation(file: File): InputLocation {
* excludes.
*/
internal fun InputLocation.toLocations(
fileOperations: FileOperations,
project: Project,
projectDir: File,
): List<Location> {
val base = when {
Expand All @@ -57,8 +57,8 @@ internal fun InputLocation.toLocations(
}
return buildList {
val fileTree = when {
base.isZip -> fileOperations.zipTree(base)
base.isDirectory -> fileOperations.fileTree(base)
base.isZip -> project.zipTree(base)
base.isDirectory -> project.fileTree(base)
else -> throw IllegalArgumentException(
"""
|Invalid path string: "$path".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import com.squareup.wire.schema.Target
import com.squareup.wire.schema.newEventListenerFactory
import java.io.File
import java.lang.reflect.Array as JavaArray
import java.net.URI
import java.util.concurrent.atomic.AtomicBoolean
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.UnknownConfigurationException
import org.gradle.api.internal.file.FileOrUriNotationConverter
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.compile.JavaCompile
Expand Down Expand Up @@ -339,9 +339,12 @@ class WirePlugin : Plugin<Project> {
}

private fun defaultSourceFolders(source: Source): Set<String> {
val parser = FileOrUriNotationConverter.parser()
return source.sourceSets.map { "src/$it/proto" }.filter { path ->
val converted = parser.parseNotation(path) as File
val converted = if (URI.create(path).isAbsolute) {
File(URI.create(path))
} else {
File(path)
}
val file =
if (!converted.isAbsolute) File(project.projectDir, converted.path) else converted
return@filter file.exists()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import okio.FileSystem
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileTree
import org.gradle.api.internal.file.FileOperations
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
Expand All @@ -46,7 +45,6 @@ import org.gradle.api.tasks.TaskAction
@CacheableTask
abstract class WireTask @Inject constructor(
objects: ObjectFactory,
private val fileOperations: FileOperations,
) : SourceTask() {

@get:OutputDirectories
Expand Down Expand Up @@ -159,8 +157,8 @@ abstract class WireTask @Inject constructor(
val projectDirAsFile = projectDir.asFile
val allTargets = targets.get()
val wireRun = WireRun(
sourcePath = sourceInput.get().flatMap { it.toLocations(fileOperations, projectDirAsFile) },
protoPath = protoInput.get().flatMap { it.toLocations(fileOperations, projectDirAsFile) },
sourcePath = sourceInput.get().flatMap { it.toLocations(project, projectDirAsFile) },
protoPath = protoInput.get().flatMap { it.toLocations(project, projectDirAsFile) },
Comment on lines +160 to +161
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

treeShakingRoots = roots.get().ifEmpty { includes },
treeShakingRubbish = prunes.get().ifEmpty { excludes },
moves = moves.get().map { it.toTypeMoverMove() },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.gradle.api.internal.file.FileOperations

plugins {
id("com.squareup.wire")
id("org.jetbrains.kotlin.jvm") version "1.9.22"
Expand All @@ -8,7 +6,6 @@ plugins {
@CacheableTask
abstract class ProtoWritingTask @Inject constructor(
objects: ObjectFactory,
private val fileOperations: FileOperations,
) : DefaultTask() {

@get:OutputDirectory
Expand Down
Loading