summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Bentele2022-02-03 11:41:00 +0100
committerManuel Bentele2022-02-03 11:41:00 +0100
commitae86250d55872ea4fa30625f8885d9b503284fc0 (patch)
tree4e9ab54f49cdd1348edd745303bd1e6163581c9e
parentDowngrade Maven assembly plugin for Java 8 compatibility (diff)
downloadmaster-sync-shared-ae86250d55872ea4fa30625f8885d9b503284fc0.tar.gz
master-sync-shared-ae86250d55872ea4fa30625f8885d9b503284fc0.tar.xz
master-sync-shared-ae86250d55872ea4fa30625f8885d9b503284fc0.zip
Fix path separator for resource URLs on Windows platforms
-rw-r--r--src/main/java/org/openslx/libvirt/xml/LibvirtXmlResources.java20
-rw-r--r--src/main/java/org/openslx/util/Resources.java15
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualboxFileFormat.java4
-rw-r--r--src/test/java/org/openslx/firmware/QemuFirmwareTestResources.java11
-rw-r--r--src/test/java/org/openslx/libvirt/xml/LibvirtXmlTestResources.java12
5 files changed, 43 insertions, 19 deletions
diff --git a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlResources.java b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlResources.java
index a6b3e39..5aa3a5b 100644
--- a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlResources.java
+++ b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlResources.java
@@ -1,8 +1,9 @@
package org.openslx.libvirt.xml;
-import java.io.File;
import java.io.InputStream;
+import org.openslx.util.Resources;
+
/**
* Collection of resource utils for a Libvirt XML document.
*
@@ -14,32 +15,33 @@ public final class LibvirtXmlResources
/**
* File path prefix of the absolute path to the libvirt resource folder in a *.jar file.
*/
- private static final String LIBVIRT_PREFIX_PATH = File.separator + "libvirt";
+ private static final String LIBVIRT_PREFIX_PATH = Resources.PATH_SEPARATOR + "libvirt";
/**
* File path prefix of the absolute path to the libosinfo resource folder in a *.jar file.
*/
- private static final String LIBOSINFO_PREFIX_PATH = File.separator + "libvirt" + File.separator + "libosinfo";
+ private static final String LIBOSINFO_PREFIX_PATH = Resources.PATH_SEPARATOR + "libvirt" + Resources.PATH_SEPARATOR
+ + "libosinfo";
/**
* File path prefix of the absolute path to the libvirt XSL resource folder in a *.jar file.
*/
- private static final String LIBVIRT_PREFIX_PATH_XSL = LIBVIRT_PREFIX_PATH + File.separator + "xsl";
+ private static final String LIBVIRT_PREFIX_PATH_XSL = LIBVIRT_PREFIX_PATH + Resources.PATH_SEPARATOR + "xsl";
/**
* File path prefix of the absolute path to the libvirt RNG resource folder in a *.jar file.
*/
- private static final String LIBVIRT_PREFIX_PATH_RNG = LIBVIRT_PREFIX_PATH + File.separator + "rng";
+ private static final String LIBVIRT_PREFIX_PATH_RNG = LIBVIRT_PREFIX_PATH + Resources.PATH_SEPARATOR + "rng";
/**
* File path prefix of the absolute path to the libosinfo RNG resource folder in a *.jar file.
*/
- private static final String LIBOSINFO_PREFIX_PATH_RNG = LIBOSINFO_PREFIX_PATH + File.separator + "rng";
-
+ private static final String LIBOSINFO_PREFIX_PATH_RNG = LIBOSINFO_PREFIX_PATH + Resources.PATH_SEPARATOR + "rng";
+
/**
* File path prefix of the absolute path to the libosinfo XML resource folder in a *.jar file.
*/
- private static final String LIBOSINFO_PREFIX_PATH_XML = LIBOSINFO_PREFIX_PATH + File.separator + "xml";
+ private static final String LIBOSINFO_PREFIX_PATH_XML = LIBOSINFO_PREFIX_PATH + Resources.PATH_SEPARATOR + "xml";
/**
* Returns a Libvirt resource as stream.
@@ -50,7 +52,7 @@ public final class LibvirtXmlResources
*/
private static InputStream getLibvirtResource( String prefix, String fileName )
{
- final String path = prefix + File.separator + fileName;
+ final String path = prefix + Resources.PATH_SEPARATOR + fileName;
return LibvirtXmlResources.class.getResourceAsStream( path );
}
diff --git a/src/main/java/org/openslx/util/Resources.java b/src/main/java/org/openslx/util/Resources.java
new file mode 100644
index 0000000..9c1dddf
--- /dev/null
+++ b/src/main/java/org/openslx/util/Resources.java
@@ -0,0 +1,15 @@
+package org.openslx.util;
+
+/**
+ * Collection of resource utils.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+public class Resources
+{
+ /**
+ * Path separator for resource {@link URL}s.
+ */
+ public static final String PATH_SEPARATOR = "/";
+}
diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualboxFileFormat.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualboxFileFormat.java
index 032e36b..b4cb7c3 100644
--- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualboxFileFormat.java
+++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualboxFileFormat.java
@@ -23,6 +23,7 @@ import javax.xml.xpath.XPathExpressionException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.openslx.util.Resources;
import org.openslx.util.Util;
import org.openslx.util.XmlHelper;
import org.openslx.virtualization.Version;
@@ -72,7 +73,8 @@ public class VirtualizationConfigurationVirtualboxFileFormat
/**
* Path to the VirtualBox file format schemas within the *.jar file.
*/
- private final static String FILE_FORMAT_SCHEMA_PREFIX_PATH = File.separator + "virtualbox" + File.separator + "xsd";
+ private final static String FILE_FORMAT_SCHEMA_PREFIX_PATH = Resources.PATH_SEPARATOR + "virtualbox"
+ + Resources.PATH_SEPARATOR + "xsd";
// list of nodes to automatically remove when reading the vbox file
private static String[] blacklist = {
diff --git a/src/test/java/org/openslx/firmware/QemuFirmwareTestResources.java b/src/test/java/org/openslx/firmware/QemuFirmwareTestResources.java
index e4c1aa7..05397e6 100644
--- a/src/test/java/org/openslx/firmware/QemuFirmwareTestResources.java
+++ b/src/test/java/org/openslx/firmware/QemuFirmwareTestResources.java
@@ -14,11 +14,12 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.apache.commons.io.FileUtils;
+import org.openslx.util.Resources;
public class QemuFirmwareTestResources
{
- private static final String QEMU_PREFIX_PATH = File.separator + "qemu";
- private static final String QEMU_PREFIX_PATH_FW = QEMU_PREFIX_PATH + File.separator + "firmware";
+ private static final String QEMU_PREFIX_PATH = Resources.PATH_SEPARATOR + "qemu";
+ private static final String QEMU_PREFIX_PATH_FW = QEMU_PREFIX_PATH + Resources.PATH_SEPARATOR + "firmware";
private static final String QEMU_TEMP_PREFIX = "qemu-";
@@ -37,7 +38,7 @@ public class QemuFirmwareTestResources
private static String getResourceDirectory( Class<?> clazz, String resourceDir ) throws IOException
{
- final String fwDirPath = resourceDir.substring( 1 ).concat( File.separator );
+ final String fwDirPath = resourceDir.substring( 1 ).concat( Resources.PATH_SEPARATOR );
final URL fwResource = clazz.getResource( resourceDir );
final File fwDirectory;
String fwDirectoryPath = null;
@@ -65,7 +66,7 @@ public class QemuFirmwareTestResources
// copy each file from the Jar to the temporary directory
fileNames.forEach( fileName -> {
- final String resourceFileName = resourceDir + File.separator + fileName;
+ final String resourceFileName = resourceDir + Resources.PATH_SEPARATOR + fileName;
final File tempFile = new File( fwDirectory.getPath() + File.separator + fileName );
final InputStream fileInput = QemuFirmwareTestResources.class.getResourceAsStream( resourceFileName );
try {
@@ -93,7 +94,7 @@ public class QemuFirmwareTestResources
public static File getQemuFirmwareSpecFile( String fileName )
{
- final String fwSpecFilePath = QEMU_PREFIX_PATH_FW + File.separator + fileName;
+ final String fwSpecFilePath = QEMU_PREFIX_PATH_FW + Resources.PATH_SEPARATOR + fileName;
final URL fwSpecFileUrl = QemuFirmwareTestResources.class.getResource( fwSpecFilePath );
return new File( fwSpecFileUrl.getFile() );
}
diff --git a/src/test/java/org/openslx/libvirt/xml/LibvirtXmlTestResources.java b/src/test/java/org/openslx/libvirt/xml/LibvirtXmlTestResources.java
index 693a442..20d2376 100644
--- a/src/test/java/org/openslx/libvirt/xml/LibvirtXmlTestResources.java
+++ b/src/test/java/org/openslx/libvirt/xml/LibvirtXmlTestResources.java
@@ -5,24 +5,28 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import org.openslx.util.Resources;
+
public final class LibvirtXmlTestResources
{
- private static final String LIBVIRT_PREFIX_PATH = File.separator + "libvirt";
- private static final String LIBVIRT_PREFIX_PATH_XML = LIBVIRT_PREFIX_PATH + File.separator + "xml";
+ private static final String LIBVIRT_PREFIX_PATH = Resources.PATH_SEPARATOR + "libvirt";
+ private static final String LIBVIRT_PREFIX_PATH_XML = LIBVIRT_PREFIX_PATH + Resources.PATH_SEPARATOR + "xml";
private static final String LIBVIRT_TEMP_PREFIX = "libvirt-";
private static final String LIBVIRT_TEMP_SUFFIX = ".xml";
public static File getLibvirtXmlFile( String libvirtXmlFileName )
{
- String libvirtXmlPath = LibvirtXmlTestResources.LIBVIRT_PREFIX_PATH_XML + File.separator + libvirtXmlFileName;
+ String libvirtXmlPath = LibvirtXmlTestResources.LIBVIRT_PREFIX_PATH_XML + Resources.PATH_SEPARATOR
+ + libvirtXmlFileName;
URL libvirtXml = LibvirtXmlTestResources.class.getResource( libvirtXmlPath );
return new File( libvirtXml.getFile() );
}
public static InputStream getLibvirtXmlStream( String libvirtXmlFileName )
{
- String libvirtXmlPath = LibvirtXmlTestResources.LIBVIRT_PREFIX_PATH_XML + File.separator + libvirtXmlFileName;
+ String libvirtXmlPath = LibvirtXmlTestResources.LIBVIRT_PREFIX_PATH_XML + Resources.PATH_SEPARATOR
+ + libvirtXmlFileName;
return LibvirtXmlTestResources.class.getResourceAsStream( libvirtXmlPath );
}