diff --git a/core/src/main/java/hudson/ClassicPluginStrategy.java b/core/src/main/java/hudson/ClassicPluginStrategy.java index bc4b350c0c..c86b2af6ce 100644 --- a/core/src/main/java/hudson/ClassicPluginStrategy.java +++ b/core/src/main/java/hudson/ClassicPluginStrategy.java @@ -59,8 +59,6 @@ import java.util.logging.Logger; import jenkins.ClassLoaderReflectionToolkit; import jenkins.ExtensionFilter; import jenkins.plugins.DetachedPluginsUtil; -import jenkins.util.AntClassLoader; -import jenkins.util.SystemProperties; import jenkins.util.URLClassLoader2; import org.apache.commons.io.output.NullOutputStream; import org.apache.tools.ant.BuildException; @@ -290,30 +288,17 @@ public class ClassicPluginStrategy implements PluginStrategy { boolean usePluginFirstClassLoader = atts != null && Boolean.parseBoolean(atts.getValue("PluginFirstClassLoader")); - if (useAntClassLoader) { - AntClassLoader classLoader; - if (usePluginFirstClassLoader) { - classLoader = new PluginFirstClassLoader(); - classLoader.setParentFirst(false); - classLoader.setParent(parent); - } else { - classLoader = new AntClassLoader(parent, true); - } - classLoader.addPathFiles(paths); - return classLoader; - } else { - List urls = new ArrayList<>(); - for (File path : paths) { - urls.add(path.toURI().toURL()); - } - URLClassLoader2 classLoader; - if (usePluginFirstClassLoader) { - classLoader = new PluginFirstClassLoader2(urls.toArray(new URL[0]), parent); - } else { - classLoader = new URLClassLoader2(urls.toArray(new URL[0]), parent); - } - return classLoader; + List urls = new ArrayList<>(); + for (File path : paths) { + urls.add(path.toURI().toURL()); } + URLClassLoader2 classLoader; + if (usePluginFirstClassLoader) { + classLoader = new PluginFirstClassLoader2(urls.toArray(new URL[0]), parent); + } else { + classLoader = new URLClassLoader2(urls.toArray(new URL[0]), parent); + } + return classLoader; } /** @@ -432,17 +417,6 @@ public class ClassicPluginStrategy implements PluginStrategy { if (classLoader instanceof DependencyClassLoader) { return (DependencyClassLoader) classLoader; } - - if (classLoader instanceof AntClassLoader) { - // AntClassLoaders hold parents not only as AntClassLoader#getParent() - // but also as AntClassLoader#getConfiguredParent() - DependencyClassLoader ret = findAncestorDependencyClassLoader( - ((AntClassLoader) classLoader).getConfiguredParent() - ); - if (ret != null) { - return ret; - } - } } return null; } @@ -716,7 +690,4 @@ public class ClassicPluginStrategy implements PluginStrategy { return null; } } - - @SuppressFBWarnings(value = "MS_SHOULD_BE_FINAL", justification = "Accessible via System Groovy Scripts") - public static /* not final */ boolean useAntClassLoader = SystemProperties.getBoolean(ClassicPluginStrategy.class.getName() + ".useAntClassLoader"); } diff --git a/core/src/main/java/hudson/PluginFirstClassLoader.java b/core/src/main/java/hudson/PluginFirstClassLoader.java deleted file mode 100644 index f652187a29..0000000000 --- a/core/src/main/java/hudson/PluginFirstClassLoader.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2004-2009, Sun Microsystems, Inc., Olivier Lamy - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package hudson; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Collection; -import java.util.Enumeration; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; -import jenkins.util.AntClassLoader; - -/** - * classLoader which use first /WEB-INF/lib/*.jar and /WEB-INF/classes before core classLoader - * you must use the pluginFirstClassLoader true in the maven-hpi-plugin - * - * @author olamy - * @since 1.371 - * @deprecated use {@link PluginFirstClassLoader2} - */ -@Deprecated -public class PluginFirstClassLoader - extends AntClassLoader -{ - public PluginFirstClassLoader() { - super(null, false); - } - - private List urls = new CopyOnWriteArrayList<>(); - - @Override - public void addPathFiles(Collection paths) - throws IOException - { - for (File f : paths) - { - urls.add(f.toURI().toURL()); - addPathFile(f); - } - } - - /** - * @return List of jar used by the plugin /WEB-INF/lib/*.jar and classes directory /WEB-INF/classes - */ - public List getURLs() - { - return urls; - } - - @Override - protected Enumeration findResources(String name, boolean skipParent) - throws IOException - { - return super.findResources(name, skipParent); - } - - @Override - public Enumeration findResources(String name) - throws IOException - { - return super.findResources(name); - } - - @Override - public URL getResource(String name) - { - return super.getResource(name); - } - - @Override - public InputStream getResourceAsStream(String name) - { - return super.getResourceAsStream(name); - } -} diff --git a/core/src/main/java/hudson/PluginWrapper.java b/core/src/main/java/hudson/PluginWrapper.java index 44956a5b3f..2161e50108 100644 --- a/core/src/main/java/hudson/PluginWrapper.java +++ b/core/src/main/java/hudson/PluginWrapper.java @@ -72,7 +72,6 @@ import jenkins.YesNoMaybe; import jenkins.model.Jenkins; import jenkins.plugins.DetachedPluginsUtil; import jenkins.security.UpdateSiteWarningsMonitor; -import jenkins.util.AntClassLoader; import jenkins.util.URLClassLoader2; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.LogFactory; @@ -414,12 +413,7 @@ public class PluginWrapper implements Comparable, ModelObject { */ @Restricted(Beta.class) public void injectJarsToClasspath(File... jars) throws Exception { - if (classLoader instanceof AntClassLoader) { - for (File f : jars) { - LOGGER.log(Level.CONFIG, () -> "Inserting " + f + " into " + shortName + " plugin's classpath"); - ((AntClassLoader) classLoader).addPathComponent(f); - } - } else if (classLoader instanceof URLClassLoader2) { + if (classLoader instanceof URLClassLoader2) { for (File f : jars) { LOGGER.log(Level.CONFIG, () -> "Inserting " + f + " into " + shortName + " plugin's classpath"); ((URLClassLoader2) classLoader).addURL(f.toURI().toURL()); diff --git a/core/src/main/java/jenkins/util/AntClassLoader.java b/core/src/main/java/jenkins/util/AntClassLoader.java deleted file mode 100644 index 1b2685f984..0000000000 --- a/core/src/main/java/jenkins/util/AntClassLoader.java +++ /dev/null @@ -1,73 +0,0 @@ -package jenkins.util; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.Collection; -import java.util.Enumeration; -import jenkins.ClassLoaderReflectionToolkit; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.types.Path; -import org.kohsuke.accmod.Restricted; -import org.kohsuke.accmod.restrictions.NoExternalUse; - -/** - * {@link org.apache.tools.ant.AntClassLoader} with loosened visibility for use with {@link - * ClassLoaderReflectionToolkit}. - * - * @deprecated use {@link URLClassLoader2} - */ -@Deprecated -@Restricted(NoExternalUse.class) -public class AntClassLoader extends org.apache.tools.ant.AntClassLoader implements JenkinsClassLoader { - - public AntClassLoader(final ClassLoader parent, final Project project, final Path classpath) { - super(parent, project, classpath); - } - - public AntClassLoader() {} - - public AntClassLoader(final Project project, final Path classpath) { - super(project, classpath); - } - - public AntClassLoader(final ClassLoader parent, final Project project, - final Path classpath, final boolean parentFirst) { - super(parent, project, classpath, parentFirst); - } - - public AntClassLoader(final Project project, final Path classpath, - final boolean parentFirst) { - super(project, classpath, parentFirst); - } - - public AntClassLoader(final ClassLoader parent, final boolean parentFirst) { - super(parent, parentFirst); - } - - public void addPathFiles(Collection paths) throws IOException { - for (File f : paths) { - addPathFile(f); - } - } - - @Override - public URL findResource(final String name) { - return super.findResource(name); - } - - @Override - public Enumeration findResources(final String name) throws IOException { - return super.findResources(name); - } - - @Override - public Class findLoadedClass2(String name) { - return super.findLoadedClass(name); - } - - @Override - public Object getClassLoadingLock(String className) { - return super.getClassLoadingLock(className); - } -} diff --git a/core/src/test/java/hudson/PluginWrapperTest.java b/core/src/test/java/hudson/PluginWrapperTest.java index 640b5eb2b4..ba63355b7d 100644 --- a/core/src/test/java/hudson/PluginWrapperTest.java +++ b/core/src/test/java/hudson/PluginWrapperTest.java @@ -24,7 +24,6 @@ import java.util.Locale; import java.util.jar.Attributes; import java.util.jar.Manifest; import jenkins.model.Jenkins; -import jenkins.util.AntClassLoader; import jenkins.util.URLClassLoader2; import org.apache.commons.lang.StringUtils; import org.junit.jupiter.api.AfterAll; @@ -106,14 +105,6 @@ public class PluginWrapperTest { @Issue("JENKINS-66563") @Test public void insertJarsIntoClassPath() throws Exception { - try (AntClassLoader cl = new AntClassLoader()) { - assertInjectingJarsWorks(cl); - } - } - - @Issue("JENKINS-66563") - @Test - public void insertJarsIntoClassPathURLCL() throws Exception { try (URLClassLoader2 cl = new URLClassLoader2(new URL[0])) { assertInjectingJarsWorks(cl); } diff --git a/test/src/test/java/jenkins/util/AntClassLoaderTest.java b/test/src/test/java/jenkins/util/AntClassLoaderTest.java deleted file mode 100644 index c8c882ed81..0000000000 --- a/test/src/test/java/jenkins/util/AntClassLoaderTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * The MIT License - * - * Copyright 2020 CloudBees, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package jenkins.util; - -import static org.junit.Assert.assertNotNull; - -import org.junit.Rule; -import org.junit.Test; -import org.jvnet.hudson.test.Issue; -import org.jvnet.hudson.test.JenkinsRule; -import org.jvnet.hudson.test.recipes.WithPlugin; - -public class AntClassLoaderTest { - - @Rule - public JenkinsRule r = new JenkinsRule(); - - @Issue("JENKINS-60644") - @WithPlugin("loads-resource.jpi") - @Test - public void loadsResource() throws Exception { - assertNotNull(r.jenkins.pluginManager.getPlugin("loads-resource").classLoader.getResourceAsStream("io/jenkins/plugins/loads_resource/stuff")); - } - -} diff --git a/test/src/test/resources/plugins/loads-resource.jpi b/test/src/test/resources/plugins/loads-resource.jpi deleted file mode 100644 index 45b9a05e98..0000000000 Binary files a/test/src/test/resources/plugins/loads-resource.jpi and /dev/null differ