Browse Source

Remove JarPluginManager

tags/release-2.0.0
Decebal Suiu 6 years ago
parent
commit
46cb21cea6

+ 4
- 7
demo/app/src/main/java/org/pf4j/demo/Boot.java View File

@@ -15,16 +15,14 @@
*/
package org.pf4j.demo;

import java.util.List;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.pf4j.DefaultPluginManager;
import org.pf4j.PluginManager;
import org.pf4j.PluginWrapper;
import org.pf4j.demo.api.Greeting;
import org.pf4j.DefaultPluginManager;
import org.pf4j.JarPluginManager;

import java.util.List;
import java.util.Set;

/**
* A boot class that start the demo.
@@ -39,7 +37,6 @@ public class Boot {

// create the plugin manager
final PluginManager pluginManager = new DefaultPluginManager();
// final PluginManager pluginManager = new JarPluginManager();

// load the plugins
pluginManager.loadPlugins();

+ 9
- 3
pf4j/src/main/java/org/pf4j/CompoundPluginRepository.java View File

@@ -25,10 +25,16 @@ import java.util.List;
*/
public class CompoundPluginRepository implements PluginRepository {

private final PluginRepository[] repositories;
private List<PluginRepository> repositories = new ArrayList<>();

public CompoundPluginRepository(PluginRepository... repositories) {
this.repositories = repositories;
public CompoundPluginRepository add(PluginRepository repository) {
if (repository == null) {
throw new IllegalArgumentException("null not allowed");
}

repositories.add(repository);

return this;
}

@Override

+ 3
- 1
pf4j/src/main/java/org/pf4j/DefaultPluginManager.java View File

@@ -83,7 +83,9 @@ public class DefaultPluginManager extends AbstractPluginManager {

@Override
protected PluginRepository createPluginRepository() {
return new DefaultPluginRepository(getPluginsRoot(), isDevelopment());
return new CompoundPluginRepository()
.add(new DefaultPluginRepository(getPluginsRoot(), isDevelopment()))
.add(new JarPluginRepository(getPluginsRoot()));
}

@Override

+ 0
- 69
pf4j/src/main/java/org/pf4j/JarPluginManager.java View File

@@ -1,69 +0,0 @@
/*
* Copyright 2016 Decebal Suiu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License 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 org.pf4j;

import org.pf4j.util.AndFileFilter;
import org.pf4j.util.DirectoryFileFilter;
import org.pf4j.util.HiddenFilter;
import org.pf4j.util.JarFileFilter;
import org.pf4j.util.NameFileFilter;
import org.pf4j.util.NotFileFilter;
import org.pf4j.util.OrFileFilter;

import java.io.FileFilter;
import java.nio.file.Path;

/**
* It's a {@link PluginManager} that loads plugin from a jar file.
* Actually, a plugin is a fat jar, a jar which contains classes from all the libraries,
* on which your project depends and, of course, the classes of current project.
*
* @author Decebal Suiu
*/
public class JarPluginManager extends DefaultPluginManager {

@Override
protected PluginRepository createPluginRepository() {
return new JarPluginRepository(getPluginsRoot(), isDevelopment());
}

class JarPluginRepository extends BasePluginRepository {

public JarPluginRepository(Path pluginsRoot, boolean development) {
super(pluginsRoot);

if (development) {
AndFileFilter pluginsFilter = new AndFileFilter(new DirectoryFileFilter());
pluginsFilter.addFileFilter(new NotFileFilter(createHiddenPluginFilter(development)));
setFilter(pluginsFilter);
} else {
setFilter(new JarFileFilter());
}
}

protected FileFilter createHiddenPluginFilter(boolean development) {
OrFileFilter hiddenPluginFilter = new OrFileFilter(new HiddenFilter());

if (development) {
hiddenPluginFilter.addFileFilter(new NameFileFilter("target"));
}

return hiddenPluginFilter;
}

}

}

+ 31
- 0
pf4j/src/main/java/org/pf4j/JarPluginRepository.java View File

@@ -0,0 +1,31 @@
/*
* Copyright 2016 Decebal Suiu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License 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 org.pf4j;

import org.pf4j.util.JarFileFilter;

import java.nio.file.Path;

/**
* @author Decebal Suiu
*/
public class JarPluginRepository extends BasePluginRepository {

public JarPluginRepository(Path pluginsRoot) {
super(pluginsRoot, new JarFileFilter());
}

}

Loading…
Cancel
Save