fix mavenized

This commit is contained in:
Branislav Stojkovic
2025-03-11 10:37:21 +01:00
parent fcfecd33cd
commit 0417947289
35 changed files with 131 additions and 162 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+10 -10
View File
@@ -47,6 +47,16 @@
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -54,11 +64,6 @@
</dependency>
<!-- Local dependencies from lib folder -->
<dependency>
<groupId>org.diylc.local</groupId>
<artifactId>AppleJavaExtensions</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.diylc.local</groupId>
<artifactId>app-framework</artifactId>
@@ -74,10 +79,5 @@
<artifactId>java-http-proxy</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.diylc.local</groupId>
<artifactId>jettison-1.0.1</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
@@ -147,7 +147,7 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
*
* @param project
* @param freshStart
* @param optional file name when loading from a file
* @param filename file name when loading from a file
*/
void loadProject(Project project, boolean freshStart, String filename);
@@ -17,12 +17,12 @@
*/
package org.diylc.lang;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
@@ -34,7 +34,7 @@ import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.IPlugInPort;
import org.diylc.utils.ResourceLoader;
import org.diylc.utils.ResourceUtils;
public class LangUtil {
@@ -89,21 +89,17 @@ public class LangUtil {
LOG.info("Loading translation for " + language);
dict = new HashMap<String, String>();
try {
String path = ResourceLoader.getFile(LANG_DIR + File.separator + language + ".txt").getAbsolutePath();
LOG.debug("Loading language file: " + path);
try (Stream<String> stream = Files.lines(
Paths.get(path), StandardCharsets.UTF_8)) {
stream.forEach(s -> {
if (s.contains("|")) {
String[] parts = s.split("\\|");
if (parts.length == 2)
dict.put(parts[0].toLowerCase().trim(), parts[1].trim());
} else {
dict.put(s.toLowerCase(), s);
}
});
} catch (IOException e) {
LOG.error("Error loading language file", e);
BufferedReader reader = new BufferedReader(new InputStreamReader(
(LangUtil.class.getResourceAsStream("/" + LANG_DIR + File.separator + language + ".txt"))));
while(reader.ready()) {
String s = reader.readLine();
if (s.contains("|")) {
String[] parts = s.split("\\|");
if (parts.length == 2)
dict.put(parts[0].toLowerCase().trim(), parts[1].trim());
} else {
dict.put(s.toLowerCase(), s);
}
}
} catch (Exception e) {
LOG.error("Error loading language file", e);
@@ -128,9 +124,8 @@ public class LangUtil {
public static List<Language> getAvailableLanguages() {
List<Language> res = new ArrayList<Language>();
File[] files = ResourceLoader.getFiles(LANG_DIR);
if (files == null)
return res;
List<File> files = ResourceUtils.getResourceFiles(LANG_DIR);
try {
for (File file : files) {
String key = file.getName().replaceFirst("[.][^.]+$", "");
@@ -80,6 +80,7 @@ import org.diylc.core.Project;
import org.diylc.core.Template;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.IAutoCreator;
import org.diylc.core.gerber.GerberExporter;
import org.diylc.core.measures.Size;
@@ -95,6 +96,11 @@ import org.diylc.test.DIYTest;
import org.diylc.test.Snapshot;
import org.diylc.utils.Constants;
import org.diylc.utils.ReflectionUtils;
import org.reflections.Reflections;
import org.reflections.util.ConfigurationBuilder;
import org.reflections.util.FilterBuilder;
import static org.reflections.scanners.Scanners.TypesAnnotated;
/**
* The main presenter class, contains core app logic and drawing routines.
@@ -442,21 +448,14 @@ public class Presenter implements IPlugInPort, IConfigListener {
if (componentTypes == null) {
LOG.info("Loading component types.");
componentTypes = new HashMap<String, List<ComponentType>>();
Reflections reflections = new Reflections(
new ConfigurationBuilder()
.forPackage("org.diylc")
.filterInputsBy(new FilterBuilder().includePackage("org.diylc.components"))
.setScanners(TypesAnnotated));
Set<Class<?>> componentTypeClasses = null;
try {
componentTypeClasses = Utils.getClasses("org.diylc.components");
File libraryFile = new File("library");
if (libraryFile.exists() && libraryFile.isDirectory() && !Utils.isMac()) {
LOG.info("Loading additional library JARs");
try {
List<Class<?>> additionalComponentTypeClasses =
JarScanner.getInstance().scanFolder("library", IDIYComponent.class);
if (additionalComponentTypeClasses != null)
componentTypeClasses.addAll(additionalComponentTypeClasses);
} catch (Exception e) {
LOG.warn("Could not find additional type classes", e);
}
}
componentTypeClasses = reflections.getTypesAnnotatedWith(ComponentDescriptor.class, false);
for (Class<?> clazz : componentTypeClasses) {
if (!Modifier.isAbstract(clazz.getModifiers()) && IDIYComponent.class.isAssignableFrom(clazz)) {
@@ -1,72 +0,0 @@
/*
*
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
*
* This file is part of DIYLC.
*
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
package org.diylc.utils;
import java.io.File;
import org.apache.log4j.Logger;
public class ResourceLoader {
private static final Logger LOG = Logger.getLogger(ResourceLoader.class);
public static File[] getFiles(String relativePath) {
String bundlePath;
try {
bundlePath = com.apple.eio.FileManager.getPathToApplicationBundle();
//LOG.debug("Detected OSX bundle path: " + bundlePath);
} catch (Exception e) {
bundlePath = null; // on non-OSX platforms
}
try {
String absolutePath;
if (bundlePath == null)
absolutePath = relativePath;
else
absolutePath = bundlePath + File.separator + "Contents" + File.separator + "Resources" + File.separator + relativePath;
LOG.debug("Looking for files in: " + absolutePath);
File absoluteFile = new File(absolutePath);
return absoluteFile.listFiles();
} catch (Exception e) {
LOG.error("Error while looking for files in: " + relativePath, e);
return null;
}
}
public static File getFile(String relativePath) {
String bundlePath;
try {
bundlePath = com.apple.eio.FileManager.getPathToApplicationBundle();
//LOG.debug("Detected OSX bundle path: " + bundlePath);
} catch (Exception e) {
bundlePath = null; // on non-OSX platforms
}
try {
String absolutePath;
if (bundlePath == null)
absolutePath = relativePath;
else
absolutePath = bundlePath + File.separator + "Contents" + File.separator + "Resources" + File.separator + relativePath;
File absoluteFile = new File(absolutePath);
return absoluteFile;
} catch (Exception e) {
LOG.error("Error while finding file: " + relativePath, e);
return null;
}
}
}
@@ -0,0 +1,38 @@
package org.diylc.utils;
import org.apache.log4j.Logger;
import org.diylc.lang.LangUtil;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
public class ResourceUtils {
private static final Logger LOG = Logger.getLogger(LangUtil.class);
public static List<File> getResourceFiles(String dir) {
List<File> files = new ArrayList<>();
URL url = LangUtil.class.getResource("/" + dir);
Path path = null;
try {
path = Paths.get(url.toURI());
Files.walk(path, 5).forEach(p -> {
if (!p.toFile().isDirectory()) {
files.add(p.toFile());
}
});
} catch (URISyntaxException e) {
LOG.error("Error loading language file", e);
} catch (IOException e) {
LOG.error("Error loading language file", e);
}
return files;
}
}