Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package com.squareup.wire.gradle.kotlin

import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.Variant
import com.squareup.wire.gradle.CustomOutput
import com.squareup.wire.gradle.JavaOutput
import com.squareup.wire.gradle.KotlinOutput
import com.squareup.wire.gradle.WireOutput
Expand Down Expand Up @@ -144,16 +143,11 @@ private class JvmOrKmpSource(
is KotlinOutput -> {
registerKotlinGeneratedSources(kotlinSourceSet, outputDirectory)
}
is CustomOutput -> {
// Custom targets are wildcards, so we add all output directories.
else -> {
// Custom and third-party outputs are wildcards, so we add all output directories.
javaSourceDirectorySet?.srcDir(outputDirectory)
registerKotlinGeneratedSources(kotlinSourceSet, outputDirectory)
}
else -> {
throw IllegalArgumentException(
"Wire output ${output::class.simpleName} is not supported in project ${project.path}",
)
}
}
}
}
Expand Down Expand Up @@ -181,16 +175,11 @@ private class AndroidSource(
// Registering with variant.sources.kotlin can hide handwritten sources from KSP.
variant.sources.java?.addGeneratedSourceDirectory(wireTask) { it.outputDirectoriesList[index] }
}
is CustomOutput -> {
// Custom targets are wildcards, so we add all output directories.
else -> {
// Custom and third-party outputs are wildcards, so we add all output directories.
variant.sources.java?.addGeneratedSourceDirectory(wireTask) { it.outputDirectoriesList[index] }
variant.sources.kotlin?.addGeneratedSourceDirectory(wireTask) { it.outputDirectoriesList[index] }
}
else -> {
throw IllegalArgumentException(
"Wire output ${output::class.simpleName} is not supported in Android project ${project.path}",
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,15 @@ class WirePluginTest {
.contains("Couldn't find SchemaHandlerClass 'NoSuchClass'")
}

@Test
fun thirdPartyOutputRegistersGeneratedSources() {
val fixtureRoot = File("src/test/projects/third-party-output")

val result = fixtureGradleRunner(fixtureRoot, "printSourceDirs").build()
assertThat(result.task(":printSourceDirs")).isNotNull()
assertThat(result.output).contains("generated${File.separator}thirdParty")
}

@Test
fun customOutputProviderBackedDsl() {
val fixtureRoot = File("src/test/projects/custom-output-provider-kotlin-dsl")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import com.squareup.wire.gradle.WireOutput
import com.squareup.wire.schema.CustomTarget
import com.squareup.wire.schema.SchemaHandler
import com.squareup.wire.schema.Target
import org.jetbrains.annotations.NotNull

buildscript {
dependencies {
classpath "com.squareup.wire:wire-gradle-plugin:$wireVersion"
}

repositories {
maven {
url new File(rootDir, "../../../../../build/localMaven").toURI().toString()
}
mavenCentral()
google()
}
}

apply plugin: 'application'
apply plugin: 'com.squareup.wire'

class ThirdPartyHandlerFactory implements SchemaHandler.Factory {
@Override
SchemaHandler create(@NotNull List<String> includes, @NotNull List<String> excludes,
boolean exclusive, @NotNull String outDirectory, @NotNull Map<String, String> options) {
throw new RuntimeException("this test only configures the project; the handler never runs")
}
}

// A third-party WireOutput subclass, as plugins building on top of Wire define them.
abstract class ThirdPartyOutput extends WireOutput {
@Override
Target toTarget(String outputDirectory) {
return new CustomTarget(['*'], [], false, outputDirectory, [:], new ThirdPartyHandlerFactory())
}
}

wire {
sourcePath 'src/main/proto'
}

def thirdPartyOutput = project.objects.newInstance(ThirdPartyOutput)
thirdPartyOutput.setOut("${buildDir}/generated/thirdParty")
wire.outputs.add(thirdPartyOutput)

tasks.register('printSourceDirs') {
def srcDirs = project.provider { sourceSets.main.java.srcDirs }
doLast {
println "sourceDirs: ${srcDirs.get()}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include ':'

dependencyResolutionManagement {
versionCatalogs {
libs {
from(files('../../../../../gradle/libs.versions.toml'))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto2";

package squareup.geology;

option java_package = "com.squareup.geology";

enum Period {
/** 145.5 million years ago — 66.0 million years ago. */
CRETACEOUS = 1;

/** 201.3 million years ago — 145.0 million years ago. */
JURASSIC = 2;

/** 252.17 million years ago — 201.3 million years ago. */
TRIASSIC = 3;
}
Loading