mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-13 20:12:14 +00:00
Remove AntClassLoader (#7846)
This commit is contained in:
1 parent
cb2c48bb57
commit
9ce1ff4e7c
7 files changed
+11
-274
No files matched your search
@@ -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<URL> 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<URL> 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");
|
||||
}
|
||||
@@ -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
|
||||
* <b>you must use the pluginFirstClassLoader true in the maven-hpi-plugin</b>
|
||||
*
|
||||
* @author olamy
|
||||
* @since 1.371
|
||||
* @deprecated use {@link PluginFirstClassLoader2}
|
||||
*/
|
||||
@Deprecated
|
||||
public class PluginFirstClassLoader
|
||||
extends AntClassLoader
|
||||
{
|
||||
public PluginFirstClassLoader() {
|
||||
super(null, false);
|
||||
}
|
||||
|
||||
private List<URL> urls = new CopyOnWriteArrayList<>();
|
||||
|
||||
@Override
|
||||
public void addPathFiles(Collection<File> 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<URL> 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);
|
||||
}
|
||||
}
|
||||
@@ -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<PluginWrapper>, 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());
|
||||
|
||||
@@ -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<File> paths) throws IOException {
|
||||
for (File f : paths) {
|
||||
addPathFile(f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL findResource(final String name) {
|
||||
return super.findResource(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<URL> 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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user