mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
fix mavenized
This commit is contained in:
@@ -17,11 +17,7 @@
|
||||
*/
|
||||
package org.diylc.presenter;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -67,9 +63,11 @@ public class BuildingBlockManager {
|
||||
// import default templates from variants.xml file only if we didn't do it already
|
||||
if (!configManager.readBoolean(IPlugInPort.DEFAULT_BLOCKS_IMPORTED_KEY, false)) {
|
||||
try {
|
||||
URL resource = Presenter.class.getResource(BLOCKS_FILE_NAME);
|
||||
if (resource != null) {
|
||||
BufferedInputStream in = new BufferedInputStream(resource.openStream());
|
||||
InputStream inputStream = Presenter.class.getResourceAsStream("/" + BLOCKS_FILE_NAME);
|
||||
if (inputStream == null) {
|
||||
return;
|
||||
}
|
||||
BufferedInputStream in = new BufferedInputStream(inputStream);
|
||||
Map<String, List<IDIYComponent<?>>> defaults =
|
||||
(Map<String, List<IDIYComponent<?>>>) ProjectFileManager.xStreamSerializer
|
||||
.fromXML(in);
|
||||
@@ -92,7 +90,6 @@ public class BuildingBlockManager {
|
||||
configManager.writeValue(IPlugInPort.BLOCKS_KEY, blocksMap);
|
||||
LOG.info(String.format("Imported %d default building blocks",
|
||||
defaults == null ? 0 : defaults.size()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not load default blocks", e);
|
||||
}
|
||||
|
||||
@@ -142,21 +142,18 @@ public class Presenter implements IPlugInPort, IConfigListener {
|
||||
// Read the latest version from the local update.xml file
|
||||
static {
|
||||
try {
|
||||
URL resource = Presenter.class.getResource("update.xml");
|
||||
if (resource != null) {
|
||||
BufferedInputStream in = new BufferedInputStream(resource.openStream());
|
||||
XStream xStream = new XStream(new DomDriver());
|
||||
xStream.addPermission(AnyTypePermission.ANY);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Version> allVersions = (List<Version>) xStream.fromXML(in);
|
||||
CURRENT_VERSION = allVersions.get(allVersions.size() - 1).getVersionNumber();
|
||||
LOG.info("Current DIYLC version: " + CURRENT_VERSION);
|
||||
RECENT_VERSIONS = allVersions.stream()
|
||||
.sorted(Comparator.comparing(x -> ((Version)x).getVersionNumber()).reversed())
|
||||
.limit(10)
|
||||
.collect(Collectors.toList());
|
||||
in.close();
|
||||
}
|
||||
BufferedInputStream in = new BufferedInputStream(Presenter.class.getResourceAsStream("/update.xml"));
|
||||
XStream xStream = new XStream(new DomDriver());
|
||||
xStream.addPermission(AnyTypePermission.ANY);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Version> allVersions = (List<Version>) xStream.fromXML(in);
|
||||
CURRENT_VERSION = allVersions.get(allVersions.size() - 1).getVersionNumber();
|
||||
LOG.info("Current DIYLC version: " + CURRENT_VERSION);
|
||||
RECENT_VERSIONS = allVersions.stream()
|
||||
.sorted(Comparator.comparing(x -> ((Version)x).getVersionNumber()).reversed())
|
||||
.limit(10)
|
||||
.collect(Collectors.toList());
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not find version number, using default", e);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.diylc.presenter;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
@@ -67,40 +68,41 @@ public class VariantManager {
|
||||
int importCount = 0;
|
||||
|
||||
try {
|
||||
URL resource = Presenter.class.getResource(VARIANTS_FILE_NAME);
|
||||
if (resource != null) {
|
||||
BufferedInputStream in = new BufferedInputStream(resource.openStream());
|
||||
Map<String, List<Template>> defaults =
|
||||
(Map<String, List<Template>>) ProjectFileManager.xStreamSerializer.fromXML(in);
|
||||
in.close();
|
||||
|
||||
Map<String, List<Template>> variantMap =
|
||||
(Map<String, List<Template>>) configManager.readObject(IPlugInPort.TEMPLATES_KEY, null);
|
||||
if (variantMap == null)
|
||||
variantMap = new HashMap<String, List<Template>>();
|
||||
|
||||
// merge default variants with user's
|
||||
for (Map.Entry<String, List<Template>> entry : defaults.entrySet()) {
|
||||
List<Template> existingVariants = variantMap.computeIfAbsent(entry.getKey(), key -> new ArrayList<Template>());
|
||||
Set<String> existingNames = existingVariants.stream()
|
||||
.map(x -> x.getName())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
for (Template variant : entry.getValue()) {
|
||||
if ((variant.getCreatedOn() == null || importDate.compareTo(variant.getCreatedOn()) < 0)
|
||||
&& !existingNames.contains(variant.getName())) {
|
||||
existingVariants.add(variant);
|
||||
importCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update templates and a flag marking that we imported them
|
||||
configManager.writeValue(IPlugInPort.DEFAULT_TEMPLATES_IMPORT_DATE_KEY,
|
||||
LocalDateTime.now());
|
||||
configManager.writeValue(IPlugInPort.TEMPLATES_KEY, variantMap);
|
||||
LOG.info(String.format("Imported default %d variants", importCount));
|
||||
InputStream inputStream = Presenter.class.getResourceAsStream("/" + VARIANTS_FILE_NAME);
|
||||
if (inputStream == null) {
|
||||
return;
|
||||
}
|
||||
BufferedInputStream in = new BufferedInputStream(inputStream);
|
||||
Map<String, List<Template>> defaults =
|
||||
(Map<String, List<Template>>) ProjectFileManager.xStreamSerializer.fromXML(in);
|
||||
in.close();
|
||||
|
||||
Map<String, List<Template>> variantMap =
|
||||
(Map<String, List<Template>>) configManager.readObject(IPlugInPort.TEMPLATES_KEY, null);
|
||||
if (variantMap == null)
|
||||
variantMap = new HashMap<String, List<Template>>();
|
||||
|
||||
// merge default variants with user's
|
||||
for (Map.Entry<String, List<Template>> entry : defaults.entrySet()) {
|
||||
List<Template> existingVariants = variantMap.computeIfAbsent(entry.getKey(), key -> new ArrayList<Template>());
|
||||
Set<String> existingNames = existingVariants.stream()
|
||||
.map(x -> x.getName())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
for (Template variant : entry.getValue()) {
|
||||
if ((variant.getCreatedOn() == null || importDate.compareTo(variant.getCreatedOn()) < 0)
|
||||
&& !existingNames.contains(variant.getName())) {
|
||||
existingVariants.add(variant);
|
||||
importCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update templates and a flag marking that we imported them
|
||||
configManager.writeValue(IPlugInPort.DEFAULT_TEMPLATES_IMPORT_DATE_KEY,
|
||||
LocalDateTime.now());
|
||||
configManager.writeValue(IPlugInPort.TEMPLATES_KEY, variantMap);
|
||||
LOG.info(String.format("Imported default %d variants", importCount));
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not load default variants", e);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.diylc.utils;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -17,9 +18,9 @@ import org.diylc.presenter.Presenter;
|
||||
public class VersionReader {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
URL resource = Presenter.class.getResource("update.xml");
|
||||
if (resource != null) {
|
||||
BufferedInputStream in = new BufferedInputStream(resource.openStream());
|
||||
InputStream inputStream = Presenter.class.getResourceAsStream("/update.xml");
|
||||
if (inputStream != null) {
|
||||
BufferedInputStream in = new BufferedInputStream(inputStream);
|
||||
XStream xStream = new XStream(new DomDriver());
|
||||
xStream.addPermission(AnyTypePermission.ANY);
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
Reference in New Issue
Block a user