Removed usage of deprecated YangParserImpl from tests in mdsal project
[mdsal.git] / binding / maven-sal-api-gen-plugin / src / test / java / org / opendaylight / yangtools / yang / unified / doc / generator / maven / RetestUtils.java
1 /*
2  * Copyright (c) 2016 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.unified.doc.generator.maven;
10
11 import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
12
13 import java.io.File;
14 import java.io.FileNotFoundException;
15 import java.io.InputStream;
16 import java.util.Collection;
17 import java.util.List;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
20 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
21 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
22 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
25
26 public class RetestUtils {
27
28     private RetestUtils() {
29         throw new UnsupportedOperationException("Utility class");
30     }
31
32     public static SchemaContext parseYangSources(StatementStreamSource... sources)
33             throws SourceException, ReactorException {
34
35         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
36                 .newBuild();
37         reactor.addSources(sources);
38
39         return reactor.buildEffective();
40     }
41
42     public static SchemaContext parseYangSources(File... files) throws SourceException, ReactorException, FileNotFoundException {
43
44         StatementStreamSource[] sources = new StatementStreamSource[files.length];
45
46         for(int i = 0; i<files.length; i++) {
47             sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i],files[i].getPath()));
48         }
49
50         return parseYangSources(sources);
51     }
52
53     public static SchemaContext parseYangSources(Collection<File> files) throws SourceException, ReactorException, FileNotFoundException {
54         return parseYangSources(files.toArray(new File[files.size()]));
55     }
56
57
58     public static SchemaContext parseYangStreams(List<InputStream> streams)
59             throws SourceException, ReactorException {
60
61         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
62                 .newBuild();
63         return reactor.buildEffective(streams);
64     }
65 }