diff options
author | Decebal Suiu <decebal.suiu@gmail.com> | 2019-04-13 23:26:28 +0300 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2019-04-13 23:26:28 +0300 |
commit | c1062e7cc77a87068ce63e0443524da98bc0ae64 (patch) | |
tree | 6182ef099f875c5cee7ab5ddebfde3278277dcf3 /pf4j/src/test | |
parent | dd45a1e6dcfdcc39b3fe182417d48a2e801f7d28 (diff) | |
download | pf4j-c1062e7cc77a87068ce63e0443524da98bc0ae64.tar.gz pf4j-c1062e7cc77a87068ce63e0443524da98bc0ae64.zip |
Improve readability
Diffstat (limited to 'pf4j/src/test')
5 files changed, 155 insertions, 199 deletions
diff --git a/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java b/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java index 91a35f5..4f13bac 100644 --- a/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java +++ b/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java @@ -39,16 +39,16 @@ public class DefaultPluginRepositoryTest { @BeforeEach public void setUp() throws IOException { - Path plugin1Path = Files.createDirectories(pluginsPath.resolve("plugin-1")); + Path plugin1Path = Files.createDirectory(pluginsPath.resolve("plugin-1")); // Prove that we can delete a folder with a file inside Files.createFile(plugin1Path.resolve("myfile")); // Create a zip file for plugin-1 to test that it is deleted when plugin is deleted Files.createFile(pluginsPath.resolve("plugin-1.zip")); - Files.createDirectories(pluginsPath.resolve("plugin-2")); - Files.createDirectories(pluginsPath.resolve("plugin-3")); + Files.createDirectory(pluginsPath.resolve("plugin-2")); + Files.createDirectory(pluginsPath.resolve("plugin-3")); // standard maven/gradle bin folder - these should be skipped in development mode because the cause errors - Files.createDirectories(pluginsPath.resolve("target")); - Files.createDirectories(pluginsPath.resolve("build")); + Files.createDirectory(pluginsPath.resolve("target")); + Files.createDirectory(pluginsPath.resolve("build")); } /** diff --git a/pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java b/pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java index 1d83c9f..2ffe01b 100644 --- a/pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java +++ b/pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java @@ -18,14 +18,16 @@ package org.pf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import org.pf4j.plugin.PluginJar; +import java.io.FileOutputStream; import java.io.IOException; -import java.nio.charset.Charset; +import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.List; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.jar.Manifest; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -44,33 +46,26 @@ public class ManifestPluginDescriptorFinderTest { @BeforeEach public void setUp() throws IOException { - Charset charset = Charset.forName("UTF-8"); + Path pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-1")); + storeManifestToPath(getPlugin1Manifest(), pluginPath); - Path pluginPath = Files.createDirectories(pluginsPath.resolve(Paths.get("test-plugin-1", "classes", "META-INF"))); - Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes()); - Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin1Manifest(), charset); - - pluginPath = Files.createDirectories(pluginsPath.resolve(Paths.get("test-plugin-2", "classes", "META-INF"))); - Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes()); - Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin2Manifest(), charset); + pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-2")); + storeManifestToPath(getPlugin2Manifest(), pluginPath); // empty plugin Files.createDirectories(pluginsPath.resolve("test-plugin-3")); // no plugin class - pluginPath = Files.createDirectories(pluginsPath.resolve(Paths.get("test-plugin-4", "classes", "META-INF"))); - Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes()); - Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin4Manifest(), charset); + pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-4")); + storeManifestToPath(getPlugin4Manifest(), pluginPath); // no plugin version - pluginPath = Files.createDirectories(pluginsPath.resolve(Paths.get("test-plugin-5", "classes", "META-INF"))); - Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes()); - Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin5Manifest(), charset); + pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-5")); + storeManifestToPath(getPlugin5Manifest(), pluginPath); // no plugin id - pluginPath = Files.createDirectories(pluginsPath.resolve(Paths.get("test-plugin-6", "classes", "META-INF"))); - Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes()); - Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin6Manifest(), charset); + pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-6")); + storeManifestToPath(getPlugin6Manifest(), pluginPath); versionManager = new DefaultVersionManager(); } @@ -115,120 +110,62 @@ public class ManifestPluginDescriptorFinderTest { assertThrows(PluginException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3"))); } - private List<String> getPlugin1Manifest() { - String[] lines = new String[] { - "Manifest-Version: 1.0\n" - + "Implementation-Title: Test Plugin #1\n" - + "Implementation-Version: 0.10.0-SNAPSHOT\n" - + "Archiver-Version: Plexus Archiver\n" - + "Built-By: Mario Franco\n" - + "Specification-Title: Test Plugin #1\n" - + "Implementation-Vendor-Id: org.pf4j.demo\n" - + "Plugin-Version: 0.0.1\n" - + "Plugin-Id: test-plugin-1\n" - + "Plugin-Description: Test Plugin 1\n" - + "Plugin-Provider: Decebal Suiu\n" - + "Plugin-Class: org.pf4j.plugin.TestPlugin\n" - + "Plugin-Dependencies: test-plugin-2,test-plugin-3@~1.0\n" - + "Plugin-Requires: *\n" - + "Plugin-License: Apache-2.0\n" - + "Created-By: Apache Maven 3.0.5\n" - + "Build-Jdk: 1.8.0_45\n" - + "Specification-Version: 0.10.0-SNAPSHOT\n" - + "\n" - + "" - }; - - return Arrays.asList(lines); + private Manifest getPlugin1Manifest() { + Map<String, String> map = new LinkedHashMap<>(8); + map.put(ManifestPluginDescriptorFinder.PLUGIN_ID, "test-plugin-1"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_CLASS, "org.pf4j.plugin.TestPlugin"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_VERSION, "0.0.1"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_DESCRIPTION, "Test Plugin 1"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_PROVIDER, "Decebal Suiu"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_DEPENDENCIES, "test-plugin-2,test-plugin-3@~1.0"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_REQUIRES, "*"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_LICENSE, "Apache-2.0"); + + return PluginJar.createManifest(map); } - private List<String> getPlugin2Manifest() { - String[] lines = new String[] { - "Manifest-Version: 1.0\n" - + "Plugin-Dependencies: \n" - + "Implementation-Title: Test Plugin #2\n" - + "Implementation-Version: 0.10.0-SNAPSHOT\n" - + "Archiver-Version: Plexus Archiver\n" - + "Built-By: Mario Franco\n" - + "Specification-Title: Test Plugin #2\n" - + "Implementation-Vendor-Id: org.pf4j.demo\n" - + "Plugin-Version: 0.0.1\n" - + "Plugin-Id: test-plugin-2\n" - + "Plugin-Provider: Decebal Suiu\n" - + "Plugin-Class: org.pf4j.plugin.TestPlugin\n" - + "Created-By: Apache Maven 3.0.5\n" - + "Build-Jdk: 1.8.0_45\n" - + "Specification-Version: 0.10.0-SNAPSHOT\n" - + "\n" - + "" - }; - - return Arrays.asList(lines); + private Manifest getPlugin2Manifest() { + Map<String, String> map = new LinkedHashMap<>(5); + map.put(ManifestPluginDescriptorFinder.PLUGIN_ID, "test-plugin-2"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_CLASS, "org.pf4j.plugin.TestPlugin"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_VERSION, "0.0.1"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_PROVIDER, "Decebal Suiu"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_DEPENDENCIES, ""); + + return PluginJar.createManifest(map); } - private List<String> getPlugin4Manifest() { - String[] lines = new String[] { - "Manifest-Version: 1.0\n" - + "Implementation-Title: Test Plugin #4\n" - + "Implementation-Version: 0.10.0-SNAPSHOT\n" - + "Archiver-Version: Plexus Archiver\n" - + "Built-By: Mario Franco\n" - + "Specification-Title: Test Plugin #4\n" - + "Implementation-Vendor-Id: org.pf4j.demo\n" - + "Plugin-Version: 0.0.1\n" - + "Plugin-Id: test-plugin-2\n" - + "Plugin-Provider: Decebal Suiu\n" - + "Created-By: Apache Maven 3.0.5\n" - + "Build-Jdk: 1.8.0_45\n" - + "Specification-Version: 0.10.0-SNAPSHOT\n" - + "\n" - + "" - }; - - return Arrays.asList(lines); + private Manifest getPlugin4Manifest() { + Map<String, String> map = new LinkedHashMap<>(3); + map.put(ManifestPluginDescriptorFinder.PLUGIN_ID, "test-plugin-1"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_VERSION, "0.0.1"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_PROVIDER, "Decebal Suiu"); + + return PluginJar.createManifest(map); } - private List<String> getPlugin5Manifest() { - String[] lines = new String[] { - "Manifest-Version: 1.0\n" - + "Implementation-Title: Test Plugin #5\n" - + "Implementation-Version: 0.10.0-SNAPSHOT\n" - + "Archiver-Version: Plexus Archiver\n" - + "Built-By: Mario Franco\n" - + "Specification-Title: Test Plugin #5\n" - + "Implementation-Vendor-Id: org.pf4j.demo\n" - + "Plugin-Id: test-plugin-2\n" - + "Plugin-Provider: Decebal Suiu\n" - + "Plugin-Class: org.pf4j.plugin.TestPlugin\n" - + "Created-By: Apache Maven 3.0.5\n" - + "Build-Jdk: 1.8.0_45\n" - + "Specification-Version: 0.10.0-SNAPSHOT\n" - + "\n" - + "" - }; - - return Arrays.asList(lines); + private Manifest getPlugin5Manifest() { + Map<String, String> map = new LinkedHashMap<>(3); + map.put(ManifestPluginDescriptorFinder.PLUGIN_ID, "test-plugin-2"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_CLASS, "org.pf4j.plugin.TestPlugin"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_PROVIDER, "Decebal Suiu"); + + return PluginJar.createManifest(map); + } + + private Manifest getPlugin6Manifest() { + Map<String, String> map = new LinkedHashMap<>(2); + map.put(ManifestPluginDescriptorFinder.PLUGIN_CLASS, "org.pf4j.plugin.TestPlugin"); + map.put(ManifestPluginDescriptorFinder.PLUGIN_PROVIDER, "Decebal Suiu"); + + return PluginJar.createManifest(map); } - private List<String> getPlugin6Manifest() { - String[] lines = new String[] { - "Manifest-Version: 1.0\n" - + "Implementation-Title: Test Plugin #6\n" - + "Implementation-Version: 0.10.0-SNAPSHOT\n" - + "Archiver-Version: Plexus Archiver\n" - + "Built-By: Mario Franco\n" - + "Specification-Title: Test Plugin #6\n" - + "Implementation-Vendor-Id: org.pf4j.demo\n" - + "Plugin-Provider: Decebal Suiu\n" - + "Plugin-Class: org.pf4j.plugin.TestPlugin\n" - + "Created-By: Apache Maven 3.0.5\n" - + "Build-Jdk: 1.8.0_45\n" - + "Specification-Version: 0.10.0-SNAPSHOT\n" - + "\n" - + "" - }; - - return Arrays.asList(lines); + private void storeManifestToPath(Manifest manifest, Path pluginPath) throws IOException { + Path path = Files.createDirectory(pluginPath.resolve("META-INF")); + try (OutputStream output = new FileOutputStream(path.resolve("MANIFEST.MF").toFile())) { + manifest.write(output); + } } } diff --git a/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java b/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java index 2be2eb8..efb326e 100644 --- a/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java +++ b/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java @@ -18,6 +18,7 @@ package org.pf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import org.pf4j.plugin.PluginZip; import java.io.FileOutputStream; import java.io.IOException; @@ -26,6 +27,8 @@ import java.io.Writer; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.util.LinkedHashMap; +import java.util.Map; import java.util.Properties; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -42,25 +45,25 @@ public class PropertiesPluginDescriptorFinderTest { @BeforeEach public void setUp() throws IOException { - Path pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-1")); + Path pluginPath = Files.createDirectory(pluginsPath.resolve("test-plugin-1")); storePropertiesToPath(getPlugin1Properties(), pluginPath); - pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-2")); + pluginPath = Files.createDirectory(pluginsPath.resolve("test-plugin-2")); storePropertiesToPath(getPlugin2Properties(), pluginPath); // empty plugin Files.createDirectories(pluginsPath.resolve("test-plugin-3")); // no plugin class - pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-4")); + pluginPath = Files.createDirectory(pluginsPath.resolve("test-plugin-4")); storePropertiesToPath(getPlugin4Properties(), pluginPath); // no plugin version - pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-5")); + pluginPath = Files.createDirectory(pluginsPath.resolve("test-plugin-5")); storePropertiesToPath(getPlugin5Properties(), pluginPath); // no plugin id - pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-6")); + pluginPath = Files.createDirectory(pluginsPath.resolve("test-plugin-6")); storePropertiesToPath(getPlugin6Properties(), pluginPath); versionManager = new DefaultVersionManager(); @@ -104,61 +107,61 @@ public class PropertiesPluginDescriptorFinderTest { } private Properties getPlugin1Properties() { - Properties properties = new Properties(); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_ID, "test-plugin-1"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_VERSION, "0.0.1"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_DESCRIPTION, "Test Plugin 1"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_PROVIDER, "Decebal Suiu"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_CLASS, "org.pf4j.plugin.TestPlugin"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_DEPENDENCIES, "test-plugin-2,test-plugin-3@~1.0"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_REQUIRES, ">=1"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_LICENSE, "Apache-2.0"); - - return properties; + Map<String, String> map = new LinkedHashMap<>(8); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_ID, "test-plugin-1"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_VERSION, "0.0.1"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_DESCRIPTION, "Test Plugin 1"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_PROVIDER, "Decebal Suiu"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_CLASS, "org.pf4j.plugin.TestPlugin"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_DEPENDENCIES, "test-plugin-2,test-plugin-3@~1.0"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_REQUIRES, ">=1"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_LICENSE, "Apache-2.0"); + + return PluginZip.createProperties(map); } private Properties getPlugin2Properties() { - Properties properties = new Properties(); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_ID, "test-plugin-2"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_VERSION, "0.0.1"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_PROVIDER, "Decebal Suiu"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_CLASS, "org.pf4j.plugin.TestPlugin"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_DEPENDENCIES, ""); - - return properties; + Map<String, String> map = new LinkedHashMap<>(5); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_ID, "test-plugin-2"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_VERSION, "0.0.1"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_PROVIDER, "Decebal Suiu"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_CLASS, "org.pf4j.plugin.TestPlugin"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_DEPENDENCIES, ""); + + return PluginZip.createProperties(map); } private Properties getPlugin4Properties() { - Properties properties = new Properties(); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_ID, "test-plugin-2"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_VERSION, "0.0.1"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_PROVIDER, "Decebal Suiu"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_DEPENDENCIES, ""); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_REQUIRES, "*"); - - return properties; + Map<String, String> map = new LinkedHashMap<>(5); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_ID, "test-plugin-2"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_VERSION, "0.0.1"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_PROVIDER, "Decebal Suiu"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_DEPENDENCIES, ""); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_REQUIRES, "*"); + + return PluginZip.createProperties(map); } private Properties getPlugin5Properties() { - Properties properties = new Properties(); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_ID, "test-plugin-2"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_PROVIDER, "Decebal Suiu"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_CLASS, "org.pf4j.plugin.TestPlugin"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_DEPENDENCIES, ""); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_REQUIRES, "*"); - - return properties; + Map<String, String> map = new LinkedHashMap<>(5); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_ID, "test-plugin-2"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_PROVIDER, "Decebal Suiu"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_CLASS, "org.pf4j.plugin.TestPlugin"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_DEPENDENCIES, ""); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_REQUIRES, "*"); + + return PluginZip.createProperties(map); } private Properties getPlugin6Properties() { - Properties properties = new Properties(); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_VERSION, "0.0.1"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_PROVIDER, "Decebal Suiu"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_CLASS, "org.pf4j.plugin.TestPlugin"); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_DEPENDENCIES, ""); - properties.setProperty(PropertiesPluginDescriptorFinder.PLUGIN_REQUIRES, "*"); - - return properties; + Map<String, String> map = new LinkedHashMap<>(5); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_VERSION, "0.0.1"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_PROVIDER, "Decebal Suiu"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_CLASS, "org.pf4j.plugin.TestPlugin"); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_DEPENDENCIES, ""); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_REQUIRES, "*"); + + return PluginZip.createProperties(map); } private void storePropertiesToPath(Properties properties, Path pluginPath) throws IOException { diff --git a/pf4j/src/test/java/org/pf4j/plugin/PluginJar.java b/pf4j/src/test/java/org/pf4j/plugin/PluginJar.java index 30b3c26..2301285 100644 --- a/pf4j/src/test/java/org/pf4j/plugin/PluginJar.java +++ b/pf4j/src/test/java/org/pf4j/plugin/PluginJar.java @@ -20,8 +20,8 @@ import org.pf4j.ManifestPluginDescriptorFinder; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Path; +import java.util.LinkedHashMap; import java.util.Map; -import java.util.Set; import java.util.jar.Attributes; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; @@ -57,6 +57,17 @@ public class PluginJar { return pluginVersion; } + public static Manifest createManifest(Map<String, String> map) { + Manifest manifest = new Manifest(); + Attributes attributes = manifest.getMainAttributes(); + attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0.0"); + for (Map.Entry<String, String> entry : map.entrySet()) { + attributes.put(new Attributes.Name(entry.getKey()), entry.getValue()); + } + + return manifest; + } + public static class Builder { private final Path path; @@ -92,20 +103,15 @@ public class PluginJar { } protected void createManifestFile() throws IOException { - Manifest manifest = new Manifest(); - Attributes attrs = manifest.getMainAttributes(); - attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0.0"); - attrs.put(new Attributes.Name(ManifestPluginDescriptorFinder.PLUGIN_ID), pluginId); - attrs.put(new Attributes.Name(ManifestPluginDescriptorFinder.PLUGIN_VERSION), pluginVersion); - attrs.put(new Attributes.Name(ManifestPluginDescriptorFinder.PLUGIN_CLASS), "org.pf4j.plugin.TestPlugin"); + Map<String, String> map = new LinkedHashMap<>(); + map.put(ManifestPluginDescriptorFinder.PLUGIN_ID, pluginId); + map.put(ManifestPluginDescriptorFinder.PLUGIN_VERSION, pluginVersion); + map.put(ManifestPluginDescriptorFinder.PLUGIN_CLASS, "org.pf4j.plugin.TestPlugin"); if (attributes != null) { - Set<String> names = attributes.keySet(); - for (String name : names) { - attrs.put(new Attributes.Name(name), attributes.get(name)); - } + map.putAll(attributes); } - JarOutputStream outputStream = new JarOutputStream(new FileOutputStream(path.toFile()), manifest); + JarOutputStream outputStream = new JarOutputStream(new FileOutputStream(path.toFile()), createManifest(map)); outputStream.close(); } diff --git a/pf4j/src/test/java/org/pf4j/plugin/PluginZip.java b/pf4j/src/test/java/org/pf4j/plugin/PluginZip.java index ee665d7..8e610c1 100644 --- a/pf4j/src/test/java/org/pf4j/plugin/PluginZip.java +++ b/pf4j/src/test/java/org/pf4j/plugin/PluginZip.java @@ -15,9 +15,12 @@ */ package org.pf4j.plugin; +import org.pf4j.PropertiesPluginDescriptorFinder; + import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Path; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Properties; import java.util.zip.ZipEntry; @@ -60,6 +63,13 @@ public class PluginZip { return path.getParent().resolve(fileName.substring(0, fileName.length() - 4)); // without ".zip" suffix } + public static Properties createProperties(Map<String, String> map) { + Properties properties = new Properties(); + properties.putAll(map); + + return properties; + } + public static class Builder { private final Path path; @@ -95,18 +105,18 @@ public class PluginZip { } protected void createPropertiesFile() throws IOException { - Properties props = new Properties(); - props.setProperty("plugin.id", pluginId); - props.setProperty("plugin.version", pluginVersion); - props.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin"); + Map<String, String> map = new LinkedHashMap<>(); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_ID, pluginId); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_VERSION, pluginVersion); + map.put(PropertiesPluginDescriptorFinder.PLUGIN_CLASS, "org.pf4j.plugin.TestPlugin"); if (properties != null) { - props.putAll(properties); + map.putAll(properties); } ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(path.toFile())); - ZipEntry propertiesFile = new ZipEntry("plugin.properties"); + ZipEntry propertiesFile = new ZipEntry(PropertiesPluginDescriptorFinder.DEFAULT_PROPERTIES_FILE_NAME); outputStream.putNextEntry(propertiesFile); - props.store(outputStream, ""); + createProperties(map).store(outputStream, ""); outputStream.closeEntry(); outputStream.close(); } |