X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnorthbound%2Fbundlescanner%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnorthbound%2Fbundlescanner%2Finternal%2FBundleScanner.java;h=c590da4dbc1c55fca296a5059061dca4a99c75ef;hb=00dba4141e5132372e68190638e083cd54e327ba;hp=a5a2073a610886d0aed68044ca70f40c44146556;hpb=bbba9ddecc8fa5835d066741328d3d812b8433b0;p=controller.git 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 a5a2073a61..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()); @@ -74,9 +77,14 @@ import org.slf4j.LoggerFactory; List> result = null; if (includeDependentBundleClasses) { result = info.getAnnotatedClasses(bundleAnnotations.values(), - pattern, context.getBundle()); + 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; @@ -240,12 +248,13 @@ import org.slf4j.LoggerFactory; public static List> loadClasses( Collection annotatedClasses, - Bundle initBundle) + Bundle initBundle, Set excludes) { List> result = new ArrayList>(); StringBuilder errors = new StringBuilder(); for (String name : annotatedClasses) { try { + if (excludes != null && excludes.contains(name)) continue; result.add(initBundle.loadClass(name)); } catch (ClassNotFoundException e) { errors.append(name).append(", "); @@ -281,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()); + } + } + }