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; package org.diylc.presenter;
import java.io.BufferedInputStream; import java.io.*;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; 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 // import default templates from variants.xml file only if we didn't do it already
if (!configManager.readBoolean(IPlugInPort.DEFAULT_BLOCKS_IMPORTED_KEY, false)) { if (!configManager.readBoolean(IPlugInPort.DEFAULT_BLOCKS_IMPORTED_KEY, false)) {
try { try {
URL resource = Presenter.class.getResource(BLOCKS_FILE_NAME); InputStream inputStream = Presenter.class.getResourceAsStream("/" + BLOCKS_FILE_NAME);
if (resource != null) { if (inputStream == null) {
BufferedInputStream in = new BufferedInputStream(resource.openStream()); return;
}
BufferedInputStream in = new BufferedInputStream(inputStream);
Map<String, List<IDIYComponent<?>>> defaults = Map<String, List<IDIYComponent<?>>> defaults =
(Map<String, List<IDIYComponent<?>>>) ProjectFileManager.xStreamSerializer (Map<String, List<IDIYComponent<?>>>) ProjectFileManager.xStreamSerializer
.fromXML(in); .fromXML(in);
@@ -92,7 +90,6 @@ public class BuildingBlockManager {
configManager.writeValue(IPlugInPort.BLOCKS_KEY, blocksMap); configManager.writeValue(IPlugInPort.BLOCKS_KEY, blocksMap);
LOG.info(String.format("Imported %d default building blocks", LOG.info(String.format("Imported %d default building blocks",
defaults == null ? 0 : defaults.size())); defaults == null ? 0 : defaults.size()));
}
} catch (Exception e) { } catch (Exception e) {
LOG.error("Could not load default blocks", 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 // Read the latest version from the local update.xml file
static { static {
try { try {
URL resource = Presenter.class.getResource("update.xml"); BufferedInputStream in = new BufferedInputStream(Presenter.class.getResourceAsStream("/update.xml"));
if (resource != null) { XStream xStream = new XStream(new DomDriver());
BufferedInputStream in = new BufferedInputStream(resource.openStream()); xStream.addPermission(AnyTypePermission.ANY);
XStream xStream = new XStream(new DomDriver()); @SuppressWarnings("unchecked")
xStream.addPermission(AnyTypePermission.ANY); List<Version> allVersions = (List<Version>) xStream.fromXML(in);
@SuppressWarnings("unchecked") CURRENT_VERSION = allVersions.get(allVersions.size() - 1).getVersionNumber();
List<Version> allVersions = (List<Version>) xStream.fromXML(in); LOG.info("Current DIYLC version: " + CURRENT_VERSION);
CURRENT_VERSION = allVersions.get(allVersions.size() - 1).getVersionNumber(); RECENT_VERSIONS = allVersions.stream()
LOG.info("Current DIYLC version: " + CURRENT_VERSION); .sorted(Comparator.comparing(x -> ((Version)x).getVersionNumber()).reversed())
RECENT_VERSIONS = allVersions.stream() .limit(10)
.sorted(Comparator.comparing(x -> ((Version)x).getVersionNumber()).reversed()) .collect(Collectors.toList());
.limit(10) in.close();
.collect(Collectors.toList());
in.close();
}
} catch (Exception e) { } catch (Exception e) {
LOG.error("Could not find version number, using default", 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.BufferedInputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
@@ -67,40 +68,41 @@ public class VariantManager {
int importCount = 0; int importCount = 0;
try { try {
URL resource = Presenter.class.getResource(VARIANTS_FILE_NAME); InputStream inputStream = Presenter.class.getResourceAsStream("/" + VARIANTS_FILE_NAME);
if (resource != null) { if (inputStream == null) {
BufferedInputStream in = new BufferedInputStream(resource.openStream()); return;
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));
} }
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) { } catch (Exception e) {
LOG.error("Could not load default variants", e); LOG.error("Could not load default variants", e);
} }
@@ -1,6 +1,7 @@
package org.diylc.utils; package org.diylc.utils;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@@ -17,9 +18,9 @@ import org.diylc.presenter.Presenter;
public class VersionReader { public class VersionReader {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
URL resource = Presenter.class.getResource("update.xml"); InputStream inputStream = Presenter.class.getResourceAsStream("/update.xml");
if (resource != null) { if (inputStream != null) {
BufferedInputStream in = new BufferedInputStream(resource.openStream()); BufferedInputStream in = new BufferedInputStream(inputStream);
XStream xStream = new XStream(new DomDriver()); XStream xStream = new XStream(new DomDriver());
xStream.addPermission(AnyTypePermission.ANY); xStream.addPermission(AnyTypePermission.ANY);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -26,8 +26,11 @@ import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import org.apache.log4j.Logger;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
import org.diylc.appframework.miscutils.IconImageConverter; 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) flexibleZOrder = true, bomPolicy = BomPolicy.NEVER_SHOW, transformer = ImageTransformer.class)
public class Image extends AbstractTransparentComponent<Void> { public class Image extends AbstractTransparentComponent<Void> {
private static final Logger LOG = Logger.getLogger(Image.class);
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static String DEFAULT_TEXT = "Double click to edit text"; public static String DEFAULT_TEXT = "Double click to edit text";
private static ImageIcon ICON; private static ImageIcon ICON;
@@ -67,10 +72,13 @@ public class Image extends AbstractTransparentComponent<Void> {
static { static {
String name = "/image.png"; String name = "/image.png";
java.net.URL imgURL = Image.class.getResource(name); try (InputStream inputStream = Image.class.getResourceAsStream(name)) {
if (imgURL != null) { if (inputStream != null) {
ICON = new ImageIcon(imgURL, name); ICON = new ImageIcon(inputStream.readAllBytes(), name);
} }
} catch (IOException e) {
LOG.error("Error loading image " + name, e);
}
} }
@Override @Override
BIN
View File
Binary file not shown.
+5
View File
@@ -107,6 +107,11 @@
<artifactId>gestures-wrapper</artifactId> <artifactId>gestures-wrapper</artifactId>
<version>0.2</version> <version>0.2</version>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
</dependency>
<!-- Local dependencies from lib folder --> <!-- Local dependencies from lib folder -->
<dependency> <dependency>
@@ -19,6 +19,7 @@ package org.diylc;
import java.awt.Desktop; import java.awt.Desktop;
import java.io.File; import java.io.File;
import java.io.InputStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.net.URL; import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
@@ -88,10 +89,9 @@ public class DIYLCStarter {
} }
} }
URL url = DIYLCStarter.class.getResource("/log4j.properties");
Properties properties = new Properties(); Properties properties = new Properties();
try { try (InputStream inputStream = DIYLCStarter.class.getResourceAsStream("/log4j.properties")) {
properties.load(url.openStream()); properties.load(inputStream);
PropertyConfigurator.configure(properties); PropertyConfigurator.configure(properties);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Could not initialize log4j configuration", e); LOG.error("Could not initialize log4j configuration", e);
@@ -222,13 +222,9 @@ public class DIYLCStarter {
} }
properties = new Properties(); properties = new Properties();
try { try (InputStream inputStream = Presenter.class.getResourceAsStream("/config.properties")) {
LOG.info("Injecting default properties."); properties.load(inputStream);
URL resource = Presenter.class.getResource("config.properties"); PropertyInjector.injectProperties(properties);
if (resource != null) {
properties.load(resource.openStream());
PropertyInjector.injectProperties(properties);
}
} catch (Exception e) { } catch (Exception e) {
LOG.error("Could not read config.properties file", e); LOG.error("Could not read config.properties file", e);
} }
@@ -1,64 +1,65 @@
/* /*
DIY Layout Creator (DIYLC). DIY Layout Creator (DIYLC).
Copyright (c) 2009-2018 held jointly by the individual authors. Copyright (c) 2009-2018 held jointly by the individual authors.
This file is part of DIYLC. This file is part of DIYLC.
DIYLC is free software: you can redistribute it and/or modify DIYLC is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
DIYLC is distributed in the hope that it will be useful, DIYLC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with DIYLC. If not, see <http://www.gnu.org/licenses/>. along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.diylc.utils; package org.diylc.utils;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.net.URL; import java.io.InputStream;
import java.util.Properties; import java.net.URL;
import org.apache.log4j.Logger; import java.util.Properties;
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.InMemoryConfigurationManager; import org.apache.log4j.PropertyConfigurator;
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
import org.diylc.DIYLCStarter;
import org.diylc.presenter.Presenter; import org.diylc.DIYLCStarter;
import org.diylc.swing.gui.DummyView; import org.diylc.presenter.Presenter;
import org.diylc.swing.gui.DummyView;
public class BatchConverter {
public class BatchConverter {
private static final Logger LOG = Logger.getLogger(BatchConverter.class);
private static final Logger LOG = Logger.getLogger(BatchConverter.class);
public static void main(String[] args) {
URL url = DIYLCStarter.class.getResource("log4j.properties"); public static void main(String[] args) {
Properties properties = new Properties(); URL url = DIYLCStarter.class.getResource("/log4j.properties");
try { Properties properties = new Properties();
properties.load(url.openStream()); try (InputStream inputStream = url.openStream()) {
PropertyConfigurator.configure(properties); properties.load(inputStream);
} catch (Exception e) { PropertyConfigurator.configure(properties);
LOG.error("Could not initialize log4j configuration", e); } catch (Exception e) {
} LOG.error("Could not initialize log4j configuration", e);
}
File dir = new File("C:\\Users\\Branislav Stojkovic\\Documents\\layouts_v1");
File[] matchingFiles = dir.listFiles(new FilenameFilter() { File dir = new File("C:\\Users\\Branislav Stojkovic\\Documents\\layouts_v1");
public boolean accept(File dir, String name) { File[] matchingFiles = dir.listFiles(new FilenameFilter() {
return true; public boolean accept(File dir, String name) {
} return true;
}); }
Presenter presenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance()); });
for (File file : matchingFiles) { Presenter presenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
if (file.getName() != "" && file.getName() != "." && file.getName() != ".." && !file.isDirectory()) for (File file : matchingFiles) {
presenter.loadProjectFromFile(file.getAbsolutePath()); if (file.getName() != "" && file.getName() != "." && file.getName() != ".." && !file.isDirectory())
presenter.saveProjectToFile(file.getParentFile().getAbsolutePath() + "\\converted\\" + file.getName(), false); presenter.loadProjectFromFile(file.getAbsolutePath());
} presenter.saveProjectToFile(file.getParentFile().getAbsolutePath() + "\\converted\\" + file.getName(), false);
} }
}
}
}
@@ -1,52 +1,53 @@
package org.diylc; package org.diylc;
import java.awt.Point; import java.awt.Point;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.net.URL; import java.io.InputStream;
import java.util.List; import java.net.URL;
import java.util.Map; import java.util.List;
import java.util.Properties; import java.util.Map;
import org.apache.log4j.PropertyConfigurator; import java.util.Properties;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.apache.log4j.PropertyConfigurator;
import org.diylc.appframework.miscutils.InMemoryConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
import org.diylc.common.ComponentType;
import org.diylc.core.IView; import org.diylc.common.ComponentType;
import org.diylc.presenter.Presenter; import org.diylc.core.IView;
import org.diylc.presenter.Presenter;
public class TestBase {
public class TestBase {
protected Presenter presenter;
protected IView view; protected Presenter presenter;
protected IView view;
public TestBase() {
URL url = DIYLCStarter.class.getResource("log4j.properties"); public TestBase() {
Properties properties = new Properties(); URL url = DIYLCStarter.class.getResource("/log4j.properties");
try { Properties properties = new Properties();
properties.load(url.openStream()); try (InputStream inputStream = url.openStream()) {
PropertyConfigurator.configure(properties); properties.load(inputStream);
} catch (Exception e) { PropertyConfigurator.configure(properties);
System.err.println("Could not initialize log4j configuration: " + e.getMessage()); } catch (Exception e) {
} System.err.println("Could not initialize log4j configuration: " + e.getMessage());
}
ConfigurationManager.getInstance().initialize("diylc-test");
view = new MockView(); ConfigurationManager.getInstance().initialize("diylc-test");
presenter = new Presenter(view, InMemoryConfigurationManager.getInstance()); view = new MockView();
} presenter = new Presenter(view, InMemoryConfigurationManager.getInstance());
}
protected void instantiateOneClick(String category, String name, Point point1) {
Map<String, List<ComponentType>> componentTypes = presenter.getComponentTypes(); protected void instantiateOneClick(String category, String name, Point point1) {
ComponentType resistorType = componentTypes.get(category).stream().filter(x -> x.getName().equals(name)).findFirst().get(); Map<String, List<ComponentType>> componentTypes = presenter.getComponentTypes();
presenter.setNewComponentTypeSlot(resistorType, null, null, false); ComponentType resistorType = componentTypes.get(category).stream().filter(x -> x.getName().equals(name)).findFirst().get();
presenter.mouseClicked(point1, MouseEvent.BUTTON1, false, false, false, 1); presenter.setNewComponentTypeSlot(resistorType, null, null, false);
} presenter.mouseClicked(point1, MouseEvent.BUTTON1, false, false, false, 1);
}
protected void instantiateTwoClick(String category, String name, Point point1, Point point2) {
Map<String, List<ComponentType>> componentTypes = presenter.getComponentTypes(); protected void instantiateTwoClick(String category, String name, Point point1, Point point2) {
ComponentType resistorType = componentTypes.get(category).stream().filter(x -> x.getName().equals(name)).findFirst().get(); Map<String, List<ComponentType>> componentTypes = presenter.getComponentTypes();
presenter.setNewComponentTypeSlot(resistorType, null, null, false); ComponentType resistorType = componentTypes.get(category).stream().filter(x -> x.getName().equals(name)).findFirst().get();
presenter.mouseClicked(point1, MouseEvent.BUTTON1, false, false, false, 1); presenter.setNewComponentTypeSlot(resistorType, null, null, false);
presenter.mouseMoved(point2, false, false, false); presenter.mouseClicked(point1, MouseEvent.BUTTON1, false, false, false, 1);
presenter.mouseClicked(point2, MouseEvent.BUTTON1, false, false, false, 1); presenter.mouseMoved(point2, false, false, false);
} presenter.mouseClicked(point2, MouseEvent.BUTTON1, false, false, false, 1);
} }
}