|
| 1 | +/* |
| 2 | + * Copyright 2025 DiffPlug |
| 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 | + * http://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 | +package com.diffplug.gradle.spotless; |
| 17 | + |
| 18 | +import javax.annotation.Nullable; |
| 19 | + |
| 20 | +import org.gradle.api.Project; |
| 21 | + |
| 22 | +public final class GradleCompat { |
| 23 | + private GradleCompat() {} |
| 24 | + |
| 25 | + @Nullable public static String findOptionalProperty(Project project, String propertyName) { |
| 26 | + @Nullable String value = project.getProviders().gradleProperty(propertyName).getOrNull(); |
| 27 | + if (value != null) { |
| 28 | + return value; |
| 29 | + } |
| 30 | + @Nullable Object property = project.findProperty(propertyName); |
| 31 | + if (property != null) { |
| 32 | + return property.toString(); |
| 33 | + } |
| 34 | + return null; |
| 35 | + } |
| 36 | + |
| 37 | + public static boolean isPropertyPresent(Project project, String propertyName) { |
| 38 | + return project.getProviders().gradleProperty(propertyName).isPresent() || |
| 39 | + project.hasProperty(propertyName); |
| 40 | + } |
| 41 | +} |
0 commit comments