Skip to content

Commit eca5e63

Browse files
authored
Merge pull request #17 from TIHBS/start-plguins-option-on-start
Optional boolean flag to enable plugins at start
2 parents c7cf9d0 + 96a09a6 commit eca5e63

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ mvn install
7373
Then, the WAR file (which can be found in the folder 'target' generated after a successful build) can be deployed on an
7474
Apache Tomcat server.
7575

76-
Required VM options while running
76+
VM options while running
7777

78-
- `pf4j.pluginsDir` path where the plugins will be stored
78+
- `pf4j.pluginsDir` path where the plugins will be stored. This property is mandatory.
79+
- `enablePluginsAtStart` boolean flag to enable plugins during startup (default false). This property is optional.
7980

8081
## Plugin management
8182

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
</dependencyManagement>
5151

5252
<dependencies>
53+
<dependency>
54+
<groupId>org.glassfish</groupId>
55+
<artifactId>javax.json</artifactId>
56+
<version>1.0.4</version>
57+
</dependency>
5358
<dependency>
5459
<groupId>org.glassfish.jersey.containers</groupId>
5560
<artifactId>jersey-container-servlet-core</artifactId>

src/main/java/blockchains/iaas/uni/stuttgart/de/management/BlockchainPluginManager.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,25 @@
1616

1717
import com.fasterxml.jackson.databind.ObjectMapper;
1818
import com.fasterxml.jackson.databind.jsontype.NamedType;
19-
import org.pf4j.*;
19+
import org.pf4j.DefaultPluginManager;
20+
import org.pf4j.PluginManager;
21+
import org.pf4j.PluginState;
22+
import org.pf4j.PluginWrapper;
23+
import org.pf4j.ManifestPluginDescriptorFinder;
24+
import org.pf4j.DependencyResolver.DependenciesNotFoundException;
25+
import org.pf4j.JarPluginLoader;
26+
import org.pf4j.PluginDescriptorFinder;
27+
import org.pf4j.PluginLoader;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
2030

2131
import java.nio.file.Path;
2232
import java.util.List;
2333

2434
public class BlockchainPluginManager {
2535

36+
private static final Logger log = LoggerFactory.getLogger(BlockchainPluginManager.class);
37+
2638
private PluginManager pluginManager = null;
2739
private static BlockchainPluginManager instance = null;
2840

@@ -41,8 +53,12 @@ protected PluginDescriptorFinder createPluginDescriptorFinder() {
4153
return new ManifestPluginDescriptorFinder();
4254
}
4355
};
56+
4457
pluginManager.loadPlugins();
4558

59+
if (Boolean.getBoolean("enablePluginsAtStart")) {
60+
pluginManager.startPlugins();
61+
}
4662
}
4763

4864
public static BlockchainPluginManager getInstance() {

src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/PluginManagerController.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.fasterxml.jackson.databind.node.ObjectNode;
77
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
88
import org.glassfish.jersey.media.multipart.FormDataParam;
9+
import org.pf4j.DependencyResolver.DependenciesNotFoundException;
910
import org.pf4j.PluginWrapper;
1011
import org.slf4j.Logger;
1112
import org.slf4j.LoggerFactory;
@@ -47,10 +48,12 @@ public Response uploadJar(@FormDataParam("file") InputStream uploadedInputStream
4748
return Response.status(Response.Status.BAD_REQUEST).entity("File already exists with same name.").build();
4849
}
4950
writeToFile(uploadedInputStream, uploadedFileLocation);
50-
51-
blockchainPluginManager.loadJar(filePath);
52-
53-
return Response.ok().build();
51+
try {
52+
blockchainPluginManager.loadJar(filePath);
53+
return Response.ok().build();
54+
} catch (DependenciesNotFoundException e) {
55+
return Response.status(400).entity(e.getMessage()).type("text/plain").build();
56+
}
5457
}
5558

5659
@POST

0 commit comments

Comments
 (0)