Skip to content

Commit

Permalink
Merge branch 'master' into improve-view-settings-2
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed Oct 12, 2024
2 parents 8c0ca4e + 4d2698f commit cb5c00f
Show file tree
Hide file tree
Showing 167 changed files with 97 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@

# Yarn
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
/war/.yarn/plugins/** binary
/.yarn/plugins/** binary
4 changes: 2 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ node/
.git

# libraries / external deps / generated files
war/src/main/js/plugin-setup-wizard/bootstrap-detached.js
src/main/js/plugin-setup-wizard/bootstrap-detached.js
war/src/main/webapp/scripts/yui
war/src/main/webapp/jsbundles/
war/src/main/scss/_bootstrap.scss
src/main/scss/_bootstrap.scss

# test files that we don't need formatted
test/src/test/resources
Expand Down
2 changes: 1 addition & 1 deletion .stylelintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
extends: "stylelint-config-standard",
customSyntax: "postcss-scss",
ignoreFiles: ["war/src/main/scss/_bootstrap.scss"],
ignoreFiles: ["src/main/scss/_bootstrap.scss"],
rules: {
"no-descending-specificity": null,
"selector-class-pattern": "[a-z]",
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/ComputerSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static List<NodeMonitor> get_monitors() {
* @deprecated Use {@link #getComputers()} instead.
* @return All {@link Computer} instances managed by this set.
*/
@Deprecated(since = "TODO")
@Deprecated(since = "2.480")
public Computer[] get_all() {
return getComputers().stream().filter(Computer.class::isInstance).toArray(Computer[]::new);
}
Expand Down
9 changes: 3 additions & 6 deletions core/src/main/java/hudson/model/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,9 @@ public synchronized void deleteArtifacts() throws IOException {
* if we fail to delete.
*/
public void delete() throws IOException {
if (isLogUpdated()) {
throw new IOException("Unable to delete " + this + " because it is still running");
}
synchronized (this) {
// Avoid concurrent delete. See https://issues.jenkins.io/browse/JENKINS-61687
if (isPendingDelete) {
Expand Down Expand Up @@ -1885,12 +1888,6 @@ protected final void execute(@NonNull RunExecution job) {
LOGGER.log(Level.SEVERE, "Failed to save build record", e);
}
}

try {
getParent().logRotate();
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to rotate log", e);
}
} finally {
onEndBuilding();
if (logger != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void onChange(Saveable o, XmlFile file) {}
* The saveable object.
* @param file
* The {@link XmlFile} for this saveable object.
* @since TODO
* @since 2.480
*/
public void onDeleted(Saveable o, XmlFile file) {}

Expand Down Expand Up @@ -92,7 +92,7 @@ public static void fireOnChange(Saveable o, XmlFile file) {

/**
* Fires the {@link #onDeleted} event.
* @since TODO
* @since 2.480
*/
public static void fireOnDeleted(Saveable o, XmlFile file) {
Listeners.notify(SaveableListener.class, false, l -> l.onDeleted(o, file));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public abstract class AuthorizationStrategy extends AbstractDescribableImpl<Auth
* Default implementation delegates to {@link #getACL(Computer)} if the computer is an instance of {@link Computer},
* otherwise it will fall back to {@link #getRootACL()}.
*
* @since TODO
* @since 2.480
**/
public @NonNull ACL getACL(@NonNull IComputer computer) {
if (computer instanceof Computer c) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/tasks/LogRotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private boolean shouldKeepRun(Run r, Run lsb, Run lstb) {
LOGGER.log(FINER, "{0} is not to be removed or purged of artifacts because it’s the last stable build", r);
return true;
}
if (r.isBuilding()) {
if (r.isLogUpdated()) {
LOGGER.log(FINER, "{0} is not to be removed or purged of artifacts because it’s still building", r);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

Expand All @@ -56,8 +57,18 @@ protected void execute(TaskListener listener) throws IOException, InterruptedExc
}
}

/**
* Runs all globally configured build discarders against a job.
*/
public static void processJob(TaskListener listener, Job job) {
GlobalBuildDiscarderConfiguration.get().getConfiguredBuildDiscarders().forEach(strategy -> {
processJob(listener, job, GlobalBuildDiscarderConfiguration.get().getConfiguredBuildDiscarders().stream());
}

/**
* Runs the specified build discarders against a job.
*/
public static void processJob(TaskListener listener, Job job, Stream<GlobalBuildDiscarderStrategy> strategies) {
strategies.forEach(strategy -> {
String displayName = strategy.getDescriptor().getDisplayName();
if (strategy.isApplicable(job)) {
try {
Expand Down
13 changes: 11 additions & 2 deletions core/src/main/java/jenkins/model/GlobalBuildDiscarderListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.kohsuke.accmod.restrictions.NoExternalUse;

/**
* Run background build discarders on an individual job once a build is finalized
* Run build discarders on an individual job once a build is finalized
*/
@Extension
@Restricted(NoExternalUse.class)
Expand All @@ -46,6 +46,15 @@ public class GlobalBuildDiscarderListener extends RunListener<Run> {
@Override
public void onFinalized(Run run) {
Job job = run.getParent();
BackgroundGlobalBuildDiscarder.processJob(new LogTaskListener(LOGGER, Level.FINE), job);
try {
// Job-level build discarder execution is unconditional.
job.logRotate();
} catch (Exception e) {
LOGGER.log(Level.WARNING, e, () -> "Failed to rotate log for " + run);
}
// Avoid calling Job.logRotate twice in case JobGlobalBuildDiscarderStrategy is configured globally.
BackgroundGlobalBuildDiscarder.processJob(new LogTaskListener(LOGGER, Level.FINE), job,
GlobalBuildDiscarderConfiguration.get().getConfiguredBuildDiscarders().stream()
.filter(s -> !(s instanceof JobGlobalBuildDiscarderStrategy)));
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/model/IComputer.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/**
* Interface for computer-like objects meant to be passed to {@code t:executors} tag.
*
* @since TODO
* @since 2.480
*/
@Restricted(Beta.class)
public interface IComputer extends AccessControlled {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/model/IDisplayExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/**
* A snapshot of the executor information for display purpose.
*
* @since TODO
* @since 2.480
*/
@Restricted(Beta.class)
public interface IDisplayExecutor {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/model/IExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/**
* Interface for an executor that can be displayed in the executors widget.
*
* @since TODO
* @since 2.480
*/
@Restricted(Beta.class)
public interface IExecutor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public ContextMenu add(Node n) {
* @since 1.513
* @deprecated use {@link #add(IComputer)} instead.
*/
@Deprecated(since = "TODO")
@Deprecated(since = "2.480")
public ContextMenu add(Computer c) {
return add((IComputer) c);
}
Expand All @@ -265,7 +265,7 @@ public ContextMenu add(Computer c) {
* Adds a {@link IComputer} instance.
* @param c the computer to add to the menu
* @return this
* @since TODO
* @since 2.480
*/
public ContextMenu add(IComputer c) {
return add(new MenuItem()
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/model/queue/ITask.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* A task that can be displayed in the executors widget.
*
* @since TODO
* @since 2.480
*/
public interface ITask extends ModelObject {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ THE SOFTWARE.
</thead>
<tbody>
<j:getStatic var="extendedReadPermission" className="hudson.model.Computer" field="EXTENDED_READ"/>
<j:forEach var="c" items="${it._all}">
<j:forEach var="c" items="${it.computers}">
<tr id="node_${c.name}">
<td data="${c.icon}" class="jenkins-table__cell--tight jenkins-table__icon">
<div class="jenkins-table__cell__button-wrapper">
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/hudson/model/Run/delete.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout">
<j:if test="${!it.building and !it.keepLog}">
<j:if test="${!it.logUpdated and !it.keepLog}">
<l:task href="${buildUrl.baseUrl}/confirmDelete" icon="icon-edit-delete icon-md" permission="${it.DELETE}" title="${%delete.build(it.displayName)}"/>
</j:if>
</j:jelly>
6 changes: 3 additions & 3 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = [
// External scripts
".pnp.cjs",
".pnp.loader.mjs",
"war/src/main/js/plugin-setup-wizard/bootstrap-detached.js",
"src/main/js/plugin-setup-wizard/bootstrap-detached.js",
"war/src/main/webapp/scripts/yui/*",
],
},
Expand Down Expand Up @@ -91,8 +91,8 @@ module.exports = [
{
files: [
"eslint.config.cjs",
"war/postcss.config.js",
"war/webpack.config.js",
"postcss.config.js",
"webpack.config.js",
".stylelintrc.js",
],
languageOptions: {
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
},
"private": true,
"scripts": {
"dev": "webpack --config war/webpack.config.js",
"prod": "webpack --config war/webpack.config.js --mode=production",
"dev": "webpack --config webpack.config.js",
"prod": "webpack --config webpack.config.js --mode=production",
"build": "yarn prod",
"start": "yarn dev --watch",
"lint:js": "eslint . && prettier --check .",
"lint:js-ci": "eslint . -f checkstyle -o target/eslint-warnings.xml && prettier --check .",
"lint:css": "stylelint war/src/main/scss",
"lint:css-ci": "stylelint war/src/main/scss --custom-formatter stylelint-checkstyle-reporter -o target/stylelint-warnings.xml",
"lint:css": "stylelint src/main/scss",
"lint:css-ci": "stylelint src/main/scss --custom-formatter stylelint-checkstyle-reporter -o target/stylelint-warnings.xml",
"lint:ci": "yarn lint:js-ci && yarn lint:css-ci",
"lint:fix": "eslint --fix . && prettier --write . && stylelint war/src/main/scss --fix",
"lint:fix": "eslint --fix . && prettier --write . && stylelint src/main/scss --fix",
"lint": "yarn lint:js && yarn lint:css"
},
"devDependencies": {
Expand All @@ -34,7 +34,7 @@
"eslint": "9.12.0",
"eslint-config-prettier": "9.1.0",
"eslint-formatter-checkstyle": "8.40.0",
"globals": "15.10.0",
"globals": "15.11.0",
"handlebars-loader": "1.7.3",
"mini-css-extract-plugin": "2.9.1",
"postcss": "8.4.47",
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ THE SOFTWARE.
<bridge-method-injector.version>1.30</bridge-method-injector.version>
<spotless.check.skip>false</spotless.check.skip>
<!-- Make sure to keep the jetty-ee9-maven-plugin version in war/pom.xml in sync with the Jetty release in Winstone: -->
<winstone.version>8.1</winstone.version>
<winstone.version>8.2</winstone.version>
<node.version>20.18.0</node.version>
</properties>

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 6 additions & 15 deletions test/src/test/java/hudson/cli/DeleteBuildsCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,18 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeFalse;

import hudson.Functions;
import hudson.model.ExecutorTest;
import hudson.model.FreeStyleProject;
import hudson.model.Item;
import hudson.model.Run;
import hudson.model.labels.LabelAtom;
import hudson.tasks.Shell;
import java.io.IOException;
import jenkins.model.Jenkins;
import org.junit.AssumptionViolatedException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

/**
Expand Down Expand Up @@ -139,24 +136,18 @@ public class DeleteBuildsCommandTest {
assertThat(result.stdout(), containsString("Deleted 0 builds"));
}

@Test public void deleteBuildsShouldSuccessEvenTheBuildIsRunning() throws Exception {
assumeFalse("You can't delete files that are in use on Windows", Functions.isWindows());
@Issue("JENKINS-73835")
@Test public void deleteBuildsShouldFailIfTheBuildIsRunning() throws Exception {
FreeStyleProject project = j.createFreeStyleProject("aProject");
ExecutorTest.startBlockingBuild(project);
assertThat(((FreeStyleProject) j.jenkins.getItem("aProject")).getBuilds(), hasSize(1));

final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ, Item.READ, Run.DELETE)
.invokeWithArgs("aProject", "1");
assertThat(result, succeeded());
assertThat(result.stdout(), containsString("Deleted 1 builds"));
assertThat(((FreeStyleProject) j.jenkins.getItem("aProject")).getBuilds(), hasSize(0));
assertThat(project.isBuilding(), equalTo(false));
try {
project.delete();
} catch (IOException | InterruptedException x) {
throw new AssumptionViolatedException("Could not delete test project (race condition?)", x);
}
assertThat(result, failedWith(1));
assertThat(result, hasNoStandardOutput());
assertThat(result.stderr(), containsString("Unable to delete aProject #1 because it is still running"));
}

@Test public void deleteBuildsShouldSuccessEvenTheBuildIsStuckInTheQueue() throws Exception {
Expand Down
14 changes: 14 additions & 0 deletions test/src/test/java/hudson/model/RunTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import hudson.ExtensionList;
Expand Down Expand Up @@ -62,6 +63,7 @@
import org.junit.experimental.categories.Category;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.SleepBuilder;
import org.jvnet.hudson.test.SmokeTest;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -128,6 +130,18 @@ public void onDeleted(Saveable o, XmlFile file) {
}
}

@Issue("JENKINS-73835")
@Test public void buildsMayNotBeDeletedWhileRunning() throws Exception {
var p = j.createFreeStyleProject();
p.getBuildersList().add(new SleepBuilder(999999));
var b = p.scheduleBuild2(0).waitForStart();
var ex = assertThrows(IOException.class, () -> b.delete());
assertThat(ex.getMessage(), containsString("Unable to delete " + b + " because it is still running"));
b.getExecutor().interrupt();
j.waitForCompletion(b);
b.delete(); // Works fine.
}

@Issue("SECURITY-1902")
@Test public void preventXssInBadgeTooltip() throws Exception {
j.jenkins.setQuietPeriod(0);
Expand Down
Loading

0 comments on commit cb5c00f

Please sign in to comment.