Skip to content

Commit

Permalink
Use task output as Java source directory (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoenig10 authored Feb 14, 2024
1 parent 0932f63 commit 99c078a
Showing 1 changed file with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ public void apply(Project project) {
createCompileSchemaTask(project, metricSchemaDir, sourceSet);

Provider<Directory> generatedJavaOutputDir = metricSchemaDir.map(file -> file.dir("generated_src"));
TaskProvider<GenerateMetricSchemaTask> generateMetricsTask = project.getTasks()
TaskProvider<GenerateMetricSchemaTask> generateMetricSchemaTask = project.getTasks()
.register(GENERATE_METRICS, GenerateMetricSchemaTask.class, task -> {
task.setGroup(TASK_GROUP);
task.setDescription("Generates bindings for producing well defined metrics");
task.getInputFile().set(compileSchemaTask.flatMap(CompileMetricSchemaTask::getOutputFile));
task.getOutputDir().set(generatedJavaOutputDir);
});

getMainSourceSet(project).getJava().srcDir(generateMetricsTask);
configureIdea(project, generateMetricsTask, generatedJavaOutputDir);
configureEclipse(project, generateMetricsTask);
configureJavaSource(project, generateMetricSchemaTask);
configureIdea(project, generateMetricSchemaTask, generatedJavaOutputDir);
configureEclipse(project, generateMetricSchemaTask);
configureProjectDependencies(project);

createManifestTask(project, metricSchemaDir, compileSchemaTask);
Expand Down Expand Up @@ -99,15 +99,17 @@ private static TaskProvider<CompileMetricSchemaTask> createCompileSchemaTask(
.named("processResources")
.configure(processResources -> processResources.dependsOn(compileMetricSchema));

SourceSet mainSourceSet = getMainSourceSet(project);
mainSourceSet.getJava().srcDir(metricSchemaDir);
mainSourceSet.resources(resources -> {
SourceDirectorySet sourceDir = project.getObjects()
.sourceDirectorySet("metricSchema", "metric schema")
.srcDir(metricSchemaDir);
sourceDir.include("metric-schema/**");
resources.source(sourceDir);
});
project.getExtensions()
.getByType(JavaPluginExtension.class)
.getSourceSets()
.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
.resources(resources -> {
SourceDirectorySet sourceDir = project.getObjects()
.sourceDirectorySet("metricSchema", "metric schema")
.srcDir(metricSchemaDir);
sourceDir.include("metric-schema/**");
resources.source(sourceDir);
});

return compileMetricSchema;
}
Expand All @@ -120,10 +122,15 @@ private static SourceDirectorySet createSourceSet(Project project) {
return sourceSet;
}

private static SourceSet getMainSourceSet(Project project) {
JavaPluginExtension javaPlugin = project.getExtensions().getByType(JavaPluginExtension.class);
javaPlugin.withSourcesJar();
return javaPlugin.getSourceSets().getByName("main");
private static void configureJavaSource(
Project project, TaskProvider<GenerateMetricSchemaTask> generateMetricSchemaTask) {
project.getExtensions()
.getByType(JavaPluginExtension.class)
.getSourceSets()
.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
.java(java -> {
java.srcDir(generateMetricSchemaTask);
});
}

private static void configureEclipse(Project project, TaskProvider<? extends Task> generateMetrics) {
Expand Down

0 comments on commit 99c078a

Please sign in to comment.