Skip to content

Commit

Permalink
[JENKINS-32328] handling tool Installers which do not have the defaul…
Browse files Browse the repository at this point in the history
…t schema
  • Loading branch information
varmenise committed Jan 22, 2016
1 parent 80a6a9e commit e7f8814
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 1 deletion.
28 changes: 27 additions & 1 deletion core/src/main/java/hudson/tools/DownloadFromUrlInstaller.java
Expand Up @@ -136,13 +136,39 @@ public Downloadable createDownloadable() {
final DownloadFromUrlInstaller.DescriptorImpl delegate = (DownloadFromUrlInstaller.DescriptorImpl)this;
return new Downloadable(getId()) {
public JSONObject reduce(List<JSONObject> jsonList) {
return delegate.reduce(jsonList);
if (isDefualtSchema(jsonList)) {

This comment has been minimized.

Copy link
@dirtyharrycallahan

dirtyharrycallahan Feb 15, 2016

isDefualtSchema or isDefaultSchema? Appears to be a typo.

This comment has been minimized.

Copy link
@varmenise

varmenise Feb 22, 2016

Author Contributor

typo, I ll fix it together with https://issues.jenkins-ci.org/browse/JENKINS-32831

return delegate.reduce(jsonList);
} else {
//if it's not default schema fall back to the super class implementation
return super.reduce(jsonList);
}
}
};
}
return new Downloadable(getId());
}

/**
* this function checks is the update center tool has the default schema
* @param jsonList the list of Update centers json files
* @return true if the schema is the default one (id, name, url), false otherwise
*/
private boolean isDefualtSchema(List<JSONObject> jsonList) {
JSONObject jsonToolInstallerList = jsonList.get(0);
ToolInstallerList toolInstallerList = (ToolInstallerList) JSONObject.toBean(jsonToolInstallerList, ToolInstallerList.class);

if (toolInstallerList != null) {
ToolInstallerEntry[] entryList = toolInstallerList.list;
ToolInstallerEntry sampleEntry = entryList[0];
if (sampleEntry != null) {
if (sampleEntry.id != null && sampleEntry.name != null && sampleEntry.url != null) {
return true;
}
}
}
return false;
}

private JSONObject reduce(List<JSONObject> jsonList) {
List<ToolInstallerEntry> reducedToolEntries = new LinkedList<>();
//collect all tool installers objects from the multiple json objects
Expand Down
34 changes: 34 additions & 0 deletions test/src/test/java/hudson/model/DownloadServiceTest.java
Expand Up @@ -9,7 +9,9 @@
import java.util.TreeSet;

import hudson.tasks.Maven;
import hudson.tools.DownloadFromUrlInstaller;
import hudson.tools.JDKInstaller;
import hudson.tools.ToolInstallation;
import jenkins.model.DownloadSettings;
import net.sf.json.JSONObject;
import org.jvnet.hudson.test.Issue;
Expand Down Expand Up @@ -127,4 +129,36 @@ public void testReduceFunctionWithJDKJsons() throws Exception {
JSONObject expectedResultJson = JSONObject.fromObject(DownloadService.loadJSON(expectedResult));
assertEquals(reducedJson, expectedResultJson);
}

public void testReduceFunctionWithNotDefaultSchemaJsons() throws Exception {
URL resource1 = DownloadServiceTest.class.getResource("hudson.plugins.cmake.CmakeInstaller1.json");
URL resource2 = DownloadServiceTest.class.getResource("hudson.plugins.cmake.CmakeInstaller2.json");
JSONObject json1 = JSONObject.fromObject(DownloadService.loadJSON(resource1));
JSONObject json2 = JSONObject.fromObject(DownloadService.loadJSON(resource2));
List<JSONObject> jsonObjectList = new ArrayList<>();
jsonObjectList.add(json1);
jsonObjectList.add(json2);
Downloadable downloadable = new GenericDownloadFromUrlInstaller.DescriptorImpl().createDownloadable();
JSONObject reducedJson = downloadable.reduce(jsonObjectList);
URL expectedResult = DownloadServiceTest.class.getResource("hudson.plugins.cmake.CmakeInstallerResult.json");
JSONObject expectedResultJson = JSONObject.fromObject(DownloadService.loadJSON(expectedResult));
assertEquals(reducedJson, expectedResultJson);
}

private static class GenericDownloadFromUrlInstaller extends DownloadFromUrlInstaller {
protected GenericDownloadFromUrlInstaller(String id) {
super(id);
}

public static final class DescriptorImpl extends DownloadFromUrlInstaller.DescriptorImpl<Maven.MavenInstaller> {
public String getDisplayName() {
return "";
}

@Override
public boolean isApplicable(Class<? extends ToolInstallation> toolType) {
return true;
}
}
}
}
@@ -0,0 +1,54 @@
downloadService.post('hudson.plugins.cmake.CmakeInstaller',{"list": [
{
"id": "3.4.2",
"name": "3.4.2",
"variants": [
{
"arch": "x86",
"os": "win32",
"url": "https://cmake.org/files/v3.4/cmake-3.4.2-win32-x86.zip"
},
{
"arch": "x86_64",
"os": "Linux",
"url": "https://cmake.org/files/v3.4/cmake-3.4.2-Linux-x86_64.tar.gz"
},
{
"arch": "i386",
"os": "Linux",
"url": "https://cmake.org/files/v3.4/cmake-3.4.2-Linux-i386.tar.gz"
},
{
"arch": "x86_64",
"os": "Darwin",
"url": "https://cmake.org/files/v3.4/cmake-3.4.2-Darwin-x86_64.tar.gz"
}
]
},
{
"id": "3.4.1",
"name": "3.4.1",
"variants": [
{
"arch": "x86",
"os": "win32",
"url": "https://cmake.org/files/v3.4/cmake-3.4.1-win32-x86.zip"
},
{
"arch": "x86_64",
"os": "Linux",
"url": "https://cmake.org/files/v3.4/cmake-3.4.1-Linux-x86_64.tar.gz"
},
{
"arch": "i386",
"os": "Linux",
"url": "https://cmake.org/files/v3.4/cmake-3.4.1-Linux-i386.tar.gz"
},
{
"arch": "x86_64",
"os": "Darwin",
"url": "https://cmake.org/files/v3.4/cmake-3.4.1-Darwin-x86_64.tar.gz"
}
]
}
]})
@@ -0,0 +1,48 @@
downloadService.post('hudson.plugins.cmake.CmakeInstaller',{"list": [
{
"id": "2.6.1",
"name": "2.6.1",
"variants": [
{
"arch": "x86",
"os": "win32",
"url": "https://cmake.org/files/v2.6/cmake-2.6.1-win32-x86.zip"
},
{
"arch": "sparc",
"os": "SunOS",
"url": "https://cmake.org/files/v2.6/cmake-2.6.1-SunOS-sparc.tar.gz"
},
{
"arch": "i386",
"os": "Linux",
"url": "https://cmake.org/files/v2.6/cmake-2.6.1-Linux-i386.tar.gz"
},
{
"arch": "n32",
"os": "IRIX64",
"url": "https://cmake.org/files/v2.6/cmake-2.6.1-IRIX64-n32.tar.gz"
},
{
"arch": "64",
"os": "IRIX64",
"url": "https://cmake.org/files/v2.6/cmake-2.6.1-IRIX64-64.tar.gz"
},
{
"arch": "9000_785",
"os": "HP-UX",
"url": "https://cmake.org/files/v2.6/cmake-2.6.1-HP-UX-9000_785.tar.gz"
},
{
"arch": "universal",
"os": "Darwin",
"url": "https://cmake.org/files/v2.6/cmake-2.6.1-Darwin-universal.tar.gz"
},
{
"arch": "powerpc",
"os": "AIX",
"url": "https://cmake.org/files/v2.6/cmake-2.6.1-AIX-powerpc.tar.gz"
}
]
}
]})
@@ -0,0 +1,54 @@
downloadService.post('hudson.plugins.cmake.CmakeInstaller',{"list": [
{
"id": "3.4.2",
"name": "3.4.2",
"variants": [
{
"arch": "x86",
"os": "win32",
"url": "https://cmake.org/files/v3.4/cmake-3.4.2-win32-x86.zip"
},
{
"arch": "x86_64",
"os": "Linux",
"url": "https://cmake.org/files/v3.4/cmake-3.4.2-Linux-x86_64.tar.gz"
},
{
"arch": "i386",
"os": "Linux",
"url": "https://cmake.org/files/v3.4/cmake-3.4.2-Linux-i386.tar.gz"
},
{
"arch": "x86_64",
"os": "Darwin",
"url": "https://cmake.org/files/v3.4/cmake-3.4.2-Darwin-x86_64.tar.gz"
}
]
},
{
"id": "3.4.1",
"name": "3.4.1",
"variants": [
{
"arch": "x86",
"os": "win32",
"url": "https://cmake.org/files/v3.4/cmake-3.4.1-win32-x86.zip"
},
{
"arch": "x86_64",
"os": "Linux",
"url": "https://cmake.org/files/v3.4/cmake-3.4.1-Linux-x86_64.tar.gz"
},
{
"arch": "i386",
"os": "Linux",
"url": "https://cmake.org/files/v3.4/cmake-3.4.1-Linux-i386.tar.gz"
},
{
"arch": "x86_64",
"os": "Darwin",
"url": "https://cmake.org/files/v3.4/cmake-3.4.1-Darwin-x86_64.tar.gz"
}
]
}
]})

1 comment on commit e7f8814

@dirtyharrycallahan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps some typos isDefualtSchema instead of isDefaultSchema?

Please sign in to comment.