Merge "BUG-997: Introduce ASTSchemaSource"
authorTony Tkacik <ttkacik@cisco.com>
Fri, 1 Aug 2014 09:15:46 +0000 (09:15 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 1 Aug 2014 09:15:46 +0000 (09:15 +0000)
26 files changed:
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/TransformerGenerator.xtend
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/util/ClassLoaderUtils.java [deleted file]
common/concepts/src/main/java/org/opendaylight/yangtools/concepts/util/ClassLoaderUtils.java [deleted file]
common/concepts/src/main/java/org/opendaylight/yangtools/concepts/util/ListenerRegistry.java
common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java [new file with mode: 0644]
common/util/src/main/java/org/opendaylight/yangtools/util/Immutables.java [moved from common/concepts/src/main/java/org/opendaylight/yangtools/concepts/util/Immutables.java with 97% similarity]
common/util/src/main/java/org/opendaylight/yangtools/util/ListenerRegistry.java [new file with mode: 0644]
yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/util/ClassLoaderUtils.java
yang/yang-maven-plugin-it/src/test/resources/test-parent/AdditionalConfig/pom.xml
yang/yang-maven-plugin-it/src/test/resources/test-parent/Correct/pom.xml
yang/yang-maven-plugin-it/src/test/resources/test-parent/GenerateTest1/pom.xml
yang/yang-maven-plugin-it/src/test/resources/test-parent/GenerateTest2/pom.xml
yang/yang-maven-plugin-it/src/test/resources/test-parent/Generator/pom.xml
yang/yang-maven-plugin-it/src/test/resources/test-parent/InvalidVersion/pom.xml
yang/yang-maven-plugin-it/src/test/resources/test-parent/MissingYangInDep/pom.xml
yang/yang-maven-plugin-it/src/test/resources/test-parent/NamingConflict/pom.xml
yang/yang-maven-plugin-it/src/test/resources/test-parent/NoGenerators/pom.xml
yang/yang-maven-plugin-it/src/test/resources/test-parent/NoOutputDir/pom.xml
yang/yang-maven-plugin-it/src/test/resources/test-parent/NoYangFiles/pom.xml
yang/yang-maven-plugin-it/src/test/resources/test-parent/UnknownGenerator/pom.xml
yang/yang-maven-plugin-it/src/test/resources/test-parent/YangRootNotExist/pom.xml
yang/yang-maven-plugin-it/src/test/resources/test-parent/pom.xml
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/ParserListenerUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java
yang/yang-parser-impl/src/test/resources/types/union-with-ext/extdef.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/types/union-with-ext/unionbug.yang [new file with mode: 0644]

index ab6b734c0bb540fdefb7bd5a94b1fa98c0cee7b8..769a9e5bb77c054510fdca274afbeb3d44a91d12 100644 (file)
@@ -29,7 +29,6 @@ import javassist.CtMethod
 import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil
 import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl
 import org.opendaylight.yangtools.binding.generator.util.Types
-import org.opendaylight.yangtools.sal.binding.generator.util.ClassLoaderUtils
 import org.opendaylight.yangtools.sal.binding.generator.util.CodeGenerationException
 import org.opendaylight.yangtools.sal.binding.generator.util.XtendHelper
 import org.opendaylight.yangtools.sal.binding.model.api.Enumeration
@@ -39,6 +38,7 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType
 import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType
 import org.opendaylight.yangtools.sal.binding.model.api.Type
 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTypeBuilder
+import org.opendaylight.yangtools.util.ClassLoaderUtils
 import org.opendaylight.yangtools.yang.binding.Augmentation
 import org.opendaylight.yangtools.yang.binding.BindingCodec
 import org.opendaylight.yangtools.yang.binding.BindingDeserializer
diff --git a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/util/ClassLoaderUtils.java b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/util/ClassLoaderUtils.java
deleted file mode 100644 (file)
index 01ed2f0..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.sal.binding.generator.util;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.locks.Lock;
-
-import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
-
-/**
- * @deprecated Use {@link org.opendaylight.yangtools.yang.binding.util.ClassLoaderUtils} instead.
- */
-@Deprecated
-public final class ClassLoaderUtils {
-
-    private ClassLoaderUtils() {
-        throw new UnsupportedOperationException("Utility class");
-    }
-
-    public static <V> V withClassLoader(final ClassLoader cls, final Callable<V> function) throws Exception {
-        checkNotNull(cls, "Classloader should not be null");
-        checkNotNull(function, "Function should not be null");
-
-        final ClassLoader oldCls = Thread.currentThread().getContextClassLoader();
-        try {
-            Thread.currentThread().setContextClassLoader(cls);
-            return function.call();
-        } finally {
-            Thread.currentThread().setContextClassLoader(oldCls);
-        }
-    }
-
-    public static <V> V withClassLoaderAndLock(final ClassLoader cls, final Lock lock, final Callable<V> function) throws Exception {
-        checkNotNull(lock, "Lock should not be null");
-
-        lock.lock();
-        try {
-            return withClassLoader(cls, function);
-        } finally {
-            lock.unlock();
-        }
-    }
-
-    /**
-     * @deprecated Use one of the other utility methods.
-     */
-    @Deprecated
-    public static <V> V withClassLoaderAndLock(final ClassLoader cls, final Optional<Lock> lock, final Callable<V> function) throws Exception {
-        if (lock.isPresent()) {
-            return withClassLoaderAndLock(cls, lock.get(), function);
-        } else {
-            return withClassLoader(cls, function);
-        }
-    }
-
-    public static Object construct(final Constructor<? extends Object> constructor, final List<Object> objects)
-            throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
-        Object[] initargs = objects.toArray(new Object[] {});
-        return constructor.newInstance(initargs);
-    }
-
-
-    public static Class<?> loadClass(final ClassLoader cls, final String name) throws ClassNotFoundException {
-        if ("byte[]".equals(name)) {
-            return byte[].class;
-        } else if("char[]".equals(name)) {
-            return char[].class;
-        }
-        try {
-            return cls.loadClass(name);
-        } catch (ClassNotFoundException e) {
-            String[] components = name.split("\\.");
-            String potentialOuter;
-            int length = components.length;
-            if (length > 2 && (potentialOuter = components[length - 2]) != null && Character.isUpperCase(potentialOuter.charAt(0))) {
-
-                    String outerName = Joiner.on(".").join(Arrays.asList(components).subList(0, length - 1));
-                    String innerName = outerName + "$" + components[length-1];
-                    return cls.loadClass(innerName);
-            } else {
-                throw e;
-            }
-        }
-    }
-
-    public static Class<?> loadClassWithTCCL(final String name) throws ClassNotFoundException {
-        return loadClass(Thread.currentThread().getContextClassLoader(), name);
-    }
-
-    public static Class<?> tryToLoadClassWithTCCL(final String fullyQualifiedName) {
-        try {
-            return loadClassWithTCCL(fullyQualifiedName);
-        } catch (ClassNotFoundException e) {
-            return null;
-        }
-    }
-}
diff --git a/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/util/ClassLoaderUtils.java b/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/util/ClassLoaderUtils.java
deleted file mode 100644 (file)
index e898e72..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.concepts.util;
-
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.concurrent.Callable;
-import java.util.concurrent.locks.Lock;
-
-/**
- * @deprecated Use {@link org.opendaylight.yangtools.yang.binding.util.ClassLoaderUtils} instead.
- */
-@Deprecated
-public final class ClassLoaderUtils {
-
-    private ClassLoaderUtils() {
-        throw new UnsupportedOperationException("Utility class");
-    }
-
-    public static <V> V withClassLoader(final ClassLoader cls, final Callable<V> function) throws Exception {
-        return withClassLoaderAndLock(cls, null, function);
-    }
-
-    public static <V> V withClassLoaderAndLock(final ClassLoader cls, final Lock lock, final Callable<V> function) throws Exception {
-        if (cls == null) {
-            throw new IllegalArgumentException("Classloader should not be null");
-        }
-        if (function == null) {
-            throw new IllegalArgumentException("Function should not be null");
-        }
-
-        if (lock != null) {
-            lock.lock();
-        }
-        ClassLoader oldCls = Thread.currentThread().getContextClassLoader();
-        try {
-            Thread.currentThread().setContextClassLoader(cls);
-            return function.call();
-        } finally {
-            Thread.currentThread().setContextClassLoader(oldCls);
-            if (lock != null) {
-                lock.unlock();
-            }
-        }
-    }
-
-    public static ParameterizedType findParameterizedType(final Class<?> subclass, final Class<?> genericType) {
-        if(subclass == null || genericType == null) {
-            throw new IllegalArgumentException("Class was not specified.");
-        }
-        for (Type type : subclass.getGenericInterfaces()) {
-            if (type instanceof ParameterizedType && genericType.equals(((ParameterizedType) type).getRawType())) {
-                return (ParameterizedType) type;
-            }
-        }
-        return null;
-    }
-
-    public static <S,G,P> Class<P> findFirstGenericArgument(final Class<S> scannedClass, final Class<G> genericType) {
-        try {
-            return withClassLoader(scannedClass.getClassLoader(), ClassLoaderUtils.<S,G,P>findFirstGenericArgumentTask(scannedClass, genericType));
-        } catch (Exception e) {
-            return null;
-        }
-    }
-
-    private static <S,G,P> Callable<Class<P>> findFirstGenericArgumentTask(final Class<S> scannedClass, final Class<G> genericType) {
-        return new Callable<Class<P>>() {
-            @Override
-            @SuppressWarnings("unchecked")
-            public Class<P> call() throws Exception {
-                final ParameterizedType augmentationGeneric = findParameterizedType(scannedClass,
-                        genericType);
-                if (augmentationGeneric == null) {
-                    return null;
-                }
-                return (Class<P>) augmentationGeneric.getActualTypeArguments()[0];
-            }
-        };
-    }
-
-    public static Type getFirstGenericParameter(final Type type) {
-        if(type instanceof ParameterizedType) {
-            return ((ParameterizedType) type).getActualTypeArguments()[0];
-        }
-        return null;
-    }
-
-}
\ No newline at end of file
index e8f271c075360830e0fb3a5045ac0b47c0022956..07cc5ae6bed889c99ae38fad922e54a3801f886f 100644 (file)
@@ -12,10 +12,16 @@ import java.util.Collections;
 import java.util.EventListener;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+
 import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 
-
+/**
+ * @deprecated Use {@link org.opendaylight.yangtools.util.ListenerRegistry} instead.
+ *
+ * @param <T>
+ */
+@Deprecated
 public class ListenerRegistry<T extends EventListener> implements Iterable<ListenerRegistration<T>> {
 
     private final ConcurrentHashMap<ListenerRegistration<? extends T>,ListenerRegistration<? extends T>> listeners;
@@ -34,7 +40,7 @@ public class ListenerRegistry<T extends EventListener> implements Iterable<Liste
         return unmodifiableView;
     }
 
-    public ListenerRegistration<T> register(T listener) {
+    public ListenerRegistration<T> register(final T listener) {
         if (listener == null) {
             throw new IllegalArgumentException("Listener should not be null.");
         }
@@ -42,28 +48,26 @@ public class ListenerRegistry<T extends EventListener> implements Iterable<Liste
         listeners.put(ret,ret);
         return ret;
     }
-    
-    public <L extends T> ListenerRegistration<L> registerWithType(L listener) {
+
+    public <L extends T> ListenerRegistration<L> registerWithType(final L listener) {
         ListenerRegistrationImpl<L> ret = new ListenerRegistrationImpl<L>(listener);
         listeners.put(ret,ret);
         return ret;
     }
-    
+
     @Override
     public java.util.Iterator<ListenerRegistration<T>> iterator() {
         return unmodifiableView.iterator();
     }
 
     @SuppressWarnings("rawtypes")
-    private void remove(ListenerRegistrationImpl registration) {
+    private void remove(final ListenerRegistrationImpl registration) {
         listeners.remove(registration);
     }
 
-    private class ListenerRegistrationImpl<P extends EventListener> //
-            extends AbstractObjectRegistration<P> //
-            implements ListenerRegistration<P> {
+    private class ListenerRegistrationImpl<P extends EventListener> extends AbstractObjectRegistration<P> implements ListenerRegistration<P> {
 
-        public ListenerRegistrationImpl(P instance) {
+        public ListenerRegistrationImpl(final P instance) {
             super(instance);
         }
 
diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java
new file mode 100644 (file)
index 0000000..6f84ef8
--- /dev/null
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.util;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Supplier;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class ClassLoaderUtils {
+    private static final Logger LOG = LoggerFactory.getLogger(ClassLoaderUtils.class);
+
+    private ClassLoaderUtils() {
+        throw new UnsupportedOperationException("Utility class");
+    }
+
+    /**
+     *
+     * Runs {@link Supplier} with provided {@link ClassLoader}.
+     *
+     * Invokes supplies function and makes sure that original {@link ClassLoader}
+     * is context {@link ClassLoader} after execution.
+     *
+     * @param cls {@link ClassLoader} to be used.
+     * @param function Function to be executed.
+     * @return Result of supplier invocation.
+     *
+     */
+    public static <V> V withClassLoader(final ClassLoader cls, final Supplier<V> function) {
+        checkNotNull(cls, "Classloader should not be null");
+        checkNotNull(function, "Function should not be null");
+
+        final ClassLoader oldCls = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(cls);
+            return function.get();
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldCls);
+        }
+    }
+
+    /**
+     *
+     * Runs {@link Callable} with provided {@link ClassLoader}.
+     *
+     * Invokes supplies function and makes sure that original {@link ClassLoader}
+     * is context {@link ClassLoader} after execution.
+     *
+     * @param cls {@link ClassLoader} to be used.
+     * @param function Function to be executed.
+     * @return Result of callable invocation.
+     *
+     */
+    public static <V> V withClassLoader(final ClassLoader cls, final Callable<V> function) throws Exception {
+        checkNotNull(cls, "Classloader should not be null");
+        checkNotNull(function, "Function should not be null");
+
+        final ClassLoader oldCls = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(cls);
+            return function.call();
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldCls);
+        }
+    }
+
+    public static Object construct(final Constructor<? extends Object> constructor, final List<Object> objects)
+            throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+        final Object[] initargs = objects.toArray();
+        return constructor.newInstance(initargs);
+    }
+
+    /**
+     *
+     * Loads class using this supplied classloader.
+     *
+     *
+     * @param cls
+     * @param name String name of class.
+     * @return
+     * @throws ClassNotFoundException
+     */
+    public static Class<?> loadClass(final ClassLoader cls, final String name) throws ClassNotFoundException {
+        if ("byte[]".equals(name)) {
+            return byte[].class;
+        }
+        if ("char[]".equals(name)) {
+            return char[].class;
+        }
+
+        try {
+            return cls.loadClass(name);
+        } catch (ClassNotFoundException e) {
+            String[] components = name.split("\\.");
+            String potentialOuter;
+            int length = components.length;
+            if (length > 2 && (potentialOuter = components[length - 2]) != null && Character.isUpperCase(potentialOuter.charAt(0))) {
+                String outerName = Joiner.on(".").join(Arrays.asList(components).subList(0, length - 1));
+                String innerName = outerName + "$" + components[length-1];
+                return cls.loadClass(innerName);
+            } else {
+                throw e;
+            }
+        }
+    }
+
+    public static Class<?> loadClassWithTCCL(final String name) throws ClassNotFoundException {
+        return loadClass(Thread.currentThread().getContextClassLoader(), name);
+    }
+
+    public static Class<?> tryToLoadClassWithTCCL(final String fullyQualifiedName) {
+        try {
+            return loadClassWithTCCL(fullyQualifiedName);
+        } catch (ClassNotFoundException e) {
+            LOG.debug("Failed to load class {}", fullyQualifiedName, e);
+            return null;
+        }
+    }
+
+    public static <S,G,P> Class<P> findFirstGenericArgument(final Class<S> scannedClass, final Class<G> genericType) {
+        return withClassLoader(scannedClass.getClassLoader(), ClassLoaderUtils.<S,G,P>findFirstGenericArgumentTask(scannedClass, genericType));
+    }
+
+    private static <S,G,P> Supplier<Class<P>> findFirstGenericArgumentTask(final Class<S> scannedClass, final Class<G> genericType) {
+        return new Supplier<Class<P>>() {
+            @Override
+            @SuppressWarnings("unchecked")
+            public Class<P> get() {
+                final ParameterizedType augmentationGeneric = findParameterizedType(scannedClass, genericType);
+                if (augmentationGeneric != null) {
+                    return (Class<P>) augmentationGeneric.getActualTypeArguments()[0];
+                }
+                return null;
+            }
+        };
+    }
+
+    public static ParameterizedType findParameterizedType(final Class<?> subclass, final Class<?> genericType) {
+        Preconditions.checkNotNull(subclass);
+        Preconditions.checkNotNull(genericType);
+
+        for (Type type : subclass.getGenericInterfaces()) {
+            if (type instanceof ParameterizedType && genericType.equals(((ParameterizedType) type).getRawType())) {
+                return (ParameterizedType) type;
+            }
+        }
+
+        LOG.debug("Class {} does not declare interface {}", subclass, genericType);
+        return null;
+    }
+
+    public static Type getFirstGenericParameter(final Type type) {
+        if (type instanceof ParameterizedType) {
+            return ((ParameterizedType) type).getActualTypeArguments()[0];
+        }
+        return null;
+    }
+}
similarity index 97%
rename from common/concepts/src/main/java/org/opendaylight/yangtools/concepts/util/Immutables.java
rename to common/util/src/main/java/org/opendaylight/yangtools/util/Immutables.java
index cc2d0186d4a03c5e7af8eaca829c3d278dc6a2cd..e10977b6de01ecd0c2254a0fd1c263f4088e8aac 100644 (file)
@@ -5,7 +5,7 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.yangtools.concepts.util;
+package org.opendaylight.yangtools.util;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ListenerRegistry.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ListenerRegistry.java
new file mode 100644 (file)
index 0000000..e8b1a3d
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.util;
+
+
+import java.util.Collections;
+import java.util.EventListener;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+
+
+public class ListenerRegistry<T extends EventListener> implements Iterable<ListenerRegistration<T>> {
+
+    private final ConcurrentHashMap<ListenerRegistration<? extends T>,ListenerRegistration<? extends T>> listeners;
+    final Set<ListenerRegistration<T>> unmodifiableView;
+
+    @SuppressWarnings("unchecked")
+    public ListenerRegistry() {
+        listeners = new ConcurrentHashMap<>();
+        // This conversion is known to be safe.
+        @SuppressWarnings("rawtypes")
+        final Set rawSet = Collections.unmodifiableSet(listeners.keySet());
+        unmodifiableView = rawSet;
+    }
+
+    public Iterable<ListenerRegistration<T>> getListeners() {
+        return unmodifiableView;
+    }
+
+    public ListenerRegistration<T> register(T listener) {
+        if (listener == null) {
+            throw new IllegalArgumentException("Listener should not be null.");
+        }
+        ListenerRegistrationImpl<T> ret = new ListenerRegistrationImpl<T>(listener);
+        listeners.put(ret,ret);
+        return ret;
+    }
+    
+    public <L extends T> ListenerRegistration<L> registerWithType(L listener) {
+        ListenerRegistrationImpl<L> ret = new ListenerRegistrationImpl<L>(listener);
+        listeners.put(ret,ret);
+        return ret;
+    }
+    
+    @Override
+    public java.util.Iterator<ListenerRegistration<T>> iterator() {
+        return unmodifiableView.iterator();
+    }
+
+    @SuppressWarnings("rawtypes")
+    private void remove(ListenerRegistrationImpl registration) {
+        listeners.remove(registration);
+    }
+
+    private class ListenerRegistrationImpl<P extends EventListener> //
+            extends AbstractObjectRegistration<P> //
+            implements ListenerRegistration<P> {
+
+        public ListenerRegistrationImpl(P instance) {
+            super(instance);
+        }
+
+        @Override
+        protected void removeRegistration() {
+            ListenerRegistry.this.remove(this);
+        }
+    }
+
+    public static <T extends EventListener> ListenerRegistry<T> create() {
+        return new ListenerRegistry<>();
+    }
+}
index fab50614f2dfccf85e73649b88d2c7071faec5ee..e9ddbfb2f151ffeb3ab8702cc6c03dbfeca38060 100644 (file)
@@ -9,6 +9,10 @@ package org.opendaylight.yangtools.yang.binding.util;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Supplier;
+
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.ParameterizedType;
@@ -21,10 +25,10 @@ import java.util.concurrent.locks.Lock;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Supplier;
-
+/**
+ * @deprecated Use {@link org.opendaylight.yangtools.util.ClassLoaderUtils} instead.
+ */
+@Deprecated
 public final class ClassLoaderUtils {
     private static final Logger LOG = LoggerFactory.getLogger(ClassLoaderUtils.class);
 
@@ -58,17 +62,17 @@ public final class ClassLoaderUtils {
     }
 
     /**
-    *
-    * Runs {@link Callable} with provided {@link ClassLoader}.
-    *
-    * Invokes supplies function and makes sure that original {@link ClassLoader}
-    * is context {@link ClassLoader} after execution.
-    *
-    * @param cls {@link ClassLoader} to be used.
-    * @param function Function to be executed.
-    * @return Result of callable invocation.
-    *
-    */
+     *
+     * Runs {@link Callable} with provided {@link ClassLoader}.
+     *
+     * Invokes supplies function and makes sure that original {@link ClassLoader}
+     * is context {@link ClassLoader} after execution.
+     *
+     * @param cls {@link ClassLoader} to be used.
+     * @param function Function to be executed.
+     * @return Result of callable invocation.
+     *
+     */
     public static <V> V withClassLoader(final ClassLoader cls, final Callable<V> function) throws Exception {
         checkNotNull(cls, "Classloader should not be null");
         checkNotNull(function, "Function should not be null");
@@ -82,20 +86,20 @@ public final class ClassLoaderUtils {
         }
     }
 
-   /**
-    *
-    * Runs {@link Callable} with provided {@link ClassLoader} and Lock.
-    *
-    * Invokes supplies function after acquiring lock
-    * and makes sure that original {@link ClassLoader}
-    * is context {@link ClassLoader} and lock is unlocked
-    * after execution.
-    *
-    * @param cls {@link ClassLoader} to be used.
-    * @param function Function to be executed.
-    * @return Result of Callable invocation.
-    *
-    */
+    /**
+     *
+     * Runs {@link Callable} with provided {@link ClassLoader} and Lock.
+     *
+     * Invokes supplies function after acquiring lock
+     * and makes sure that original {@link ClassLoader}
+     * is context {@link ClassLoader} and lock is unlocked
+     * after execution.
+     *
+     * @param cls {@link ClassLoader} to be used.
+     * @param function Function to be executed.
+     * @return Result of Callable invocation.
+     *
+     */
     public static <V> V withClassLoaderAndLock(final ClassLoader cls, final Lock lock, final Supplier<V> function) {
         checkNotNull(lock, "Lock should not be null");
 
@@ -138,9 +142,9 @@ public final class ClassLoaderUtils {
             String potentialOuter;
             int length = components.length;
             if (length > 2 && (potentialOuter = components[length - 2]) != null && Character.isUpperCase(potentialOuter.charAt(0))) {
-                    String outerName = Joiner.on(".").join(Arrays.asList(components).subList(0, length - 1));
-                    String innerName = outerName + "$" + components[length-1];
-                    return cls.loadClass(innerName);
+                String outerName = Joiner.on(".").join(Arrays.asList(components).subList(0, length - 1));
+                String innerName = outerName + "$" + components[length-1];
+                return cls.loadClass(innerName);
             } else {
                 throw e;
             }
index 28bb2d9b70fae8919781070080404200e6a9e308..dc2cbd1e676460ec7138752c2b1d0716637b7089 100644 (file)
@@ -11,7 +11,7 @@
     <parent>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>test-parent</artifactId>
-        <version>1.0</version>
+        <version>0.6.2-SNAPSHOT</version>
     </parent>
 
     <artifactId>additional-config</artifactId>
@@ -20,7 +20,7 @@
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
             <artifactId>yang-maven-plugin-spi</artifactId>
-            <version>${it-project.version}</version>
+            <version>${project.version}</version>
         </dependency>
     </dependencies>
 
@@ -29,7 +29,7 @@
             <plugin>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
-                <version>${it-project.version}</version>
+                <version>${project.version}</version>
                 <executions>
                     <execution>
                         <goals>
@@ -71,7 +71,7 @@
                     <dependency>
                         <groupId>org.opendaylight.yangtools</groupId>
                         <artifactId>yang-maven-plugin-spi</artifactId>
-                        <version>${it-project.version}</version>
+                        <version>${project.version}</version>
                         <type>test-jar</type>
                     </dependency>
                 </dependencies>
index 82640e8ee674c05da066fd37e43e607cef2ab3c2..d99dd0319a341fe919aef2f8c360f1bf7b25824a 100644 (file)
@@ -11,7 +11,7 @@
     <parent>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>test-parent</artifactId>
-        <version>1.0</version>
+        <version>0.6.2-SNAPSHOT</version>
     </parent>
 
     <artifactId>correct</artifactId>
@@ -20,7 +20,7 @@
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
             <artifactId>yang-maven-plugin-spi</artifactId>
-            <version>${it-project.version}</version>
+            <version>${project.version}</version>
         </dependency>
     </dependencies>
 
@@ -29,7 +29,7 @@
             <plugin>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
-                <version>${it-project.version}</version>
+                <version>${project.version}</version>
                 <executions>
                     <execution>
                         <goals>
@@ -56,7 +56,7 @@
                     <dependency>
                         <groupId>org.opendaylight.yangtools</groupId>
                         <artifactId>yang-maven-plugin-spi</artifactId>
-                        <version>${it-project.version}</version>
+                        <version>${project.version}</version>
                         <type>test-jar</type>
                     </dependency>
                 </dependencies>
index cd7be965d193bb026422989970260e4dc81d5068..3d931010a355f00051f96274b3755acf487e9289 100644 (file)
@@ -11,7 +11,7 @@
     <parent>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>test-parent</artifactId>
-        <version>1.0</version>
+        <version>0.6.2-SNAPSHOT</version>
     </parent>
 
     <artifactId>generator-test1</artifactId>
@@ -25,7 +25,7 @@
             <plugin>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
-                <version>${it-project.version}</version>
+                <version>${project.version}</version>
                 <executions>
                     <execution>
                         <goals>
@@ -51,7 +51,7 @@
                     <dependency>
                         <groupId>org.opendaylight.yangtools</groupId>
                         <artifactId>yang-maven-plugin-spi</artifactId>
-                        <version>${it-project.version}</version>
+                        <version>${project.version}</version>
                         <type>test-jar</type>
                     </dependency>
                 </dependencies>
index 948c025898f9c0aa7b3040fe1a43fa2aac5e1e59..3063698e67e7b56a1263bf9e0ca093c966029905 100644 (file)
@@ -11,7 +11,7 @@
     <parent>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>test-parent</artifactId>
-        <version>1.0</version>
+        <version>0.6.2-SNAPSHOT</version>
     </parent>
 
     <artifactId>generator-test2</artifactId>
@@ -24,9 +24,9 @@
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
             <artifactId>generator-test1</artifactId>
-            <version>${it-project.version}</version>
+            <version>${project.version}</version>
             <scope>system</scope>
-            <systemPath>${project.basedir}/../GenerateTest1/target/generator-test1-1.0.jar</systemPath>
+            <systemPath>${project.basedir}/../GenerateTest1/target/generator-test1-${project.version}.jar</systemPath>
         </dependency>
     </dependencies>
 
@@ -35,7 +35,7 @@
             <plugin>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
-                <version>${it-project.version}</version>
+                <version>${project.version}</version>
                 <executions>
                     <execution>
                         <goals>
@@ -61,7 +61,7 @@
                     <dependency>
                         <groupId>org.opendaylight.yangtools</groupId>
                         <artifactId>yang-maven-plugin-spi</artifactId>
-                        <version>${it-project.version}</version>
+                        <version>${project.version}</version>
                         <type>test-jar</type>
                     </dependency>
                 </dependencies>
index be217f8d6255961d34c8fa3ffcadb382a22d2461..c764eca085f5d39f41422a4206abce176417e671 100644 (file)
@@ -11,7 +11,7 @@
     <parent>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>test-parent</artifactId>
-        <version>1.0</version>
+        <version>0.6.2-SNAPSHOT</version>
     </parent>
 
     <artifactId>generator</artifactId>
@@ -21,7 +21,7 @@
             <plugin>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
-                <version>${it-project.version}</version>
+                <version>${project.version}</version>
                 <executions>
                     <execution>
                         <goals>
@@ -48,7 +48,7 @@
                     <dependency>
                         <groupId>org.opendaylight.yangtools</groupId>
                         <artifactId>yang-maven-plugin-spi</artifactId>
-                        <version>${it-project.version}</version>
+                        <version>${project.version}</version>
                         <type>test-jar</type>
                     </dependency>
                 </dependencies>
index 8c45963a8d63ded42e593aa1b9a3c5431ca4b6a8..2e9982c5dd8bd423de49401ce6c27632d40eb14c 100644 (file)
@@ -11,7 +11,7 @@
     <parent>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>test-parent</artifactId>
-        <version>1.0</version>
+        <version>0.6.2-SNAPSHOT</version>
     </parent>
 
     <artifactId>invalid-version</artifactId>
@@ -48,7 +48,7 @@
             <plugin>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
-                <version>${it-project.version}</version>
+                <version>${project.version}</version>
                 <executions>
                     <execution>
                         <goals>
@@ -76,7 +76,7 @@
                     <dependency>
                         <groupId>org.opendaylight.yangtools</groupId>
                         <artifactId>yang-maven-plugin-spi</artifactId>
-                        <version>${it-project.version}</version>
+                        <version>${project.version}</version>
                         <type>test-jar</type>
                     </dependency>
                 </dependencies>
index 8ade2b1a9cff9883cc9df15831b40ee6f0bc0991..5641d3ac275f86cdfb7d947735e6117c89a4b078 100644 (file)
@@ -11,7 +11,7 @@
     <parent>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>test-parent</artifactId>
-        <version>1.0</version>
+        <version>0.6.2-SNAPSHOT</version>
     </parent>
 
     <artifactId>missing-yang-in-dep</artifactId>
@@ -21,7 +21,7 @@
             <plugin>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
-                <version>${it-project.version}</version>
+                <version>${project.version}</version>
                 <executions>
                     <execution>
                         <goals>
@@ -58,7 +58,7 @@
                     <dependency>
                         <groupId>org.opendaylight.yangtools</groupId>
                         <artifactId>yang-maven-plugin-spi</artifactId>
-                        <version>${it-project.version}</version>
+                        <version>${project.version}</version>
                         <type>test-jar</type>
                     </dependency>
                 </dependencies>
index 6fc2c8070530474f06cb82cd7cebec991ff63588..0fae6f793252995fb3fb30d911965f0d209ec469 100644 (file)
@@ -11,7 +11,7 @@
     <parent>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>test-parent</artifactId>
-        <version>1.0</version>
+        <version>0.6.2-SNAPSHOT</version>
     </parent>
 
     <artifactId>naming-conflict</artifactId>
@@ -21,7 +21,7 @@
             <plugin>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
-                <version>${it-project.version}</version>
+                <version>${project.version}</version>
                 <executions>
                     <execution>
                         <goals>
@@ -46,7 +46,7 @@
                     <dependency>
                         <groupId>org.opendaylight.yangtools</groupId>
                         <artifactId>maven-sal-api-gen-plugin</artifactId>
-                        <version>${it-project.version}</version>
+                        <version>${project.version}</version>
                         <type>jar</type>
                     </dependency>
                 </dependencies>
index d236de3e0afa46f4a10baec305422b5935ed5620..0a91e17da1c767c29b094e38fc51646598ee3667 100644 (file)
@@ -11,7 +11,7 @@
     <parent>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>test-parent</artifactId>
-        <version>1.0</version>
+        <version>0.6.2-SNAPSHOT</version>
     </parent>
 
     <artifactId>no-generators</artifactId>
             <plugin>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
-                <version>${it-project.version}</version>
+                <version>${project.version}</version>
                 <executions>
                     <execution>
                         <goals>
                             <goal>generate-sources</goal>
                         </goals>
-                        <configuration>
+                        <configuration combine.self="override">
                             <yangFilesRootDir>../files</yangFilesRootDir>
                             <inspectDependencies>false</inspectDependencies>
                             <codeGenerators>
@@ -49,7 +49,7 @@
                     <dependency>
                         <groupId>org.opendaylight.yangtools</groupId>
                         <artifactId>yang-maven-plugin-spi</artifactId>
-                        <version>${it-project.version}</version>
+                        <version>${project.version}</version>
                         <type>test-jar</type>
                     </dependency>
                 </dependencies>
index 20ba31ae929fe4a01dface59bbbca1836292c75c..0ead9af0c645f3291e2a252d0cc2f200866a1226 100644 (file)
@@ -11,7 +11,7 @@
     <parent>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>test-parent</artifactId>
-        <version>1.0</version>
+        <version>0.6.2-SNAPSHOT</version>
     </parent>
 
     <artifactId>no-output-dir</artifactId>
@@ -21,7 +21,7 @@
             <plugin>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
-                <version>${it-project.version}</version>
+                <version>${project.version}</version>
                 <executions>
                     <execution>
                         <goals>
@@ -48,7 +48,7 @@
                     <dependency>
                         <groupId>org.opendaylight.yangtools</groupId>
                         <artifactId>yang-maven-plugin-spi</artifactId>
-                        <version>${it-project.version}</version>
+                        <version>${project.version}</version>
                         <type>test-jar</type>
                     </dependency>
                 </dependencies>
index 3cac79593b097d8e8a4c3435e788fa7a0e9f7494..36603f33dbc71105c8f923fa4e42813f490edadf 100644 (file)
@@ -11,7 +11,7 @@
     <parent>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>test-parent</artifactId>
-        <version>1.0</version>
+        <version>0.6.2-SNAPSHOT</version>
     </parent>
 
     <artifactId>no-yang-files</artifactId>
@@ -21,7 +21,7 @@
             <plugin>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
-                <version>${it-project.version}</version>
+                <version>${project.version}</version>
                 <executions>
                     <execution>
                         <goals>
@@ -48,7 +48,7 @@
                     <dependency>
                         <groupId>org.opendaylight.yangtools</groupId>
                         <artifactId>yang-maven-plugin-spi</artifactId>
-                        <version>${it-project.version}</version>
+                        <version>${project.version}</version>
                         <type>test-jar</type>
                     </dependency>
                 </dependencies>
index 853e8e0c0e814af4ef001b87a3a83b0f2d72e711..b58576d5ea254f3e9fce2490250b10e1787fac7d 100644 (file)
@@ -11,7 +11,7 @@
     <parent>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>test-parent</artifactId>
-        <version>1.0</version>
+        <version>0.6.2-SNAPSHOT</version>
     </parent>
 
     <artifactId>unknown-generator</artifactId>
@@ -21,7 +21,7 @@
             <plugin>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
-                <version>${it-project.version}</version>
+                <version>${project.version}</version>
                 <executions>
                     <execution>
                         <goals>
@@ -56,7 +56,7 @@
                     <dependency>
                         <groupId>org.opendaylight.yangtools</groupId>
                         <artifactId>yang-maven-plugin-spi</artifactId>
-                        <version>${it-project.version}</version>
+                        <version>${project.version}</version>
                         <type>test-jar</type>
                     </dependency>
                 </dependencies>
index 8bb27a854b4154caed8c9d270c8ea8afa5e92e3e..1da608feb4dc7d0724a7aaf0a4d946d933d5daec 100644 (file)
@@ -11,7 +11,7 @@
     <parent>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>test-parent</artifactId>
-        <version>1.0</version>
+        <version>0.6.2-SNAPSHOT</version>
     </parent>
 
     <artifactId>yang-root-not-exist</artifactId>
@@ -21,7 +21,7 @@
             <plugin>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
-                <version>${it-project.version}</version>
+                <version>${project.version}</version>
                 <executions>
                     <execution>
                         <goals>
index 58085fce5f61564df11893f9529434f4c1d915fc..18aa62fd4f3899cb9ea1c4bb734758896d9f42be 100644 (file)
@@ -8,15 +8,17 @@
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
 
+    <parent>
+        <groupId>org.opendaylight.yangtools</groupId>
+        <artifactId>yangtools-parent</artifactId>
+        <version>0.6.2-SNAPSHOT</version>
+        <relativePath>/../../common/parent/pom.xml</relativePath>
+    </parent>
+
     <groupId>org.opendaylight.yangtools</groupId>
     <artifactId>test-parent</artifactId>
-    <version>1.0</version>
     <packaging>pom</packaging>
 
-    <properties>
-        <it-project.version>0.6.2-SNAPSHOT</it-project.version>
-    </properties>
-
     <modules>
         <module>additional-config</module>
         <module>correct</module>
index 2757c10e1e755162440c1102b5d0ee37108e75b3..542506045d031de4381010e849d29f9aef56b614 100644 (file)
@@ -1069,10 +1069,12 @@ public final class ParserListenerUtils {
 
             if (parent instanceof TypeDefinitionBuilder) {
                 TypeDefinitionBuilder typedef = (TypeDefinitionBuilder) parent;
-                typedef.setRanges(rangeStatements);
-                typedef.setLengths(lengthStatements);
-                typedef.setPatterns(patternStatements);
-                typedef.setFractionDigits(fractionDigits);
+                if (!(typedef instanceof UnionTypeBuilder)) {
+                    typedef.setRanges(rangeStatements);
+                    typedef.setLengths(lengthStatements);
+                    typedef.setPatterns(patternStatements);
+                    typedef.setFractionDigits(fractionDigits);
+                }
                 return unknownType.build();
             } else {
                 TypeDefinition<?> baseType = unknownType.build();
index 050f62092877a093f389eb8b12dca545749c1bc6..022cda45a59eae835f5989e2597f6e492bcbc2ad 100644 (file)
@@ -16,6 +16,7 @@ import static org.junit.Assert.assertTrue;
 import java.io.File;
 import java.math.BigInteger;
 import java.net.URI;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
 import org.junit.Before;
@@ -333,4 +334,13 @@ public class TypesResolutionTest {
         assertNotNull(type);
     }
 
+    @Test
+    public void testUnionWithExt() throws Exception {
+        File extdef = new File(getClass().getResource("/types/union-with-ext/extdef.yang").toURI());
+        File unionbug = new File(getClass().getResource("/types/union-with-ext/unionbug.yang").toURI());
+        File inet = new File(getClass().getResource("/ietf/ietf-inet-types@2010-09-24.yang").toURI());
+        YangContextParser parser = new YangParserImpl();
+        parser.parseFiles(Arrays.asList(extdef, unionbug, inet));
+    }
+
 }
diff --git a/yang/yang-parser-impl/src/test/resources/types/union-with-ext/extdef.yang b/yang/yang-parser-impl/src/test/resources/types/union-with-ext/extdef.yang
new file mode 100644 (file)
index 0000000..68a568b
--- /dev/null
@@ -0,0 +1,13 @@
+module "extdef" {
+    yang-version 1;
+    namespace "urn:test:bug:extdef";
+    prefix "extdef";
+
+    revision 2012-04-16 {
+    }
+
+    extension "help" {
+        argument "text";
+    }
+
+}
diff --git a/yang/yang-parser-impl/src/test/resources/types/union-with-ext/unionbug.yang b/yang/yang-parser-impl/src/test/resources/types/union-with-ext/unionbug.yang
new file mode 100644 (file)
index 0000000..a882168
--- /dev/null
@@ -0,0 +1,31 @@
+module unionbug {
+    yang-version 1;
+    namespace "urn:test:bug:unionbug";
+    prefix "unionbug";
+
+    import extdef {
+        prefix extdef;
+    }
+
+    import ietf-inet-types {
+        prefix "inet";
+    }
+
+    revision 2012-04-16 {
+    }
+
+    typedef address {
+        type union {
+            type inet:ip-address {
+                extdef:help "IP address";
+            }
+            type inet:ip-prefix {
+                extdef:help "Subnet";
+            }
+            type string {
+                extdef:help "Address name";
+            }
+        }
+    }
+
+}