Browse Source

use PluginState.DISABLE instead of PluginManger.isPluginDisabled()

pull/9/head
Decebal Suiu 11 years ago
parent
commit
33baceffd7
  1. 12
      pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java
  2. 9
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java
  3. 10
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginManager.java
  4. 37
      pf4j/src/main/java/ro/fortsoft/pf4j/util/PluginUtils.java

12
pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java

@ -126,10 +126,6 @@ public class DefaultPluginManager implements PluginManager {
return resolvedPlugins;
}
public PluginWrapper getPlugin(String pluginId) {
return plugins.get(pluginId);
}
@Override
public List<PluginWrapper> getUnresolvedPlugins() {
return unresolvedPlugins;
@ -140,6 +136,11 @@ public class DefaultPluginManager implements PluginManager {
return startedPlugins;
}
@Override
public PluginWrapper getPlugin(String pluginId) {
return plugins.get(pluginId);
}
@Override
public String loadPlugin(File pluginArchiveFile) {
if (pluginArchiveFile == null || !pluginArchiveFile.exists()) {
@ -588,8 +589,7 @@ public class DefaultPluginManager implements PluginManager {
return new PluginClasspath();
}
@Override
public boolean isPluginDisabled(String pluginId) {
protected boolean isPluginDisabled(String pluginId) {
if (enabledPlugins.isEmpty()) {
return disabledPlugins.contains(pluginId);
}

9
pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java

@ -96,7 +96,7 @@ public class PluginClassLoader extends URLClassLoader {
@Override
public URL getResource(String name) {
if (pluginManager.isPluginDisabled(pluginDescriptor.getPluginId())) {
if (PluginState.DISABLED == getPlugin().getPluginState()) {
return null;
}
@ -105,10 +105,15 @@ public class PluginClassLoader extends URLClassLoader {
@Override
public Enumeration<URL> getResources(String name) throws IOException {
if (pluginManager.isPluginDisabled(pluginDescriptor.getPluginId())) {
if (PluginState.DISABLED == getPlugin().getPluginState()) {
return Collections.emptyEnumeration();
}
return super.getResources(name);
}
private PluginWrapper getPlugin() {
return pluginManager.getPlugin(pluginDescriptor.getPluginId());
}
}

10
pf4j/src/main/java/ro/fortsoft/pf4j/PluginManager.java

@ -49,6 +49,14 @@ public interface PluginManager {
*/
public List<PluginWrapper> getStartedPlugins();
/**
* Retrieves the plugin with this id.
*
* @param pluginId
* @return the plugin
*/
public PluginWrapper getPlugin(String pluginId);
/**
* Load plugins.
*/
@ -94,8 +102,6 @@ public interface PluginManager {
*/
public boolean unloadPlugin(String pluginId);
public boolean isPluginDisabled(String pluginId);
/**
* Disables a plugin from being loaded.
*

37
pf4j/src/main/java/ro/fortsoft/pf4j/util/PluginUtils.java

@ -1,37 +0,0 @@
/*
* Copyright 2014 Decebal Suiu
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with
* the License. You may obtain a copy of the License in the LICENSE file, or at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package ro.fortsoft.pf4j.util;
import ro.fortsoft.pf4j.PluginManager;
import ro.fortsoft.pf4j.PluginState;
import ro.fortsoft.pf4j.PluginWrapper;
import java.util.List;
/**
* @author Decebal Suiu
*/
public class PluginUtils {
public static boolean isPluginStarted(PluginManager pluginManager, String pluginId) {
List<PluginWrapper> startedPlugins = pluginManager.getStartedPlugins();
for (PluginWrapper plugin: startedPlugins) {
if (pluginId.equals(plugin.getPluginId())) {
return PluginState.STARTED == plugin.getPluginState();
}
}
return false;
}
}
Loading…
Cancel
Save