Skip to content

Commit

Permalink
Merge branch 'master' into update-forms-2
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Feb 7, 2022
2 parents c029eb9 + 0447d16 commit c743801
Show file tree
Hide file tree
Showing 43 changed files with 571 additions and 212 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ N/A
- [ ] Changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developer, depending on the change). [Examples](https://github.com/jenkins-infra/jenkins.io/blob/master/content/_data/changelogs/weekly.yml)
* Fill-in the `Proposed changelog entries` section only if there are breaking changes or other changes which may require extra steps from users during the upgrade
- [ ] Appropriate autotests or explanation to why this change has no tests
- [ ] New public classes, fields, and methods are annotated with `@Restricted` or have `@since TODO` Javadoc, as appropriate.
- [ ] For dependency updates: links to external changelogs and, if possible, full diffs

<!-- For new API and extension points: Link to the reference implementation in open-source (or example in Javadoc) -->
Expand Down
3 changes: 3 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ updates:
- dependency-name: "javax.servlet.servlet-api"
# needs a jakarta upgrade project, imports changed
- dependency-name: "jakarta.servlet.jsp.jstl.jakarta.servlet.jsp.jstl-api"
# Starting with version 2.0.2, this library requires Java 11
- dependency-name: "org.glassfish.tyrus.bundles:tyrus-standalone-client-jdk"
versions: [">=2.0.2"]
# see https://github.com/jenkinsci/jenkins/pull/4224 can't be updated without breaking api
- dependency-name: "org.jfree:jfreechart"
# the dependency is actually provided by the Web container, hence it is aligned with Jetty. See https://github.com/jenkinsci/jenkins/pull/5211
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
# Drafts your next Release notes as Pull Requests are merged into "master"
- name: Generate GitHub Release Draft
id: release-drafter
uses: release-drafter/release-drafter@v5.17.6
uses: release-drafter/release-drafter@v5.18.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Generates a YAML changelog file using https://github.com/jenkinsci/jenkins-core-changelog-generator
Expand Down
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ THE SOFTWARE.
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.18</version>
<version>1.4.19</version>
</dependency>
<dependency>
<groupId>net.sf.kxml</groupId>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ THE SOFTWARE.
<properties>
<staplerFork>true</staplerFork>
<hamcrest.version>2.2</hamcrest.version>
<xmlunit.version>2.8.4</xmlunit.version>
<xmlunit.version>2.9.0</xmlunit.version>
</properties>

<dependencyManagement>
Expand Down
9 changes: 3 additions & 6 deletions core/src/main/java/hudson/WebAppMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public void run() {
Files.deleteIfExists(BootFailure.getBootFailureFile(_home).toPath());

// at this point we are open for business and serving requests normally
LOGGER.info("Jenkins is fully up and running");
Jenkins.get().getLifecycle().onReady();
success = true;
} catch (Error e) {
new HudsonFailedToLoad(e).publish(context, _home);
Expand Down Expand Up @@ -322,14 +322,11 @@ public FileAndDescription(File file, String description) {
/**
* Determines the home directory for Jenkins.
*
* <p>
* We look for a setting that affects the smallest scope first, then bigger ones later.
* <p>We look for a setting that affects the smallest scope first, then bigger ones later.
*
* <p>
* People makes configuration mistakes, so we are trying to be nice
* <p>People make configuration mistakes, so we are trying to be nice
* with those by doing {@link String#trim()}.
*
* <p>
* @return the File alongside with some description to help the user troubleshoot issues
*/
public FileAndDescription getHomeDir(ServletContextEvent event) {
Expand Down
88 changes: 88 additions & 0 deletions core/src/main/java/hudson/lifecycle/Lifecycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

package hudson.lifecycle;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.ExtensionPoint;
import hudson.Functions;
import hudson.Util;
Expand All @@ -32,6 +34,7 @@
import java.io.UncheckedIOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
Expand All @@ -52,6 +55,19 @@
public abstract class Lifecycle implements ExtensionPoint {
private static Lifecycle INSTANCE = null;

public Lifecycle() {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins != null) {
try {
jenkins.cleanUp();
} catch (Throwable t) {
LOGGER.log(Level.SEVERE, "Failed to clean up. Shutdown will continue.", t);
}
}
}));
}

/**
* Gets the singleton instance.
*
Expand Down Expand Up @@ -107,6 +123,9 @@ public void verifyRestartable() throws RestartNotSupportedException {
} else if (System.getenv("SMF_FMRI") != null && System.getenv("SMF_RESTARTER") != null) {
// when we are run by Solaris SMF, these environment variables are set.
instance = new SolarisSMFLifecycle();
} else if (System.getenv("NOTIFY_SOCKET") != null) {
// When we are running under systemd with Type=notify, this environment variable is set.
instance = new SystemdLifecycle();
} else {
// if run on Unix, we can do restart
try {
Expand Down Expand Up @@ -232,5 +251,74 @@ public boolean canRestart() {
}
}

/**
* Called when Jenkins startup is finished or when Jenkins has finished reloading its
* configuration.
*
* @since 2.333
*/
public void onReady() {
LOGGER.log(Level.INFO, "Jenkins is fully up and running");
}

/**
* Called when Jenkins is reloading its configuration.
*
* <p>Callers must also send an {@link #onReady()} notification when Jenkins has finished
* reloading its configuration.
*
* @since 2.333
*/
public void onReload(@NonNull String user, @CheckForNull String remoteAddr) {
if (remoteAddr != null) {
LOGGER.log(
Level.INFO,
"Reloading Jenkins as requested by {0} from {1}",
new Object[] {user, remoteAddr});
} else {
LOGGER.log(Level.INFO, "Reloading Jenkins as requested by {0}", user);
}
}

/**
* Called when Jenkins is beginning its shutdown.
*
* @since 2.333
*/
public void onStop(@NonNull String user, @CheckForNull String remoteAddr) {
if (remoteAddr != null) {
LOGGER.log(
Level.INFO,
"Stopping Jenkins as requested by {0} from {1}",
new Object[] {user, remoteAddr});
} else {
LOGGER.log(Level.INFO, "Stopping Jenkins as requested by {0}", user);
}
}

/**
* Tell the service manager to extend the startup or shutdown timeout. The value specified is a
* time during which either {@link #onExtendTimeout(long, TimeUnit)} must be called again or
* startup/shutdown must complete.
*
* @param timeout The amount by which to extend the timeout.
* @param unit The time unit of the timeout argument.
*
* @since TODO
*/
public void onExtendTimeout(long timeout, @NonNull TimeUnit unit) {}

/**
* Called when Jenkins service state has changed.
*
* @param status The status string. This is free-form and can be used for various purposes:
* general state feedback, completion percentages, human-readable error message, etc.
*
* @since 2.333
*/
public void onStatusUpdate(String status) {
LOGGER.log(Level.INFO, status);
}

private static final Logger LOGGER = Logger.getLogger(Lifecycle.class.getName());
}
69 changes: 69 additions & 0 deletions core/src/main/java/hudson/lifecycle/SystemdLifecycle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package hudson.lifecycle;

import com.sun.jna.LastErrorException;
import com.sun.jna.Library;
import com.sun.jna.Native;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

/**
* {@link Lifecycle} that delegates its responsibility to {@code systemd(1)}.
*
* @author Basil Crow
*/
@Restricted(NoExternalUse.class)
@Extension(optional = true)
public class SystemdLifecycle extends ExitLifecycle {

private static final Logger LOGGER = Logger.getLogger(SystemdLifecycle.class.getName());

interface Systemd extends Library {
Systemd INSTANCE = Native.load("systemd", Systemd.class);

int sd_notify(int unset_environment, String state) throws LastErrorException;
}

@Override
public void onReady() {
super.onReady();
notify("READY=1");
}

@Override
public void onReload(@NonNull String user, @CheckForNull String remoteAddr) {
super.onReload(user, remoteAddr);
notify("RELOADING=1");
}

@Override
public void onStop(@NonNull String user, @CheckForNull String remoteAddr) {
super.onStop(user, remoteAddr);
notify("STOPPING=1");
}

@Override
public void onExtendTimeout(long timeout, @NonNull TimeUnit unit) {
super.onExtendTimeout(timeout, unit);
notify(String.format("EXTEND_TIMEOUT_USEC=%d", unit.toMicros(timeout)));
}

@Override
public void onStatusUpdate(String status) {
super.onStatusUpdate(status);
notify(String.format("STATUS=%s", status));
}

private static synchronized void notify(String message) {
try {
Systemd.INSTANCE.sd_notify(0, message);
} catch (LastErrorException e) {
LOGGER.log(Level.WARNING, null, e);
}
}
}
3 changes: 0 additions & 3 deletions core/src/main/java/hudson/model/AbstractItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,6 @@ public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOExcep
* then it will be loaded, then this method will be invoked
* to perform any implementation-specific work.
*
* <p>
*
*
* @param src
* Item from which it's copied from. The same type as {@code this}. Never null.
*/
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/hudson/model/Queue.java
Original file line number Diff line number Diff line change
Expand Up @@ -1919,9 +1919,8 @@ default CauseOfBlockage getCauseOfBlockage() {
* amongst all the free executors on all possibly suitable nodes.
* NOTE: To be able to re-use the same node during the next run this key should not change from one run to
* another. You probably want to compute that key based on the job's name.
* <p>
* @return by default: {@link #getFullDisplayName()}
*
* @return by default: {@link #getFullDisplayName()}
* @see hudson.model.LoadBalancer
*/
default String getAffinityKey() { return getFullDisplayName(); }
Expand Down
6 changes: 1 addition & 5 deletions core/src/main/java/hudson/scheduler/Hash.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@
/**
* Generates a pseudo-random sequence of integers in the specified range.
*
* <p>
* {@link CronTab} supports tokens like '@daily', which means "do it once a day".
* <p>{@link CronTab} supports tokens like '@daily', which means "do it once a day".
* Exactly which time of the day this gets scheduled is randomized --- randomized
* in the sense that it's spread out when many jobs choose @daily, but it's at
* the same time stable so that every job sticks to a specific time of the day
* even after the configuration is updated.
*
* <p>
*
*
* @author Kohsuke Kawaguchi
* @since 1.448
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
* This causes the container to perform authentication, but there's no way
* to find out whether the user has been successfully authenticated or not.
* So to find this out, we then redirect the user to
* {@link jenkins.model.Jenkins#doSecured(StaplerRequest, StaplerResponse) {@code /secured/...} page}.
* {@link jenkins.model.Jenkins#doSecured(StaplerRequest, StaplerResponse) /secured/... page}.
*
* <p>
* The handler of the above URL checks if the user is authenticated,
Expand Down
4 changes: 1 addition & 3 deletions core/src/main/java/hudson/util/LogTaskListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@
import java.util.logging.LogRecord;
import java.util.logging.Logger;

// TODO: AbstractTaskListener is empty now, but there are dependencies on that e.g. Ruby Runtime - JENKINS-48116)
// The change needs API deprecation policy or external usages cleanup.

/**
* {@link TaskListener} which sends messages to a {@link Logger}.
*/
@SuppressWarnings("deprecation") // to preserve serial form
public class LogTaskListener extends AbstractTaskListener implements TaskListener, Closeable {

// would be simpler to delegate to the LogOutputStream but this would incompatibly change the serial form
Expand Down
4 changes: 1 addition & 3 deletions core/src/main/java/hudson/util/StreamTaskListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
import jenkins.util.SystemProperties;
import org.kohsuke.stapler.framework.io.WriterOutputStream;

// TODO: AbstractTaskListener is empty now, but there are dependencies on that e.g. Ruby Runtime - JENKINS-48116)
// The change needs API deprecation policy or external usages cleanup.

/**
* {@link TaskListener} that generates output into a single stream.
*
Expand All @@ -59,6 +56,7 @@
*
* @author Kohsuke Kawaguchi
*/
@SuppressWarnings("deprecation") // to preserve serial form
public class StreamTaskListener extends AbstractTaskListener implements TaskListener, Closeable {
@NonNull
private PrintStream out;
Expand Down
7 changes: 0 additions & 7 deletions core/src/main/java/hudson/util/XStream2.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import jenkins.model.Jenkins;
import jenkins.util.xstream.SafeURLConverter;

Expand Down Expand Up @@ -570,18 +569,12 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co
throw new ConversionException("Refusing to unmarshal " + reader.getNodeName() + " for security reasons; see https://www.jenkins.io/redirect/class-filter/");
}

/** TODO see comment in {@code whitelisted-classes.txt} */
private static final Pattern JRUBY_PROXY = Pattern.compile("org[.]jruby[.]proxy[.].+[$]Proxy\\d+");

@Override
public boolean canConvert(Class type) {
if (type == null) {
return false;
}
String name = type.getName();
if (JRUBY_PROXY.matcher(name).matches()) {
return false;
}
// claim we can convert all the scary stuff so we can throw exceptions when attempting to do so
return ClassFilter.DEFAULT.isBlacklisted(name) || ClassFilter.DEFAULT.isBlacklisted(type);
}
Expand Down
Loading

0 comments on commit c743801

Please sign in to comment.