X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fkernel%2FDataModels.java;h=acf0dbf7cbf9dbd97e4aa95d26df1c068d7586a1;hb=d169026cb1939009fd90ac46a11f480cb3d803c0;hp=da6328163cc9804c8b95f877440b560f979f7d40;hpb=088c1b517a543e935d8ab65c3b2fd2d0269b551d;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/internal/kernel/DataModels.java b/org.argeo.cms/src/org/argeo/cms/internal/kernel/DataModels.java index da6328163..acf0dbf7c 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/kernel/DataModels.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/kernel/DataModels.java @@ -1,6 +1,6 @@ package org.argeo.cms.internal.kernel; -import static org.argeo.node.DataModelNamespace.CMS_DATA_MODEL_NAMESPACE; +import static org.argeo.api.DataModelNamespace.CMS_DATA_MODEL_NAMESPACE; import java.util.ArrayList; import java.util.Collections; @@ -10,8 +10,8 @@ import java.util.TreeMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.argeo.api.DataModelNamespace; import org.argeo.cms.CmsException; -import org.argeo.node.DataModelNamespace; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; @@ -27,7 +27,7 @@ class DataModels implements BundleListener { public DataModels(BundleContext bc) { for (Bundle bundle : bc.getBundles()) - processBundle(bundle); + processBundle(bundle, null); bc.addBundleListener(this); } @@ -45,7 +45,7 @@ class DataModels implements BundleListener { @Override public void bundleChanged(BundleEvent event) { if (event.getType() == Bundle.RESOLVED) { - processBundle(event.getBundle()); + processBundle(event.getBundle(), null); } else if (event.getType() == Bundle.UNINSTALLED) { BundleWiring wiring = event.getBundle().adapt(BundleWiring.class); List providedDataModels = wiring.getCapabilities(CMS_DATA_MODEL_NAMESPACE); @@ -58,11 +58,19 @@ class DataModels implements BundleListener { } - protected void processBundle(Bundle bundle) { + protected void processBundle(Bundle bundle, List scannedBundles) { + if (scannedBundles != null && scannedBundles.contains(bundle)) + throw new IllegalStateException("Cycle in CMS data model requirements for " + bundle); BundleWiring wiring = bundle.adapt(BundleWiring.class); if (wiring == null) { - log.warn("Bundle " + bundle.getSymbolicName() + " #" + bundle.getBundleId() + " (" + bundle.getLocation() - + ") cannot be adapted to a wiring"); + int bundleState = bundle.getState(); + if (bundleState != Bundle.INSTALLED && bundleState != Bundle.UNINSTALLED) {// ignore unresolved bundles + log.warn("Bundle " + bundle.getSymbolicName() + " #" + bundle.getBundleId() + " (" + + bundle.getLocation() + ") cannot be adapted to a wiring"); + } else { + if (log.isTraceEnabled()) + log.warn("Bundle " + bundle.getSymbolicName() + " is not resolved."); + } return; } List providedDataModels = wiring.getCapabilities(CMS_DATA_MODEL_NAMESPACE); @@ -71,7 +79,12 @@ class DataModels implements BundleListener { List requiredDataModels = wiring.getRequiredWires(CMS_DATA_MODEL_NAMESPACE); // process requirements first for (BundleWire bundleWire : requiredDataModels) { - processBundle(bundleWire.getProvider().getBundle()); + List nextScannedBundles = new ArrayList<>(); + if (scannedBundles != null) + nextScannedBundles.addAll(scannedBundles); + nextScannedBundles.add(bundle); + Bundle providerBundle = bundleWire.getProvider().getBundle(); + processBundle(providerBundle, nextScannedBundles); } for (BundleCapability bundleCapability : providedDataModels) { String name = (String) bundleCapability.getAttributes().get(DataModelNamespace.NAME);