2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.mdsal.binding2;
11 import com.google.common.annotations.Beta;
15 import org.opendaylight.yangtools.yang.model.api.Module;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
17 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
18 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
19 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
20 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 public final class TestUtils {
28 private static final Logger LOG = LoggerFactory.getLogger(TestUtils.class);
31 throw new UnsupportedOperationException("Utility class");
34 public static Set<Module> loadModules(final URI resourceDirectory)
35 throws SourceException, ReactorException {
36 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
38 File[] files = new File(resourceDirectory).listFiles();
40 for (File file : files) {
41 if (file.getName().endsWith(".yang")) {
42 addSources(reactor, new YangStatementSourceImpl(file.getPath(), true));
44 LOG.info("Ignoring non-yang file {}", file);
48 EffectiveSchemaContext ctx = reactor.buildEffective();
49 return ctx.getModules();
52 private static void addSources(final CrossSourceStatementReactor.BuildAction reactor,
53 final YangStatementSourceImpl... sources) {
54 for (YangStatementSourceImpl source : sources) {
55 reactor.addSource(source);