diff --git a/pf4j/src/main/java/org/pf4j/PropertiesPluginDescriptorFinder.java b/pf4j/src/main/java/org/pf4j/PropertiesPluginDescriptorFinder.java index 3e9e1c1..31afee9 100644 --- a/pf4j/src/main/java/org/pf4j/PropertiesPluginDescriptorFinder.java +++ b/pf4j/src/main/java/org/pf4j/PropertiesPluginDescriptorFinder.java @@ -36,7 +36,16 @@ public class PropertiesPluginDescriptorFinder implements PluginDescriptorFinder private static final Logger log = LoggerFactory.getLogger(PropertiesPluginDescriptorFinder.class); - private static final String DEFAULT_PROPERTIES_FILE_NAME = "plugin.properties"; + public static final String DEFAULT_PROPERTIES_FILE_NAME = "plugin.properties"; + + public static final String PLUGIN_ID = "plugin.id"; + public static final String PLUGIN_DESCRIPTION = "plugin.description"; + public static final String PLUGIN_CLASS = "plugin.class"; + public static final String PLUGIN_VERSION = "plugin.version"; + public static final String PLUGIN_PROVIDER = "plugin.provider"; + public static final String PLUGIN_DEPENDENCIES = "plugin.dependencies"; + public static final String PLUGIN_REQUIRES = "plugin.requires"; + public static final String PLUGIN_LICENSE = "plugin.license"; protected String propertiesFileName; @@ -98,38 +107,38 @@ public class PropertiesPluginDescriptorFinder implements PluginDescriptorFinder DefaultPluginDescriptor pluginDescriptor = createPluginDescriptorInstance(); // TODO validate !!! - String id = properties.getProperty("plugin.id"); + String id = properties.getProperty(PLUGIN_ID); pluginDescriptor.setPluginId(id); - String description = properties.getProperty("plugin.description"); + String description = properties.getProperty(PLUGIN_DESCRIPTION); if (StringUtils.isNullOrEmpty(description)) { pluginDescriptor.setPluginDescription(""); } else { pluginDescriptor.setPluginDescription(description); } - String clazz = properties.getProperty("plugin.class"); + String clazz = properties.getProperty(PLUGIN_CLASS); if (StringUtils.isNotNullOrEmpty(clazz)) { pluginDescriptor.setPluginClass(clazz); } - String version = properties.getProperty("plugin.version"); + String version = properties.getProperty(PLUGIN_VERSION); if (StringUtils.isNotNullOrEmpty(version)) { pluginDescriptor.setPluginVersion(version); } - String provider = properties.getProperty("plugin.provider"); + String provider = properties.getProperty(PLUGIN_PROVIDER); pluginDescriptor.setProvider(provider); - String dependencies = properties.getProperty("plugin.dependencies"); + String dependencies = properties.getProperty(PLUGIN_DEPENDENCIES); pluginDescriptor.setDependencies(dependencies); - String requires = properties.getProperty("plugin.requires"); + String requires = properties.getProperty(PLUGIN_REQUIRES); if (StringUtils.isNotNullOrEmpty(requires)) { pluginDescriptor.setRequires(requires); } - pluginDescriptor.setLicense(properties.getProperty("plugin.license")); + pluginDescriptor.setLicense(properties.getProperty(PLUGIN_LICENSE)); return pluginDescriptor; } diff --git a/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java b/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java index a65c84e..2be2eb8 100644 --- a/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java +++ b/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java @@ -43,25 +43,25 @@ public class PropertiesPluginDescriptorFinderTest { @BeforeEach public void setUp() throws IOException { Path pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-1")); - storePropertiesToPath(getPlugin1Properties(), pluginPath.resolve("plugin.properties")); + storePropertiesToPath(getPlugin1Properties(), pluginPath); pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-2")); - storePropertiesToPath(getPlugin2Properties(), pluginPath.resolve("plugin.properties")); + storePropertiesToPath(getPlugin2Properties(), pluginPath); // empty plugin Files.createDirectories(pluginsPath.resolve("test-plugin-3")); // no plugin class pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-4")); - storePropertiesToPath(getPlugin4Properties(), pluginPath.resolve("plugin.properties")); + storePropertiesToPath(getPlugin4Properties(), pluginPath); // no plugin version pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-5")); - storePropertiesToPath(getPlugin5Properties(), pluginPath.resolve("plugin.properties")); + storePropertiesToPath(getPlugin5Properties(), pluginPath); // no plugin id pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-6")); - storePropertiesToPath(getPlugin6Properties(), pluginPath.resolve("plugin.properties")); + storePropertiesToPath(getPlugin6Properties(), pluginPath); versionManager = new DefaultVersionManager(); } @@ -105,63 +105,64 @@ public class PropertiesPluginDescriptorFinderTest { private Properties getPlugin1Properties() { Properties properties = new Properties(); - properties.setProperty("plugin.id", "test-plugin-1"); - properties.setProperty("plugin.version", "0.0.1"); - properties.setProperty("plugin.description", "Test Plugin 1"); - properties.setProperty("plugin.provider", "Decebal Suiu"); - properties.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin"); - properties.setProperty("plugin.dependencies", "test-plugin-2,test-plugin-3@~1.0"); - properties.setProperty("plugin.requires", ">=1"); - properties.setProperty("plugin.license", "Apache-2.0"); + 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; } private Properties getPlugin2Properties() { Properties properties = new Properties(); - properties.setProperty("plugin.id", "test-plugin-2"); - properties.setProperty("plugin.version", "0.0.1"); - properties.setProperty("plugin.provider", "Decebal Suiu"); - properties.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin"); - properties.setProperty("plugin.dependencies", ""); + 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; } private Properties getPlugin4Properties() { Properties properties = new Properties(); - properties.setProperty("plugin.id", "test-plugin-2"); - properties.setProperty("plugin.version", "0.0.1"); - properties.setProperty("plugin.provider", "Decebal Suiu"); - properties.setProperty("plugin.dependencies", ""); - properties.setProperty("plugin.requires", "*"); + 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; } private Properties getPlugin5Properties() { Properties properties = new Properties(); - properties.setProperty("plugin.id", "test-plugin-2"); - properties.setProperty("plugin.provider", "Decebal Suiu"); - properties.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin"); - properties.setProperty("plugin.dependencies", ""); - properties.setProperty("plugin.requires", "*"); + 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; } private Properties getPlugin6Properties() { Properties properties = new Properties(); - properties.setProperty("plugin.version", "0.0.1"); - properties.setProperty("plugin.provider", "Decebal Suiu"); - properties.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin"); - properties.setProperty("plugin.dependencies", ""); - properties.setProperty("plugin.requires", "*"); + 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; } - private void storePropertiesToPath(Properties properties, Path path) throws IOException { + private void storePropertiesToPath(Properties properties, Path pluginPath) throws IOException { + Path path = pluginPath.resolve(PropertiesPluginDescriptorFinder.DEFAULT_PROPERTIES_FILE_NAME); try (Writer writer = new OutputStreamWriter(new FileOutputStream(path.toFile()), StandardCharsets.UTF_8)) { properties.store(writer, ""); }