From: Robert Varga Date: Thu, 1 Aug 2019 12:52:09 +0000 (+0200) Subject: Remove javassist-based code X-Git-Tag: v5.0.0~111 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=d50b9a01f6230480e62cf38f8190077df7b91a00;p=mdsal.git Remove javassist-based code This removes deprecated use of javassist. Change-Id: Ia5686ce24052222cadb7465e66916b0db5b05ff3 Signed-off-by: Robert Varga --- diff --git a/binding/mdsal-binding-dom-adapter/pom.xml b/binding/mdsal-binding-dom-adapter/pom.xml index 11293e858c..a93bd6acb2 100644 --- a/binding/mdsal-binding-dom-adapter/pom.xml +++ b/binding/mdsal-binding-dom-adapter/pom.xml @@ -34,10 +34,6 @@ com.google.guava guava - - org.javassist - javassist - org.opendaylight.mdsal mdsal-binding-api diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/util/BindingBrokerTestFactory.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/util/BindingBrokerTestFactory.java index e51bb5c6c4..5996952f7c 100644 --- a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/util/BindingBrokerTestFactory.java +++ b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/util/BindingBrokerTestFactory.java @@ -12,16 +12,11 @@ import com.google.common.base.Preconditions; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import java.util.concurrent.ExecutorService; -import javassist.ClassPool; @Beta public class BindingBrokerTestFactory { - - private static final ClassPool CLASS_POOL = ClassPool.getDefault(); - private boolean startWithParsedSchema = true; private ExecutorService executor; - private ClassPool classPool; public boolean isStartWithParsedSchema() { return startWithParsedSchema; @@ -44,18 +39,4 @@ public class BindingBrokerTestFactory { ListeningExecutorService listenableExecutor = MoreExecutors.listeningDecorator(executor); return new BindingTestContext(listenableExecutor, startWithParsedSchema); } - - @Deprecated - public ClassPool getClassPool() { - if (classPool == null) { - return CLASS_POOL; - } - - return classPool; - } - - @Deprecated - public void setClassPool(final ClassPool classPool) { - this.classPool = classPool; - } } diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/util/BindingTestContext.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/util/BindingTestContext.java index 894e8b76d5..777c55cd42 100644 --- a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/util/BindingTestContext.java +++ b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/util/BindingTestContext.java @@ -15,7 +15,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import java.util.Set; -import javassist.ClassPool; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.binding.api.MountPointService; import org.opendaylight.mdsal.binding.api.NotificationPublishService; @@ -92,12 +91,6 @@ public class BindingTestContext implements AutoCloseable { return codec; } - @Deprecated - protected BindingTestContext(final ListeningExecutorService executor, - final ClassPool classPool, final boolean startWithSchema) { - this(executor, startWithSchema); - } - protected BindingTestContext(final ListeningExecutorService executor, final boolean startWithSchema) { this.executor = executor; this.startWithSchema = startWithSchema; diff --git a/binding/mdsal-binding-dom-codec/pom.xml b/binding/mdsal-binding-dom-codec/pom.xml index db4e784158..f95727551a 100644 --- a/binding/mdsal-binding-dom-codec/pom.xml +++ b/binding/mdsal-binding-dom-codec/pom.xml @@ -25,10 +25,6 @@ - - org.javassist - javassist - net.bytebuddy diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/AbstractGenerator.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/AbstractGenerator.java deleted file mode 100644 index cc38139c61..0000000000 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/AbstractGenerator.java +++ /dev/null @@ -1,24 +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.mdsal.binding.dom.codec.gen.impl; - -/** - * Package-private base class for sharing the loading capability. - * - * @deprecated This class is superseded by an internal implementation. - */ -@Deprecated -abstract class AbstractGenerator { - /** - * Ensure that the serializer class for specified class is loaded and return its name. - * - * @param cls Data object class - * @return Serializer class name - */ - protected abstract String loadSerializerFor(Class cls); -} \ No newline at end of file diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/AbstractStreamWriterGenerator.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/AbstractStreamWriterGenerator.java deleted file mode 100644 index d1c501f5a8..0000000000 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/AbstractStreamWriterGenerator.java +++ /dev/null @@ -1,335 +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.mdsal.binding.dom.codec.gen.impl; - -import static com.google.common.base.Preconditions.checkArgument; -import static java.util.Objects.requireNonNull; - -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.Map.Entry; -import javassist.CannotCompileException; -import javassist.CtClass; -import javassist.CtField; -import javassist.CtMethod; -import javassist.Modifier; -import javassist.NotFoundException; -import org.opendaylight.mdsal.binding.dom.codec.gen.spi.StaticConstantDefinition; -import org.opendaylight.mdsal.binding.dom.codec.util.AugmentableDispatchSerializer; -import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext; -import org.opendaylight.mdsal.binding.generator.util.JavassistUtils; -import org.opendaylight.mdsal.binding.model.api.GeneratedType; -import org.opendaylight.mdsal.binding.model.util.Types; -import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections; -import org.opendaylight.yangtools.util.ClassLoaderUtils; -import org.opendaylight.yangtools.yang.binding.BindingStreamEventWriter; -import org.opendaylight.yangtools.yang.binding.DataContainer; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.DataObjectSerializerImplementation; -import org.opendaylight.yangtools.yang.binding.DataObjectSerializerRegistry; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode; -import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus; -import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Deprecated -abstract class AbstractStreamWriterGenerator extends AbstractGenerator implements DataObjectSerializerGenerator { - private static final Logger LOG = LoggerFactory.getLogger(AbstractStreamWriterGenerator.class); - - protected static final String SERIALIZE_METHOD_NAME = "serialize"; - protected static final AugmentableDispatchSerializer AUGMENTABLE = new AugmentableDispatchSerializer(); - private static final Field FIELD_MODIFIERS = getModifiersField(); - - private final LoadingCache, DataObjectSerializerImplementation> implementations; - private final CtClass[] serializeArguments; - private final JavassistUtils javassist; - private BindingRuntimeContext context; - - private static Field getModifiersField() { - /* - * Cache reflection access to field modifiers field. We need this to set - * fix the static declared fields to final once we initialize them. If we - * cannot get access, that's fine, too. - */ - final Field field; - try { - field = Field.class.getDeclaredField("modifiers"); - } catch (NoSuchFieldException | SecurityException e) { - LOG.warn("Could not get modifiers field, serializers run at decreased efficiency", e); - return null; - } - - try { - AccessController.doPrivileged((PrivilegedAction) () -> { - field.setAccessible(true); - return null; - }); - } catch (SecurityException e) { - LOG.warn("Could not get access to modifiers field, serializers run at decreased efficiency", e); - return null; - } - - return field; - } - - protected AbstractStreamWriterGenerator(final JavassistUtils utils) { - this.javassist = requireNonNull(utils, "JavassistUtils instance is required."); - synchronized (javassist) { - this.serializeArguments = new CtClass[] { - javassist.asCtClass(DataObjectSerializerRegistry.class), - javassist.asCtClass(DataObject.class), - javassist.asCtClass(BindingStreamEventWriter.class), - }; - javassist.appendClassLoaderIfMissing(DataObjectSerializerPrototype.class.getClassLoader()); - } - this.implementations = CacheBuilder.newBuilder() - .removalListener(notification -> LOG.debug("onRemoval: cause={}, wasEvicted={}", - notification.getCause(), notification.wasEvicted())) - .weakKeys().build(new SerializerImplementationLoader()); - LOG.debug("AbstractStreamWriterGenerator constructor, new instance: {}", this); - } - - @Override - public final DataObjectSerializerImplementation getSerializer(final Class type) { - return implementations.getUnchecked(type); - } - - @Override - public final void onBindingRuntimeContextUpdated(final BindingRuntimeContext runtime) { - this.context = runtime; - LOG.debug("onBindingRuntimeContextUpdated() : {}", runtime); - } - - @Override - protected final String loadSerializerFor(final Class cls) { - return getSerializer(cls).getClass().getName(); - } - - private final class SerializerImplementationLoader - extends CacheLoader, DataObjectSerializerImplementation> { - - private static final String GETINSTANCE_METHOD_NAME = "getInstance"; - private static final String SERIALIZER_SUFFIX = "$StreamWriter"; - - private String getSerializerName(final Class type) { - return type.getName() + SERIALIZER_SUFFIX; - } - - @Override - @SuppressWarnings("unchecked") - public DataObjectSerializerImplementation load(final Class type) throws Exception { - checkArgument(BindingReflections.isBindingClass(type)); - checkArgument(DataContainer.class.isAssignableFrom(type), - "DataContainer is not assingnable from %s from classloader %s.", type, type.getClassLoader()); - - final String serializerName = getSerializerName(type); - - Class cls; - try { - cls = (Class) ClassLoaderUtils - .loadClass(type.getClassLoader(), serializerName); - } catch (final ClassNotFoundException e) { - cls = generateSerializer(type, serializerName); - } - - final DataObjectSerializerImplementation obj = - (DataObjectSerializerImplementation) cls.getDeclaredMethod(GETINSTANCE_METHOD_NAME).invoke(null); - LOG.trace("Loaded serializer {} for class {}", obj, type); - return obj; - } - - private Class generateSerializer(final Class type, - final String serializerName) throws CannotCompileException, IllegalAccessException, - IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, - NoSuchFieldException { - LOG.debug("generateSerializer() due to Cache miss: typeName={}, typeClassLoader={}, serializerName={}", - type.getTypeName(), type.getClassLoader(), serializerName); - final DataObjectSerializerSource source = generateEmitterSource(type, serializerName); - final CtClass poolClass = generateEmitter0(type, source, serializerName); - final Class cls = - poolClass.toClass(type.getClassLoader(), type.getProtectionDomain()) - .asSubclass(DataObjectSerializerImplementation.class); - - /* - * Due to OSGi class loader rules we cannot initialize the fields during - * construction, as the initializer expressions do not see our implementation - * classes. This should be almost as good as that, as we are resetting the - * fields to final before ever leaking the class. - */ - for (final StaticConstantDefinition constant : source.getStaticConstants()) { - final Field field = cls.getDeclaredField(constant.getName()); - field.setAccessible(true); - field.set(null, constant.getValue()); - - if (FIELD_MODIFIERS != null) { - FIELD_MODIFIERS.setInt(field, field.getModifiers() | Modifier.FINAL); - } - } - - return cls; - } - } - - private DataObjectSerializerSource generateEmitterSource(final Class type, final String serializerName) { - Types.typeForClass(type); - javassist.appendClassLoaderIfMissing(type.getClassLoader()); - final Entry typeWithSchema = context.getTypeWithSchema(type); - final GeneratedType generatedType = typeWithSchema.getKey(); - final WithStatus schema = typeWithSchema.getValue(); - - final DataObjectSerializerSource source; - if (schema instanceof ContainerSchemaNode) { - source = generateContainerSerializer(generatedType, (ContainerSchemaNode) schema); - } else if (schema instanceof ListSchemaNode) { - final ListSchemaNode casted = (ListSchemaNode) schema; - if (casted.getKeyDefinition().isEmpty()) { - source = generateUnkeyedListEntrySerializer(generatedType, casted); - } else { - source = generateMapEntrySerializer(generatedType, casted); - } - } else if (schema instanceof AugmentationSchemaNode) { - source = generateSerializer(generatedType,(AugmentationSchemaNode) schema); - } else if (schema instanceof CaseSchemaNode) { - source = generateCaseSerializer(generatedType,(CaseSchemaNode) schema); - } else if (schema instanceof NotificationDefinition) { - source = generateNotificationSerializer(generatedType,(NotificationDefinition) schema); - } else { - throw new UnsupportedOperationException("Schema type " + schema.getClass() + " is not supported"); - } - return source; - } - - private CtClass generateEmitter0(final Class type, final DataObjectSerializerSource source, - final String serializerName) { - final CtClass product; - - /* - * getSerializerBody() has side effects, such as loading classes and codecs, it should be run in model class - * loader in order to correctly reference load child classes. - * - * Furthermore the fact that getSerializedBody() can trigger other code generation to happen, we need to take - * care of this before calling instantiatePrototype(), as that will call our customizer with the lock held, - * hence any code generation will end up being blocked on the javassist lock. - */ - final String body = ClassLoaderUtils.getWithClassLoader(type.getClassLoader(), source::getSerializerBody) - .toString(); - - try { - product = javassist.instantiatePrototype(DataObjectSerializerPrototype.class.getName(), serializerName, - cls -> { - // Generate any static fields - for (final StaticConstantDefinition def : source.getStaticConstants()) { - final CtField field = new CtField(javassist.asCtClass(def.getType()), def.getName(), cls); - field.setModifiers(Modifier.PRIVATE + Modifier.STATIC); - cls.addField(field); - } - - // Replace serialize() -- may reference static fields - final CtMethod serializeTo = cls.getDeclaredMethod(SERIALIZE_METHOD_NAME, serializeArguments); - serializeTo.setBody(body); - - // The prototype is not visible, so we need to take care of that - cls.setModifiers(Modifier.setPublic(cls.getModifiers())); - }); - } catch (NotFoundException | CannotCompileException e) { - LOG.error("Failed to instatiate serializer {}", source, e); - throw new LinkageError("Unexpected instantation problem: serializer prototype not found", e); - } - return product; - } - - /** - * Generates serializer source code for supplied container node, which will read supplied binding type and invoke - * proper methods on supplied {@link BindingStreamEventWriter}. - * - *

- * Implementation is required to recursively invoke events for all reachable binding objects. - * - * @param type Binding type of container - * @param node Schema of container - * @return Source for container node writer - */ - protected abstract DataObjectSerializerSource generateContainerSerializer(GeneratedType type, - ContainerSchemaNode node); - - /** - * Generates serializer source for supplied case node, which will read supplied binding type and invoke proper - * methods on supplied {@link BindingStreamEventWriter}. - * - *

- * Implementation is required to recursively invoke events for all reachable binding objects. - * - * @param type Binding type of case - * @param node Schema of case - * @return Source for case node writer - */ - protected abstract DataObjectSerializerSource generateCaseSerializer(GeneratedType type, CaseSchemaNode node); - - /** - * Generates serializer source for supplied list node, which will read supplied binding type and invoke proper - * methods on supplied {@link BindingStreamEventWriter}. - * - *

- * Implementation is required to recursively invoke events for all reachable binding objects. - * - * @param type Binding type of list - * @param node Schema of list - * @return Source for list node writer - */ - protected abstract DataObjectSerializerSource generateMapEntrySerializer(GeneratedType type, ListSchemaNode node); - - /** - * Generates serializer source for supplied list node, which will read supplied binding type and invoke proper - * methods on supplied {@link BindingStreamEventWriter}. - * - *

- * Implementation is required to recursively invoke events for all reachable binding objects. - * - * @param type Binding type of list - * @param node Schema of list - * @return Source for list node writer - */ - protected abstract DataObjectSerializerSource generateUnkeyedListEntrySerializer(GeneratedType type, - ListSchemaNode node); - - /** - * Generates serializer source for supplied augmentation node, which will read supplied binding type and invoke - * proper methods on supplied {@link BindingStreamEventWriter}. - * - *

- * Implementation is required to recursively invoke events for all reachable binding objects. - * - * @param type Binding type of augmentation - * @param schema Schema of augmentation - * @return Source for augmentation node writer - */ - protected abstract DataObjectSerializerSource generateSerializer(GeneratedType type, AugmentationSchemaNode schema); - - /** - * Generates serializer source for notification node, which will read supplied binding type and invoke proper - * methods on supplied {@link BindingStreamEventWriter}. - * - *

- * Implementation is required to recursively invoke events for all reachable binding objects. - * - * @param type Binding type of notification - * @param node Schema of notification - * @return Source for notification node writer - */ - protected abstract DataObjectSerializerSource generateNotificationSerializer(GeneratedType type, - NotificationDefinition node); -} diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/AugmentableDataNodeContainerEmitterSource.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/AugmentableDataNodeContainerEmitterSource.java deleted file mode 100644 index 5e3bdd4fb4..0000000000 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/AugmentableDataNodeContainerEmitterSource.java +++ /dev/null @@ -1,33 +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.mdsal.binding.dom.codec.gen.impl; - -import org.opendaylight.mdsal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.yang.binding.DataObjectSerializerImplementation; -import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; - -@Deprecated -abstract class AugmentableDataNodeContainerEmitterSource extends DataNodeContainerSerializerSource { - private static final String AUGMENTABLE_SERIALIZER = "AUGMENTABLE_SERIALIZER"; - - AugmentableDataNodeContainerEmitterSource(final AbstractStreamWriterGenerator generator, final GeneratedType type, - final DataNodeContainer node) { - super(generator, type, node); - /* - * Eventhough intuition says the serializer could reference the generator directly, that is not true in OSGi - * environment -- so we need to resolve the reference first and inject it as a static constant. - */ - staticConstant(AUGMENTABLE_SERIALIZER, DataObjectSerializerImplementation.class, - StreamWriterGenerator.AUGMENTABLE); - } - - @Override - protected void emitAfterBody(final StringBuilder sb) { - sb.append(statement(invoke(AUGMENTABLE_SERIALIZER, "serialize", REGISTRY, INPUT, STREAM))); - } -} \ No newline at end of file diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/DataNodeContainerSerializerSource.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/DataNodeContainerSerializerSource.java deleted file mode 100644 index e4261182e9..0000000000 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/DataNodeContainerSerializerSource.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2014, 2015 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.mdsal.binding.dom.codec.gen.impl; - -import static com.google.common.base.Preconditions.checkState; -import static java.util.Objects.requireNonNull; - -import java.util.HashMap; -import java.util.Map; -import org.opendaylight.mdsal.binding.dom.codec.util.BindingSchemaMapping; -import org.opendaylight.mdsal.binding.dom.codec.util.ChoiceDispatchSerializer; -import org.opendaylight.mdsal.binding.model.api.GeneratedType; -import org.opendaylight.mdsal.binding.model.api.MethodSignature; -import org.opendaylight.mdsal.binding.model.api.ParameterizedType; -import org.opendaylight.mdsal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.binding.BindingSerializer; -import org.opendaylight.yangtools.yang.binding.BindingStreamEventWriter; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.DataObjectSerializerImplementation; -import org.opendaylight.yangtools.yang.binding.DataObjectSerializerRegistry; -import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Deprecated -abstract class DataNodeContainerSerializerSource extends DataObjectSerializerSource { - - private static final Logger LOG = LoggerFactory.getLogger(DataNodeContainerSerializerSource.class); - - protected static final String INPUT = "_input"; - private static final String CHOICE_PREFIX = "CHOICE_"; - - protected final DataNodeContainer schemaNode; - private final GeneratedType dtoType; - - DataNodeContainerSerializerSource(final AbstractGenerator generator, final GeneratedType type, - final DataNodeContainer node) { - super(generator); - this.dtoType = requireNonNull(type); - this.schemaNode = requireNonNull(node); - } - - /** - * Return the character sequence which should be used for start event. - * - * @return Start event character sequence - */ - protected abstract CharSequence emitStartEvent(); - - @Override - protected CharSequence getSerializerBody() { - final StringBuilder sb = new StringBuilder() - .append("{\n") - .append(statement(assign(DataObjectSerializerRegistry.class, REGISTRY, "$1"))) - .append(statement(assign(dtoType, INPUT, cast(dtoType, "$2")))) - .append(statement(assign(BindingStreamEventWriter.class, STREAM, - cast(BindingStreamEventWriter.class, "$3")))) - .append(statement(assign(BindingSerializer.class, SERIALIZER, null))) - .append("if (") - .append(STREAM) - .append(" instanceof ") - .append(BindingSerializer.class.getName()) - .append(") {") - .append(statement(assign(SERIALIZER, cast(BindingSerializer.class, STREAM)))) - .append('}') - .append(statement(emitStartEvent())); - - emitBody(sb); - emitAfterBody(sb); - - return sb.append(statement(endNode())) - .append(statement("return null")) - .append('}'); - } - - /** - * Allows for customization of emitting code, which is processed after - * normal DataNodeContainer body. Ideal for augmentations or others. - */ - protected void emitAfterBody(final StringBuilder sb) { - // No-op - } - - private static Map collectAllProperties(final GeneratedType type, final Map hashMap) { - for (final MethodSignature definition : type.getMethodDefinitions()) { - hashMap.put(definition.getName(), definition.getReturnType()); - } - for (final Type parent : type.getImplements()) { - if (parent instanceof GeneratedType) { - collectAllProperties((GeneratedType) parent, hashMap); - } - } - return hashMap; - } - - private void emitBody(final StringBuilder sb) { - final Map getterToType = collectAllProperties(dtoType, new HashMap()); - for (final DataSchemaNode schemaChild : schemaNode.getChildNodes()) { - if (!schemaChild.isAugmenting()) { - final String getter = BindingSchemaMapping.getGetterMethodName(schemaChild); - final Type childType = getterToType.get(getter); - checkState(childType != null, "Unable to find type for child node %s. Expected child nodes: %s", - schemaChild.getPath(), getterToType); - emitChild(sb, getter, childType, schemaChild); - } - } - } - - private void emitChild(final StringBuilder sb, final String getterName, final Type childType, - final DataSchemaNode schemaChild) { - sb.append(statement(assign(childType, getterName, cast(childType, invoke(INPUT, getterName))))); - - sb.append("if (").append(getterName).append(" != null) {\n"); - emitChildInner(sb, getterName, childType, schemaChild); - sb.append("}\n"); - } - - private void emitChildInner(final StringBuilder sb, final String getterName, final Type childType, - final DataSchemaNode child) { - if (child instanceof LeafSchemaNode) { - sb.append(statement(leafNode(child.getQName().getLocalName(), getterName))); - } else if (child instanceof AnyXmlSchemaNode) { - sb.append(statement(anyxmlNode(child.getQName().getLocalName(), getterName))); - } else if (child instanceof LeafListSchemaNode) { - final CharSequence startEvent; - if (((LeafListSchemaNode) child).isUserOrdered()) { - startEvent = startOrderedLeafSet(child.getQName().getLocalName(),invoke(getterName, "size")); - } else { - startEvent = startLeafSet(child.getQName().getLocalName(),invoke(getterName, "size")); - } - sb.append(statement(startEvent)); - final Type valueType = ((ParameterizedType) childType).getActualTypeArguments()[0]; - sb.append(forEach(getterName, valueType, statement(leafSetEntryNode(CURRENT)))); - sb.append(statement(endNode())); - } else if (child instanceof ListSchemaNode) { - final Type valueType = ((ParameterizedType) childType).getActualTypeArguments()[0]; - final ListSchemaNode casted = (ListSchemaNode) child; - emitList(sb, getterName, valueType, casted); - } else if (child instanceof ContainerSchemaNode) { - sb.append(tryToUseCacheElse(getterName, statement(staticInvokeEmitter(childType, getterName)))); - } else if (child instanceof ChoiceSchemaNode) { - final String propertyName = CHOICE_PREFIX + childType.getName(); - staticConstant(propertyName, DataObjectSerializerImplementation.class, - ChoiceDispatchSerializer.from(loadClass(childType))); - sb.append(tryToUseCacheElse(getterName, statement(invoke(propertyName, - StreamWriterGenerator.SERIALIZE_METHOD_NAME, REGISTRY, cast(DataObject.class, getterName), STREAM)))); - } - } - - private static StringBuilder tryToUseCacheElse(final String getterName, final CharSequence statement) { - return new StringBuilder() - .append("if (").append(SERIALIZER).append(" == null || ") - .append(invoke(SERIALIZER, "serialize", getterName)).append(" == null) {\n") - .append(statement) - .append('}'); - } - - private void emitList(final StringBuilder sb, final String getterName, final Type valueType, - final ListSchemaNode child) { - final CharSequence startEvent; - - sb.append(statement(assign("int", "_count", invoke(getterName, "size")))); - if (child.getKeyDefinition().isEmpty()) { - startEvent = startUnkeyedList(classReference(valueType), "_count"); - } else if (child.isUserOrdered()) { - startEvent = startOrderedMapNode(classReference(valueType), "_count"); - } else { - startEvent = startMapNode(classReference(valueType), "_count"); - } - sb.append(statement(startEvent)); - sb.append(forEach(getterName, valueType, tryToUseCacheElse(CURRENT, statement(staticInvokeEmitter(valueType, - CURRENT))))); - sb.append(statement(endNode())); - } -} diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/DataObjectSerializerGenerator.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/DataObjectSerializerGenerator.java deleted file mode 100644 index 6cba594d26..0000000000 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/DataObjectSerializerGenerator.java +++ /dev/null @@ -1,33 +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.mdsal.binding.dom.codec.gen.impl; - -import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext; -import org.opendaylight.yangtools.yang.binding.DataObjectSerializerImplementation; - -/** - * Public interface exposed from generator implementation. - * - * @deprecated This interface is superseded by an internal implementation. - */ -@Deprecated -public interface DataObjectSerializerGenerator { - /** - * Get a serializer for a particular type. - * - * @param type Type class - * @return Serializer instance. - */ - DataObjectSerializerImplementation getSerializer(Class type); - - /** - * Notify the generator that the runtime context has been updated. - * @param runtime New runtime context - */ - void onBindingRuntimeContextUpdated(BindingRuntimeContext runtime); -} diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/DataObjectSerializerPrototype.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/DataObjectSerializerPrototype.java deleted file mode 100644 index 6b51495889..0000000000 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/DataObjectSerializerPrototype.java +++ /dev/null @@ -1,43 +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.mdsal.binding.dom.codec.gen.impl; - -import org.opendaylight.yangtools.yang.binding.BindingStreamEventWriter; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.DataObjectSerializerImplementation; -import org.opendaylight.yangtools.yang.binding.DataObjectSerializerRegistry; - -/** - * Prototype of a DataObjectSerializerImplementation. This is a template class, which the - * {@link AbstractStreamWriterGenerator} uses to instantiate {@link DataObjectSerializerImplementation} on a per-type - * basis. During that time, the {@link #serialize(DataObjectSerializerRegistry, DataObject, BindingStreamEventWriter)} - * method will be replaced by the real implementation. - */ -@Deprecated -final class DataObjectSerializerPrototype implements DataObjectSerializerImplementation { - private static final DataObjectSerializerPrototype INSTANCE = new DataObjectSerializerPrototype(); - - private DataObjectSerializerPrototype() { - // Intentionally hidden, subclasses can replace it - } - - /** - * Return the shared serializer instance. - * - * @return Global singleton instance. - */ - public static DataObjectSerializerPrototype getInstance() { - return INSTANCE; - } - - @Override - public void serialize(final DataObjectSerializerRegistry reg, final DataObject obj, - final BindingStreamEventWriter stream) { - throw new UnsupportedOperationException("Prototype body, this code should never be invoked."); - } -} diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/DataObjectSerializerSource.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/DataObjectSerializerSource.java deleted file mode 100644 index 818dfee89e..0000000000 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/DataObjectSerializerSource.java +++ /dev/null @@ -1,150 +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.mdsal.binding.dom.codec.gen.impl; - -import static java.util.Objects.requireNonNull; - -import org.opendaylight.mdsal.binding.dom.codec.gen.spi.AbstractSource; -import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy; -import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy; -import org.opendaylight.mdsal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.binding.BindingStreamEventWriter; -import org.opendaylight.yangtools.yang.binding.DataContainer; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.DataObjectSerializerRegistry; - -@Deprecated -abstract class DataObjectSerializerSource extends AbstractSource { - - private static final ClassLoadingStrategy STRATEGY = GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(); - - protected static final String SERIALIZER = "_serializer"; - protected static final String STREAM = "_stream"; - protected static final String ITERATOR = "_iterator"; - protected static final String CURRENT = "_current"; - protected static final String REGISTRY = "_registry"; - - private final AbstractGenerator generator; - - /** - * Create a new source. - * - * @param generator Parent generator - */ - DataObjectSerializerSource(final AbstractGenerator generator) { - this.generator = requireNonNull(generator); - } - - @SuppressWarnings("unchecked") - protected Class loadClass(final Type childType) { - try { - return (Class) STRATEGY.loadClass(childType); - } catch (final ClassNotFoundException e) { - throw new IllegalStateException("Could not load referenced class ", e); - } - } - - /** - * Returns body of static serialize method. - * - *

    - *
  • {@link DataObjectSerializerRegistry} - registry of serializers - *
  • {@link DataObject} - object to be serialized - *
  • {@link BindingStreamEventWriter} - writer to which events should be serialized. - *
- * - * @return Valid javassist code describing static serialization body. - */ - protected abstract CharSequence getSerializerBody(); - - // FIXME: 5.0.0: consider optimizing streaming use through returning StringBuilder from common methods - protected static final CharSequence leafNode(final String localName, final CharSequence value) { - return invoke(STREAM, "leafNode", escape(localName), value); - } - - protected static final CharSequence startLeafSet(final String localName, final CharSequence expected) { - return invoke(STREAM, "startLeafSet", escape(localName), expected); - } - - protected static final CharSequence startOrderedLeafSet(final String localName, final CharSequence expected) { - return invoke(STREAM, "startOrderedLeafSet", escape(localName), expected); - } - - protected static final CharSequence leafSetEntryNode(final CharSequence value) { - return invoke(STREAM, "leafSetEntryNode", value); - } - - protected static final CharSequence startContainerNode(final CharSequence type, final CharSequence expected) { - return invoke(STREAM, "startContainerNode", type, expected); - } - - protected static final CharSequence escape(final String localName) { - return '"' + localName + '"'; - } - - protected static final CharSequence startUnkeyedList(final CharSequence type, final CharSequence expected) { - return invoke(STREAM, "startUnkeyedList", type, expected); - } - - protected static final CharSequence startUnkeyedListItem(final CharSequence expected) { - return invoke(STREAM, "startUnkeyedListItem", expected); - } - - protected static final CharSequence startMapNode(final CharSequence type,final CharSequence expected) { - return invoke(STREAM, "startMapNode", type, expected); - } - - protected static final CharSequence startOrderedMapNode(final CharSequence type,final CharSequence expected) { - return invoke(STREAM, "startOrderedMapNode", type, expected); - } - - protected static final CharSequence startMapEntryNode(final CharSequence key, final CharSequence expected) { - return invoke(STREAM, "startMapEntryNode", key, expected); - } - - protected static final CharSequence startAugmentationNode(final CharSequence key) { - return invoke(STREAM, "startAugmentationNode", key); - } - - protected static final CharSequence startChoiceNode(final CharSequence localName, final CharSequence expected) { - return invoke(STREAM, "startChoiceNode", localName, expected); - } - - protected static final CharSequence startCaseNode(final CharSequence localName, final CharSequence expected) { - return invoke(STREAM, "startCase", localName, expected); - } - - protected static final CharSequence anyxmlNode(final String localName, final CharSequence value) - throws IllegalArgumentException { - return invoke(STREAM, "anyxmlNode", escape(localName), value); - } - - protected static final CharSequence endNode() { - return invoke(STREAM, "endNode"); - } - - protected static final CharSequence forEach(final String iterable,final Type valueType,final CharSequence body) { - return forEach(iterable, ITERATOR, valueType.getFullyQualifiedName(), CURRENT, body); - } - - protected static final CharSequence classReference(final Type type) { - return type.getFullyQualifiedName() + ".class"; - } - - protected final CharSequence staticInvokeEmitter(final Type childType, final String name) { - final Class cls; - try { - cls = STRATEGY.loadClass(childType); - } catch (final ClassNotFoundException e) { - throw new IllegalStateException("Failed to invoke emitter", e); - } - - final String className = this.generator.loadSerializerFor(cls) + ".getInstance()"; - return invoke(className, AbstractStreamWriterGenerator.SERIALIZE_METHOD_NAME, REGISTRY, name, STREAM); - } -} diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/StreamWriterGenerator.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/StreamWriterGenerator.java deleted file mode 100644 index 99022f36ac..0000000000 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/StreamWriterGenerator.java +++ /dev/null @@ -1,118 +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.mdsal.binding.dom.codec.gen.impl; - -import org.opendaylight.mdsal.binding.dom.codec.util.AugmentableDispatchSerializer; -import org.opendaylight.mdsal.binding.dom.codec.util.ChoiceDispatchSerializer; -import org.opendaylight.mdsal.binding.generator.util.JavassistUtils; -import org.opendaylight.mdsal.binding.model.api.GeneratedType; -import org.opendaylight.mdsal.binding.spec.naming.BindingMapping; -import org.opendaylight.yangtools.yang.binding.BindingStreamEventWriter; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.DataObjectSerializerImplementation; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode; -import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; - -/** - * Concrete implementation of {@link AbstractStreamWriterGenerator} which in runtime generates classes implementing - * {@link DataObjectSerializerImplementation} interface and are used to serialize Binding {@link DataObject}. - * - *

- * Actual implementation of codecs is done via static methods, which allows for static wiring of codecs. Choice codec - * and Augmentable codecs are static properties of parent codec and stateless implementations are used - * ({@link ChoiceDispatchSerializer}, {@link AugmentableDispatchSerializer}), which uses registry to dispatch to - * concrete item codec. - * - * @deprecated This class is superseded by an internal implementation. - */ -@Deprecated -public final class StreamWriterGenerator extends AbstractStreamWriterGenerator { - private static final String UNKNOWN_SIZE = BindingStreamEventWriter.class.getName() + ".UNKNOWN_SIZE"; - - private StreamWriterGenerator(final JavassistUtils utils) { - super(utils); - } - - /** - * Create a new instance backed by a specific {@link JavassistUtils} instance. - * - * @param utils JavassistUtils instance to use - * @return A new generator - */ - public static DataObjectSerializerGenerator create(final JavassistUtils utils) { - return new StreamWriterGenerator(utils); - } - - @Override - protected DataObjectSerializerSource generateContainerSerializer(final GeneratedType type, - final ContainerSchemaNode node) { - return new AugmentableDataNodeContainerEmitterSource(this, type, node) { - @Override - public CharSequence emitStartEvent() { - return startContainerNode(classReference(type), UNKNOWN_SIZE); - } - }; - } - - @Override - protected DataObjectSerializerSource generateNotificationSerializer(final GeneratedType type, - final NotificationDefinition node) { - return new AugmentableDataNodeContainerEmitterSource(this, type, node) { - @Override - public CharSequence emitStartEvent() { - return startContainerNode(classReference(type), UNKNOWN_SIZE); - } - }; - } - - @Override - protected DataObjectSerializerSource generateCaseSerializer(final GeneratedType type, final CaseSchemaNode node) { - return new AugmentableDataNodeContainerEmitterSource(this, type, node) { - @Override - public CharSequence emitStartEvent() { - return startCaseNode(classReference(type),UNKNOWN_SIZE); - } - }; - } - - @Override - protected DataObjectSerializerSource generateUnkeyedListEntrySerializer(final GeneratedType type, - final ListSchemaNode node) { - return new AugmentableDataNodeContainerEmitterSource(this, type, node) { - @Override - public CharSequence emitStartEvent() { - return startUnkeyedListItem(UNKNOWN_SIZE); - } - }; - } - - @Override - protected DataObjectSerializerSource generateSerializer(final GeneratedType type, - final AugmentationSchemaNode schema) { - return new DataNodeContainerSerializerSource(this, type, schema) { - @Override - public CharSequence emitStartEvent() { - return startAugmentationNode(classReference(type)); - } - }; - } - - @Override - protected DataObjectSerializerSource generateMapEntrySerializer(final GeneratedType type, - final ListSchemaNode node) { - return new AugmentableDataNodeContainerEmitterSource(this, type, node) { - @Override - public CharSequence emitStartEvent() { - return startMapEntryNode(invoke(INPUT, BindingMapping.IDENTIFIABLE_KEY_NAME), UNKNOWN_SIZE); - } - }; - } -} diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingNormalizedNodeCodecRegistry.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingNormalizedNodeCodecRegistry.java index a284cc3df7..6edcf424f9 100644 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingNormalizedNodeCodecRegistry.java +++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingNormalizedNodeCodecRegistry.java @@ -29,7 +29,6 @@ import org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNo import org.opendaylight.mdsal.binding.dom.codec.api.BindingLazyContainerNode; import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeWriterFactory; -import org.opendaylight.mdsal.binding.dom.codec.gen.impl.DataObjectSerializerGenerator; import org.opendaylight.mdsal.binding.dom.codec.util.AbstractBindingLazyContainerNode; import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext; @@ -67,15 +66,13 @@ public class BindingNormalizedNodeCodecRegistry implements DataObjectSerializerR BindingCodecTreeFactory, BindingNormalizedNodeWriterFactory, BindingNormalizedNodeSerializer { private static final Logger LOG = LoggerFactory.getLogger(BindingNormalizedNodeCodecRegistry.class); - private final DataObjectSerializerGenerator generator; - private static final AtomicReferenceFieldUpdater UPDATER = AtomicReferenceFieldUpdater.newUpdater(BindingNormalizedNodeCodecRegistry.class, BindingCodecContext.class, "codecContext"); private volatile BindingCodecContext codecContext; public BindingNormalizedNodeCodecRegistry() { - this.generator = null; + } public BindingNormalizedNodeCodecRegistry(final BindingRuntimeContext codecContext) { @@ -83,11 +80,6 @@ public class BindingNormalizedNodeCodecRegistry implements DataObjectSerializerR onBindingRuntimeContextUpdated(codecContext); } - @Deprecated - public BindingNormalizedNodeCodecRegistry(final DataObjectSerializerGenerator generator) { - this.generator = requireNonNull(generator); - } - @Override public DataObjectSerializer getSerializer(final Class type) { return codecContext().getSerializer(type); @@ -106,11 +98,7 @@ public class BindingNormalizedNodeCodecRegistry implements DataObjectSerializerR } final BindingCodecContext updated = new BindingCodecContext(context, this); - if (UPDATER.compareAndSet(this, current, updated)) { - if (generator != null) { - generator.onBindingRuntimeContextUpdated(context); - } - } else { + if (!UPDATER.compareAndSet(this, current, updated)) { LOG.warn("Concurrent update of runtime context (expected={} current={}) detected at ", current, codecContext, new Throwable()); } diff --git a/binding/mdsal-binding-generator-impl/pom.xml b/binding/mdsal-binding-generator-impl/pom.xml index f0fb3997db..51b0bc5545 100644 --- a/binding/mdsal-binding-generator-impl/pom.xml +++ b/binding/mdsal-binding-generator-impl/pom.xml @@ -21,11 +21,6 @@ bundle - - org.javassist - javassist - - org.opendaylight.yangtools yang-data-api diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/ClassCustomizer.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/ClassCustomizer.java deleted file mode 100644 index 62c7ce5b71..0000000000 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/ClassCustomizer.java +++ /dev/null @@ -1,32 +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.mdsal.binding.generator.util; - -import com.google.common.annotations.Beta; -import javassist.CannotCompileException; -import javassist.CtClass; -import javassist.NotFoundException; - -/** - * Interface allowing customization of classes after loading. - * - * @deprecated Code generation is a concert separate from type mapping and is an implementation detail. - */ -@Beta -@Deprecated -@FunctionalInterface -public interface ClassCustomizer { - /** - * Customize a class. - * - * @param cls Class to be customized - * @throws CannotCompileException when a javassist error occurs - * @throws NotFoundException when a javassist error occurs - */ - void customizeClass(CtClass cls) throws CannotCompileException, NotFoundException; -} diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/ClassGenerator.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/ClassGenerator.java deleted file mode 100644 index 56728cd03c..0000000000 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/ClassGenerator.java +++ /dev/null @@ -1,16 +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.mdsal.binding.generator.util; - -import javassist.CannotCompileException; -import javassist.CtClass; - -@Deprecated -public interface ClassGenerator { - void process(CtClass cls) throws CannotCompileException; -} diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/DefaultSourceCodeGenerator.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/DefaultSourceCodeGenerator.java deleted file mode 100644 index ce44f64c5b..0000000000 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/DefaultSourceCodeGenerator.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2014 Brocade Communications 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.mdsal.binding.generator.util; - -import com.google.common.io.Files; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.io.BufferedWriter; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import javassist.CtClass; -import javassist.CtField; -import javassist.CtMethod; -import javassist.Modifier; -import javassist.NotFoundException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * The default implementation of the SourceCodeGenerator interface that generates readable source code - * for a runtime generated class. The appendField/appendMethod methods output source code to a temporary - * StringBuilder. When outputGeneratedSource is called, the entire class source code is generated and - * written to a file under a specified directory. - * - * @author Thomas Pantelis - * - * @deprecated Code generation is a concert separate from type mapping and is an implementation detail. - */ -@Deprecated -public class DefaultSourceCodeGenerator implements SourceCodeGenerator { - private static final Logger LOG = LoggerFactory.getLogger(DefaultSourceCodeGenerator.class); - - private static final String GENERATED_SOURCE_DIR_PROP = "org.opendaylight.yangtools.sal.generatedCodecSourceDir"; - - private final StringBuilder builder = new StringBuilder(); - private final String generatedSourceDir; - - /** - * Constructor. - * - * @param generatedSourceDir the directory in which to put generated source files. If null, the directory - * is obtained from a system property (org.opendaylight.yangtools.sal.generatedCodecSourceDir) or - * defaults to "generated-codecs". - */ - public DefaultSourceCodeGenerator(final String generatedSourceDir) { - if (generatedSourceDir != null) { - this.generatedSourceDir = generatedSourceDir; - } else { - this.generatedSourceDir = System.getProperty(GENERATED_SOURCE_DIR_PROP, "generated-codecs"); - } - } - - @Override - public void appendField(final CtField field, final String value) { - try { - builder.append('\n') - .append(Modifier.toString(field.getModifiers())) - .append(' ').append(field.getType().getName()).append(' ') - .append(field.getName()); - if (value != null) { - builder.append(" = ").append(value); - } - - builder.append(";\n"); - } catch (NotFoundException e) { - LOG.error("Error building field source for {}", field.getName(), e); - } - } - - @Override - public void appendMethod(final CtMethod method, final String code) { - try { - builder.append('\n') - .append(Modifier.toString(method.getModifiers())) - .append(' ').append(method.getReturnType().getName()) - .append(' ').append(method.getName()).append("( "); - - CtClass[] paramTypes = method.getParameterTypes(); - if (paramTypes != null) { - for (int i = 0; i < paramTypes.length; i++) { - if (i > 0) { - builder.append(", "); - } - builder.append(paramTypes[i].getName()).append(" $") - .append(i + 1); - } - } - - builder.append(" )\n").append(code).append("\n\n"); - } catch (NotFoundException e) { - LOG.error("Error building method source for {}", method.getName(), e); - } - } - - @Override - @SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE") - public void outputGeneratedSource(final CtClass ctClass) { - String name = ctClass.getName(); - - StringBuilder classBuilder = new StringBuilder(); - classBuilder.append(Modifier.toString(ctClass.getModifiers())) - .append(" class ").append(ctClass.getSimpleName()); - - try { - CtClass superClass = ctClass.getSuperclass(); - if (superClass != null) { - classBuilder.append(" extends ").append(superClass.getName()); - } - - CtClass[] interfaces = ctClass.getInterfaces(); - if (interfaces.length > 0) { - classBuilder.append(" implements "); - for (int i = 0; i < interfaces.length; i++) { - if (i > 0) { - classBuilder.append(", "); - } - - classBuilder.append(interfaces[i].getName()); - } - } - - classBuilder.append(" {\n").append(builder).append("\n}"); - } catch (NotFoundException e) { - LOG.error("Error building class source for {}", name, e); - return; - } - - File dir = new File(generatedSourceDir); - if (!dir.mkdir()) { - LOG.warn("Failed to create directory {}, attempting to continue", generatedSourceDir); - } - - try (BufferedWriter writer = Files.newWriter(new File(dir, name + ".java"), StandardCharsets.UTF_8)) { - writer.append(classBuilder); - writer.flush(); - } catch (IOException e) { - LOG.error("Error writing class source for {}", name, e); - } - } -} diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/FieldGenerator.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/FieldGenerator.java deleted file mode 100644 index 3b8b7e840b..0000000000 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/FieldGenerator.java +++ /dev/null @@ -1,15 +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.mdsal.binding.generator.util; - -import javassist.CtField; - -@Deprecated -public interface FieldGenerator { - void process(CtField field); -} diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/JavassistUtils.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/JavassistUtils.java deleted file mode 100644 index 74ee3e14f0..0000000000 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/JavassistUtils.java +++ /dev/null @@ -1,120 +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.mdsal.binding.generator.util; - -import static java.util.Objects.requireNonNull; - -import com.google.common.annotations.Beta; -import java.util.Map; -import java.util.WeakHashMap; -import javassist.CannotCompileException; -import javassist.ClassClassPath; -import javassist.ClassPath; -import javassist.ClassPool; -import javassist.CtClass; -import javassist.LoaderClassPath; -import javassist.NotFoundException; -import org.checkerframework.checker.lock.qual.GuardedBy; -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Users of this utility class are expected to synchronize on this instance it they need to ensure atomic operations - * on it. Individual operations are synchronized and therefore are thread-safe. - * - * @deprecated This class has been deprecated due to not being quite able to work in multi-classloader environments - * without holding strong central references. - */ -@Deprecated -@NonNullByDefault -public final class JavassistUtils { - private static final Logger LOG = LoggerFactory.getLogger(JavassistUtils.class); - private static final Map INSTANCES = new WeakHashMap<>(); - - @GuardedBy("this") - private final Map loaderClassPaths = new WeakHashMap<>(); - @GuardedBy("this") - private final ClassPool classPool; - - private JavassistUtils(final ClassPool pool) { - classPool = requireNonNull(pool); - } - - /** - * Get a utility instance for a particular class pool. A new instance is - * created if this is a new pool. If an instance already exists, is is - * returned. - * - * @param pool Backing class pool - * @return shared utility instance for specified pool - */ - public static synchronized JavassistUtils forClassPool(final ClassPool pool) { - return INSTANCES.computeIfAbsent(requireNonNull(pool), JavassistUtils::new); - } - - /** - * Instantiate a new class based on a prototype. The class is set to automatically prune. The {@code customizer} - * is guaranteed to run with this object locked. - * - * @param prototype Prototype class fully qualified name - * @param fqn Target class fully qualified name - * @param customizer Customization callback to be invoked on the new class - * @return An instance of the new class - * @throws NotFoundException when the prototype class is not found - */ - @Beta - @SuppressWarnings("checkstyle:illegalCatch") - public synchronized CtClass instantiatePrototype(final String prototype, final String fqn, - final ClassCustomizer customizer) throws CannotCompileException, NotFoundException { - final CtClass result = classPool.getAndRename(prototype, fqn); - try { - customizer.customizeClass(result); - } catch (CannotCompileException | NotFoundException e) { - result.detach(); - throw e; - } catch (Exception e) { - LOG.warn("Failed to customize {} from prototype {}", fqn, prototype, e); - result.detach(); - throw new IllegalStateException(String.format("Failed to instantiate prototype %s as %s", prototype, fqn), - e); - } - - result.stopPruning(false); - return result; - } - - @GuardedBy("this") - public CtClass asCtClass(final Class cls) { - try { - return classPool.get(cls.getName()); - } catch (NotFoundException nfe1) { - appendClassLoaderIfMissing(cls.getClassLoader()); - try { - return classPool.get(cls.getName()); - } catch (final NotFoundException nfe2) { - LOG.warn("Appending ClassClassPath for {}", cls, nfe2); - classPool.appendClassPath(new ClassClassPath(cls)); - try { - return classPool.get(cls.getName()); - } catch (NotFoundException e) { - LOG.warn("Failed to load class {} from pool {}", cls, classPool, e); - throw new IllegalStateException("Failed to load class", e); - } - } - } - } - - public synchronized void appendClassLoaderIfMissing(final ClassLoader loader) { - if (!loaderClassPaths.containsKey(loader)) { - final ClassPath ctLoader = new LoaderClassPath(loader); - classPool.appendClassPath(ctLoader); - loaderClassPaths.put(loader, ctLoader); - } - } -} diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/NullSourceCodeGenerator.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/NullSourceCodeGenerator.java deleted file mode 100644 index de654b2b1c..0000000000 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/NullSourceCodeGenerator.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2014 Brocade Communications 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.mdsal.binding.generator.util; - -import javassist.CtClass; -import javassist.CtField; -import javassist.CtMethod; - -/** - * Implementation of the SourceCodeGenerator interface that does nothing. - * - * @author Thomas Pantelis - */ -@Deprecated -public class NullSourceCodeGenerator implements SourceCodeGenerator { - - @Override - public void appendField(final CtField field, final String value) { - } - - @Override - public void appendMethod(final CtMethod method, final String code) { - } - - @Override - public void outputGeneratedSource(final CtClass ctClass) { - } -} diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/SourceCodeGenerator.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/SourceCodeGenerator.java deleted file mode 100644 index c208095b30..0000000000 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/SourceCodeGenerator.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2014 Brocade Communications 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.mdsal.binding.generator.util; - -import javassist.CtClass; -import javassist.CtField; -import javassist.CtMethod; - -/** - * Interface for a class that that generates readable source code for a runtime generated class. - * The appendField/appendMethod methods append source code to a temporary output. When outputGeneratedSource - * is called, the entire class source code is generated and outputted. - * - * @author Thomas Pantelis - * @deprecated Code generation is a concert separate from type mapping and is an implementation detail. Most notably - * there may actually not be intermediate source code. - */ -@Deprecated -public interface SourceCodeGenerator { - - /** - * Appends the given class field and value to the temporary output. - */ - void appendField(CtField field, String value); - - /** - * Appends the given method and source code body to the temporary output. - */ - void appendMethod(CtMethod method, String code); - - /** - * Generates the full source code for the given class and outputs it. - */ - void outputGeneratedSource(CtClass ctClass); -} \ No newline at end of file diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/SourceCodeGeneratorFactory.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/SourceCodeGeneratorFactory.java deleted file mode 100644 index e2566a7227..0000000000 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/SourceCodeGeneratorFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2014 Brocade Communications 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.mdsal.binding.generator.util; - -/** - * Factory class for creating SourceCodeGenerator instances. - * - * @author Thomas Pantelis - * @deprecated Code generation is a concert separate from type mapping and is an implementation detail. - */ -@Deprecated -public class SourceCodeGeneratorFactory { - - private static final String GENERATE_CODEC_SOURCE_PROP = "org.opendaylight.yangtools.sal.generateCodecSource"; - - private static final SourceCodeGenerator NULL_GENERATOR = new NullSourceCodeGenerator(); - - /** - * Gets a SourceCodeGenerator instance. - * - *

- * Generation of source code is controlled by the org.opendaylight.yangtools.sal.generateCodecSource - * system property. If set to true, a DefaultSourceCodeGenerator instance is returned, otherwise a - * NullSourceCodeGenerator is returned. - * - * @param generatedSourceDir the directory in which to put generated source files. If null, - * a default is used (see DefaultSourceCodeGenerator). - */ - public SourceCodeGenerator getInstance(final String generatedSourceDir) { - boolean generateSource = Boolean.getBoolean(GENERATE_CODEC_SOURCE_PROP); - if (generateSource) { - return new DefaultSourceCodeGenerator(generatedSourceDir); - } - - return NULL_GENERATOR; - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/util/JavassistUtilsTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/util/JavassistUtilsTest.java deleted file mode 100644 index 50129e8151..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/util/JavassistUtilsTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2016 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.mdsal.binding.generator.util; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; - -import javassist.CannotCompileException; -import javassist.ClassPool; -import javassist.NotFoundException; -import org.junit.Test; - -@Deprecated -public class JavassistUtilsTest { - - @Test - public void forClassPool() throws CannotCompileException, NotFoundException { - final JavassistUtils javassistUtils = JavassistUtils.forClassPool(ClassPool.getDefault()); - final ClassGenerator classGenerator = mock(ClassGenerator.class); - doNothing().when(classGenerator).process(any()); - - final ClassCustomizer classCustomizer = mock(ClassCustomizer.class); - doNothing().when(classCustomizer).customizeClass(any()); - assertNotNull(javassistUtils.instantiatePrototype("javassist.CtNewClass", "leWut", classCustomizer)); - } - - @Test - public void privateConstructTest() throws Exception { - assertFalse(JavassistUtils.class.getDeclaredConstructor(ClassPool.class).isAccessible()); - } -} \ No newline at end of file diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/util/SourceCodeGeneratorFactoryTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/util/SourceCodeGeneratorFactoryTest.java deleted file mode 100644 index ac464341c0..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/util/SourceCodeGeneratorFactoryTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2016 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.mdsal.binding.generator.util; - -import static java.util.Arrays.stream; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.CALLS_REAL_METHODS; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; - -import com.google.common.collect.ImmutableList; -import java.io.File; -import java.lang.reflect.Field; -import javassist.ClassPool; -import javassist.CtClass; -import javassist.CtField; -import javassist.CtMethod; -import javassist.bytecode.AccessFlag; -import javassist.bytecode.ClassFile; -import org.junit.Test; - -@Deprecated -public class SourceCodeGeneratorFactoryTest { - - private static final SourceCodeGeneratorFactory FACTORY = new SourceCodeGeneratorFactory(); - private SourceCodeGenerator generator; - private String propKey; - - @Test - public void basicFactoryTest() throws Exception { - final Field propField = SourceCodeGeneratorFactory.class.getDeclaredField("GENERATE_CODEC_SOURCE_PROP"); - propField.setAccessible(true); - propKey = (String) propField.get(FACTORY); - final String propValue; - final boolean present; - - propValue = System.getProperty(propKey, null); - present = propValue != null; - - testWithPropertyPresent(); - testWithoutPropertyPresent(); - - if (present) { - System.setProperty(propKey, propValue); - } else { - System.clearProperty(propKey); - } - } - - private void testWithPropertyPresent() throws Exception { - System.clearProperty(propKey); - System.setProperty(propKey, "true"); - generator = FACTORY.getInstance(null); - assertTrue(generator instanceof DefaultSourceCodeGenerator); - } - - private void testWithoutPropertyPresent() throws Exception { - System.clearProperty(propKey); - generator = FACTORY.getInstance(null); - assertTrue(generator instanceof NullSourceCodeGenerator); - } - - @Test - public void nullSourceCodeGenTest() throws Exception { - generator = new NullSourceCodeGenerator(); - generator.appendField(null, null); - } - - @Test - public void defaultSourceCodeGenTest() throws Exception { - final File dir = new File("testDir"); - assertTrue(cleanup(dir)); - - generator = new DefaultSourceCodeGenerator(dir.getName()); - final CtClass ctClass = mock(CtClass.class, CALLS_REAL_METHODS); - doReturn(Boolean.FALSE).when(ctClass).isFrozen(); - ctClass.setName("TestClass"); - final ClassPool classPool = mock(ClassPool.class); - doReturn(ctClass).when(classPool).get((String) any()); - doNothing().when(ctClass).setName("TestClass"); - doReturn(ctClass).when(ctClass).getSuperclass(); - doReturn(new CtClass[] {ctClass,ctClass}).when(ctClass).getInterfaces(); - doReturn(classPool).when(ctClass).getClassPool(); - doReturn(Boolean.FALSE).when(ctClass).isArray(); - doReturn(Boolean.FALSE).when(ctClass).isPrimitive(); - doReturn(AccessFlag.toModifier(AccessFlag.PUBLIC)).when(ctClass).getModifiers(); - final ClassFile classFile = new ClassFile(false,"test", null); - doReturn(classFile).when(ctClass).getClassFile2(); - doReturn(Boolean.FALSE).when(ctClass).isFrozen(); - doReturn("testClass").when(ctClass).getName(); - final CtField ctField = mock(CtField.class); - doReturn(AccessFlag.toModifier(AccessFlag.PUBLIC)).when(ctField).getModifiers(); - doReturn(ctClass).when(ctField).getType(); - doReturn("testField").when(ctField).getName(); - final CtMethod ctMethod = new CtMethod(ctClass,"method", new CtClass[] { ctClass , ctClass }, ctClass); - - generator.appendField(ctField, "b"); - generator.appendMethod(ctMethod, "c"); - generator.outputGeneratedSource(ctClass); - - assertTrue(dir.exists()); - assertTrue(dir.isDirectory()); - assertFalse(ImmutableList.of(dir.listFiles()).isEmpty()); - - assertTrue(cleanup(dir)); - } - - private static boolean cleanup(final File dir) { - if (!dir.exists()) { - return true; - } - - stream(dir.listFiles()).forEach(File::delete); - return dir.delete(); - } -} diff --git a/features/odl-mdsal-binding-runtime/pom.xml b/features/odl-mdsal-binding-runtime/pom.xml index f9a5dc812c..5008ef401b 100644 --- a/features/odl-mdsal-binding-runtime/pom.xml +++ b/features/odl-mdsal-binding-runtime/pom.xml @@ -21,12 +21,6 @@ MD-SAL Java Binding runtime - - org.opendaylight.odlparent - odl-javassist-3 - xml - features - org.opendaylight.yangtools odl-yangtools-data diff --git a/features/odl-mdsal-binding-runtime/src/main/feature/feature.xml b/features/odl-mdsal-binding-runtime/src/main/feature/feature.xml index 2e0a7d2578..e069c5da6d 100644 --- a/features/odl-mdsal-binding-runtime/src/main/feature/feature.xml +++ b/features/odl-mdsal-binding-runtime/src/main/feature/feature.xml @@ -1,7 +1,6 @@ - odl-javassist-3 odl-yangtools-data odl-yangtools-parser