提交 1e80c681 编写于 作者: V Valentina Armenise

[FIXED JENKINS-34883] use an ovverridable createDefaultUpdateSite method

上级 1e746f6e
......@@ -160,7 +160,7 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
*/
public static final String ID_DEFAULT = SystemProperties.getString(UpdateCenter.class.getName()+".defaultUpdateSiteId", "default");
public static final String LEGACY_ID_DEFAULT = "default";
public static final String PREDEFINED_UPDATE_SITE_ID = "default";
@Restricted(NoExternalUse.class)
public static final String ID_UPLOAD = "_upload";
......@@ -847,7 +847,6 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
* Loads the data from the disk into this object.
*/
public synchronized void load() throws IOException {
UpdateSite defaultSite = new UpdateSite(LEGACY_ID_DEFAULT, config.getUpdateCenterUrl() + "update-center.json");
XmlFile file = getConfigFile();
if(file.exists()) {
try {
......@@ -855,23 +854,31 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to load "+file, e);
}
boolean defaultSiteExists = false;
for (UpdateSite site : sites) {
// replace the legacy site with the new site
if (site.isLegacyDefault()) {
sites.remove(site);
sites.add(defaultSite);
break;
} else if (ID_DEFAULT.equals(site.getId())) {
defaultSiteExists = true;
}
}
if (!defaultSiteExists) {
sites.add(createDefaultUpdateSite());
}
} else {
if (sites.isEmpty()) {
// If there aren't already any UpdateSources, add the default one.
// to maintain compatibility with existing UpdateCenterConfiguration, create the default one as specified by UpdateCenterConfiguration
sites.add(defaultSite);
sites.add(createDefaultUpdateSite());
}
}
}
public UpdateSite createDefaultUpdateSite() {
return new UpdateSite(PREDEFINED_UPDATE_SITE_ID, config.getUpdateCenterUrl() + "update-center.json");
}
private XmlFile getConfigFile() {
return new XmlFile(XSTREAM,new File(Jenkins.getInstance().root,
UpdateCenter.class.getName()+".xml"));
......
......@@ -435,7 +435,7 @@ public class UpdateSite {
* Is this the legacy default update center site?
*/
public boolean isLegacyDefault() {
return id.equals(UpdateCenter.ID_DEFAULT) && url.startsWith("http://hudson-ci.org/") || url.startsWith("http://updates.hudson-labs.org/");
return id.equals(UpdateCenter.PREDEFINED_UPDATE_SITE_ID) && url.startsWith("http://hudson-ci.org/") || url.startsWith("http://updates.hudson-labs.org/");
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册