Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Anathema reads the latest version from github tags #242

Merged
merged 1 commit into from

1 participant

@UrsKR
Owner

As discussed in anathema/anathema.github.com#7, this serves to simplify our distribution process.
Instead of reading the latest version from a file we manually update, comparing the build dates, Anathema now parses the tags in the github repository and determines the highest version number.

Im ambivalent about this change, because on the one hand, it makes releases way easier without complicating our process or polluting our repository, but on the other hand, it adds a new dependency, the github API.

I'll leave this open for a day or two and wait for comments.

@UrsKR UrsKR referenced this pull request in anathema/anathema.github.com
Closed

Find out latest version and release date automatically #7

@UrsKR UrsKR merged commit 70f5c72 into master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 26, 2012
  1. @UrsKR
This page is out of date. Refresh to see the latest.
Showing with 399 additions and 231 deletions.
  1. +0 −1  Character_Equipment_Impl/build.gradle
  2. +0 −1  Magic_Description/build.gradle
  3. +1 −0  Platform/build.gradle
  4. +12 −8 Platform/src/net/sf/anathema/framework/Version.java
  5. +1 −1  Platform/src/net/sf/anathema/framework/module/AnathemaCoreMenu.java
  6. +0 −95 Platform/src/net/sf/anathema/framework/presenter/action/menu/help/UpdateChecker.java
  7. +48 −48 ...rm/src/net/sf/anathema/framework/presenter/action/menu/help/{ → updatecheck}/AnathemaUpdateAction.java
  8. +15 −0 Platform/src/net/sf/anathema/framework/presenter/action/menu/help/updatecheck/JsonTagLoader.java
  9. +6 −0 Platform/src/net/sf/anathema/framework/presenter/action/menu/help/updatecheck/Tag.java
  10. +24 −0 Platform/src/net/sf/anathema/framework/presenter/action/menu/help/updatecheck/TagVersionFinder.java
  11. +94 −0 Platform/src/net/sf/anathema/framework/presenter/action/menu/help/updatecheck/UpdateChecker.java
  12. +84 −77 Platform/src/net/sf/anathema/framework/presenter/action/menu/help/{ → updatecheck}/UpdateDialogPage.java
  13. +24 −0 Platform/src/net/sf/anathema/framework/presenter/action/menu/help/updatecheck/UrlLoader.java
  14. +41 −0 Platform/test/net/sf/anathema/framework/presenter/action/menu/help/updatecheck/JsonTagLoaderTest.java
  15. +49 −0 Platform/test/net/sf/anathema/framework/presenter/action/menu/help/updatecheck/TagVersionFinderTest.java
View
1  Character_Equipment_Impl/build.gradle
@@ -3,7 +3,6 @@ dependencies {
compile project(':Character_Library')
compile project(':Character_Solar')
compile project(':Character_Reporting')
- compile 'com.google.code.gson:gson:2.1'
testCompile parent.ext.testDependencies
testCompile project(path: ':Lib', configuration: 'tests')
testCompile project(path: ':Character_Generic', configuration: 'tests')
View
1  Magic_Description/build.gradle
@@ -1,7 +1,6 @@
dependencies{
compile project(':Character_Main')
compile project(':Character_Generic')
- compile 'com.google.code.gson:gson:2.1'
testCompile parent.ext.testDependencies
}
sourceSets{
View
1  Platform/build.gradle
@@ -4,6 +4,7 @@ dependencies {
compile 'org.reflections:reflections:0.9.7'
compile 'org.slf4j:slf4j-simple:1.6.4'
compile 'com.itextpdf:itextpdf:5.2.0'
+ compile 'com.google.code.gson:gson:2.1'
compile project(':Lib_Workflow')
compile project(':Lib_Gui')
testCompile parent.ext.testDependencies
View
20 Platform/src/net/sf/anathema/framework/Version.java
@@ -5,6 +5,18 @@
public class Version implements Comparable<Version> {
+ public static boolean isParseable(String versionString) {
+ try {
+ String[] split = versionString.split("\\."); //$NON-NLS-1$ //$NON-NLS-2$
+ for (String numbers : split) {
+ Integer.valueOf(numbers);
+ }
+ return true;
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
private int majorVersion;
private int minorVersion;
private int revision;
@@ -41,14 +53,6 @@ private void parseVersion(String string) {
}
}
- public void updateTo(Version version) {
- if (compareTo(version) < 0) {
- majorVersion = version.majorVersion;
- minorVersion = version.minorVersion;
- revision = version.revision;
- }
- }
-
@Override
public int compareTo(Version version) {
if (version.getClass() != getClass()) {
View
2  Platform/src/net/sf/anathema/framework/module/AnathemaCoreMenu.java
@@ -6,7 +6,7 @@
import net.sf.anathema.framework.presenter.action.AnathemaLoadAction;
import net.sf.anathema.framework.presenter.action.AnathemaNewAction;
import net.sf.anathema.framework.presenter.action.menu.help.AnathemaAboutAction;
-import net.sf.anathema.framework.presenter.action.menu.help.AnathemaUpdateAction;
+import net.sf.anathema.framework.presenter.action.menu.help.updatecheck.AnathemaUpdateAction;
import net.sf.anathema.framework.presenter.action.preferences.AnathemaPreferencesAction;
import net.sf.anathema.framework.presenter.action.preferences.IPreferencesElement;
import net.sf.anathema.framework.presenter.itemmanagement.SelectedItemCloseAction;
View
95 Platform/src/net/sf/anathema/framework/presenter/action/menu/help/UpdateChecker.java
@@ -1,95 +0,0 @@
-package net.sf.anathema.framework.presenter.action.menu.help;
-
-import net.sf.anathema.lib.control.IChangeListener;
-import net.sf.anathema.lib.message.MessageType;
-import net.sf.anathema.lib.resources.IResources;
-import org.jmock.example.announcer.Announcer;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.util.Date;
-import java.util.Locale;
-
-public class UpdateChecker implements IUpdateChecker {
-
- public static final String Update_Url = "http://anathema.github.com/version/version.txt";
- private final IResources resources;
- private final Announcer<IChangeListener> control = Announcer.to(IChangeListener.class);
- private IMessageData data;
- private String remoteVersion;
- private Boolean success = null;
-
- public UpdateChecker(IResources resources) {
- this.resources = resources;
- }
-
- public void checkForUpdates() {
- try {
- String response = getVersionData();
- String[] split = response.split("#"); //$NON-NLS-1$
- boolean newVersionAvailable = remoteIsNewer(split[1]);
- this.remoteVersion = split[0];
- if (newVersionAvailable) {
- this.success = true;
- this.data = new MessageData("Help.UpdateCheck.Outdated", MessageType.INFORMATION); //$NON-NLS-1$
- }
- else {
- this.success = true;
- this.data = new MessageData("Help.UpdateCheck.UpToDate", MessageType.INFORMATION); //$NON-NLS-1$
- }
- }
- catch (IOException e) {
- this.success = false;
- this.data = new MessageData("Help.UpdateCheck.IOException", MessageType.ERROR); //$NON-NLS-1$
- }
- catch (Exception e) {
- this.success = false;
- this.data = new MessageData("Help.UpdateCheck.GeneralException", MessageType.ERROR); //$NON-NLS-1$
- }
- control.announce().changeOccurred();
- }
-
- @Override
- public Boolean isCheckSuccessful() {
- return success;
- }
-
- @Override
- public String getCurrentVersion() {
- return resources.getString("Anathema.Version.Numeric"); //$NON-NLS-1$
- }
-
- @Override
- public String getLatestVersion() {
- return remoteVersion;
- }
-
- @Override
- public IMessageData getMessageData() {
- return data;
- }
-
- private boolean remoteIsNewer(String string) throws ParseException {
- DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH);
- Date currentVersionDate = dateFormat.parse(resources.getString("Anathema.Version.Built")); //$NON-NLS-1$
- Date remoteVersionDate = dateFormat.parse(string);
- return currentVersionDate.compareTo(remoteVersionDate) < 0;
- }
-
- private String getVersionData() throws IOException {
- URL url = new URL(Update_Url); //$NON-NLS-1$
- BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
- String response = in.readLine();
- in.close();
- return response;
- }
-
- @Override
- public void addDataChangedListener(IChangeListener listener) {
- control.addListener(listener);
- }
-}
View
96 ...ction/menu/help/AnathemaUpdateAction.java → ...elp/updatecheck/AnathemaUpdateAction.java
@@ -1,49 +1,49 @@
-package net.sf.anathema.framework.presenter.action.menu.help;
-
-import net.sf.anathema.lib.control.IChangeListener;
-import net.sf.anathema.lib.gui.action.SmartAction;
-import net.sf.anathema.lib.gui.dialog.userdialog.UserDialog;
-import net.sf.anathema.lib.gui.dialog.userdialog.page.IDialogPage;
-import net.sf.anathema.lib.resources.IResources;
-
-import javax.swing.Action;
-import java.awt.Component;
-
-public class AnathemaUpdateAction extends SmartAction {
-
- private static final long serialVersionUID = -9188349625150813107L;
-
- public static Action createMenuAction(IResources resources) {
- AnathemaUpdateAction action = new AnathemaUpdateAction(resources);
- action.setName(resources.getString("Help.UpdateCheck.Title")); //$NON-NLS-1$
- return action;
- }
-
- private IResources resources;
-
- public AnathemaUpdateAction(IResources resources) {
- this.resources = resources;
- }
-
- @Override
- protected void execute(Component parentComponent) {
- final UpdateChecker updateChecker = new UpdateChecker(resources);
- IDialogPage page = new UpdateDialogPage(resources, updateChecker);
- final UserDialog dialog = new UserDialog(parentComponent, page);
- dialog.getDialog().setModal(false);
- updateChecker.addDataChangedListener(new IChangeListener() {
- @Override
- public void changeOccurred() {
- dialog.updateDescription();
- dialog.getDialogControl().checkInputValid();
- }
- });
- dialog.show();
- new Thread(new Runnable() {
- @Override
- public void run() {
- updateChecker.checkForUpdates();
- }
- }).start();
- }
+package net.sf.anathema.framework.presenter.action.menu.help.updatecheck;
+
+import net.sf.anathema.lib.control.IChangeListener;
+import net.sf.anathema.lib.gui.action.SmartAction;
+import net.sf.anathema.lib.gui.dialog.userdialog.UserDialog;
+import net.sf.anathema.lib.gui.dialog.userdialog.page.IDialogPage;
+import net.sf.anathema.lib.resources.IResources;
+
+import javax.swing.Action;
+import java.awt.Component;
+
+public class AnathemaUpdateAction extends SmartAction {
+
+ private static final long serialVersionUID = -9188349625150813107L;
+
+ public static Action createMenuAction(IResources resources) {
+ AnathemaUpdateAction action = new AnathemaUpdateAction(resources);
+ action.setName(resources.getString("Help.UpdateCheck.Title")); //$NON-NLS-1$
+ return action;
+ }
+
+ private IResources resources;
+
+ public AnathemaUpdateAction(IResources resources) {
+ this.resources = resources;
+ }
+
+ @Override
+ protected void execute(Component parentComponent) {
+ final UpdateChecker updateChecker = new UpdateChecker(resources);
+ IDialogPage page = new UpdateDialogPage(resources, updateChecker);
+ final UserDialog dialog = new UserDialog(parentComponent, page);
+ dialog.getDialog().setModal(false);
+ updateChecker.addDataChangedListener(new IChangeListener() {
+ @Override
+ public void changeOccurred() {
+ dialog.updateDescription();
+ dialog.getDialogControl().checkInputValid();
+ }
+ });
+ dialog.show();
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ updateChecker.checkForUpdates();
+ }
+ }).start();
+ }
}
View
15 ...m/src/net/sf/anathema/framework/presenter/action/menu/help/updatecheck/JsonTagLoader.java
@@ -0,0 +1,15 @@
+package net.sf.anathema.framework.presenter.action.menu.help.updatecheck;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+
+import java.lang.reflect.Type;
+import java.util.List;
+
+public class JsonTagLoader {
+ public List<Tag> loadFrom(String json) {
+ Type type = new TypeToken<List<Tag>>() {
+ }.getType();
+ return new Gson().fromJson(json, type);
+ }
+}
View
6 Platform/src/net/sf/anathema/framework/presenter/action/menu/help/updatecheck/Tag.java
@@ -0,0 +1,6 @@
+package net.sf.anathema.framework.presenter.action.menu.help.updatecheck;
+
+public class Tag {
+
+ public String name;
+}
View
24 ...rc/net/sf/anathema/framework/presenter/action/menu/help/updatecheck/TagVersionFinder.java
@@ -0,0 +1,24 @@
+package net.sf.anathema.framework.presenter.action.menu.help.updatecheck;
+
+import net.sf.anathema.framework.Version;
+
+import java.util.List;
+
+public class TagVersionFinder {
+
+ public static final Version Unidentified_Version = new Version(0, 0, 0);
+
+ public Version findLatestTaggedVersion(List<Tag> tags) {
+ Version latestVersion = Unidentified_Version;
+ for (Tag tag : tags) {
+ String versionString = tag.name.replace("v", "");
+ if (Version.isParseable(versionString)) {
+ Version version = new Version(versionString);
+ if (version.isLargerThan(latestVersion)) {
+ latestVersion = version;
+ }
+ }
+ }
+ return latestVersion;
+ }
+}
View
94 ...m/src/net/sf/anathema/framework/presenter/action/menu/help/updatecheck/UpdateChecker.java
@@ -0,0 +1,94 @@
+package net.sf.anathema.framework.presenter.action.menu.help.updatecheck;
+
+import net.sf.anathema.framework.Version;
+import net.sf.anathema.framework.presenter.action.menu.help.IMessageData;
+import net.sf.anathema.framework.presenter.action.menu.help.IUpdateChecker;
+import net.sf.anathema.framework.presenter.action.menu.help.MessageData;
+import net.sf.anathema.lib.control.IChangeListener;
+import net.sf.anathema.lib.resources.IResources;
+import org.jmock.example.announcer.Announcer;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.List;
+
+import static net.sf.anathema.lib.message.MessageType.ERROR;
+import static net.sf.anathema.lib.message.MessageType.INFORMATION;
+
+public class UpdateChecker implements IUpdateChecker {
+
+ public static final String Update_Url = "https://api.github.com/repos/anathema/anathema/tags";
+ private final Announcer<IChangeListener> control = Announcer.to(IChangeListener.class);
+ private final IResources resources;
+ private IMessageData data;
+ private Version remoteVersion = TagVersionFinder.Unidentified_Version;
+ private Boolean success;
+
+ public UpdateChecker(IResources resources) {
+ this.resources = resources;
+ }
+
+ public void checkForUpdates() {
+ try {
+ String response = new UrlLoader(Update_Url).readAll();
+ List<Tag> tags = new JsonTagLoader().loadFrom(response);
+ this.remoteVersion = new TagVersionFinder().findLatestTaggedVersion(tags);
+ boolean couldNotDetermineVersion = remoteVersion == TagVersionFinder.Unidentified_Version;
+ if (couldNotDetermineVersion) {
+ setErrorState("Help.UpdateCheck.GeneralException");
+ } else {
+ boolean newVersionAvailable = remoteIsNewer(remoteVersion);
+ if (newVersionAvailable) {
+ setSuccessState("Help.UpdateCheck.Outdated");
+ } else {
+ setSuccessState("Help.UpdateCheck.UpToDate");
+ }
+ }
+ } catch (IOException e) {
+ setErrorState("Help.UpdateCheck.IOException");
+ } catch (Exception e) {
+ setErrorState("Help.UpdateCheck.GeneralException");
+ }
+ control.announce().changeOccurred();
+ }
+
+ private void setErrorState(String key) {
+ this.success = false;
+ this.data = new MessageData(key, ERROR);
+ }
+
+ private void setSuccessState(String key) {
+ this.success = true;
+ this.data = new MessageData(key, INFORMATION);
+ }
+
+ @Override
+ public Boolean isCheckSuccessful() {
+ return success;
+ }
+
+ @Override
+ public String getCurrentVersion() {
+ return resources.getString("Anathema.Version.Numeric"); //$NON-NLS-1$
+ }
+
+ @Override
+ public String getLatestVersion() {
+ return remoteVersion.asString();
+ }
+
+ @Override
+ public IMessageData getMessageData() {
+ return data;
+ }
+
+ private boolean remoteIsNewer(Version remoteVersion) throws ParseException {
+ Version currentVersion = new Version(getCurrentVersion());
+ return remoteVersion.isLargerThan(currentVersion);
+ }
+
+ @Override
+ public void addDataChangedListener(IChangeListener listener) {
+ control.addListener(listener);
+ }
+}
View
161 ...er/action/menu/help/UpdateDialogPage.java → ...nu/help/updatecheck/UpdateDialogPage.java
@@ -1,78 +1,85 @@
-package net.sf.anathema.framework.presenter.action.menu.help;
-
-import net.disy.commons.swing.layout.grid.GridDialogLayout;
-import net.disy.commons.swing.layout.grid.IGridDialogLayoutData;
-import net.sf.anathema.lib.control.IChangeListener;
-import net.sf.anathema.lib.gui.dialog.userdialog.page.AbstractDialogPage;
-import net.sf.anathema.lib.message.BasicMessage;
-import net.sf.anathema.lib.message.IBasicMessage;
-import net.sf.anathema.lib.resources.IResources;
-
-import javax.swing.JComponent;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-
-public class UpdateDialogPage extends AbstractDialogPage {
-
- private final IResources resources;
- private final IUpdateChecker checker;
- private final JLabel latestVersionLabel = new JLabel("?.??"); //$NON-NLS-1$
-
- public UpdateDialogPage(IResources resources, IUpdateChecker checker) {
- super(resources.getString("Help.UpdateCheck.Checking")); //$NON-NLS-1$
- this.resources = resources;
- this.checker = checker;
- checker.addDataChangedListener(new IChangeListener() {
- @Override
- public void changeOccurred() {
- updateLatestVersionLabel();
- }
- });
- updateLatestVersionLabel();
- }
-
- private void updateLatestVersionLabel() {
- String latestVersion = checker.getLatestVersion();
- latestVersionLabel.setText(latestVersion != null ? latestVersion : "?.??"); //$NON-NLS-1$
- }
-
- @Override
- public JComponent createContent() {
- JPanel panel = new JPanel(new GridDialogLayout(2, false));
- panel.add(new JLabel(getString("Help.UpdateCheck.CurrentVersion") + ":"), IGridDialogLayoutData.DEFAULT); //$NON-NLS-1$ //$NON-NLS-2$
- panel.add(new JLabel(checker.getCurrentVersion()), IGridDialogLayoutData.DEFAULT);
- panel.add(new JLabel(getString("Help.UpdateCheck.LatestVersion") + ":"), IGridDialogLayoutData.DEFAULT); //$NON-NLS-1$ //$NON-NLS-2$
- panel.add(latestVersionLabel, IGridDialogLayoutData.DEFAULT);
- return panel;
- }
-
- @Override
- public IBasicMessage createCurrentMessage() {
- IMessageData messageData = checker.getMessageData();
- if (messageData == null) {
- return getDefaultMessage();
- }
- return new BasicMessage(getString(messageData.getKey()), messageData.getType());
- }
-
- @Override
- public String getDescription() {
- Boolean success = checker.isCheckSuccessful();
- if (success == null) {
- return getString("Help.UpdateCheck.Checking"); //$NON-NLS-1$
- }
- else if (success) {
- return getString("Help.UpdateCheck.Success"); //$NON-NLS-1$
- }
- return getString("Help.UpdateCheck.Failure"); //$NON-NLS-1$
- }
-
- @Override
- public String getTitle() {
- return getString("Help.UpdateCheck.Title"); //$NON-NLS-1$
- }
-
- private String getString(String key) {
- return resources.getString(key);
- }
+package net.sf.anathema.framework.presenter.action.menu.help.updatecheck;
+
+import net.disy.commons.swing.layout.grid.GridDialogLayout;
+import net.disy.commons.swing.layout.grid.IGridDialogLayoutData;
+import net.sf.anathema.framework.presenter.action.menu.help.IMessageData;
+import net.sf.anathema.framework.presenter.action.menu.help.IUpdateChecker;
+import net.sf.anathema.lib.control.IChangeListener;
+import net.sf.anathema.lib.gui.dialog.userdialog.page.AbstractDialogPage;
+import net.sf.anathema.lib.message.BasicMessage;
+import net.sf.anathema.lib.message.IBasicMessage;
+import net.sf.anathema.lib.resources.IResources;
+
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+public class UpdateDialogPage extends AbstractDialogPage {
+
+ private final IResources resources;
+ private final IUpdateChecker checker;
+ private final JLabel latestVersionLabel = new JLabel("?.??"); //$NON-NLS-1$
+
+ public UpdateDialogPage(IResources resources, IUpdateChecker checker) {
+ super(resources.getString("Help.UpdateCheck.Checking")); //$NON-NLS-1$
+ this.resources = resources;
+ this.checker = checker;
+ checker.addDataChangedListener(new IChangeListener() {
+ @Override
+ public void changeOccurred() {
+ updateLatestVersionLabel();
+ }
+ });
+ updateLatestVersionLabel();
+ }
+
+ private void updateLatestVersionLabel() {
+ Boolean checkSuccessful = checker.isCheckSuccessful();
+ if (checkSuccessful != null && checkSuccessful) {
+ latestVersionLabel.setText(checker.getLatestVersion());
+ } else {
+ latestVersionLabel.setText("?.?.?");
+ }
+ }
+
+ @Override
+ public JComponent createContent() {
+ JPanel panel = new JPanel(new GridDialogLayout(2, false));
+ panel.add(new JLabel(getString("Help.UpdateCheck.CurrentVersion") + ":"),
+ IGridDialogLayoutData.DEFAULT); //$NON-NLS-1$ //$NON-NLS-2$
+ panel.add(new JLabel(checker.getCurrentVersion()), IGridDialogLayoutData.DEFAULT);
+ panel.add(new JLabel(getString("Help.UpdateCheck.LatestVersion") + ":"),
+ IGridDialogLayoutData.DEFAULT); //$NON-NLS-1$ //$NON-NLS-2$
+ panel.add(latestVersionLabel, IGridDialogLayoutData.DEFAULT);
+ return panel;
+ }
+
+ @Override
+ public IBasicMessage createCurrentMessage() {
+ IMessageData messageData = checker.getMessageData();
+ if (messageData == null) {
+ return getDefaultMessage();
+ }
+ return new BasicMessage(getString(messageData.getKey()), messageData.getType());
+ }
+
+ @Override
+ public String getDescription() {
+ Boolean success = checker.isCheckSuccessful();
+ if (success == null) {
+ return getString("Help.UpdateCheck.Checking"); //$NON-NLS-1$
+ } else if (success) {
+ return getString("Help.UpdateCheck.Success"); //$NON-NLS-1$
+ }
+ return getString("Help.UpdateCheck.Failure"); //$NON-NLS-1$
+ }
+
+ @Override
+ public String getTitle() {
+ return getString("Help.UpdateCheck.Title"); //$NON-NLS-1$
+ }
+
+ private String getString(String key) {
+ return resources.getString(key);
+ }
}
View
24 Platform/src/net/sf/anathema/framework/presenter/action/menu/help/updatecheck/UrlLoader.java
@@ -0,0 +1,24 @@
+package net.sf.anathema.framework.presenter.action.menu.help.updatecheck;
+
+import org.apache.commons.io.IOUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+public class UrlLoader {
+
+ private final String urlString;
+
+ public UrlLoader(String url) {
+ this.urlString = url;
+ }
+
+ public String readAll() throws IOException {
+ URL url = new URL(urlString);
+ InputStream input = url.openStream();
+ String response = IOUtils.toString(input);
+ input.close();
+ return response;
+ }
+}
View
41 ...t/net/sf/anathema/framework/presenter/action/menu/help/updatecheck/JsonTagLoaderTest.java
@@ -0,0 +1,41 @@
+package net.sf.anathema.framework.presenter.action.menu.help.updatecheck;
+
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class JsonTagLoaderTest {
+
+ @Test
+ public void producesTag() throws Exception {
+ String json = "[{}]";
+ List<Tag> tags = new JsonTagLoader().loadFrom(json);
+ assertThat(tags.size(), is(1));
+ }
+
+ @Test
+ public void producesTagWithName() throws Exception {
+ String json = "[{\"name\":\"v4.2.1\"}]";
+ List<Tag> tags = new JsonTagLoader().loadFrom(json);
+ assertThat(tags.get(0).name, is("v4.2.1"));
+ }
+
+ @Test
+ public void producesTagFromFullCode() throws Exception {
+ String json = "[\n" +
+ " {\n" +
+ " \"commit\": {\n" +
+ " \"sha\": \"e986584d8aac4f035511f8ea68c495881582a9a3\",\n" +
+ " \"url\": \"https://api.github.com/repos/anathema/anathema/commits/e986584d8aac4f035511f8ea68c495881582a9a3\"\n" +
+ " },\n" +
+ " \"zipball_url\": \"https://github.com/anathema/anathema/zipball/v4.1.0\",\n" +
+ " \"tarball_url\": \"https://github.com/anathema/anathema/tarball/v4.1.0\",\n" +
+ " \"name\": \"v4.1.0\"\n" +
+ " }]";
+ List<Tag> tags = new JsonTagLoader().loadFrom(json);
+ assertThat(tags.get(0).name, is("v4.1.0"));
+ }
+}
View
49 ...et/sf/anathema/framework/presenter/action/menu/help/updatecheck/TagVersionFinderTest.java
@@ -0,0 +1,49 @@
+package net.sf.anathema.framework.presenter.action.menu.help.updatecheck;
+
+import net.sf.anathema.framework.Version;
+import org.junit.Test;
+
+import java.util.List;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class TagVersionFinderTest {
+
+ @Test
+ public void returnsVersionFromTag() throws Exception {
+ TagVersionFinder finder = new TagVersionFinder();
+ Tag tag = createTag("v4.1.0");
+ List<Tag> tags = newArrayList(tag);
+ Version version = finder.findLatestTaggedVersion(tags);
+ assertThat(version.compareTo(new Version(4, 1, 0)), is(0));
+ }
+
+ @Test
+ public void returnsLatestVersionFromTag() throws Exception {
+ TagVersionFinder finder = new TagVersionFinder();
+ Tag tag410 = createTag("v4.1.0");
+ Tag tag411 = createTag("v4.1.1");
+ List<Tag> tags = newArrayList(tag410, tag411);
+ Version version = finder.findLatestTaggedVersion(tags);
+ assertThat(version.compareTo(new Version(4, 1, 1)), is(0));
+ }
+
+ @Test
+ public void ignoresNonVersionTags() throws Exception {
+ TagVersionFinder finder = new TagVersionFinder();
+ Tag tag410 = createTag("v4.1.0");
+ Tag tag411 = createTag("v4.1.1");
+ Tag tagIllegible = createTag("vwvvv");
+ List<Tag> tags = newArrayList(tag410, tag411, tagIllegible);
+ Version version = finder.findLatestTaggedVersion(tags);
+ assertThat(version.compareTo(new Version(4, 1, 1)), is(0));
+ }
+
+ private Tag createTag(String version) {
+ Tag tag410 = new Tag();
+ tag410.name = version;
+ return tag410;
+ }
+}
Something went wrong with that request. Please try again.