Merge branch '2.0.x'

pull/14059/merge
Andy Wilkinson 6 years ago
commit e3e3a44045

@ -26,6 +26,7 @@ import java.util.concurrent.Callable;
import org.gradle.api.Action; import org.gradle.api.Action;
import org.gradle.api.Plugin; import org.gradle.api.Plugin;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.file.FileCollection; import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact; import org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact;
import org.gradle.api.plugins.ApplicationPlugin; import org.gradle.api.plugins.ApplicationPlugin;
@ -145,37 +146,49 @@ final class JavaPluginAction implements PluginApplicationAction {
} }
private void configureAdditionalMetadataLocations(JavaCompile compile) { private void configureAdditionalMetadataLocations(JavaCompile compile) {
compile.doFirst((task) -> { compile.doFirst(new AdditionalMetadataLocationsConfigurer());
}
private static class AdditionalMetadataLocationsConfigurer implements Action<Task> {
@Override
public void execute(Task task) {
if (!(task instanceof JavaCompile)) {
return;
}
JavaCompile compile = (JavaCompile) task;
if (hasConfigurationProcessorOnClasspath(compile)) { if (hasConfigurationProcessorOnClasspath(compile)) {
findMatchingSourceSet(compile).ifPresent( findMatchingSourceSet(compile).ifPresent(
(sourceSet) -> configureAdditionalMetadataLocations(compile, (sourceSet) -> configureAdditionalMetadataLocations(compile,
sourceSet)); sourceSet));
} }
}); }
}
private boolean hasConfigurationProcessorOnClasspath(JavaCompile compile) {
private Optional<SourceSet> findMatchingSourceSet(JavaCompile compile) { Set<File> files = (compile.getOptions().getAnnotationProcessorPath() != null)
return compile.getProject().getConvention().getPlugin(JavaPluginConvention.class) ? compile.getOptions().getAnnotationProcessorPath().getFiles()
.getSourceSets().stream().filter((sourceSet) -> sourceSet : compile.getClasspath().getFiles();
.getCompileJavaTaskName().equals(compile.getName())) return files.stream().map(File::getName).anyMatch(
.findFirst(); (name) -> name.startsWith("spring-boot-configuration-processor"));
} }
private boolean hasConfigurationProcessorOnClasspath(JavaCompile compile) { private Optional<SourceSet> findMatchingSourceSet(JavaCompile compile) {
Set<File> files = (compile.getOptions().getAnnotationProcessorPath() != null) return compile
? compile.getOptions().getAnnotationProcessorPath().getFiles() .getProject().getConvention().getPlugin(JavaPluginConvention.class)
: compile.getClasspath().getFiles(); .getSourceSets().stream().filter((sourceSet) -> sourceSet
return files.stream().map(File::getName).anyMatch( .getCompileJavaTaskName().equals(compile.getName()))
(name) -> name.startsWith("spring-boot-configuration-processor")); .findFirst();
} }
private void configureAdditionalMetadataLocations(JavaCompile compile,
SourceSet sourceSet) {
String locations = StringUtils.collectionToCommaDelimitedString(
sourceSet.getResources().getSrcDirs());
compile.getOptions().getCompilerArgs().add(
"-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations="
+ locations);
}
private void configureAdditionalMetadataLocations(JavaCompile compile,
SourceSet sourceSet) {
String locations = StringUtils
.collectionToCommaDelimitedString(sourceSet.getResources().getSrcDirs());
compile.getOptions().getCompilerArgs().add(
"-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations="
+ locations);
} }
} }

Loading…
Cancel
Save