mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-09 10:06:13 +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.
|
||||
*
|
||||
|
||||
@@ -640,8 +640,7 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
|
||||
}
|
||||
for (UpdateSite s : sites) {
|
||||
Plugin p = s.getPlugin(artifactId);
|
||||
if (p!=null) {
|
||||
if (minVersion.isNewerThan(new VersionNumber(p.version))) continue;
|
||||
if (checkMinVersion(p, minVersion)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
@@ -649,6 +648,28 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets plugin info from all available sites
|
||||
* @return list of plugins
|
||||
*/
|
||||
@Restricted(NoExternalUse.class)
|
||||
public @Nonnull List<Plugin> getPluginFromAllSites(String artifactId,
|
||||
@CheckForNull VersionNumber minVersion) {
|
||||
ArrayList<Plugin> result = new ArrayList<>();
|
||||
for (UpdateSite s : sites) {
|
||||
Plugin p = s.getPlugin(artifactId);
|
||||
if (checkMinVersion(p, minVersion)) {
|
||||
result.add(p);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean checkMinVersion(@CheckForNull Plugin p, @CheckForNull VersionNumber minVersion) {
|
||||
return p != null
|
||||
&& (minVersion == null || !minVersion.isNewerThan(new VersionNumber(p.version)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a Jenkins upgrade.
|
||||
*/
|
||||
@RequirePOST
|
||||
|
||||
Reference in new issue
Block a user