Skip to content

Commit

Permalink
Merge branch 'master' into ControllerToAgentCallable
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick authored Nov 4, 2024
2 parents f073fcb + ed57499 commit bba1ff0
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 92 deletions.
62 changes: 42 additions & 20 deletions core/src/main/java/hudson/model/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import hudson.BulkChange;
import hudson.EnvVars;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import hudson.FeedAdapter;
import hudson.PermalinkList;
Expand Down Expand Up @@ -221,29 +222,20 @@ public void onLoad(ItemGroup<? extends Item> parent, String name)

TextFile f = getNextBuildNumberFile();
if (f.exists()) {
// starting 1.28, we store nextBuildNumber in a separate file.
// but old Hudson didn't do it, so if the file doesn't exist,
// assume that nextBuildNumber was read from config.xml
try {
synchronized (this) {
this.nextBuildNumber = Integer.parseInt(f.readTrim());
}
} catch (NumberFormatException e) {
LOGGER.log(Level.WARNING, "Corruption in {0}: {1}", new Object[] {f, e});
//noinspection StatementWithEmptyBody
if (this instanceof LazyBuildMixIn.LazyLoadingJob) {
// allow LazyBuildMixIn.onLoad to fix it
} else {
RunT lB = getLastBuild();
synchronized (this) {
this.nextBuildNumber = lB != null ? lB.getNumber() + 1 : 1;
}
saveNextBuildNumber();
RunT lB = getLastBuild();
synchronized (this) {
this.nextBuildNumber = lB != null ? lB.getNumber() + 1 : 1;
}
saveNextBuildNumber();
}
} else {
// From the old Hudson, or doCreateItem. Create this file now.
saveNextBuildNumber();
} else if (nextBuildNumber == 0) {
nextBuildNumber = 1;
}

if (properties == null) // didn't exist < 1.72
Expand Down Expand Up @@ -346,12 +338,42 @@ public boolean isKeepDependencies() {
}

/**
* Allocates a new buildCommand number.
* Allocates a new build number.
* @see BuildNumberAssigner
*/
public synchronized int assignBuildNumber() throws IOException {
int r = nextBuildNumber++;
saveNextBuildNumber();
return r;
public int assignBuildNumber() throws IOException {
return ExtensionList.lookupFirst(BuildNumberAssigner.class).assignBuildNumber(this, this::saveNextBuildNumber);
}

/**
* Alternate strategy for assigning build numbers.
*/
@Restricted(Beta.class)
public interface BuildNumberAssigner extends ExtensionPoint {
/**
* Implementation of {@link Job#assignBuildNumber}.
*/
int assignBuildNumber(Job<?, ?> job, SaveNextBuildNumber saveNextBuildNumber) throws IOException;
/**
* Provides an externally accessible alias for {@link Job#saveNextBuildNumber}, which is {@code protected}.
* ({@link #getNextBuildNumber} and {@link #fastUpdateNextBuildNumber} are already accessible.)
*/
interface SaveNextBuildNumber {
void call() throws IOException;
}
}

@Restricted(DoNotUse.class)
@Extension(ordinal = -1000)
public static final class DefaultBuildNumberAssigner implements BuildNumberAssigner {
@Override
public int assignBuildNumber(Job<?, ?> job, SaveNextBuildNumber saveNextBuildNumber) throws IOException {
synchronized (job) {
int r = job.nextBuildNumber++;
saveNextBuildNumber.call();
return r;
}
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/jenkins/model/lazy/LazyBuildMixIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOExcep
int max = _builds.maxNumberOnDisk();
int next = asJob().getNextBuildNumber();
if (next <= max) {
LOGGER.log(Level.WARNING, "JENKINS-27530: improper nextBuildNumber {0} detected in {1} with highest build number {2}; adjusting", new Object[] {next, asJob(), max});
asJob().updateNextBuildNumber(max + 1);
LOGGER.log(Level.FINE, "nextBuildNumber {0} detected in {1} with highest build number {2}; adjusting", new Object[] {next, asJob(), max});
asJob().fastUpdateNextBuildNumber(max + 1);
}
RunMap<RunT> currentBuilds = this.builds;
if (parent != null) {
Expand Down
28 changes: 8 additions & 20 deletions core/src/main/java/jenkins/security/stapler/TypedFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import hudson.ExtensionList;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.util.SystemProperties;
Expand All @@ -25,8 +23,6 @@
public class TypedFilter implements FieldRef.Filter, FunctionList.Filter {
private static final Logger LOGGER = Logger.getLogger(TypedFilter.class.getName());

private static final Map<Class<?>, Boolean> staplerCache = new HashMap<>();

private boolean isClassAcceptable(Class<?> clazz) {
if (clazz.isArray()) {
// special case to allow klass.isArray() dispatcher
Expand All @@ -46,31 +42,23 @@ private boolean isClassAcceptable(Class<?> clazz) {
return false;
}
}
return SKIP_TYPE_CHECK || isStaplerRelevantCached(clazz);
return SKIP_TYPE_CHECK || isStaplerRelevant.get(clazz);
}

private static boolean isStaplerRelevantCached(@NonNull Class<?> clazz) {
if (staplerCache.containsKey(clazz)) {
return staplerCache.get(clazz);
private static final ClassValue<Boolean> isStaplerRelevant = new ClassValue<>() {
@Override
protected Boolean computeValue(Class<?> clazz) {
return isSpecificClassStaplerRelevant(clazz) || isSuperTypesStaplerRelevant(clazz);
}
boolean ret = isStaplerRelevant(clazz);

staplerCache.put(clazz, ret);
return ret;
}

@Restricted(NoExternalUse.class)
public static boolean isStaplerRelevant(@NonNull Class<?> clazz) {
return isSpecificClassStaplerRelevant(clazz) || isSuperTypesStaplerRelevant(clazz);
}
};

private static boolean isSuperTypesStaplerRelevant(@NonNull Class<?> clazz) {
Class<?> superclass = clazz.getSuperclass();
if (superclass != null && isStaplerRelevantCached(superclass)) {
if (superclass != null && isStaplerRelevant.get(superclass)) {
return true;
}
for (Class<?> interfaceClass : clazz.getInterfaces()) {
if (isStaplerRelevantCached(interfaceClass)) {
if (isStaplerRelevant.get(interfaceClass)) {
return true;
}
}
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/resources/lib/hudson/rssBar_tr.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Legend=İkonlar hakkında
All=Tümü
Failures=Başarısız olanlar
LatestBuilds=Son yapılandırmalar
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@
"eslint-formatter-checkstyle": "8.40.0",
"globals": "15.11.0",
"handlebars-loader": "1.7.3",
"mini-css-extract-plugin": "2.9.1",
"mini-css-extract-plugin": "2.9.2",
"postcss": "8.4.47",
"postcss-loader": "8.1.1",
"postcss-preset-env": "10.0.8",
"postcss-scss": "4.0.9",
"prettier": "3.3.3",
"sass": "1.80.4",
"sass-loader": "16.0.2",
"sass": "1.80.5",
"sass-loader": "16.0.3",
"style-loader": "4.0.0",
"stylelint": "16.10.0",
"stylelint-checkstyle-reporter": "1.0.0",
"stylelint-config-standard": "36.0.1",
"webpack": "5.95.0",
"webpack": "5.96.1",
"webpack-cli": "5.1.4",
"webpack-remove-empty-scripts": "1.0.4"
},
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ THE SOFTWARE.
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.19.0</version>
<version>10.20.0</version>
</dependency>
</dependencies>
<executions>
Expand Down
9 changes: 4 additions & 5 deletions test/src/test/java/hudson/tasks/LogRotatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;

import hudson.Functions;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
Expand All @@ -50,10 +52,8 @@
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.FailureBuilder;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
Expand All @@ -64,9 +64,6 @@
*/
public class LogRotatorTest {

@ClassRule
public static BuildWatcher watcher = new BuildWatcher();

@Rule
public JenkinsRule j = new JenkinsRule();

Expand Down Expand Up @@ -103,6 +100,8 @@ public void successVsFailureWithRemoveLastBuild() throws Exception {

@Test
public void ableToDeleteCurrentBuild() throws Exception {
assumeFalse("Deleting the current build while is is completing does not work consistently on Windows",
Functions.isWindows());
var p = j.createFreeStyleProject();
// Keep 0 builds, i.e. immediately delete builds as they complete.
LogRotator logRotator = new LogRotator(-1, 0, -1, -1);
Expand Down
Loading

0 comments on commit bba1ff0

Please sign in to comment.