use of org.zaproxy.zap.control.AddOn.ExtensionRunRequirements in project zaproxy by zaproxy.
the class AddOnLoader method getExtensions.
/**
* Returns all {@code Extension}s of the given {@code addOn}.
* <p>
* The discovery of {@code Extension}s is done by resorting to {@link AddOn#MANIFEST_FILE_NAME manifest file} bundled in the
* add-on.
* <p>
* Extensions with unfulfilled dependencies are not be returned.
* <p>
* <strong>Note:</strong> If the add-on is not installed the method returns an empty list.
*
* @param addOn the add-on whose extensions will be returned
* @return a list containing the {@code Extension}s of the given {@code addOn}
* @since 2.4.0
* @see Extension
* @see #getExtensions()
*/
public List<Extension> getExtensions(AddOn addOn) {
AddOnClassLoader addOnClassLoader = this.addOnLoaders.get(addOn.getId());
if (addOnClassLoader == null) {
return Collections.emptyList();
}
List<Extension> extensions = new ArrayList<>();
extensions.addAll(loadAddOnExtensions(addOn, addOn.getExtensions(), addOnClassLoader));
if (addOn.hasExtensionsWithDeps()) {
AddOn.AddOnRunRequirements reqs = addOn.calculateRunRequirements(aoc.getInstalledAddOns());
for (ExtensionRunRequirements extReqs : reqs.getExtensionRequirements()) {
if (extReqs.isRunnable()) {
List<AddOnClassLoader> dependencies = new ArrayList<>(extReqs.getDependencies().size());
for (AddOn addOnDep : extReqs.getDependencies()) {
dependencies.add(addOnLoaders.get(addOnDep.getId()));
}
AddOnClassLoader extAddOnClassLoader = new AddOnClassLoader(addOnClassLoader, dependencies, addOn.getExtensionAddOnClassnames(extReqs.getClassname()));
Extension ext = loadAddOnExtension(addOn, extReqs.getClassname(), extAddOnClassLoader);
if (ext != null) {
extensions.add(ext);
}
} else if (logger.isDebugEnabled()) {
logger.debug("Can't run extension '" + extReqs.getClassname() + "' of add-on '" + addOn.getName() + "' because of missing requirements: " + AddOnRunIssuesUtils.getRunningIssues(extReqs));
}
}
}
return extensions;
}
use of org.zaproxy.zap.control.AddOn.ExtensionRunRequirements in project zaproxy by zaproxy.
the class AddOnLoader method checkAndLoadDependentExtensions.
/**
* Checks and loads all the extensions that have (now) all required dependencies fulfilled.
* <p>
* Should be called after an installation of an add-on.
*
* @see #addAddOnImpl(AddOn)
* @since 2.4.0
*/
private void checkAndLoadDependentExtensions() {
boolean changed = false;
for (Entry<String, AddOnClassLoader> entry : new HashMap<>(addOnLoaders).entrySet()) {
AddOn runningAddOn = aoc.getAddOn(entry.getKey());
for (String extClassName : runningAddOn.getExtensionsWithDeps()) {
if (!runningAddOn.isExtensionLoaded(extClassName)) {
AddOn.AddOnRunRequirements reqs = runningAddOn.calculateExtensionRunRequirements(extClassName, aoc.getInstalledAddOns());
ExtensionRunRequirements extReqs = reqs.getExtensionRequirements().get(0);
if (extReqs.isRunnable()) {
List<AddOnClassLoader> dependencies = new ArrayList<>(extReqs.getDependencies().size());
for (AddOn addOnDep : extReqs.getDependencies()) {
dependencies.add(addOnLoaders.get(addOnDep.getId()));
}
AddOnClassLoader extAddOnClassLoader = new AddOnClassLoader(entry.getValue(), dependencies, runningAddOn.getExtensionAddOnClassnames(extClassName));
Extension ext = loadAddOnExtension(runningAddOn, extReqs.getClassname(), extAddOnClassLoader);
AddOnInstaller.installAddOnExtension(runningAddOn, ext);
runnableAddOns.get(runningAddOn).add(extReqs.getClassname());
changed = true;
}
}
}
}
if (changed) {
saveAddOnsRunState(runnableAddOns);
}
}
Aggregations