Browse Source

Merge pull request #133 from cominvent/plugin-license

Support for adding license information to the plugins
pull/134/head
Decebal Suiu 8 years ago committed by GitHub
parent
commit
d7d1eec24e
  1. 2
      pf4j/src/main/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinder.java
  2. 19
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java
  3. 2
      pf4j/src/main/java/ro/fortsoft/pf4j/PropertiesPluginDescriptorFinder.java
  4. 2
      pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java
  5. 2
      pf4j/src/test/java/ro/fortsoft/pf4j/PropertiesPluginDescriptorFinderTest.java

2
pf4j/src/main/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinder.java

@ -74,6 +74,8 @@ public abstract class ManifestPluginDescriptorFinder implements PluginDescriptor
pluginDescriptor.setRequires(requires);
}
pluginDescriptor.setLicense(attributes.getValue("Plugin-License"));
return pluginDescriptor;
}

19
pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java

@ -39,6 +39,7 @@ public class PluginDescriptor {
private Expression requires;
private String provider;
private List<PluginDependency> dependencies;
private String license;
public PluginDescriptor() {
requires = gte("0.0.0"); // Any
@ -87,6 +88,13 @@ public class PluginDescriptor {
return provider;
}
/**
* Returns the legal license of this plugin, e.g. "Apache-2.0", "MIT" etc
*/
public String getLicense() {
return license;
}
/**
* Returns all dependencies declared by this plugin.
* Returns an empty array if this plugin does not declare any require.
@ -99,8 +107,9 @@ public class PluginDescriptor {
public String toString() {
return "PluginDescriptor [pluginId=" + pluginId + ", pluginClass="
+ pluginClass + ", version=" + version + ", provider="
+ provider + ", dependencies=" + dependencies
+ "]";
+ provider + ", dependencies=" + dependencies + ", description="
+ pluginDescription + ", requires=" + requires + ", license="
+ license + "]";
}
void setPluginId(String pluginId) {
@ -125,7 +134,7 @@ public class PluginDescriptor {
void setRequires(String requires) {
Parser<Expression> parser = ExpressionParser.newInstance();
this.requires = parser.parse(requires);
setRequires(parser.parse(requires));
}
void setRequires(Expression requires) {
@ -155,4 +164,8 @@ public class PluginDescriptor {
}
}
public void setLicense(String license) {
this.license = license;
}
}

2
pf4j/src/main/java/ro/fortsoft/pf4j/PropertiesPluginDescriptorFinder.java

@ -108,6 +108,8 @@ public class PropertiesPluginDescriptorFinder implements PluginDescriptorFinder
pluginDescriptor.setRequires(requires);
}
pluginDescriptor.setLicense(properties.getProperty("plugin.license"));
return pluginDescriptor;
}

2
pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java

@ -90,6 +90,7 @@ public class ManifestPluginDescriptorFinderTest {
assertEquals("test-plugin-2", plugin1.getDependencies().get(0).getPluginId());
assertEquals("test-plugin-3", plugin1.getDependencies().get(1).getPluginId());
assertEquals("~1.0", plugin1.getDependencies().get(1).getPluginVersionSupport());
assertEquals("Apache-2.0", plugin1.getLicense());
assertTrue(plugin1.getRequires().interpret(Version.valueOf("1.0.0")));
assertEquals("test-plugin-2", plugin2.getPluginId());
@ -153,6 +154,7 @@ public class ManifestPluginDescriptorFinderTest {
+ "Plugin-Class: ro.fortsoft.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"

2
pf4j/src/test/java/ro/fortsoft/pf4j/PropertiesPluginDescriptorFinderTest.java

@ -78,6 +78,7 @@ public class PropertiesPluginDescriptorFinderTest {
assertEquals("test-plugin-2", plugin1.getDependencies().get(0).getPluginId());
assertEquals("test-plugin-3", plugin1.getDependencies().get(1).getPluginId());
assertEquals("~1.0", plugin1.getDependencies().get(1).getPluginVersionSupport());
assertEquals("Apache-2.0", plugin1.getLicense());
assertTrue(plugin1.getRequires().interpret(Version.valueOf("1.0.0")));
assertEquals("test-plugin-2", plugin2.getPluginId());
@ -122,6 +123,7 @@ public class PropertiesPluginDescriptorFinderTest {
+ "plugin.class=ro.fortsoft.pf4j.plugin.TestPlugin\n"
+ "plugin.dependencies=test-plugin-2,test-plugin-3@~1.0\n"
+ "plugin.requires=*\n"
+ "plugin.license=Apache-2.0\n"
+ "\n"
+ ""
};

Loading…
Cancel
Save