Skip to content

Commit

Permalink
Fixed #215
Browse files Browse the repository at this point in the history
 o Added JenkinsVersion which is capable of
   comparing different versions correctly.
   The implementation is taken from the
   Maven project which contains a class
   ComparableVersion which handled everything
   I need here.
  • Loading branch information
khmarbaise committed Dec 11, 2016
1 parent c596050 commit 344b791
Show file tree
Hide file tree
Showing 9 changed files with 827 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ target
.classpath
.project
.settings
test-output
25 changes: 25 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@

### API Changes

* [Fixed Issue 215][issue-215]

The JenkinsServer class will return `JenkinsVersion` instead of String if you
call `getJenkinsVersion()`.

```java
public class JenkinsVersion ... {
public boolean isGreaterThan(String version);
public boolean isGreaterOrEqual(String version);
public boolean isLessThan(String version);
public boolean isLessOrEqual(String version);
public boolean isEqualTo(String version);
}
```

The `JenkinsVersion` class can be used to compare different versions with
each other.

```java
JenkinsVersion jv = new JenkinsVersion("1.651.1");
assertThat(jv.isGreaterThan("1.651.1")).isFalse();
```


* [Fixed issue 184][issue-184]

Based on the differences between getting a TestReport for a MavenJob type and
Expand Down Expand Up @@ -916,6 +940,7 @@ TestReport testReport = mavenJob.getLastSuccessfulBuild().getTestReport();
[issue-207]: https://github.com/jenkinsci/java-client-api/issues/207
[issue-209]: https://github.com/jenkinsci/java-client-api/issues/209
[issue-211]: https://github.com/jenkinsci/java-client-api/issues/211
[issue-215]: https://github.com/jenkinsci/java-client-api/issues/215
[pull-123]: https://github.com/jenkinsci/java-client-api/pull/123
[pull-149]: https://github.com/jenkinsci/java-client-api/pull/149
[pull-158]: https://github.com/jenkinsci/java-client-api/pull/158
Expand Down
2 changes: 1 addition & 1 deletion jenkins-client-it-docker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
</plugins>
</build>
<properties>
<docker.container.network>http://192.168.99.100:8080</docker.container.network>
<docker.container.network>http://127.0.0.1:8080</docker.container.network>
</properties>
<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,31 @@ public void beforeMethod() throws IOException {
jobXml = jenkinsServer.getJobXml("test");
}

private static final String[] CONFIG_XML = { "<?xml version='1.0' encoding='UTF-8'?>", "<project>", " <actions/>",
" <description>This is the description with umlauts äöü</description>",
" <keepDependencies>false</keepDependencies>", " <properties/>", " <scm class=\"hudson.scm.NullSCM\"/>",
" <canRoam>true</canRoam>", " <disabled>false</disabled>",
" <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>",
" <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>", " <triggers/>",
" <concurrentBuild>false</concurrentBuild>", " <builders>", " <hudson.tasks.Shell>",
" <command>echo &quot;test&quot;</command>", " </hudson.tasks.Shell>", " </builders>",
" <publishers/>", " <buildWrappers/>", "</project>" };
//@formatter:off
private static final String[] CONFIG_XML = {
"<?xml version='1.0' encoding='UTF-8'?>",
"<project>",
" <actions/>",
" <description>This is the description with umlauts äöü</description>",
" <keepDependencies>false</keepDependencies>",
" <properties/>",
" <scm class=\"hudson.scm.NullSCM\"/>",
" <canRoam>true</canRoam>",
" <disabled>false</disabled>",
" <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>",
" <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>",
" <triggers/>",
" <concurrentBuild>false</concurrentBuild>",
" <builders>",
" <hudson.tasks.Shell>",
" <command>echo &quot;test&quot;</command>",
" </hudson.tasks.Shell>",
" </builders>",
" <publishers/>",
" <buildWrappers/>",
"</project>"
};
//@formatter:on

@Test
public void getJobXmlShouldReturnTheExpectedConfigXml() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import org.testng.SkipException;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.offbytwo.jenkins.helper.JenkinsVersion;
import com.offbytwo.jenkins.model.Plugin;
import com.offbytwo.jenkins.model.PluginManager;

Expand All @@ -26,18 +26,17 @@ public void beforeMethod() throws IOException {
@Test
public void getPluginsShouldReturn9ForJenkins20() {
// TODO: Check why there is such a difference in the number of Plugins?
if (!jenkinsServer.getVersion().equals("2.0")) {
throw new SkipException("Not Version 2.0");
if (jenkinsServer.getVersion().isLessThan("2.0")) {
throw new SkipException("Not Version 2.0 (" + jenkinsServer.getVersion() + ")");
}
assertThat(pluginManager.getPlugins()).hasSize(9);
}

@Test
public void getPluginsShouldReturn27ForJenkins1651() {
List<String> asList = Arrays.asList("1.651", "1.651.1", "1.651.2", "1.651.3");
// TODO: Check why there is such a difference in the number of Plugins?
if (!asList.contains(jenkinsServer.getVersion())) {
throw new SkipException("Not Version 1.651");
JenkinsVersion jv = jenkinsServer.getVersion();
if (jv.isLessThan("1.651") && jv.isGreaterThan("1.651.3")) {
throw new SkipException("Not Version 1.651 (" + jv.toString() + ")");
}
assertThat(pluginManager.getPlugins()).hasSize(27);
}
Expand All @@ -52,8 +51,8 @@ private Plugin createPlugin(String shortName, String version) {
@Test
public void getPluginsShouldReturnTheListOfInstalledPluginsForJenkins20() {

if (!jenkinsServer.getVersion().equals("2.0")) {
throw new SkipException("Not Version 2.0");
if (jenkinsServer.getVersion().isLessThan("2.0")) {
throw new SkipException("Not Version 2.0 (" + jenkinsServer.getVersion() + ")");
}

// TODO: The list of plugins is contained in the plugin.txt
Expand Down Expand Up @@ -91,12 +90,12 @@ public void getPluginsShouldReturnTheListOfInstalledPluginsForJenkins20() {

@Test
public void getPluginsShouldReturnTheListOfInstalledPluginsFor1651() {
List<String> asList = Arrays.asList("1.651", "1.651.1", "1.651.2", "1.651.3");
JenkinsVersion jv = jenkinsServer.getVersion();
if (jv.isLessThan("1.651") && jv.isGreaterThan("1.651.3")) {
throw new SkipException("Not Version 1.651 (" + jv + ")");
}

// TODO: Check why there is such a difference in the number of Plugins?
if (!asList.contains(jenkinsServer.getVersion())) {
throw new SkipException("Not Version 1.651");
}
// TODO: The list of plugins is contained in the plugin.txt
// which should be read and used as base of comparison.
// instead of maintaining at two locations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.common.collect.Maps;
import com.offbytwo.jenkins.client.JenkinsHttpClient;
import com.offbytwo.jenkins.client.util.EncodingUtils;
import com.offbytwo.jenkins.helper.JenkinsVersion;
import com.offbytwo.jenkins.model.Build;
import com.offbytwo.jenkins.model.Computer;
import com.offbytwo.jenkins.model.ComputerSet;
Expand Down Expand Up @@ -100,15 +101,16 @@ public boolean isRunning() {
}

/**
* @return The Jenkins version.
* @return {@link JenkinsVersion}
*/
public String getVersion() {
public JenkinsVersion getVersion() {
if (client.getJenkinsVersion().isEmpty()) {
// Force a request to get at least once
// HttpHeader
isRunning();
}
return client.getJenkinsVersion();
JenkinsVersion jv = new JenkinsVersion(client.getJenkinsVersion());
return jv;
}

/**
Expand Down
Loading

0 comments on commit 344b791

Please sign in to comment.