Skip to content

Commit

Permalink
Merge pull request #2363 from varmenise/JENKINS-34883
Browse files Browse the repository at this point in the history
[FIXED JENKINS-34883] the legacy default update site can be different from the one specified by ID_DEFAULT
  • Loading branch information
varmenise committed May 23, 2016
2 parents b0fd310 + fd7e6c6 commit 02e4bc5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions core/src/main/java/hudson/model/UpdateCenter.java
Expand Up @@ -153,12 +153,14 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
*/
private static final int PLUGIN_DOWNLOAD_READ_TIMEOUT = SystemProperties.getInteger(UpdateCenter.class.getName()+".pluginDownloadReadTimeoutSeconds", 60) * 1000;

public static final String PREDEFINED_UPDATE_SITE_ID = "default";

/**
* {@linkplain UpdateSite#getId() ID} of the default update site.
* @since 1.483 - public property
* @since TODO - configurable via system property
*/
public static final String ID_DEFAULT = SystemProperties.getString(UpdateCenter.class.getName()+".defaultUpdateSiteId", "default");
public static final String ID_DEFAULT = SystemProperties.getString(UpdateCenter.class.getName()+".defaultUpdateSiteId", PREDEFINED_UPDATE_SITE_ID);

@Restricted(NoExternalUse.class)
public static final String ID_UPLOAD = "_upload";
Expand Down Expand Up @@ -845,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(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());
}
}
}

protected 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 02e4bc5

Please sign in to comment.