Skip to content

Commit 8dddcef

Browse files
authored
Don't use FileOrUriNotationConverter (#3288)
* Don't use FileOrUriNotationConverter It's an internal API in Gradle. * Fix non-empty check * Fixup failing test --------- Co-authored-by: Jesse Wilson <[email protected]>
1 parent 7d3be25 commit 8dddcef

File tree

2 files changed

+15
-28
lines changed

2 files changed

+15
-28
lines changed

wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireExtension.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import org.gradle.api.artifacts.MinimalExternalModuleDependency
2424
import org.gradle.api.artifacts.ProjectDependency
2525
import org.gradle.api.file.ConfigurableFileCollection
2626
import org.gradle.api.internal.catalog.DelegatingProjectDependency
27-
import org.gradle.api.internal.file.FileOrUriNotationConverter
2827
import org.gradle.api.provider.Provider
2928
import org.gradle.api.provider.ProviderConvertible
3029

@@ -299,11 +298,10 @@ open class WireExtension(
299298
isCanBeConsumed = false
300299
isTransitive = false
301300
}
302-
internal val sourceDirectoriesAndLocalJars = mutableListOf<File>()
303301

304302
/** Calling this will resolve the configuration. */
305303
internal val roots: Set<File>
306-
get() = configuration.files + sourceDirectoriesAndLocalJars
304+
get() = configuration.files
307305
private val files: ConfigurableFileCollection by lazy(NONE) {
308306
val files = project.files()
309307
project.dependencies.add(configuration.name, files)
@@ -333,16 +331,17 @@ open class WireExtension(
333331

334332
/** Sets a local or a remote jar. Examples: "libs/protos.jar", or "com.example:protos:1.0.0". */
335333
fun srcJar(jar: String) {
336-
srcFileOrConfiguration(jar)
337-
}
334+
// Attempt to parse 'jar' as a path or 'file:' URI.
335+
val fileOrNull = try {
336+
project.file(jar)
337+
} catch (e: Exception) {
338+
null // Probably a dependency string like "com.example:protos:1.0.0".
339+
}
338340

339-
private fun srcFileOrConfiguration(jar: String) {
340-
isEmpty = false
341-
val parser = FileOrUriNotationConverter.parser()
342-
val converted = parser.parseNotation(jar)
343-
when (converted) {
344-
is File -> sourceDirectoriesAndLocalJars += project.file(jar)
345-
else -> addDependency(jar)
341+
if (fileOrNull != null) {
342+
addDependency(project.files(fileOrNull))
343+
} else {
344+
addDependency(jar)
346345
}
347346
}
348347

wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WirePlugin.kt

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
@file:OptIn(ExperimentalStdlibApi::class)
17-
1816
package com.squareup.wire.gradle
1917

2018
import com.squareup.wire.VERSION
@@ -31,7 +29,6 @@ import java.util.concurrent.atomic.AtomicBoolean
3129
import org.gradle.api.Plugin
3230
import org.gradle.api.Project
3331
import org.gradle.api.artifacts.UnknownConfigurationException
34-
import org.gradle.api.internal.file.FileOrUriNotationConverter
3532
import org.gradle.api.tasks.SourceSet
3633
import org.gradle.api.tasks.SourceSetContainer
3734
import org.gradle.api.tasks.compile.JavaCompile
@@ -195,20 +192,15 @@ class WirePlugin : Plugin<Project> {
195192
task.group = GROUP
196193
task.description = "Generate protobuf implementation for ${source.name}"
197194

198-
var addedSourcesDependencies = 0
199195
// Flatten all the input files here. Changes to any of them will cause the task to re-run.
200196
for (rootSet in protoSourceProtoRootSets) {
201197
task.source(rootSet.configuration)
202-
val sourceDirectoriesAndLocalJars = rootSet.sourceDirectoriesAndLocalJars.toTypedArray()
203-
addedSourcesDependencies += sourceDirectoriesAndLocalJars.size
204-
task.source(*sourceDirectoriesAndLocalJars)
205198
}
206199
// We only want to add ProtoPath sources if we have other sources already. The WireTask
207200
// would otherwise run even through we have no sources.
208-
if (addedSourcesDependencies > 0) {
201+
if (!task.source.isEmpty) {
209202
for (rootSet in protoPathProtoRootSets) {
210203
task.source(rootSet.configuration)
211-
task.source(*rootSet.sourceDirectoriesAndLocalJars.toTypedArray())
212204
}
213205
}
214206

@@ -339,13 +331,9 @@ class WirePlugin : Plugin<Project> {
339331
}
340332

341333
private fun defaultSourceFolders(source: Source): Set<String> {
342-
val parser = FileOrUriNotationConverter.parser()
343-
return source.sourceSets.map { "src/$it/proto" }.filter { path ->
344-
val converted = parser.parseNotation(path) as File
345-
val file =
346-
if (!converted.isAbsolute) File(project.projectDir, converted.path) else converted
347-
return@filter file.exists()
348-
}.toSet()
334+
return source.sourceSets.map { "src/$it/proto" }
335+
.filter { path -> File(project.projectDir, path).exists() }
336+
.toSet()
349337
}
350338

351339
internal companion object {

0 commit comments

Comments
 (0)