fix mavenized

This commit is contained in:
Branislav Stojkovic
2025-03-11 12:18:00 +01:00
parent 0417947289
commit e088b5e8c9
10 changed files with 198 additions and 190 deletions
@@ -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();
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>>();
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());
// 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++;
}
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));
}
// 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")
@@ -26,8 +26,11 @@ import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import org.apache.log4j.Logger;
import org.apache.poi.util.IOUtils;
import org.diylc.appframework.miscutils.IconImageConverter;
@@ -55,6 +58,8 @@ import org.diylc.core.annotations.PercentEditor;
flexibleZOrder = true, bomPolicy = BomPolicy.NEVER_SHOW, transformer = ImageTransformer.class)
public class Image extends AbstractTransparentComponent<Void> {
private static final Logger LOG = Logger.getLogger(Image.class);
private static final long serialVersionUID = 1L;
public static String DEFAULT_TEXT = "Double click to edit text";
private static ImageIcon ICON;
@@ -67,10 +72,13 @@ public class Image extends AbstractTransparentComponent<Void> {
static {
String name = "/image.png";
java.net.URL imgURL = Image.class.getResource(name);
if (imgURL != null) {
ICON = new ImageIcon(imgURL, name);
}
try (InputStream inputStream = Image.class.getResourceAsStream(name)) {
if (inputStream != null) {
ICON = new ImageIcon(inputStream.readAllBytes(), name);
}
} catch (IOException e) {
LOG.error("Error loading image " + name, e);
}
}
@Override
BIN
View File
Binary file not shown.
+5
View File
@@ -107,6 +107,11 @@
<artifactId>gestures-wrapper</artifactId>
<version>0.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
</dependency>
<!-- Local dependencies from lib folder -->
<dependency>
@@ -19,6 +19,7 @@ package org.diylc;
import java.awt.Desktop;
import java.io.File;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.Arrays;
@@ -88,10 +89,9 @@ public class DIYLCStarter {
}
}
URL url = DIYLCStarter.class.getResource("/log4j.properties");
Properties properties = new Properties();
try {
properties.load(url.openStream());
try (InputStream inputStream = DIYLCStarter.class.getResourceAsStream("/log4j.properties")) {
properties.load(inputStream);
PropertyConfigurator.configure(properties);
} catch (Exception e) {
LOG.error("Could not initialize log4j configuration", e);
@@ -222,13 +222,9 @@ public class DIYLCStarter {
}
properties = new Properties();
try {
LOG.info("Injecting default properties.");
URL resource = Presenter.class.getResource("config.properties");
if (resource != null) {
properties.load(resource.openStream());
PropertyInjector.injectProperties(properties);
}
try (InputStream inputStream = Presenter.class.getResourceAsStream("/config.properties")) {
properties.load(inputStream);
PropertyInjector.injectProperties(properties);
} catch (Exception e) {
LOG.error("Could not read config.properties file", e);
}
@@ -23,6 +23,7 @@ package org.diylc.utils;
import java.io.File;
import java.io.FilenameFilter;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;
import org.apache.log4j.Logger;
@@ -38,10 +39,10 @@ public class BatchConverter {
private static final Logger LOG = Logger.getLogger(BatchConverter.class);
public static void main(String[] args) {
URL url = DIYLCStarter.class.getResource("log4j.properties");
URL url = DIYLCStarter.class.getResource("/log4j.properties");
Properties properties = new Properties();
try {
properties.load(url.openStream());
try (InputStream inputStream = url.openStream()) {
properties.load(inputStream);
PropertyConfigurator.configure(properties);
} catch (Exception e) {
LOG.error("Could not initialize log4j configuration", e);
@@ -2,6 +2,7 @@ package org.diylc;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import java.util.Map;
@@ -20,10 +21,10 @@ public class TestBase {
protected IView view;
public TestBase() {
URL url = DIYLCStarter.class.getResource("log4j.properties");
URL url = DIYLCStarter.class.getResource("/log4j.properties");
Properties properties = new Properties();
try {
properties.load(url.openStream());
try (InputStream inputStream = url.openStream()) {
properties.load(inputStream);
PropertyConfigurator.configure(properties);
} catch (Exception e) {
System.err.println("Could not initialize log4j configuration: " + e.getMessage());