Test of multiple revisions of module
[yangtools.git] / yang-validation-tool / src / main / java / org / opendaylight / yangtools / yang / validation / tool / retest / RetestUtils.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.yangtools.yang.validation.tool.retest;
10
11 import java.io.File;
12 import java.io.FileInputStream;
13 import java.io.FileNotFoundException;
14 import java.util.Collection;
15
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
18 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
19 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
20 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
23
24 public class RetestUtils {
25
26     private RetestUtils() {
27         throw new UnsupportedOperationException("Utility class");
28     }
29
30     public static SchemaContext parseYangSources(StatementStreamSource... sources) throws SourceException,
31             ReactorException {
32
33         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
34         reactor.addSources(sources);
35
36         return reactor.buildEffective();
37     }
38
39     public static SchemaContext parseYangSources(File... files) throws SourceException, ReactorException,
40             FileNotFoundException {
41
42         StatementStreamSource[] sources = new StatementStreamSource[files.length];
43
44         for (int i = 0; i < files.length; i++) {
45             sources[i] = new YangStatementSourceImpl(new FileInputStream(files[i]));
46         }
47
48         return parseYangSources(sources);
49     }
50
51     public static SchemaContext parseYangSources(Collection<File> files) throws SourceException, ReactorException,
52             FileNotFoundException {
53         return parseYangSources(files.toArray(new File[files.size()]));
54     }
55 }