plough
6 years ago
5 changed files with 198 additions and 34 deletions
@ -0,0 +1,61 @@
|
||||
package com.fr.design.onlineupdate.push; |
||||
|
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.xml.XMLPrintWriter; |
||||
import com.fr.stable.xml.XMLReadable; |
||||
import com.fr.stable.xml.XMLWriter; |
||||
import com.fr.stable.xml.XMLableReader; |
||||
|
||||
/** |
||||
* 持久化与设计器自动推送更新相关的配置 |
||||
* Created by plough on 2019/4/8. |
||||
*/ |
||||
public class DesignerPushUpdateConfigManager implements XMLReadable, XMLWriter { |
||||
public static final String XML_TAG = "DesignerPushUpdateConfigManager"; |
||||
private static DesignerPushUpdateConfigManager singleton; |
||||
|
||||
private boolean autoPushUpdateEnabled = true; // 是否开启自动推送更新
|
||||
private String lastIgnoredVersion = StringUtils.EMPTY; // 最近一次跳过的更新版本
|
||||
|
||||
private DesignerPushUpdateConfigManager() { |
||||
} |
||||
|
||||
public static DesignerPushUpdateConfigManager getInstance() { |
||||
if (singleton == null) { |
||||
singleton = new DesignerPushUpdateConfigManager(); |
||||
} |
||||
return singleton; |
||||
} |
||||
|
||||
@Override |
||||
public void readXML(XMLableReader reader) { |
||||
if (reader.isAttr()) { |
||||
this.setAutoPushUpdateEnabled(reader.getAttrAsBoolean("autoPushUpdateEnabled", true)); |
||||
this.setLastIgnoredVersion(reader.getAttrAsString("lastIgnoredVersion", StringUtils.EMPTY)); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void writeXML(XMLPrintWriter writer) { |
||||
writer.startTAG(XML_TAG); |
||||
writer.attr("autoPushUpdateEnabled", autoPushUpdateEnabled); |
||||
writer.attr("lastIgnoredVersion", lastIgnoredVersion); |
||||
writer.end(); |
||||
} |
||||
|
||||
public boolean isAutoPushUpdateEnabled() { |
||||
return autoPushUpdateEnabled; |
||||
} |
||||
|
||||
public void setAutoPushUpdateEnabled(boolean autoPushUpdateEnabled) { |
||||
this.autoPushUpdateEnabled = autoPushUpdateEnabled; |
||||
} |
||||
|
||||
public String getLastIgnoredVersion() { |
||||
return lastIgnoredVersion; |
||||
} |
||||
|
||||
public void setLastIgnoredVersion(String lastIgnoredVersion) { |
||||
this.lastIgnoredVersion = lastIgnoredVersion; |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.fr.design.onlineupdate.push; |
||||
|
||||
import com.fr.general.GeneralContext; |
||||
import com.fr.workspace.WorkContext; |
||||
|
||||
/** |
||||
* Created by plough on 2019/4/8. |
||||
*/ |
||||
public class DesignerPushUpdateManager { |
||||
private static DesignerPushUpdateManager singleton; |
||||
// private DesignerUpdateInfo updateInfo;
|
||||
|
||||
private DesignerPushUpdateManager() { |
||||
|
||||
} |
||||
|
||||
public static DesignerPushUpdateManager getInstance() { |
||||
if (singleton == null) { |
||||
singleton = new DesignerPushUpdateManager(); |
||||
} |
||||
return singleton; |
||||
} |
||||
|
||||
/** |
||||
* "自动更新推送"选项是否生效 |
||||
*/ |
||||
public boolean isAutoPushUpdateSupported() { |
||||
// 远程设计和非中文环境,都不生效
|
||||
return WorkContext.getCurrent().isLocal() && GeneralContext.isChineseEnv(); |
||||
} |
||||
/** |
||||
* 检查更新,如果有合适的更新版本,则弹窗 |
||||
*/ |
||||
// public void checkAndPop() {
|
||||
// updateInfo.
|
||||
// }
|
||||
|
||||
|
||||
} |
@ -0,0 +1,72 @@
|
||||
package com.fr.design.onlineupdate.push; |
||||
|
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.xml.XMLPrintWriter; |
||||
import com.fr.stable.xml.XMLableReader; |
||||
import com.fr.third.javax.xml.stream.XMLStreamException; |
||||
import org.junit.Test; |
||||
|
||||
import java.io.PrintWriter; |
||||
import java.io.StringReader; |
||||
import java.io.StringWriter; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
import static org.junit.Assert.assertSame; |
||||
import static org.junit.Assert.assertTrue; |
||||
|
||||
|
||||
/** |
||||
* Created by plough on 2019/4/8. |
||||
*/ |
||||
public class DesignerPushUpdateConfigManagerTest { |
||||
|
||||
@Test |
||||
public void testSingleton() { |
||||
DesignerPushUpdateConfigManager m1 = DesignerPushUpdateConfigManager.getInstance(); |
||||
DesignerPushUpdateConfigManager m2 = DesignerPushUpdateConfigManager.getInstance(); |
||||
assertSame(m1, m2); |
||||
} |
||||
|
||||
@Test |
||||
public void testDefaultValue() throws XMLStreamException { |
||||
DesignerPushUpdateConfigManager configManager = DesignerPushUpdateConfigManager.getInstance(); |
||||
XMLableReader xmlReader = XMLableReader.createXMLableReader(new StringReader("<xml></xml>")); |
||||
xmlReader.readXMLObject(configManager); |
||||
|
||||
assertEquals(StringUtils.EMPTY, configManager.getLastIgnoredVersion()); |
||||
assertTrue(configManager.isAutoPushUpdateEnabled()); |
||||
} |
||||
|
||||
@Test |
||||
public void testReadAndWrite() throws XMLStreamException { |
||||
final String initLastIngnoredVersion = "1.1.2"; |
||||
final boolean initAutoPushEnabled = false; |
||||
|
||||
DesignerPushUpdateConfigManager configManager = DesignerPushUpdateConfigManager.getInstance(); |
||||
|
||||
configManager.setLastIgnoredVersion(initLastIngnoredVersion); |
||||
configManager.setAutoPushUpdateEnabled(initAutoPushEnabled); |
||||
|
||||
// 写入 xml
|
||||
StringWriter sw = new StringWriter(); |
||||
XMLPrintWriter writer = XMLPrintWriter.create(new PrintWriter(sw)); |
||||
configManager.writeXML(writer); |
||||
writer.flush(); |
||||
writer.close(); |
||||
|
||||
String xml_str = sw.getBuffer().toString(); |
||||
|
||||
// 临时修改配置
|
||||
configManager.setAutoPushUpdateEnabled(true); |
||||
configManager.setLastIgnoredVersion("0.20.1"); |
||||
|
||||
// 从 xml 中读取
|
||||
StringReader sr = new StringReader(xml_str); |
||||
XMLableReader xmlReader = XMLableReader.createXMLableReader(sr); |
||||
xmlReader.readXMLObject(configManager); |
||||
|
||||
// 验证:与写入时的配置一致
|
||||
assertEquals(initLastIngnoredVersion, configManager.getLastIgnoredVersion()); |
||||
assertEquals(initAutoPushEnabled, configManager.isAutoPushUpdateEnabled()); |
||||
} |
||||
} |
Loading…
Reference in new issue