if (pluginId != null) {
PluginWrapper pluginWrapper = pluginManager.getPlugin(pluginId);
- if (PluginState.STARTED != pluginWrapper.getPluginState()) {
+ if (!pluginWrapper.getPluginState().isStarted()) {
return result;
}
List<String> missingPluginIds = new ArrayList<>();
for (String requiredPluginId : extensionInfo.getPlugins()) {
PluginWrapper requiredPlugin = pluginManager.getPlugin(requiredPluginId);
- if (requiredPlugin == null || !PluginState.STARTED.equals(requiredPlugin.getPluginState())) {
+ if (requiredPlugin == null || !requiredPlugin.getPluginState().isStarted()) {
missingPluginIds.add(requiredPluginId);
}
}
if (pluginId != null) {
PluginWrapper pluginWrapper = pluginManager.getPlugin(pluginId);
- if (PluginState.STARTED != pluginWrapper.getPluginState()) {
+ if (!pluginWrapper.getPluginState().isStarted()) {
return result;
}
// clear cache
entries = null;
- // By default we're assuming, that no checks for extension dependencies are necessary.
+ // By default, we're assuming, that no checks for extension dependencies are necessary.
//
// A plugin, that has an optional dependency to other plugins, might lead to unloadable
// Java classes (NoClassDefFoundError) at application runtime due to possibly missing
- // dependencies. Therefore we're enabling the check for optional extensions, if the
+ // dependencies. Therefore, we're enabling the check for optional extensions, if the
// started plugin contains at least one optional plugin dependency.
- if (checkForExtensionDependencies == null && PluginState.STARTED.equals(event.getPluginState())) {
+ if (checkForExtensionDependencies == null && event.getPluginState().isStarted()) {
for (PluginDependency dependency : event.getPlugin().getDescriptor().getDependencies()) {
if (dependency.isOptional()) {
log.debug("Enable check for extension dependencies via ASM.");
* <p>
* This feature is enabled by default, if at least one available plugin makes use of
* optional plugin dependencies. Those optional plugins might not be available at runtime.
- * Therefore any extension is checked by default against available plugins before its
+ * Therefore, any extension is checked by default against available plugins before its
* instantiation.
* <p>
* Notice: This feature requires the optional <a href="https://asm.ow2.io/">ASM library</a>
* <p>
* This feature is enabled by default, if at least one available plugin makes use of
* optional plugin dependencies. Those optional plugins might not be available at runtime.
- * Therefore any extension is checked by default against available plugins before its
+ * Therefore, any extension is checked by default against available plugins before its
* instantiation.
* <p>
* Notice: This feature requires the optional <a href="https://asm.ow2.io/">ASM library</a>
PluginState pluginState;
try {
pluginState = stopPlugin(pluginId, false);
- if (PluginState.STARTED == pluginState) {
+ if (pluginState.isStarted()) {
return false;
}
PluginWrapper pluginWrapper = getPlugin(pluginId);
// stop the plugin if it's started
PluginState pluginState = stopPlugin(pluginId);
- if (PluginState.STARTED == pluginState) {
+ if (pluginState.isStarted()) {
log.error("Failed to stop plugin '{}' on delete", pluginId);
return false;
}
public void startPlugins() {
for (PluginWrapper pluginWrapper : resolvedPlugins) {
PluginState pluginState = pluginWrapper.getPluginState();
- if ((PluginState.DISABLED != pluginState) && (PluginState.STARTED != pluginState)) {
+ if (!pluginState.isDisabled() && !pluginState.isStarted()) {
try {
log.info("Start plugin '{}'", getPluginLabel(pluginWrapper.getDescriptor()));
pluginWrapper.getPlugin().start();
PluginWrapper pluginWrapper = getPlugin(pluginId);
PluginDescriptor pluginDescriptor = pluginWrapper.getDescriptor();
PluginState pluginState = pluginWrapper.getPluginState();
- if (PluginState.STARTED == pluginState) {
+ if (pluginState.isStarted()) {
log.debug("Already started plugin '{}'", getPluginLabel(pluginDescriptor));
return PluginState.STARTED;
}
return pluginState;
}
- if (PluginState.DISABLED == pluginState) {
+ if (pluginState.isDisabled()) {
// automatically enable plugin on manual plugin start
if (!enablePlugin(pluginId)) {
return pluginState;
while (itr.hasNext()) {
PluginWrapper pluginWrapper = itr.next();
PluginState pluginState = pluginWrapper.getPluginState();
- if (PluginState.STARTED == pluginState) {
+ if (pluginState.isStarted()) {
try {
log.info("Stop plugin '{}'", getPluginLabel(pluginWrapper.getDescriptor()));
pluginWrapper.getPlugin().stop();
PluginWrapper pluginWrapper = getPlugin(pluginId);
PluginDescriptor pluginDescriptor = pluginWrapper.getDescriptor();
PluginState pluginState = pluginWrapper.getPluginState();
- if (PluginState.DISABLED == pluginState) {
+ if (pluginState.isDisabled()) {
log.debug("Already disabled plugin '{}'", getPluginLabel(pluginDescriptor));
return true;
- } else if (PluginState.STARTED == pluginState) {
- if (PluginState.STOPPED != stopPlugin(pluginId)) {
+ } else if (pluginState.isStarted()) {
+ if (!stopPlugin(pluginId).isStopped()) {
log.error("Failed to stop plugin '{}' on disable", getPluginLabel(pluginDescriptor));
return false;
}
PluginDescriptor pluginDescriptor = pluginWrapper.getDescriptor();
PluginState pluginState = pluginWrapper.getPluginState();
- if (PluginState.DISABLED != pluginState) {
+ if (!pluginState.isDisabled()) {
log.debug("Plugin '{}' is not disabled", getPluginLabel(pluginDescriptor));
return true;
}
PluginWrapper pluginWrapper = plugins.get(pluginId);
if (unresolvedPlugins.remove(pluginWrapper)) {
PluginState pluginState = pluginWrapper.getPluginState();
- if (pluginState != PluginState.DISABLED) {
+ if (!pluginState.isDisabled()) {
pluginWrapper.setPluginState(PluginState.RESOLVED);
}
this.status = status;
}
+ /**
+ * Returns {@code true} if the value is {@link #CREATED}.
+ */
+ public boolean isCreated() {
+ return this == CREATED;
+ }
+
+ /**
+ * Returns {@code true} if the value is {@link #DISABLED}.
+ */
+ public boolean isDisabled() {
+ return this == DISABLED;
+ }
+
+ /**
+ * Returns {@code true} if the value is {@link #RESOLVED}.
+ */
+ public boolean isResolved() {
+ return this == RESOLVED;
+ }
+
+ /**
+ * Returns {@code true} if the value is {@link #STARTED}.
+ */
+ public boolean isStarted() {
+ return this == STARTED;
+ }
+
+ /**
+ * Returns {@code true} if the value is {@link #STOPPED}.
+ */
+ public boolean isStopped() {
+ return this == STOPPED;
+ }
+
+ /**
+ * Returns {@code true} if the value is {@link #FAILED}.
+ */
+ public boolean isFailed() {
+ return this == FAILED;
+ }
+
+ /**
+ * Returns {@code true} if the value is {@link #UNLOADED}.
+ */
+ public boolean isUnloaded() {
+ return this == UNLOADED;
+ }
+
public boolean equals(String status) {
- return (this.status.equalsIgnoreCase(status));
+ return this.status.equalsIgnoreCase(status);
}
@Override
cache = new HashMap<>();
pluginManager.addPluginStateListener(event -> {
- if (event.getPluginState() != PluginState.STARTED) {
+ if (!event.getPluginState().isStarted()) {
cache.remove(event.getPlugin().getPluginClassLoader());
}
});
assertFalse(pluginZip.file().exists());
Optional<PluginStateEvent> unloadedEvent = receivedEvents.stream()
- .filter(event -> event.getPluginState() == PluginState.UNLOADED)
+ .filter(event -> event.getPluginState().isUnloaded())
.findFirst();
assertTrue(unloadedEvent.isPresent());
assertFalse(pluginJar.file().exists());
Optional<PluginStateEvent> unloadedEvent = receivedEvents.stream()
- .filter(event -> event.getPluginState() == PluginState.UNLOADED)
+ .filter(event -> event.getPluginState().isUnloaded())
.findFirst();
assertTrue(unloadedEvent.isPresent());
assertFalse(pluginZip.file().exists());
Optional<PluginStateEvent> unloadedEvent = receivedEvents.stream()
- .filter(event -> event.getPluginState() == PluginState.UNLOADED)
+ .filter(event -> event.getPluginState().isUnloaded())
.findFirst();
assertTrue(unloadedEvent.isPresent());