|
|
|
@ -16,17 +16,17 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.build.architecture; |
|
|
|
package org.springframework.boot.build.architecture; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.plugins.JavaPlugin; |
|
|
|
import org.gradle.api.plugins.JavaPlugin; |
|
|
|
import org.gradle.api.plugins.JavaPluginExtension; |
|
|
|
import org.gradle.api.plugins.JavaPluginExtension; |
|
|
|
import org.gradle.api.tasks.SourceSet; |
|
|
|
import org.gradle.api.tasks.SourceSet; |
|
|
|
import org.gradle.api.tasks.TaskProvider; |
|
|
|
import org.gradle.api.tasks.TaskProvider; |
|
|
|
|
|
|
|
import org.gradle.api.tasks.compile.JavaCompile; |
|
|
|
import org.gradle.language.base.plugins.LifecycleBasePlugin; |
|
|
|
import org.gradle.language.base.plugins.LifecycleBasePlugin; |
|
|
|
|
|
|
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompileTool; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
@ -46,28 +46,45 @@ public class ArchitecturePlugin implements Plugin<Project> { |
|
|
|
|
|
|
|
|
|
|
|
private void registerTasks(Project project, ArchitectureCheckExtension extension) { |
|
|
|
private void registerTasks(Project project, ArchitectureCheckExtension extension) { |
|
|
|
JavaPluginExtension javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class); |
|
|
|
JavaPluginExtension javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class); |
|
|
|
List<TaskProvider<ArchitectureCheck>> packageTangleChecks = new ArrayList<>(); |
|
|
|
|
|
|
|
for (SourceSet sourceSet : javaPluginExtension.getSourceSets()) { |
|
|
|
for (SourceSet sourceSet : javaPluginExtension.getSourceSets()) { |
|
|
|
TaskProvider<ArchitectureCheck> checkPackageTangles = project.getTasks() |
|
|
|
registerArchitectureCheck(sourceSet, "java", project).configure((task) -> { |
|
|
|
.register("checkArchitecture" + StringUtils.capitalize(sourceSet.getName()), ArchitectureCheck.class, |
|
|
|
task.setClasses(project.files(project.getTasks() |
|
|
|
(task) -> { |
|
|
|
.named(sourceSet.getCompileTaskName("java"), JavaCompile.class) |
|
|
|
|
|
|
|
.flatMap((compile) -> compile.getDestinationDirectory()))); |
|
|
|
|
|
|
|
task.getNullMarkedEnabled().set(extension.getNullMarked().getEnabled()); |
|
|
|
|
|
|
|
task.getNullMarkedIgnoredPackages().set(extension.getNullMarked().getIgnoredPackages()); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
project.getPlugins() |
|
|
|
|
|
|
|
.withId("org.jetbrains.kotlin.jvm", |
|
|
|
|
|
|
|
(kotlinPlugin) -> registerArchitectureCheck(sourceSet, "kotlin", project).configure((task) -> { |
|
|
|
|
|
|
|
task.setClasses(project.files(project.getTasks() |
|
|
|
|
|
|
|
.named(sourceSet.getCompileTaskName("kotlin"), KotlinCompileTool.class) |
|
|
|
|
|
|
|
.flatMap((compile) -> compile.getDestinationDirectory()))); |
|
|
|
|
|
|
|
task.getNullMarkedEnabled().set(false); |
|
|
|
|
|
|
|
task.getNullMarkedIgnoredPackages().set(Collections.emptySet()); |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private TaskProvider<ArchitectureCheck> registerArchitectureCheck(SourceSet sourceSet, String language, |
|
|
|
|
|
|
|
Project project) { |
|
|
|
|
|
|
|
TaskProvider<ArchitectureCheck> checkArchitecture = project.getTasks() |
|
|
|
|
|
|
|
.register( |
|
|
|
|
|
|
|
"checkArchitecture" |
|
|
|
|
|
|
|
+ StringUtils.capitalize(sourceSet.getName() + StringUtils.capitalize(language)), |
|
|
|
|
|
|
|
ArchitectureCheck.class, (task) -> { |
|
|
|
task.getSourceSet().set(sourceSet.getName()); |
|
|
|
task.getSourceSet().set(sourceSet.getName()); |
|
|
|
task.getCompileClasspath().from(sourceSet.getCompileClasspath()); |
|
|
|
task.getCompileClasspath().from(sourceSet.getCompileClasspath()); |
|
|
|
task.setClasses(sourceSet.getOutput().getClassesDirs()); |
|
|
|
|
|
|
|
task.getResourcesDirectory().set(sourceSet.getOutput().getResourcesDir()); |
|
|
|
task.getResourcesDirectory().set(sourceSet.getOutput().getResourcesDir()); |
|
|
|
task.dependsOn(sourceSet.getProcessResourcesTaskName()); |
|
|
|
task.dependsOn(sourceSet.getProcessResourcesTaskName()); |
|
|
|
task.setDescription("Checks the architecture of the classes of the " + sourceSet.getName() |
|
|
|
task.setDescription("Checks the architecture of the " + language + " classes of the " |
|
|
|
+ " source set."); |
|
|
|
+ sourceSet.getName() + " source set."); |
|
|
|
task.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP); |
|
|
|
task.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP); |
|
|
|
task.getNullMarkedEnabled().set(extension.getNullMarked().getEnabled()); |
|
|
|
|
|
|
|
task.getNullMarkedIgnoredPackages().set(extension.getNullMarked().getIgnoredPackages()); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
packageTangleChecks.add(checkPackageTangles); |
|
|
|
project.getTasks() |
|
|
|
} |
|
|
|
.named(LifecycleBasePlugin.CHECK_TASK_NAME) |
|
|
|
if (!packageTangleChecks.isEmpty()) { |
|
|
|
.configure((check) -> check.dependsOn(checkArchitecture)); |
|
|
|
TaskProvider<Task> checkTask = project.getTasks().named(LifecycleBasePlugin.CHECK_TASK_NAME); |
|
|
|
return checkArchitecture; |
|
|
|
checkTask.configure((check) -> check.dependsOn(packageTangleChecks)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|