Skip to content

Commit 0c4755a

Browse files
committed
[JENKINS-27993] Increase @exported visibility on PluginWrapper properties
The /pluginManager/api/json endpoint returned empty objects for each plugin because all @exported properties had default visibility (1), which is not rendered when nested inside PluginManager at the default API depth. Increase visibility to 2 on key properties (shortName, version, longName, displayName, url, active, enabled, hasUpdate) so they appear at the default depth. Also add @exported to getDisplayName() as the non-deprecated replacement for getLongName().
1 parent 8a9e67a commit 0c4755a

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ public PluginWrapper(PluginManager parent, File archive, Manifest manifest, URL
522522
this.archive = archive;
523523
}
524524

525+
@Exported(visibility = 2)
525526
@Override
526527
public String getDisplayName() {
527528
String displayName = getLongName();
@@ -595,7 +596,7 @@ public List<Dependency> getOptionalDependencies() {
595596
/**
596597
* Returns the short name suitable for URL.
597598
*/
598-
@Exported
599+
@Exported(visibility = 2)
599600
public String getShortName() {
600601
return shortName;
601602
}
@@ -627,7 +628,7 @@ public String getShortName() {
627628
* null if this information is unavailable.
628629
* @since 1.283
629630
*/
630-
@Exported
631+
@Exported(visibility = 2)
631632
public String getUrl() {
632633
// first look in update center metadata
633634
List<UpdateSite.Plugin> siteMetadataList = getInfoFromAllSites();
@@ -662,7 +663,7 @@ public String toString() {
662663
*
663664
* @deprecated For most purposes, use {@link #getDisplayName()}.
664665
*/
665-
@Exported
666+
@Exported(visibility = 2)
666667
@Deprecated
667668
public String getLongName() {
668669
String name = manifest.getMainAttributes().getValue("Long-Name");
@@ -683,7 +684,7 @@ public YesNoMaybe supportsDynamicLoad() {
683684
/**
684685
* Returns the version number of this plugin
685686
*/
686-
@Exported
687+
@Exported(visibility = 2)
687688
public String getVersion() {
688689
return getVersionOf(manifest);
689690
}
@@ -894,7 +895,7 @@ private Set<String> dependentsToCheck(PluginDisableStrategy strategy) {
894895
/**
895896
* Returns true if this plugin is enabled for this session.
896897
*/
897-
@Exported
898+
@Exported(visibility = 2)
898899
public boolean isActive() {
899900
return active && !hasCycleDependency();
900901
}
@@ -921,7 +922,7 @@ public boolean isBundled() {
921922
* If true, the plugin is going to be activated next time
922923
* Jenkins runs.
923924
*/
924-
@Exported
925+
@Exported(visibility = 2)
925926
public boolean isEnabled() {
926927
return !disableFile.exists();
927928
}
@@ -1080,7 +1081,7 @@ private List<UpdateSite.Plugin> getInfoFromAllSites() {
10801081
* This method is conservative in the sense that if the version number is incomprehensible,
10811082
* it always returns false.
10821083
*/
1083-
@Exported
1084+
@Exported(visibility = 2)
10841085
public boolean hasUpdate() {
10851086
return getUpdateInfo() != null;
10861087
}

test/src/test/java/hudson/PluginManagerTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,37 @@ void pluginListJSONApi() throws Throwable {
542542
});
543543
}
544544

545+
@Issue("JENKINS-27993")
546+
@WithPlugin("htmlpublisher.jpi")
547+
@Test
548+
void pluginManagerApiJsonReturnsPluginDetails() throws Throwable {
549+
session.then(r -> {
550+
JSONObject response = r.getJSON("pluginManager/api/json").getJSONObject();
551+
JSONArray plugins = response.getJSONArray("plugins");
552+
assertThat(plugins, not(empty()));
553+
554+
// Find the htmlpublisher plugin in the response
555+
JSONObject htmlPublisher = null;
556+
for (int i = 0; i < plugins.size(); i++) {
557+
JSONObject plugin = plugins.getJSONObject(i);
558+
if ("htmlpublisher".equals(plugin.optString("shortName"))) {
559+
htmlPublisher = plugin;
560+
break;
561+
}
562+
}
563+
assertNotNull(htmlPublisher, "htmlpublisher plugin should be present in API response");
564+
565+
// Verify key properties are present at default depth (visibility = 2)
566+
assertNotNull(htmlPublisher.optString("shortName", null), "shortName should be exported at default depth");
567+
assertNotNull(htmlPublisher.optString("version", null), "version should be exported at default depth");
568+
assertNotNull(htmlPublisher.optString("longName", null), "longName should be exported at default depth");
569+
assertNotNull(htmlPublisher.optString("displayName", null), "displayName should be exported at default depth");
570+
assertTrue(htmlPublisher.has("active"), "active should be exported at default depth");
571+
assertTrue(htmlPublisher.has("enabled"), "enabled should be exported at default depth");
572+
assertTrue(htmlPublisher.has("hasUpdate"), "hasUpdate should be exported at default depth");
573+
});
574+
}
575+
545576
@Issue("JENKINS-41684")
546577
@Test
547578
void requireSystemDuringLoad() throws Throwable {

0 commit comments

Comments
 (0)