Skip to content

Commit

Permalink
Merge pull request #2555 from square/bquenaudon.2023-07-31.provide
Browse files Browse the repository at this point in the history
Provide proto output to sourceSet's resources
  • Loading branch information
oldergod authored Jul 31, 2023
2 parents 09448bd + 84e434c commit a551023
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,13 @@ class WirePlugin : Plugin<Project> {
source.javaSourceDirectorySet?.srcDir(taskOutputDirectories)
source.registerGeneratedDirectory?.invoke(taskOutputDirectories)

val protoOutputDirectory = task.map { it.protoLibraryOutput }
if (extension.protoLibrary) {
val sourceSets = project.extensions.getByType(SourceSetContainer::class.java)
// Note that there are no source sets for some platforms such as native.
if (sourceSets.isNotEmpty()) {
sourceSets.getByName("main") { main: SourceSet ->
main.resources.srcDir(project.libraryProtoOutputPath())
main.resources.srcDir(protoOutputDirectory)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,25 @@ class WirePluginTest {
assertThat(generatedProto2).exists()
}

@Test
fun protoLibrary() {
val fixtureRoot = File("src/test/projects/proto-library")

val result = gradleRunner.runFixture(fixtureRoot) {
withArguments("jar", "--stacktrace", "--info").build()
}

println(result.output)
assertThat(result.output)
.contains("Writing squareup/dinosaurs/dinosaur.proto")
.contains("Writing squareup/geology/period.proto")

ZipFile(File(fixtureRoot, "build/libs/proto-library.jar")).use {
assertThat(it.getEntry("squareup/geology/period.proto")).isNotNull()
assertThat(it.getEntry("squareup/dinosaurs/dinosaur.proto")).isNotNull()
}
}

@Test
fun sourceDirExclude() {
val fixtureRoot = File("src/test/projects/sourcedir-exclude")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id 'kotlin'
id 'com.squareup.wire'
}

wire {
protoLibrary = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
syntax = "proto2";

package squareup.dinosaurs;

option java_package = "com.squareup.dinosaurs";

import "squareup/geology/period.proto";

message Dinosaur {
/** Common name of this dinosaur, like "Stegosaurus". */
optional string name = 1;

/** URLs with images of this dinosaur. */
repeated string picture_urls = 2;

optional double length_meters = 3;
optional double mass_kilograms = 4;
optional squareup.geology.Period period = 5;
}
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;
}

0 comments on commit a551023

Please sign in to comment.