mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-10-28 03:55:20 +00:00
[JENKINS-59679] Use plugin URL from the update site rather than the manifest (#4273)
* Use plugin URL from the update site rather than the manifest * Avoid Mockito when not needed * Resolve plugin URL from multiple update sites
This commit is contained in:
1 parent
3a8c1efdcd
commit
40b68eaadb
6 files changed
+160
-27
No files matched your search
@@ -521,20 +521,30 @@ public class PluginWrapper implements Comparable<PluginWrapper>, ModelObject {
|
||||
*/
|
||||
@Exported
|
||||
public String getUrl() {
|
||||
// first look for the manifest entry. This is new in maven-hpi-plugin 1.30
|
||||
// first look in update center metadata
|
||||
List<UpdateSite.Plugin> siteMetadataList = getInfoFromAllSites();
|
||||
String firstSiteUrl = null;
|
||||
if (!siteMetadataList.isEmpty()) {
|
||||
firstSiteUrl = siteMetadataList.get(0).wiki;
|
||||
if (allUrlsMatch(firstSiteUrl, siteMetadataList)) {
|
||||
return firstSiteUrl;
|
||||
}
|
||||
}
|
||||
|
||||
// if update sites give different / empty results,
|
||||
// use manifest (since maven-hpi-plugin 1.30)
|
||||
String url = manifest.getMainAttributes().getValue("Url");
|
||||
if(url!=null) return url;
|
||||
|
||||
// fallback to update center metadata
|
||||
UpdateSite.Plugin ui = getInfo();
|
||||
if(ui!=null) return ui.wiki;
|
||||
|
||||
return null;
|
||||
if (url != null) {
|
||||
return url;
|
||||
}
|
||||
return firstSiteUrl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
private boolean allUrlsMatch(String url, List<UpdateSite.Plugin> uiList) {
|
||||
return uiList.stream().allMatch(k -> k.wiki != null && k.wiki.equals(url));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Plugin:" + getShortName();
|
||||
}
|
||||
@@ -972,6 +982,11 @@ public class PluginWrapper implements Comparable<PluginWrapper>, ModelObject {
|
||||
return uc.getPlugin(getShortName());
|
||||
}
|
||||
|
||||
private List<UpdateSite.Plugin> getInfoFromAllSites() {
|
||||
UpdateCenter uc = Jenkins.get().getUpdateCenter();
|
||||
return uc.getPluginFromAllSites(getShortName(), getVersionNumber());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this plugin has update in the update center.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user