mirror of https://github.com/pf4j/pf4j.git
Decebal Suiu
10 years ago
4 changed files with 184 additions and 39 deletions
@ -0,0 +1,52 @@
|
||||
/* |
||||
* Copyright 2012 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; |
||||
|
||||
import java.io.File; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author Decebal Suiu |
||||
* @author Mário Franco |
||||
*/ |
||||
public class CompoundPluginRepository implements PluginRepository { |
||||
|
||||
private final PluginRepository[] repositories; |
||||
|
||||
public CompoundPluginRepository(PluginRepository... repositories) { |
||||
this.repositories = repositories; |
||||
} |
||||
|
||||
@Override |
||||
public List<File> getPluginArchives() { |
||||
List<File> file = new ArrayList<>(); |
||||
for (PluginRepository repository : repositories) { |
||||
file.addAll(repository.getPluginArchives()); |
||||
} |
||||
|
||||
return file; |
||||
} |
||||
|
||||
@Override |
||||
public boolean deletePluginArchive(String pluginPath) { |
||||
for (PluginRepository repository : repositories) { |
||||
if (repository.deletePluginArchive(pluginPath)) { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,67 @@
|
||||
/* |
||||
* Copyright 2012 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; |
||||
|
||||
import ro.fortsoft.pf4j.util.FileUtils; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileFilter; |
||||
import java.util.Arrays; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author Decebal Suiu |
||||
* @author Mário Franco |
||||
*/ |
||||
public class DefaultPluginRepository implements PluginRepository { |
||||
|
||||
private final File directory; |
||||
private final FileFilter filter; |
||||
|
||||
public DefaultPluginRepository(File directory, FileFilter filter) { |
||||
this.directory = directory; |
||||
this.filter = filter; |
||||
} |
||||
|
||||
@Override |
||||
public List<File> getPluginArchives() { |
||||
File[] files = directory.listFiles(filter); |
||||
|
||||
return (files != null) ? Arrays.asList(files) : Collections.<File>emptyList(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean deletePluginArchive(String pluginPath) { |
||||
File[] files = directory.listFiles(filter); |
||||
if (files != null) { |
||||
File pluginArchive = null; |
||||
// strip prepended "/" from the plugin path
|
||||
String dirName = pluginPath.substring(1); |
||||
// find the zip file that matches the plugin path
|
||||
for (File archive : files) { |
||||
String name = archive.getName().substring(0, archive.getName().lastIndexOf('.')); |
||||
if (name.equals(dirName)) { |
||||
pluginArchive = archive; |
||||
break; |
||||
} |
||||
} |
||||
if (pluginArchive != null && pluginArchive.exists()) { |
||||
return FileUtils.delete(pluginArchive); |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,41 @@
|
||||
/* |
||||
* Copyright 2012 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; |
||||
|
||||
import java.io.File; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Directory whose contents are .zip files used as plugins. |
||||
* |
||||
* @author Decebal Suiu |
||||
* @author Mário Franco |
||||
*/ |
||||
public interface PluginRepository { |
||||
|
||||
/** |
||||
* List all plugin archive filed. |
||||
* |
||||
* @return a list of files |
||||
*/ |
||||
public List<File> getPluginArchives(); |
||||
|
||||
/** |
||||
* Removes a plugin from the repository. |
||||
* |
||||
* @param pluginPath the plugin path |
||||
* @return true if deleted |
||||
*/ |
||||
public boolean deletePluginArchive(String pluginPath); |
||||
|
||||
} |
Loading…
Reference in new issue