/* * 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.binding2; import com.google.common.annotations.Beta; import java.io.File; import java.net.URI; import java.util.Set; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Beta public final class TestUtils { private static final Logger LOG = LoggerFactory.getLogger(TestUtils.class); private TestUtils() { throw new UnsupportedOperationException("Utility class"); } public static Set loadModules(final URI resourceDirectory) throws SourceException, ReactorException { final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR .newBuild(); File[] files = new File(resourceDirectory).listFiles(); for (File file : files) { if (file.getName().endsWith(".yang")) { addSources(reactor, new YangStatementSourceImpl(file.getPath(), true)); } else { LOG.info("Ignoring non-yang file {}", file); } } EffectiveSchemaContext ctx = reactor.buildEffective(); return ctx.getModules(); } private static void addSources(final CrossSourceStatementReactor.BuildAction reactor, final YangStatementSourceImpl... sources) { for (YangStatementSourceImpl source : sources) { reactor.addSource(source); } } }