|
| 1 | +/* |
| 2 | + * Copyright 2012-2024 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.build; |
| 18 | + |
| 19 | +import io.spring.nohttp.gradle.NoHttpCheckstylePlugin; |
| 20 | +import io.spring.nohttp.gradle.NoHttpExtension; |
| 21 | +import org.gradle.api.Project; |
| 22 | +import org.gradle.api.file.ConfigurableFileTree; |
| 23 | +import org.gradle.api.plugins.quality.Checkstyle; |
| 24 | + |
| 25 | +/** |
| 26 | + * Conventions that are applied to enforce that no HTTP urls are used. |
| 27 | + * |
| 28 | + * @author Phillip Webb |
| 29 | + */ |
| 30 | +public class NoHttpConventions { |
| 31 | + |
| 32 | + void apply(Project project) { |
| 33 | + project.getPluginManager().apply(NoHttpCheckstylePlugin.class); |
| 34 | + configureNoHttpExtension(project, project.getExtensions().getByType(NoHttpExtension.class)); |
| 35 | + project.getTasks() |
| 36 | + .named(NoHttpCheckstylePlugin.CHECKSTYLE_NOHTTP_TASK_NAME, Checkstyle.class) |
| 37 | + .configure((task) -> task.getConfigDirectory().set(project.getRootProject().file("src/nohttp"))); |
| 38 | + } |
| 39 | + |
| 40 | + private void configureNoHttpExtension(Project project, NoHttpExtension extension) { |
| 41 | + extension.setAllowlistFile(project.getRootProject().file("src/nohttp/allowlist.lines")); |
| 42 | + ConfigurableFileTree source = extension.getSource(); |
| 43 | + source.exclude("bin/**"); |
| 44 | + source.exclude("build/**"); |
| 45 | + source.exclude("out/**"); |
| 46 | + source.exclude("target/**"); |
| 47 | + source.exclude(".settings/**"); |
| 48 | + source.exclude(".classpath"); |
| 49 | + source.exclude(".project"); |
| 50 | + source.exclude(".gradle"); |
| 51 | + source.exclude("**/docker/export.tar"); |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments