From f72cf55fbaf9fe6adafbd7aebf0db8be27c95d11 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Thu, 24 Mar 2022 08:41:36 +0100 Subject: [PATCH] Add clone of IgnoreEmptyDirectories annotation to allow compiling the forbiddenapis task with it. This works around problems with Grdale 7.4+. Closes #189 --- .../gradle/CheckForbiddenApis.java | 5 +++ .../api/tasks/IgnoreEmptyDirectories.java | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/main/java/org/gradle/api/tasks/IgnoreEmptyDirectories.java diff --git a/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApis.java b/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApis.java index f8244e1..b5cf364 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApis.java +++ b/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApis.java @@ -40,11 +40,14 @@ import org.gradle.api.file.FileTreeElement; import org.gradle.api.specs.Spec; import org.gradle.api.tasks.CompileClasspath; +import org.gradle.api.tasks.IgnoreEmptyDirectories; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.InputFiles; import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.Optional; import org.gradle.api.tasks.ParallelizableTask; +import org.gradle.api.tasks.PathSensitive; +import org.gradle.api.tasks.PathSensitivity; import org.gradle.api.tasks.SkipWhenEmpty; import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.VerificationTask; @@ -465,6 +468,8 @@ public CheckForbiddenApis include(@SuppressWarnings("rawtypes") Closure arg0) { /** Returns the classes to check. */ @InputFiles @SkipWhenEmpty + @IgnoreEmptyDirectories + @PathSensitive(PathSensitivity.RELATIVE) public FileTree getClassFiles() { return getClassesDirs().getAsFileTree().matching(getPatternSet()); } diff --git a/src/main/java/org/gradle/api/tasks/IgnoreEmptyDirectories.java b/src/main/java/org/gradle/api/tasks/IgnoreEmptyDirectories.java new file mode 100644 index 0000000..62efda0 --- /dev/null +++ b/src/main/java/org/gradle/api/tasks/IgnoreEmptyDirectories.java @@ -0,0 +1,39 @@ +/* + * Copyright 2020 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 + * + * http://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.gradle.api.tasks; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis; + +/** + * Attached to an input property to specify that directories should be ignored + * when snapshotting inputs. Files within directories and subdirectories will be + * snapshot, but the directories themselves will be ignored. Empty directories, + * and directories that contain only empty directories will have no effect on the + * resulting snapshot. + *

Copy of Gradle 6.8 annotation to allow compilation of {@link CheckForbiddenApis}. + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.FIELD}) +public @interface IgnoreEmptyDirectories { +} \ No newline at end of file