Last active
September 8, 2015 11:10
-
-
Save tuxedo0801/0bc4ad265131b2d46643 to your computer and use it in GitHub Desktop.
JarPluginManager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.root1.kad.pf4j.util; | |
import ro.fortsoft.pf4j.util.ExtensionFileFilter; | |
/** | |
* File filter that accepts all files ending with .JAR. | |
* This filter is case insensitive. | |
* | |
* @author Alexander Christian | |
*/ | |
public class JarFileFilter extends ExtensionFileFilter { | |
/** | |
* The extension that this filter will search for. | |
*/ | |
private static final String JAR_EXTENSION = ".JAR"; | |
public JarFileFilter() { | |
super(JAR_EXTENSION); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.root1.kad.pf4j; | |
import java.util.ArrayList; | |
import java.util.List; | |
import ro.fortsoft.pf4j.PluginClasspath; | |
public class JarPluginClasspath extends PluginClasspath { | |
public JarPluginClasspath() { | |
super(); | |
} | |
protected void addResources() { | |
classesDirectories.add("."); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.root1.kad.pf4j; | |
import ro.fortsoft.pf4j.*; | |
import ro.fortsoft.pf4j.util.*; | |
public class JarPluginManager extends DefaultPluginManager { | |
@Override | |
protected PluginClasspath createPluginClasspath() { | |
if (RuntimeMode.DEVELOPMENT.equals(getRuntimeMode())) { | |
return new DevelopmentPluginClasspath(); | |
} | |
return new JarPluginClasspath(); | |
} | |
@Override | |
protected PluginRepository createPluginRepository() { | |
return new DefaultPluginRepository(pluginsDirectory, new JarFileFilter()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- plugin pom.xml: No additional assembly.xml required. Just use the "all-in-on-jar". --> | |
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
...... | |
<properties> | |
<!-- PF4J Plugin Settings --> | |
<plugin.id>knx-logic-plugin</plugin.id> | |
<plugin.class>de.root1.kad.logicplugin.LogicPlugin</plugin.class> | |
<plugin.version>1.0.0</plugin.version> | |
<plugin.provider>AC</plugin.provider> | |
<plugin.dependencies></plugin.dependencies> | |
</properties> | |
..... | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-assembly-plugin</artifactId> | |
<version>2.5.4</version> | |
<configuration> | |
<archive> | |
<manifestEntries> | |
<Plugin-Id>${plugin.id}</Plugin-Id> | |
<Plugin-Class>${plugin.class}</Plugin-Class> | |
<Plugin-Version>${plugin.version}</Plugin-Version> | |
<Plugin-Provider>${plugin.provider}</Plugin-Provider> | |
<Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies> | |
</manifestEntries> | |
</archive> | |
<descriptorRefs> | |
<descriptorRef>jar-with-dependencies</descriptorRef> | |
</descriptorRefs> | |
</configuration> | |
<!-- extend phase package to assembly the archives --> | |
<executions> | |
<execution> | |
<id>make-assembly</id> | |
<phase>package</phase> | |
<goals> | |
<goal>single</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
..... | |
</project> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.root1.kad.pf4j; | |
public class Test { | |
public static void main(String[] args) { | |
JarPluginManager pm = new JarPluginManager(); | |
pm.loadPlugins(); | |
pm.startPlugins(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment