use of com.linkedin.pegasus.gradle.tasks.GenerateAvroSchemaTask in project rest.li by linkedin.
the class PegasusPlugin method configureAvroSchemaGeneration.
@SuppressWarnings("deprecation")
protected void configureAvroSchemaGeneration(Project project, SourceSet sourceSet) {
File dataSchemaDir = project.file(getDataSchemaPath(project, sourceSet));
File avroDir = project.file(getGeneratedDirPath(project, sourceSet, AVRO_SCHEMA_GEN_TYPE) + File.separatorChar + "avro");
// generate avro schema files from data schema
Task generateAvroSchemaTask = project.getTasks().create(sourceSet.getTaskName("generate", "avroSchema"), GenerateAvroSchemaTask.class, task -> {
task.setInputDir(dataSchemaDir);
task.setDestinationDir(avroDir);
task.setResolverPath(getDataModelConfig(project, sourceSet));
task.setCodegenClasspath(project.getConfigurations().getByName(PEGASUS_PLUGIN_CONFIGURATION));
if (isPropertyTrue(project, ENABLE_ARG_FILE)) {
task.setEnableArgFile(true);
}
task.onlyIf(t -> {
if (task.getInputDir().exists()) {
@SuppressWarnings("unchecked") Map<String, PegasusOptions> pegasusOptions = (Map<String, PegasusOptions>) project.getExtensions().getExtraProperties().get("pegasus");
if (pegasusOptions.get(sourceSet.getName()).hasGenerationMode(PegasusOptions.GenerationMode.AVRO)) {
return true;
}
}
return !project.getConfigurations().getByName("avroSchemaGenerator").isEmpty();
});
task.doFirst(new CacheableAction<>(t -> deleteGeneratedDir(project, sourceSet, AVRO_SCHEMA_GEN_TYPE)));
});
project.getTasks().getByName(sourceSet.getCompileJavaTaskName()).dependsOn(generateAvroSchemaTask);
// create avro schema jar file
Task avroSchemaJarTask = project.getTasks().create(sourceSet.getName() + "AvroSchemaJar", Jar.class, task -> {
// add path prefix to each file in the data schema directory
task.from(avroDir, copySpec -> copySpec.eachFile(fileCopyDetails -> fileCopyDetails.setPath("avro" + File.separatorChar + fileCopyDetails.getPath())));
// FIXME change to #getArchiveAppendix().set(...); breaks backwards-compatibility before 5.1
task.setAppendix(getAppendix(sourceSet, "avro-schema"));
task.setDescription("Generate an avro schema jar");
});
if (!isTestSourceSet(sourceSet)) {
project.getArtifacts().add("avroSchema", avroSchemaJarTask);
} else {
project.getArtifacts().add("testAvroSchema", avroSchemaJarTask);
}
}
Aggregations