From f9379f45765d6218d17a85d6e46dec69cd46a2a9 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 18 Mar 2024 13:57:53 -0700 Subject: [PATCH] Apply nohttp check per-project rather than at root Switch nohttp checks to a convention that is applied per-project rather than at the root. This should help to reduce memory consumption. Closes gh-42332 --- build.gradle | 21 -------- buildSrc/build.gradle | 1 + .../boot/build/ConventionsPlugin.java | 3 +- .../boot/build/NoHttpConventions.java | 54 +++++++++++++++++++ 4 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 buildSrc/src/main/java/org/springframework/boot/build/NoHttpConventions.java diff --git a/build.gradle b/build.gradle index 0795f569d49e..4f490c8e7c19 100644 --- a/build.gradle +++ b/build.gradle @@ -1,29 +1,12 @@ plugins { id "base" id "org.jetbrains.kotlin.jvm" apply false // https://youtrack.jetbrains.com/issue/KT-30276 - id "io.spring.nohttp" version "0.0.11" } description = "Spring Boot Build" defaultTasks 'build' -nohttp { - allowlistFile = project.file("src/nohttp/allowlist.lines") - source.exclude "**/bin/**" - source.exclude "**/build/**" - source.exclude "**/out/**" - source.exclude "**/target/**" - source.exclude "**/.settings/**" - source.exclude "**/.classpath" - source.exclude "**/.project" - source.exclude "spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/docker/export.tar" -} - -check { - dependsOn checkstyleNohttp -} - allprojects { group "org.springframework.boot" @@ -41,7 +24,3 @@ allprojects { resolutionStrategy.cacheChangingModulesFor 0, "minutes" } } - -tasks.named("checkstyleNohttp").configure { - maxHeapSize = "1536m" -} diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index f2382ffc1bc1..d8b44f640c68 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -53,6 +53,7 @@ dependencies { implementation("org.springframework:spring-context") implementation("org.springframework:spring-core") implementation("org.springframework:spring-web") + implementation("io.spring.nohttp:nohttp-gradle:0.0.11") testImplementation("org.assertj:assertj-core:${versions.assertj}") testImplementation("org.hamcrest:hamcrest:${versions.hamcrest}") diff --git a/buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java index 8a50535a4365..03c5ab14819c 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,6 +43,7 @@ public class ConventionsPlugin implements Plugin { @Override public void apply(Project project) { + new NoHttpConventions().apply(project); new JavaConventions().apply(project); new MavenPublishingConventions().apply(project); new AsciidoctorConventions().apply(project); diff --git a/buildSrc/src/main/java/org/springframework/boot/build/NoHttpConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/NoHttpConventions.java new file mode 100644 index 000000000000..7b4847ff2aec --- /dev/null +++ b/buildSrc/src/main/java/org/springframework/boot/build/NoHttpConventions.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.build; + +import io.spring.nohttp.gradle.NoHttpCheckstylePlugin; +import io.spring.nohttp.gradle.NoHttpExtension; +import org.gradle.api.Project; +import org.gradle.api.file.ConfigurableFileTree; +import org.gradle.api.plugins.quality.Checkstyle; + +/** + * Conventions that are applied to enforce that no HTTP urls are used. + * + * @author Phillip Webb + */ +public class NoHttpConventions { + + void apply(Project project) { + project.getPluginManager().apply(NoHttpCheckstylePlugin.class); + configureNoHttpExtension(project, project.getExtensions().getByType(NoHttpExtension.class)); + project.getTasks() + .named(NoHttpCheckstylePlugin.CHECKSTYLE_NOHTTP_TASK_NAME, Checkstyle.class) + .configure((task) -> task.getConfigDirectory().set(project.getRootProject().file("src/nohttp"))); + } + + private void configureNoHttpExtension(Project project, NoHttpExtension extension) { + extension.setAllowlistFile(project.getRootProject().file("src/nohttp/allowlist.lines")); + ConfigurableFileTree source = extension.getSource(); + source.exclude("bin/**"); + source.exclude("build/**"); + source.exclude("out/**"); + source.exclude("target/**"); + source.exclude(".settings/**"); + source.exclude(".classpath"); + source.exclude(".project"); + source.exclude(".gradle"); + source.exclude("**/docker/export.tar"); + } + +}