[Git][java-team/gradle][master] New patch ignoring the plugins listed in debian/gradle.ignoreRules

Emmanuel Bourg (@ebourg) gitlab at salsa.debian.org
Wed Sep 30 09:26:42 BST 2026



Emmanuel Bourg pushed to branch master at Debian Java Maintainers / gradle


Commits:
e462cb24 by Emmanuel Bourg at 2026-09-30T10:19:32+02:00
New patch ignoring the plugins listed in debian/gradle.ignoreRules

- - - - -


3 changed files:

- debian/changelog
- + debian/patches/gradle-debian-helper-plugin-filter.patch
- debian/patches/series


Changes:

=====================================
debian/changelog
=====================================
@@ -1,3 +1,10 @@
+gradle (4.6-2) unstable; urgency=medium
+
+  * Team upload
+  * Ignore the plugins listed in debian/gradle.ignoreRules
+
+ -- Emmanuel Bourg <ebourg at apache.org>  Wed, 30 Sep 2026 10:19:19 +0200
+
 gradle (4.6-1) unstable; urgency=medium
 
   * Team upload


=====================================
debian/patches/gradle-debian-helper-plugin-filter.patch
=====================================
@@ -0,0 +1,403 @@
+Description: Ignore the plugins and projects listed in debian/gradle.ignoreRules
+ With this patch Gradle ignores the plugins, projects and blocks declared in 
+ debian/gradle.ignoreRules. The rules are parsed by gradle-debian-helper, called
+ by reflection because Gradle does not depend on it. Nothing is ignored when the
+ file is absent or the helper isn't installed.
+Author: Emmanuel Bourg <ebourg at apache.org>
+Forwarded: not-needed
+--- a/subprojects/core/src/main/java/org/gradle/api/internal/plugins/DefaultPluginManager.java
++++ b/subprojects/core/src/main/java/org/gradle/api/internal/plugins/DefaultPluginManager.java
+@@ -32,6 +32,7 @@
+ import org.gradle.api.reflect.ObjectInstantiationException;
+ import org.gradle.configuration.ConfigurationTargetIdentifier;
+ import org.gradle.internal.Cast;
++import org.gradle.internal.debian.DebianIgnoreRules;
+ import org.gradle.internal.operations.BuildOperationContext;
+ import org.gradle.internal.operations.BuildOperationExecutor;
+ import org.gradle.internal.operations.RunnableBuildOperation;
+@@ -118,6 +119,10 @@
+     }
+ 
+     public void apply(String pluginId) {
++        if (DebianIgnoreRules.isIgnoredPlugin(pluginId)) {
++            return;
++        }
++
+         PluginImplementation<?> plugin = pluginRegistry.lookup(DefaultPluginId.unvalidated(pluginId));
+         if (plugin == null) {
+             throw new UnknownPluginException("Plugin with id '" + pluginId + "' not found.");
+--- a/subprojects/core/src/main/java/org/gradle/api/internal/plugins/DefaultObjectConfigurationAction.java
++++ b/subprojects/core/src/main/java/org/gradle/api/internal/plugins/DefaultObjectConfigurationAction.java
+@@ -24,6 +24,7 @@
+ import org.gradle.api.plugins.ObjectConfigurationAction;
+ import org.gradle.api.plugins.PluginAware;
+ import org.gradle.configuration.ScriptPlugin;
++import org.gradle.internal.debian.DebianIgnoreRules;
+ import org.gradle.configuration.ScriptPluginFactory;
+ import org.gradle.groovy.scripts.ScriptSource;
+ import org.gradle.groovy.scripts.TextResourceScriptSource;
+@@ -100,6 +101,10 @@
+ 
+     private void applyScript(Object script) {
+         URI scriptUri = resolver.resolveUri(script);
++        if (DebianIgnoreRules.isIgnoredScript(scriptUri.getPath())) {
++            return;
++        }
++
+         TextResource resource = resourceLoader.loadUri("script", scriptUri);
+         ScriptSource scriptSource = new TextResourceScriptSource(resource);
+         ClassLoaderScope classLoaderScopeChild = classLoaderScope.createChild("script-" + scriptUri.toString());
+--- a/subprojects/core/src/main/java/org/gradle/initialization/DefaultSettings.java
++++ b/subprojects/core/src/main/java/org/gradle/initialization/DefaultSettings.java
+@@ -25,6 +25,7 @@
+ import org.gradle.api.initialization.dsl.ScriptHandler;
+ import org.gradle.api.internal.FeaturePreviews;
+ import org.gradle.api.internal.GradleInternal;
++import org.gradle.internal.debian.DebianIgnoreRules;
+ import org.gradle.api.internal.SettingsInternal;
+ import org.gradle.api.internal.file.FileResolver;
+ import org.gradle.api.internal.initialization.ClassLoaderScope;
+@@ -138,6 +139,10 @@
+ 
+     public void include(String... projectPaths) {
+         for (String projectPath : projectPaths) {
++            if (DebianIgnoreRules.isIgnoredProject(projectPath)) {
++                continue;
++            }
++
+             String subPath = "";
+             String[] pathElements = removeTrailingColon(projectPath).split(":");
+             DefaultProjectDescriptor parentProjectDescriptor = rootProjectDescriptor;
+@@ -155,6 +160,10 @@
+ 
+     public void includeFlat(String... projectNames) {
+         for (String projectName : projectNames) {
++            if (DebianIgnoreRules.isIgnoredProject(projectName)) {
++                continue;
++            }
++
+             createProjectDescriptor(rootProjectDescriptor, projectName,
+                 new File(rootProjectDescriptor.getProjectDir().getParentFile(), projectName));
+         }
+--- a/subprojects/core/src/main/java/org/gradle/groovy/scripts/internal/DefaultScriptCompilationHandler.java
++++ b/subprojects/core/src/main/java/org/gradle/groovy/scripts/internal/DefaultScriptCompilationHandler.java
+@@ -27,6 +27,7 @@
+ import org.codehaus.groovy.classgen.Verifier;
+ import org.codehaus.groovy.control.CompilationFailedException;
+ import org.codehaus.groovy.control.CompilationUnit;
++import org.gradle.internal.debian.DebianIgnoreRules;
+ import org.codehaus.groovy.control.CompilerConfiguration;
+ import org.codehaus.groovy.control.MultipleCompilationErrorsException;
+ import org.codehaus.groovy.control.Phases;
+@@ -111,7 +112,7 @@
+ 
+         final EmptyScriptDetector emptyScriptDetector = new EmptyScriptDetector();
+         final PackageStatementDetector packageDetector = new PackageStatementDetector();
+-        GroovyClassLoader groovyClassLoader = new GroovyClassLoader(classLoader, configuration, false) {
++        GroovyClassLoader groovyClassLoader = new GroovyClassLoader(DebianIgnoreRules.wrap(classLoader), configuration, false) {
+             @Override
+             protected CompilationUnit createCompilationUnit(CompilerConfiguration compilerConfiguration,
+                                                             CodeSource codeSource) {
+@@ -351,7 +352,7 @@
+                 }
+                 try {
+                     // Classloader scope will be handled by the cache, class will be released when the classloader is.
+-                    ClassLoader loader = classLoaderCache.put(classLoaderId, new ScriptClassLoader(source, classLoader, new DefaultClassPath(scriptCacheDir), sourceHashCode));
++                    ClassLoader loader = classLoaderCache.put(classLoaderId, new ScriptClassLoader(source, DebianIgnoreRules.wrap(classLoader), new DefaultClassPath(scriptCacheDir), sourceHashCode));
+                     scriptClass = loader.loadClass(source.getClassName()).asSubclass(scriptBaseClass);
+                 } catch (Exception e) {
+                     File expectedClassFile = new File(scriptCacheDir, source.getClassName() + ".class");
+--- /dev/null
++++ b/subprojects/core/src/main/java/org/gradle/internal/debian/DebianIgnoreRules.java
+@@ -0,0 +1,121 @@
++/*
++ * Copyright 2026 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.internal.debian;
++
++import java.io.File;
++import java.lang.reflect.Method;
++
++/**
++ * Tells what the package being built has chosen to ignore, as declared in its
++ * debian/gradle.ignoreRules file: a plugin, by its identifier or by the name of
++ * its class, a script applied with <tt>apply from:</tt>, or a project of the
++ * build.
++ *
++ * <p>The rules are read by gradle-debian-helper, which is called by reflection
++ * because Gradle doesn't depend on it. Nothing is ignored when the file is
++ * absent, or when the helper isn't installed. The presence of the file is the
++ * only switch: the <tt>gradle-debian-helper.hook.enabled</tt> property is not
++ * consulted, it belongs to the artifact resolution hook.</p>
++ */
++public class DebianIgnoreRules {
++
++    private static final File RULES = new File("debian/gradle.ignoreRules");
++
++    private DebianIgnoreRules() {
++    }
++
++    /**
++     * Tells if the script applied with <tt>apply from:</tt> at the specified
++     * path is ignored. The rules hold a path relative to the root of the
++     * package, so that they don't depend on the build directory.
++     */
++    public static boolean isIgnoredScript(String path) {
++        return path != null && isIgnored(path, "isScriptIgnored", "script");
++    }
++
++    /**
++     * Tells if the project at the specified path is ignored, and must therefore
++     * not be included in the build. The packages commonly build a subset of the
++     * projects declared by the settings file.
++     */
++    public static boolean isIgnoredProject(String path) {
++        return path != null && isIgnored(path, "isProjectIgnored", "project");
++    }
++
++    /**
++     * Wraps the class loader compiling a build script with one serving an empty
++     * plugin for the class names listed in the rules, so that a plugin applied
++     * by its class rather than by its identifier can be ignored too. Groovy
++     * looks the name up while compiling the script, and silently turns it into
++     * a chain of property accesses when it doesn't resolve, which is why the
++     * class has to exist rather than the application be intercepted.
++     *
++     * <p>The loader of the package being built is returned unchanged when the
++     * rules file is absent, so that nothing is inserted in the class loader
++     * hierarchy of the builds that don't use it.</p>
++     */
++    public static ClassLoader wrap(ClassLoader parent) {
++        return exists() ? new StubPluginClassLoader(parent) : parent;
++    }
++
++    /**
++     * Tells if the package being built declares any rule, that is if the
++     * debian/gradle.ignoreRules file exists.
++     */
++    public static boolean exists() {
++        return RULES.exists();
++    }
++
++    /**
++     * Tells if the plugin with the specified identifier is ignored, whichever
++     * way the build script declares it.
++     */
++    public static boolean isIgnoredPlugin(String id) {
++        return isIgnored(id, "isPluginIgnored", "plugin");
++    }
++
++    /**
++     * Tells if the class with the specified name is ignored, either as a plugin
++     * applied by its class, or as a class coming with an ignored plugin.
++     */
++    public static boolean isIgnoredClass(String name) {
++        return isIgnored(name, "isClassIgnored", "class");
++    }
++
++    private static boolean isIgnored(String value, String method, String kind) {
++        if (!exists()) {
++            return false;
++        }
++
++        try {
++            Class<?> rulesClass = Class.forName("org.debian.gradle.plugin.IgnoreRules");
++            Object rules = rulesClass.getMethod("read").invoke(null);
++            Method ignored = rulesClass.getMethod(method, String.class);
++
++            if (Boolean.TRUE.equals(ignored.invoke(rules, value))) {
++                System.out.println("\tIgnoring the " + kind + " " + value);
++                return true;
++            }
++
++        } catch (Throwable t) {
++            System.out.println("\tCouldn't read the ignored plugins:");
++            t.printStackTrace();
++        }
++
++        return false;
++    }
++}
+--- /dev/null
++++ b/subprojects/core/src/main/java/org/gradle/internal/debian/StubPluginClassLoader.java
+@@ -0,0 +1,69 @@
++/*
++ * Copyright 2026 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.internal.debian;
++
++import org.objectweb.asm.ClassWriter;
++import org.objectweb.asm.MethodVisitor;
++import org.objectweb.asm.Opcodes;
++
++/**
++ * Defines an empty implementation of Plugin for the class names the package
++ * being built has chosen to ignore, and delegates everything else to its
++ * parent. It wraps the class loaders of the build scripts, see
++ * {@link DebianIgnoreRules#wrap}.
++ */
++class StubPluginClassLoader extends ClassLoader {
++
++    StubPluginClassLoader(ClassLoader parent) {
++        super(parent);
++    }
++
++    @Override
++    protected Class<?> findClass(String name) throws ClassNotFoundException {
++        if (!DebianIgnoreRules.isIgnoredClass(name)) {
++            throw new ClassNotFoundException(name);
++        }
++
++        byte[] bytes = emptyPlugin(name);
++        return defineClass(name, bytes, 0, bytes.length);
++    }
++
++    private byte[] emptyPlugin(String name) {
++        String internalName = name.replace('.', '/');
++
++        ClassWriter writer = new ClassWriter(0);
++        writer.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, internalName, null, "java/lang/Object",
++                new String[] {"org/gradle/api/Plugin"});
++
++        MethodVisitor constructor = writer.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
++        constructor.visitCode();
++        constructor.visitVarInsn(Opcodes.ALOAD, 0);
++        constructor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
++        constructor.visitInsn(Opcodes.RETURN);
++        constructor.visitMaxs(1, 1);
++        constructor.visitEnd();
++
++        MethodVisitor apply = writer.visitMethod(Opcodes.ACC_PUBLIC, "apply", "(Ljava/lang/Object;)V", null, null);
++        apply.visitCode();
++        apply.visitInsn(Opcodes.RETURN);
++        apply.visitMaxs(0, 2);
++        apply.visitEnd();
++
++        writer.visitEnd();
++        return writer.toByteArray();
++    }
++}
+--- /dev/null
++++ b/subprojects/plugin-use/src/main/java/org/gradle/plugin/use/internal/DebianPluginRequestApplicator.java
+@@ -0,0 +1,64 @@
++/*
++ * Copyright 2026 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.plugin.use.internal;
++
++import org.gradle.api.internal.initialization.ClassLoaderScope;
++import org.gradle.api.internal.initialization.ScriptHandlerInternal;
++import org.gradle.api.internal.plugins.PluginManagerInternal;
++import org.gradle.internal.debian.DebianIgnoreRules;
++import org.gradle.plugin.management.internal.DefaultPluginRequests;
++import org.gradle.plugin.management.internal.PluginRequestInternal;
++import org.gradle.plugin.management.internal.PluginRequests;
++
++import javax.annotation.Nullable;
++
++import java.util.ArrayList;
++import java.util.List;
++
++/**
++ * Discards the plugin requests the package being built has chosen to ignore, as
++ * declared in its debian/gradle.ignoreRules file, and passes the others on to
++ * the applicator it decorates. A request is dropped before being resolved, so
++ * the plugin is neither downloaded nor applied.
++ *
++ * @see DebianIgnoreRules
++ */
++public class DebianPluginRequestApplicator implements PluginRequestApplicator {
++
++    private final PluginRequestApplicator delegate;
++
++    public DebianPluginRequestApplicator(PluginRequestApplicator delegate) {
++        this.delegate = delegate;
++    }
++
++    @Override
++    public void applyPlugins(PluginRequests requests, ScriptHandlerInternal scriptHandler,
++                             @Nullable PluginManagerInternal target, ClassLoaderScope classLoaderScope) {
++        delegate.applyPlugins(discardIgnoredPlugins(requests), scriptHandler, target, classLoaderScope);
++    }
++
++    private PluginRequests discardIgnoredPlugins(PluginRequests requests) {
++        List<PluginRequestInternal> kept = new ArrayList<PluginRequestInternal>();
++        for (PluginRequestInternal request : requests) {
++            if (!DebianIgnoreRules.isIgnoredPlugin(request.getId().getId())) {
++                kept.add(request);
++            }
++        }
++
++        return kept.size() == requests.size() ? requests : new DefaultPluginRequests(kept);
++    }
++}
+--- a/subprojects/plugin-use/src/main/java/org/gradle/plugin/internal/PluginUsePluginServiceRegistry.java
++++ b/subprojects/plugin-use/src/main/java/org/gradle/plugin/internal/PluginUsePluginServiceRegistry.java
+@@ -33,6 +33,7 @@
+ import org.gradle.initialization.layout.BuildLayout;
+ import org.gradle.initialization.layout.BuildLayoutConfiguration;
+ import org.gradle.initialization.layout.BuildLayoutFactory;
++import org.gradle.internal.debian.DebianIgnoreRules;
+ import org.gradle.internal.Factory;
+ import org.gradle.internal.classpath.CachedClasspathTransformer;
+ import org.gradle.internal.event.ListenerManager;
+@@ -47,6 +48,7 @@
+ import org.gradle.plugin.management.internal.autoapply.AutoAppliedPluginRegistry;
+ import org.gradle.plugin.management.internal.autoapply.DefaultAutoAppliedPluginHandler;
+ import org.gradle.plugin.management.internal.autoapply.DefaultAutoAppliedPluginRegistry;
++import org.gradle.plugin.use.internal.DebianPluginRequestApplicator;
+ import org.gradle.plugin.use.internal.DefaultPluginRequestApplicator;
+ import org.gradle.plugin.use.internal.InjectedPluginClasspath;
+ import org.gradle.plugin.use.internal.PluginDependencyResolutionServices;
+@@ -92,9 +94,11 @@
+         PluginRequestApplicator createPluginRequestApplicator(PluginRegistry pluginRegistry, PluginDependencyResolutionServices dependencyResolutionServices,
+                                                               PluginResolverFactory pluginResolverFactory, PluginResolutionStrategyInternal internalPluginResolutionStrategy,
+                                                               PluginInspector pluginInspector, CachedClasspathTransformer cachedClasspathTransformer) {
+-            return new DefaultPluginRequestApplicator(
++            PluginRequestApplicator applicator = new DefaultPluginRequestApplicator(
+                 pluginRegistry, pluginResolverFactory, dependencyResolutionServices.getPluginRepositoriesProvider(),
+                 internalPluginResolutionStrategy, pluginInspector, cachedClasspathTransformer);
++
++            return DebianIgnoreRules.exists() ? new DebianPluginRequestApplicator(applicator) : applicator;
+         }
+ 
+         InjectedClasspathPluginResolver createInjectedClassPathPluginResolver(ClassLoaderScopeRegistry classLoaderScopeRegistry, PluginInspector pluginInspector,


=====================================
debian/patches/series
=====================================
@@ -45,3 +45,4 @@ java25-compat.patch
 snakeyaml-2-compatibility.patch
 java9-modules-compatibility.patch
 serializer-equality.patch
+gradle-debian-helper-plugin-filter.patch



View it on GitLab: https://salsa.debian.org/java-team/gradle/-/commit/e462cb2476bcd753bce8a84b8c81cb778311460a

-- 
View it on GitLab: https://salsa.debian.org/java-team/gradle/-/commit/e462cb2476bcd753bce8a84b8c81cb778311460a
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20260930/024b5905/attachment.htm>


More information about the pkg-java-commits mailing list