Skip to content

Commit aeec2cb

Browse files
Merge branch 'master' into migrate_to_junit5_test_2
2 parents 61aed5d + d70bc2e commit aeec2cb

36 files changed

+211
-894
lines changed

core/src/main/java/hudson/PluginManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,10 @@ public HttpResponse doPluginsSearch(@QueryParameter String query, @QueryParamete
15571557
releaseTimestamp.put("displayValue", Messages.PluginManager_ago(Functions.getTimeSpanString(plugin.releaseTimestamp)));
15581558
jsonObject.put("releaseTimestamp", releaseTimestamp);
15591559
}
1560+
if (plugin.healthScore != null) {
1561+
jsonObject.put("healthScore", plugin.healthScore);
1562+
jsonObject.put("healthScoreClass", plugin.healthScoreClass);
1563+
}
15601564
return jsonObject;
15611565
})
15621566
.collect(toList());

core/src/main/java/hudson/PluginWrapper.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ public boolean hasDerivedDependencyErrors() {
222222
*/
223223
private static Set<String> CORE_ONLY_DEPENDANT = Set.of("jenkins-core");
224224

225+
private Integer healthScore;
226+
225227
/**
226228
* Set the list of components that depend on this plugin.
227229
* @param dependents The list of components that depend on this plugin.
@@ -423,6 +425,32 @@ public void injectJarsToClasspath(File... jars) throws Exception {
423425

424426
}
425427

428+
@Restricted(NoExternalUse.class) // Jelly use only
429+
public Integer getHealthScore() {
430+
if (this.healthScore == null) {
431+
this.healthScore = getInfoFromAllSites().stream()
432+
.filter(Objects::nonNull)
433+
.filter(p -> p.healthScore != null)
434+
.findFirst()
435+
.map(plugin -> plugin.healthScore)
436+
.orElse(null);
437+
}
438+
return this.healthScore;
439+
}
440+
441+
@Restricted(NoExternalUse.class)
442+
public static String getHealthScoreClassForScore(int score) {
443+
if (score > 80) return "top";
444+
if (score > 60) return "middle";
445+
return "bottom";
446+
}
447+
448+
@Restricted(NoExternalUse.class) // Jelly use only
449+
public String getHealthScoreClass() {
450+
if (this.healthScore == null) return null;
451+
return getHealthScoreClassForScore(this.healthScore);
452+
}
453+
426454
@ExportedBean
427455
public static final class Dependency {
428456
@Exported

core/src/main/java/hudson/model/Job.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
import jenkins.model.ModelObjectWithChildren;
9898
import jenkins.model.PeepholePermalink;
9999
import jenkins.model.ProjectNamingStrategy;
100-
import jenkins.model.RunIdMigrator;
101100
import jenkins.model.lazy.LazyBuildMixIn;
102101
import jenkins.scm.RunWithSCM;
103102
import jenkins.security.HexStringConfidentialKey;
@@ -192,10 +191,6 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
192191
// this should have been DescribableList but now it's too late
193192
protected CopyOnWriteList<JobProperty<? super JobT>> properties = new CopyOnWriteList<>();
194193

195-
@Restricted(NoExternalUse.class)
196-
@SuppressFBWarnings(value = "PA_PUBLIC_PRIMITIVE_ATTRIBUTE", justification = "Preserve API compatibility")
197-
public transient RunIdMigrator runIdMigrator;
198-
199194
protected Job(ItemGroup parent, String name) {
200195
super(parent, name);
201196
}
@@ -206,20 +201,19 @@ public synchronized void save() throws IOException {
206201
holdOffBuildUntilSave = holdOffBuildUntilUserSave;
207202
}
208203

209-
@Override public void onCreatedFromScratch() {
210-
super.onCreatedFromScratch();
211-
runIdMigrator = new RunIdMigrator();
212-
runIdMigrator.created(getBuildDir());
213-
}
214-
215204
@Override
216205
public void onLoad(ItemGroup<? extends Item> parent, String name)
217206
throws IOException {
218207
super.onLoad(parent, name);
219208

220-
File buildDir = getBuildDir();
221-
runIdMigrator = new RunIdMigrator();
222-
runIdMigrator.migrate(buildDir, Jenkins.get().getRootDir());
209+
// see https://github.com/jenkinsci/jenkins/pull/10456#issuecomment-2748112449
210+
// This code can be deleted after several Jenkins releases,
211+
// when it is likely that everyone is running a version equal or higher to this version.
212+
var buildDirPath = getBuildDir().toPath();
213+
if (Files.deleteIfExists(buildDirPath.resolve("legacyIds"))) {
214+
LOGGER.info("Deleting legacyIds file in " + buildDirPath + ". See https://issues.jenkins"
215+
+ ".io/browse/JENKINS-75465 for more information.");
216+
}
223217

224218
TextFile f = getNextBuildNumberFile();
225219
if (f.exists()) {

core/src/main/java/hudson/model/RunMap.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@
4545
import java.util.SortedMap;
4646
import java.util.logging.Level;
4747
import java.util.logging.Logger;
48-
import jenkins.model.RunIdMigrator;
4948
import jenkins.model.lazy.AbstractLazyLoadRunMap;
5049
import jenkins.model.lazy.BuildReference;
51-
import jenkins.model.lazy.LazyBuildMixIn;
5250
import org.kohsuke.accmod.Restricted;
5351
import org.kohsuke.accmod.restrictions.NoExternalUse;
5452

@@ -72,10 +70,6 @@ public final class RunMap<R extends Run<?, R>> extends AbstractLazyLoadRunMap<R>
7270

7371
private Constructor<R> cons;
7472

75-
/** Normally overwritten by {@link LazyBuildMixIn#onLoad} or {@link LazyBuildMixIn#onCreatedFromScratch}, in turn created during {@link Job#onLoad}. */
76-
@Restricted(NoExternalUse.class)
77-
public RunIdMigrator runIdMigrator = new RunIdMigrator();
78-
7973
// TODO: before first complete build
8074
// patch up next/previous build link
8175

@@ -156,7 +150,6 @@ public void remove() {
156150
@Override
157151
public boolean removeValue(R run) {
158152
run.dropLinks();
159-
runIdMigrator.delete(dir, run.getId());
160153
return super.removeValue(run);
161154
}
162155

@@ -227,14 +220,13 @@ public R put(R r) {
227220
return super._put(r);
228221
}
229222

223+
@CheckForNull
230224
@Override public R getById(String id) {
231-
int n;
232225
try {
233-
n = Integer.parseInt(id);
234-
} catch (NumberFormatException x) {
235-
n = runIdMigrator.findNumber(id);
226+
return getByNumber(Integer.parseInt(id));
227+
} catch (NumberFormatException e) { // see https://issues.jenkins.io/browse/JENKINS-75476
228+
return null;
236229
}
237-
return getByNumber(n);
238230
}
239231

240232
/**

core/src/main/java/hudson/model/UpdateCenter.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,20 @@ public String getDefaultBaseUrl() {
765765
return result;
766766
}
767767

768+
@Restricted(NoExternalUse.class)
769+
public boolean isHealthScoresAvailable() {
770+
for (UpdateSite site : sites) {
771+
final Data data = site.getData();
772+
if (data == null) {
773+
continue;
774+
}
775+
if (data.healthScoresAvailable) {
776+
return true;
777+
}
778+
}
779+
return false;
780+
}
781+
768782
private boolean checkMinVersion(@CheckForNull Plugin p, @CheckForNull VersionNumber minVersion) {
769783
return p != null
770784
&& (minVersion == null || !minVersion.isNewerThan(new VersionNumber(p.version)));

core/src/main/java/hudson/model/UpdateSite.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,9 @@ public final class Data {
611611
*/
612612
public final String connectionCheckUrl;
613613

614+
@Restricted(NoExternalUse.class)
615+
public final boolean healthScoresAvailable;
616+
614617
Data(JSONObject o) {
615618
this.sourceId = Util.intern((String) o.get("id"));
616619
JSONObject c = o.optJSONObject("core");
@@ -649,6 +652,8 @@ public final class Data {
649652
}
650653
}
651654

655+
boolean healthScoresAvailable = false;
656+
652657
for (Map.Entry<String, JSONObject> e : (Set<Map.Entry<String, JSONObject>>) o.getJSONObject("plugins").entrySet()) {
653658
Plugin p = new Plugin(sourceId, e.getValue());
654659
// JENKINS-33308 - include implied dependencies for older plugins that may need them
@@ -662,6 +667,10 @@ public final class Data {
662667
}
663668
plugins.put(Util.intern(e.getKey()), p);
664669

670+
if (p.healthScore != null) {
671+
healthScoresAvailable = true;
672+
}
673+
665674
// compatibility with update sites that have no separate 'deprecated' top-level entry.
666675
// Also do this even if there are deprecations to potentially allow limiting the top-level entry to overridden URLs.
667676
if (p.hasCategory("deprecated")) {
@@ -671,6 +680,8 @@ public final class Data {
671680
}
672681
}
673682

683+
this.healthScoresAvailable = healthScoresAvailable;
684+
674685
connectionCheckUrl = (String) o.get("connectionCheckUrl");
675686
}
676687

@@ -1256,6 +1267,12 @@ public final class Plugin extends Entry {
12561267
@Restricted(NoExternalUse.class)
12571268
public IssueTracker[] issueTrackers;
12581269

1270+
@Restricted(NoExternalUse.class)
1271+
public final Integer healthScore;
1272+
1273+
@Restricted(NoExternalUse.class)
1274+
public final String healthScoreClass;
1275+
12591276
@DataBoundConstructor
12601277
public Plugin(String sourceId, JSONObject o) {
12611278
super(sourceId, o, UpdateSite.this.url);
@@ -1292,6 +1309,12 @@ public Plugin(String sourceId, JSONObject o) {
12921309
int optionalDepCount = (int) ja.stream().filter(IS_DEP_PREDICATE.and(IS_NOT_OPTIONAL.negate())).count();
12931310
dependencies = getPresizedMutableMap(depCount);
12941311
optionalDependencies = getPresizedMutableMap(optionalDepCount);
1312+
this.healthScore = o.has("health") ? o.getInt("health") : null;
1313+
if (healthScore != null) {
1314+
this.healthScoreClass = PluginWrapper.getHealthScoreClassForScore(healthScore);
1315+
} else {
1316+
this.healthScoreClass = null;
1317+
}
12951318

12961319
for (Object jo : o.getJSONArray("dependencies")) {
12971320
JSONObject depObj = (JSONObject) jo;

0 commit comments

Comments
 (0)