X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnorthbound%2Fbundlescanner%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnorthbound%2Fbundlescanner%2Finternal%2FBundleScanner.java;h=c590da4dbc1c55fca296a5059061dca4a99c75ef;hp=3e517e9a1f717e3b9a8c889c5b34b2f3bf3d7351;hb=af3eaa839bf6f6c86495b24d2174eeb6624501c0;hpb=665b37faa9977f3d5e20117c487aec918e762e0d diff --git a/opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleScanner.java b/opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleScanner.java index 3e517e9a1f..c590da4dbc 100644 --- a/opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleScanner.java +++ b/opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleScanner.java @@ -22,6 +22,8 @@ import java.util.Map; import java.util.Set; import java.util.regex.Pattern; +import javax.xml.bind.annotation.XmlRootElement; + import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; @@ -66,6 +68,7 @@ import org.slf4j.LoggerFactory; public List> getAnnotatedClasses(BundleContext context, String[] annotations, + Set excludes, boolean includeDependentBundleClasses) { BundleInfo info = bundleAnnotations.get(context.getBundle().getBundleId()); @@ -73,9 +76,15 @@ import org.slf4j.LoggerFactory; Pattern pattern = mergePatterns(annotations, false); List> result = null; if (includeDependentBundleClasses) { - result = info.getAnnotatedClasses(bundleAnnotations.values(), pattern); + result = info.getAnnotatedClasses(bundleAnnotations.values(), + pattern, context.getBundle(), excludes); + // reverse the list to give precedence to the types loaded from the + // initiating bundle + Collections.reverse(result); + // validate for conflicts only when searching dependencies + validate(result); } else { - result = info.getAnnotatedClasses(pattern); + result = info.getAnnotatedClasses(pattern, excludes); } LOGGER.debug("Annotated classes detected: {} matching: {}", result, pattern); return result; @@ -237,17 +246,24 @@ import org.slf4j.LoggerFactory; // find bundle dependencies } - public static List> loadClasses(Bundle bundle, - Collection annotatedClasses) + public static List> loadClasses( + Collection annotatedClasses, + Bundle initBundle, Set excludes) { List> result = new ArrayList>(); + StringBuilder errors = new StringBuilder(); for (String name : annotatedClasses) { try { - result.add(bundle.loadClass(name)); - } catch (Exception e) { - LOGGER.error("Unable to load class: {}", name, e); + if (excludes != null && excludes.contains(name)) continue; + result.add(initBundle.loadClass(name)); + } catch (ClassNotFoundException e) { + errors.append(name).append(", "); } } + if (LOGGER.isDebugEnabled() && errors.length() > 0) { + LOGGER.debug("Bundle: {} could not load classes: {}", + initBundle.getSymbolicName(), errors.toString()); + } return result; } @@ -274,4 +290,31 @@ import org.slf4j.LoggerFactory; return Pattern.compile(regex.toString()); } + private void validate(List> classes) { + if (classes == null || classes.size() == 0) return; + Map names = new HashMap(); + StringBuilder conflictsMsg = new StringBuilder(); + for (Class c : classes) { + XmlRootElement root = (XmlRootElement) c.getAnnotation(XmlRootElement.class); + if (root == null) continue; + String rootName = root.name(); + if ("##default".equals(rootName)) { + String clsName = c.getSimpleName(); + rootName = Character.toLowerCase(clsName.charAt(0)) + clsName.substring(1); + } + String other = names.get(rootName); + if (other != null && !other.equals(c.getName())) { + conflictsMsg.append(System.lineSeparator()) + .append("[").append(rootName).append(":") + .append(c.getName()).append(",").append(other) + .append("]"); + } else { + names.put(rootName, c.getName()); + } + } + if (conflictsMsg.length() > 0) { + LOGGER.warn("JAXB type conflicts detected : {}", conflictsMsg.toString()); + } + } + }