Skip to content

Commit

Permalink
[FIXED JENKINS-34883] use an ovverridable createDefaultUpdateSite method
Browse files Browse the repository at this point in the history
  • Loading branch information
varmenise committed May 20, 2016
1 parent 1e746f6 commit 1e80c68
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions core/src/main/java/hudson/model/UpdateCenter.java
Expand Up @@ -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";
Expand Down Expand Up @@ -847,31 +847,38 @@ public synchronized void save() {
* 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 {
sites.replaceBy(((PersistedList)file.unmarshal(sites)).toList());
} 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"));
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/UpdateSite.java
Expand Up @@ -435,7 +435,7 @@ public String getDownloadUrl() {
* 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/");
}

/**
Expand Down

0 comments on commit 1e80c68

Please sign in to comment.