Skip to content

Commit

Permalink
Merge branch 'master' into update-forms
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Nov 22, 2021
2 parents 4a8e448 + 65b9f1c commit 40191ec
Show file tree
Hide file tree
Showing 102 changed files with 563 additions and 268 deletions.
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ THE SOFTWARE.
<dependency> <!-- https://docs.spring.io/spring-security/site/docs/5.4.0-M1/reference/html5/#getting-maven-no-boot -->
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-bom</artifactId>
<version>5.5.3</version>
<version>5.6.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
92 changes: 39 additions & 53 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future;
import java.util.function.Function;
Expand Down Expand Up @@ -327,7 +329,7 @@ PluginManager doCreate(@NonNull Class<? extends PluginManager> klass,
*/
// implementation is minimal --- just enough to run XStream
// and load plugin-contributed classes.
public final ClassLoader uberClassLoader = new UberClassLoader();
public final ClassLoader uberClassLoader = new UberClassLoader(activePlugins);

/**
* Once plugin is uploaded, this flag becomes true.
Expand Down Expand Up @@ -2171,70 +2173,56 @@ public <T> T of(String key, Class<T> type, Supplier<T> func) {
/**
* {@link ClassLoader} that can see all plugins.
*/
public final class UberClassLoader extends ClassLoader {
public static final class UberClassLoader extends ClassLoader {
private final List<PluginWrapper> activePlugins;

/** Cache of loaded, or known to be unloadable, classes. */
private final Map<String,Class<?>> loaded = new HashMap<>();
private final ConcurrentMap<String, Optional<Class<?>>> loaded = new ConcurrentHashMap<>();

static {
registerAsParallelCapable();
}

public UberClassLoader() {
public UberClassLoader(List<PluginWrapper> activePlugins) {
super(PluginManager.class.getClassLoader());
this.activePlugins = activePlugins;
}

@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
if (name.startsWith("SimpleTemplateScript")) { // cf. groovy.text.SimpleTemplateEngine
throw new ClassNotFoundException("ignoring " + name);
}
synchronized (loaded) {
if (loaded.containsKey(name)) {
Class<?> c = loaded.get(name);
if (c != null) {
return c;
return loaded.computeIfAbsent(name, this::computeValue).orElseThrow(() -> new ClassNotFoundException(name));
}

private Optional<Class<?>> computeValue(String name) {
for (PluginWrapper p : activePlugins) {
try {
if (FAST_LOOKUP) {
return Optional.of(ClassLoaderReflectionToolkit.loadClass(p.classLoader, name));
} else {
throw new ClassNotFoundException("cached miss for " + name);
return Optional.of(p.classLoader.loadClass(name));
}
} catch (ClassNotFoundException e) {
// Not found. Try the next class loader.
}
}
if (FAST_LOOKUP) {
for (PluginWrapper p : activePlugins) {
try {
Class<?> c = ClassLoaderReflectionToolkit.loadClass(p.classLoader, name);
synchronized (loaded) {
loaded.put(name, c);
}
return c;
} catch (ClassNotFoundException e) {
//not found. try next
}
}
} else {
for (PluginWrapper p : activePlugins) {
try {
return p.classLoader.loadClass(name);
} catch (ClassNotFoundException e) {
//not found. try next
}
}
}
synchronized (loaded) {
loaded.put(name, null);
}
// not found in any of the classloader. delegate.
throw new ClassNotFoundException(name);
// Not found in any of the class loaders. Delegate.
return Optional.empty();
}

@Override
protected URL findResource(String name) {
if (FAST_LOOKUP) {
for (PluginWrapper p : activePlugins) {
URL url = ClassLoaderReflectionToolkit._findResource(p.classLoader, name);
if(url!=null)
return url;
}
} else {
for (PluginWrapper p : activePlugins) {
URL url = p.classLoader.getResource(name);
if(url!=null)
return url;
for (PluginWrapper p : activePlugins) {
URL url;
if (FAST_LOOKUP) {
url = ClassLoaderReflectionToolkit._findResource(p.classLoader, name);
} else {
url = p.classLoader.getResource(name);
}
if (url != null) {
return url;
}
}
return null;
Expand All @@ -2243,12 +2231,10 @@ protected URL findResource(String name) {
@Override
protected Enumeration<URL> findResources(String name) throws IOException {
List<URL> resources = new ArrayList<>();
if (FAST_LOOKUP) {
for (PluginWrapper p : activePlugins) {
resources.addAll(Collections.list(ClassLoaderReflectionToolkit._findResources(p.classLoader, name)));
}
} else {
for (PluginWrapper p : activePlugins) {
for (PluginWrapper p : activePlugins) {
if (FAST_LOOKUP) {
resources.addAll(Collections.list(ClassLoaderReflectionToolkit._findResources(p.classLoader, name)));
} else {
resources.addAll(Collections.list(p.classLoader.getResources(name)));
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/PluginWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public boolean isDeprecated() {
* plugin</a>. *
*
* @throws Exception if the File could not be inserted into the classpath for some reason.
* @since TODO
* @since 2.313
*/
@Restricted(Beta.class)
public void injectJarsToClasspath(File... jars) throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/ExecutorListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ default void taskAccepted(Executor executor, Queue.Task task) {}
* Called whenever a task is started by an executor.
* @param executor The executor.
* @param task The task.
* @since TODO
* @since 2.318
*/
default void taskStarted(Executor executor, Queue.Task task) {}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/Queue.java
Original file line number Diff line number Diff line change
Expand Up @@ -2076,7 +2076,7 @@ public interface Executable extends Runnable {
* If {@link #getParent} has a distinct {@link SubTask#getOwnerTask},
* then it should be the case that {@code getParentExecutable().getParent() == getParent().getOwnerTask()}.
* @return a <em>distinct</em> executable (never {@code this}, unlike the default of {@link SubTask#getOwnerTask}!); or null if this executable was already at top level
* @since TODO, but implementations can already implement this with a lower core dependency.
* @since 2.313, but implementations can already implement this with a lower core dependency.
*/
default @CheckForNull Executable getParentExecutable() {
return null;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
* accesses a /user/arbitraryName URL.
* <p>
* Unfortunately this constitutes a CSRF vulnerability, as malicious users can make admins create arbitrary numbers
* of ephemeral user records, so the behavior was changed in Jenkins 2.TODO / 2.32.2.
* of ephemeral user records, so the behavior was changed in Jenkins 2.44 / 2.32.2.
* <p>
* As some users may be relying on the previous behavior, setting this to true restores the previous behavior. This
* is not recommended.
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/triggers/Trigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ public void run(AbstractProject p) {

@SuppressFBWarnings("MS_SHOULD_BE_FINAL")
@Restricted(NoExternalUse.class)
@RestrictedSince("TODO")
@RestrictedSince("2.289")
/**
* Used to be milliseconds, now is seconds since Jenkins 2.TODO.
* Used to be milliseconds, now is seconds since Jenkins 2.289.
*/
public static /* non-final for Groovy */ long CRON_THRESHOLD = SystemProperties.getLong(Trigger.class.getName() + ".CRON_THRESHOLD", 30L); // Default threshold 30s

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/util/ChartUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public static void adjustChebyshev(CategoryDataset dataset, NumberAxis yAxis) {
}

@Restricted(NoExternalUse.class)
@RestrictedSince("2.TODO")
@RestrictedSince("2.301")
public static final double CHEBYSHEV_N = 3;

static {
Expand Down
15 changes: 9 additions & 6 deletions core/src/main/java/hudson/util/ListBoxModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package hudson.util;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.ModelObject;
import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -98,11 +99,13 @@ public static final class Option {
* Text to be displayed to user.
*/
@Exported
@NonNull
public String name;
/**
* The value that gets sent to the server when the form is submitted.
*/
@Exported
@NonNull
public String value;

/**
Expand All @@ -111,15 +114,15 @@ public static final class Option {
@Exported
public boolean selected;

public Option(String name, String value) {
public Option(@NonNull String name, @NonNull String value) {
this(name,value,false);
}

public Option(String name) {
public Option(@NonNull String name) {
this(name,name,false);
}

public Option(String name, String value, boolean selected) {
public Option(@NonNull String name, @NonNull String value, boolean selected) {
this.name = name;
this.value = value;
this.selected = selected;
Expand All @@ -146,18 +149,18 @@ public ListBoxModel(Option... data) {
super(Arrays.asList(data));
}

public void add(String displayName, String value) {
public void add(@NonNull String displayName, @NonNull String value) {
add(new Option(displayName,value));
}

public void add(ModelObject usedForDisplayName, String value) {
public void add(ModelObject usedForDisplayName, @NonNull String value) {
add(usedForDisplayName.getDisplayName(), value);
}

/**
* A version of the {@link #add(String, String)} method where the display name and the value are the same.
*/
public ListBoxModel add(String nameAndValue) {
public ListBoxModel add(@NonNull String nameAndValue) {
add(nameAndValue,nameAndValue);
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/util/XStream2.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public XStream2(HierarchicalStreamDriver hierarchicalStreamDriver) {
}

/**
* @since TODO
* @since 2.318
*/
public XStream2(ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
ClassLoaderReference classLoaderReference, Mapper mapper, ConverterLookup converterLookup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private static class FindClass {
* @param name The binary name of the class.
* @return The resulting {@link Class} object.
* @throws ClassNotFoundException If the class could not be found.
* @since 2.TODO
* @since 2.321
*/
public static @NonNull Class<?> loadClass(ClassLoader cl, String name) throws ClassNotFoundException {
synchronized (getClassLoadingLock(cl, name)) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/management/ConfigureLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ConfigureLink extends ManagementLink {

@Override
public String getIconFileName() {
return "gear.png";
return "gear2.png";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public boolean getMasterToSlaveAccessControl() {
}

/**
* @since TODO
* @since 2.310
*/
public boolean getAgentToControllerAccessControl() {
return !rule.getMasterKillSwitch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
/**
* When an agent tries to access build directories on the controller, limit it to those for builds running on that agent.
*
* @since TODO
* @since 2.319
*/
@Restricted(NoExternalUse.class)
public class RunningBuildFilePathFilter extends ReflectiveFilePathFilter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private boolean configureDescriptor(StaplerRequest req, JSONObject json, Descrip
}

@Restricted(NoExternalUse.class)
@RestrictedSince("2.TODO")
@RestrictedSince("2.301")
public static final Predicate<Descriptor> FILTER = input -> input.getCategory() instanceof ToolConfigurationCategory;

private static final Logger LOGGER = Logger.getLogger(GlobalToolConfiguration.class.getName());
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/util/xstream/XStreamDOM.java
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,6 @@ public XStreamDOM unmarshalElement(HierarchicalStreamReader r, UnmarshallingCont
}

@Restricted(NoExternalUse.class)
@RestrictedSince("2.TODO")
@RestrictedSince("2.301")
public static final XmlFriendlyReplacer REPLACER = new XmlFriendlyReplacer();
}
Loading

0 comments on commit 40191ec

Please sign in to comment.