From 8b972204da64a5e6aa9196d4f1d9acd3677da0f7 Mon Sep 17 00:00:00 2001 From: vvdleun <22765050+vvdleun@users.noreply.github.com> Date: Wed, 15 May 2019 00:03:40 +0200 Subject: [PATCH] Fixed several bugs and worked around bugs in Golo compiler so that it compiles with Golo 3.3 final release --- build.gradle | 2 +- src/main/golo/include/maintypes/Song.golo | 2 +- .../golo/include/players/bluos/BluOsMonitor.golo | 2 +- .../include/players/bluos/BluOsStatusXMLParser.golo | 4 ++-- .../golo/include/players/heos/HeosSlaveMonitor.golo | 2 +- .../include/players/musiccast/MusicCastMonitor.golo | 12 ++++++++---- .../golo/include/threads/PlayerMonitorThread.golo | 4 ++-- src/main/golo/include/utils/SimpleXMLParser.golo | 4 ++-- ...sXMLParser.java => BluOsStatusXMLParserImpl.java} | 4 ++-- ...SimpleXMLParser.java => SimpleXMLParserImpl.java} | 4 ++-- ...Tests.java => BluOsStatusXMLParserImplTests.java} | 8 ++++---- 11 files changed, 26 insertions(+), 22 deletions(-) rename src/main/java/nl/vincentvanderleun/scrobbler/bluos/{BluOsStatusXMLParser.java => BluOsStatusXMLParserImpl.java} (98%) rename src/main/java/nl/vincentvanderleun/utils/{SimpleXMLParser.java => SimpleXMLParserImpl.java} (97%) rename src/test/java/nl/vincentvanderleun/scrobbler/bluos/{BluOsStatusXMLParserTests.java => BluOsStatusXMLParserImplTests.java} (90%) diff --git a/build.gradle b/build.gradle index dfa5120..7fdb707 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ repositories { } mainClassName = 'audiostreamerscrobbler.Audiostreamerscrobbler' -ext.goloDependency = 'org.eclipse.golo:golo:3.3.0-M1' +ext.goloDependency = 'org.eclipse.golo:golo:3.3.0' dependencies { golo goloDependency diff --git a/src/main/golo/include/maintypes/Song.golo b/src/main/golo/include/maintypes/Song.golo index ce91fdb..28d5611 100644 --- a/src/main/golo/include/maintypes/Song.golo +++ b/src/main/golo/include/maintypes/Song.golo @@ -1,4 +1,4 @@ -module audiostreamerscrobbler.maintypes.Song +module audiostreamerscrobbler.maintypes.SongType struct Song = { name, diff --git a/src/main/golo/include/players/bluos/BluOsMonitor.golo b/src/main/golo/include/players/bluos/BluOsMonitor.golo index dfd11ac..75c6a12 100644 --- a/src/main/golo/include/players/bluos/BluOsMonitor.golo +++ b/src/main/golo/include/players/bluos/BluOsMonitor.golo @@ -1,6 +1,6 @@ module audiostreamerscrobbler.players.bluos.BluOsMonitor -import audiostreamerscrobbler.maintypes.Song.types.Song +import audiostreamerscrobbler.maintypes.SongType.types.Song import audiostreamerscrobbler.players.bluos.BluOsStatusXMLParser import audiostreamerscrobbler.players.helpers.PollBasedMonitorHelper import audiostreamerscrobbler.threads.PlayerMonitorThreadTypes.types.MonitorThreadTypes diff --git a/src/main/golo/include/players/bluos/BluOsStatusXMLParser.golo b/src/main/golo/include/players/bluos/BluOsStatusXMLParser.golo index 2749add..c552852 100644 --- a/src/main/golo/include/players/bluos/BluOsStatusXMLParser.golo +++ b/src/main/golo/include/players/bluos/BluOsStatusXMLParser.golo @@ -1,6 +1,6 @@ module audiostreamerscrobbler.players.bluos.BluOsStatusXMLParser -import nl.vincentvanderleun.scrobbler.bluos.BluOsStatusXMLParser +import nl.vincentvanderleun.scrobbler.bluos.BluOsStatusXMLParserImpl struct BluOsStatus = { success, @@ -15,7 +15,7 @@ struct BluOsStatus = { } function createBluOsStatusXMLParser = { - let bluOsStatusParser = BluOsStatusXMLParser() + let bluOsStatusParser = BluOsStatusXMLParserImpl() let parser = DynamicObject("BluOsStatusXMLParser"): define("_bluOsStatusParser", bluOsStatusParser): diff --git a/src/main/golo/include/players/heos/HeosSlaveMonitor.golo b/src/main/golo/include/players/heos/HeosSlaveMonitor.golo index ca13308..d5dd7b4 100644 --- a/src/main/golo/include/players/heos/HeosSlaveMonitor.golo +++ b/src/main/golo/include/players/heos/HeosSlaveMonitor.golo @@ -1,6 +1,6 @@ module audiostreamerscrobbler.players.heos.HeosSlaveMonitor -import audiostreamerscrobbler.maintypes.Song +import audiostreamerscrobbler.maintypes.SongType.types.Song import audiostreamerscrobbler.players.heos.HeosConnectionSingleton import audiostreamerscrobbler.threads.PlayerMonitorThreadTypes.types.MonitorThreadTypes import audiostreamerscrobbler.utils.ThreadUtils diff --git a/src/main/golo/include/players/musiccast/MusicCastMonitor.golo b/src/main/golo/include/players/musiccast/MusicCastMonitor.golo index ebea79e..f181b51 100644 --- a/src/main/golo/include/players/musiccast/MusicCastMonitor.golo +++ b/src/main/golo/include/players/musiccast/MusicCastMonitor.golo @@ -1,6 +1,7 @@ module audiostreamerscrobbler.players.musiccast.MusicCastMonitor -import audiostreamerscrobbler.maintypes.{AppMetadata, Song} +import audiostreamerscrobbler.maintypes.AppMetadata +import audiostreamerscrobbler.maintypes.SongType.types.Song import audiostreamerscrobbler.threads.PlayerMonitorThreadTypes.types.MonitorThreadTypes import audiostreamerscrobbler.utils.{NetworkUtils, UrlUtils, ThreadUtils} @@ -76,13 +77,16 @@ local function _createAndRunThread = |monitor| { let status = JSON.parse(statusString) let netUsbStatus = status: get("netusb") + # println(netUsbStatus) if (netUsbStatus isnt null) { var song = null if (netUsbStatus: containsKey("play_info_updated")) { song = getAndRegisterCurrentStatus(monitor) } else if (netUsbStatus: containsKey("play_time")) { song = monitor: _song() - song: position(netUsbStatus: get("play_time"): intValue()) + if(song isnt null) { + song: position(netUsbStatus: get("play_time"): intValue()) + } } # Inform MonitorThread about status @@ -143,6 +147,7 @@ local function getAndRegisterCurrentStatus = |monitor| { monitor: _song(song) return song } catch (ex) { + throw(ex) monitor: _lastSuccess(false) } return null @@ -178,11 +183,10 @@ local function isPlayerPlaying = |playInfo| { } local function convertPlayInfoToSong = |playInfo| { - let song = Song( + return Song( playInfo: get("track"), playInfo: get("artist"), playInfo: get("album"), playInfo: get("play_time"): intValue(), playInfo: get("total_time"): intValue()) - return song } \ No newline at end of file diff --git a/src/main/golo/include/threads/PlayerMonitorThread.golo b/src/main/golo/include/threads/PlayerMonitorThread.golo index 84017ad..ae1e804 100644 --- a/src/main/golo/include/threads/PlayerMonitorThread.golo +++ b/src/main/golo/include/threads/PlayerMonitorThread.golo @@ -1,6 +1,6 @@ module audiostreamerscrobbler.threads.PlayerMonitorThread -import audiostreamerscrobbler.maintypes.Song +import audiostreamerscrobbler.maintypes.SongType import java.time.{Duration, Instant} @@ -89,7 +89,7 @@ local function monitorCallback = |monitorThread, monitorState| { } local function handleMonitorState = |monitorThread, monitorState| { - var action = monitorAction.NoAction() + var action = MonitorStateActions.NoAction() case { when monitorState: isMonitoring() { } diff --git a/src/main/golo/include/utils/SimpleXMLParser.golo b/src/main/golo/include/utils/SimpleXMLParser.golo index 38d1cd4..353798d 100644 --- a/src/main/golo/include/utils/SimpleXMLParser.golo +++ b/src/main/golo/include/utils/SimpleXMLParser.golo @@ -1,6 +1,6 @@ module audiostreamerscrobbler.utils.SimpleXMLParser -import nl.vincentvanderleun.utils.SimpleXMLParser +import nl.vincentvanderleun.utils.SimpleXMLParserImpl import nl.vincentvanderleun.utils.SimpleXMLParserCallback import gololang.Adapters @@ -12,7 +12,7 @@ union events = { } function createSimpleXMLParser = { - let xmlParser = SimpleXMLParser() + let xmlParser = SimpleXMLParserImpl() let parser = DynamicObject("SimpleXMLParser"): define("_xmlParser", xmlParser): diff --git a/src/main/java/nl/vincentvanderleun/scrobbler/bluos/BluOsStatusXMLParser.java b/src/main/java/nl/vincentvanderleun/scrobbler/bluos/BluOsStatusXMLParserImpl.java similarity index 98% rename from src/main/java/nl/vincentvanderleun/scrobbler/bluos/BluOsStatusXMLParser.java rename to src/main/java/nl/vincentvanderleun/scrobbler/bluos/BluOsStatusXMLParserImpl.java index 5743234..13c29fe 100644 --- a/src/main/java/nl/vincentvanderleun/scrobbler/bluos/BluOsStatusXMLParser.java +++ b/src/main/java/nl/vincentvanderleun/scrobbler/bluos/BluOsStatusXMLParserImpl.java @@ -15,7 +15,7 @@ import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; -public class BluOsStatusXMLParser { +public class BluOsStatusXMLParserImpl { private static final Set STATUS_XML_ELEMENTS = new HashSet<>(); private final SAXParser saxParser; @@ -31,7 +31,7 @@ public class BluOsStatusXMLParser { STATUS_XML_ELEMENTS.add("totlen"); } - public BluOsStatusXMLParser() { + public BluOsStatusXMLParserImpl() { try { SAXParserFactory factory = SAXParserFactory.newInstance(); saxParser = factory.newSAXParser(); diff --git a/src/main/java/nl/vincentvanderleun/utils/SimpleXMLParser.java b/src/main/java/nl/vincentvanderleun/utils/SimpleXMLParserImpl.java similarity index 97% rename from src/main/java/nl/vincentvanderleun/utils/SimpleXMLParser.java rename to src/main/java/nl/vincentvanderleun/utils/SimpleXMLParserImpl.java index 7ee5b92..ddffc0b 100644 --- a/src/main/java/nl/vincentvanderleun/utils/SimpleXMLParser.java +++ b/src/main/java/nl/vincentvanderleun/utils/SimpleXMLParserImpl.java @@ -13,10 +13,10 @@ import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; -public class SimpleXMLParser { +public class SimpleXMLParserImpl { private final SAXParser saxParser; - public SimpleXMLParser() { + public SimpleXMLParserImpl() { try { SAXParserFactory parserFactory = SAXParserFactory.newInstance(); this.saxParser = parserFactory.newSAXParser(); diff --git a/src/test/java/nl/vincentvanderleun/scrobbler/bluos/BluOsStatusXMLParserTests.java b/src/test/java/nl/vincentvanderleun/scrobbler/bluos/BluOsStatusXMLParserImplTests.java similarity index 90% rename from src/test/java/nl/vincentvanderleun/scrobbler/bluos/BluOsStatusXMLParserTests.java rename to src/test/java/nl/vincentvanderleun/scrobbler/bluos/BluOsStatusXMLParserImplTests.java index 8cc71d1..8df9c61 100644 --- a/src/test/java/nl/vincentvanderleun/scrobbler/bluos/BluOsStatusXMLParserTests.java +++ b/src/test/java/nl/vincentvanderleun/scrobbler/bluos/BluOsStatusXMLParserImplTests.java @@ -9,8 +9,8 @@ import org.junit.Before; import org.junit.Test; -public class BluOsStatusXMLParserTests { - private BluOsStatusXMLParser bluOsStatusXMLParser; +public class BluOsStatusXMLParserImplTests { + private BluOsStatusXMLParserImpl bluOsStatusXMLParserImpl; String BLUOS_STATUS_XML_DATA = "\r\n" + "\r\n" + @@ -48,14 +48,14 @@ public class BluOsStatusXMLParserTests { @Before public void init() { - bluOsStatusXMLParser = new BluOsStatusXMLParser(); + bluOsStatusXMLParserImpl = new BluOsStatusXMLParserImpl(); } @Test public void mustParseBluOsStatusXML() throws IOException { ByteArrayInputStream inputStream = new ByteArrayInputStream(BLUOS_STATUS_XML_DATA.getBytes()); - BluOsParsedStatus status = bluOsStatusXMLParser.parse(inputStream); + BluOsParsedStatus status = bluOsStatusXMLParserImpl.parse(inputStream); assertEquals("The Voice Of Love", status.getAlbum()); assertEquals("Julee Cruise", status.getArtist());