Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update yangtools to 6.0.7 #53

Merged
merged 12 commits into from
Sep 25, 2022
10 changes: 5 additions & 5 deletions cli/src/main/java/com/mrv/yangtools/codegen/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.ModuleLike;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -116,10 +116,10 @@ void init() throws FileNotFoundException {
void generate() throws IOException, ReactorException {
final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*.yang");

final SchemaContext context = buildSchemaContext(yangDir, p -> matcher.matches(p.getFileName()));
final EffectiveModelContext context = buildEffectiveModelContext(yangDir, p -> matcher.matches(p.getFileName()));

if(log.isInfoEnabled()) {
String modulesSting = context.getModules().stream().map(ModuleIdentifier::getName).collect(Collectors.joining(", "));
String modulesSting = context.getModules().stream().map(ModuleLike::getName).collect(Collectors.joining(", "));

log.info("Modules found in the {} are {}", yangDir, modulesSting);
}
Expand Down Expand Up @@ -176,7 +176,7 @@ private void validate(String basePath) {
URI.create(basePath);
}

private SchemaContext buildSchemaContext(String dir, Predicate<Path> accept)
private EffectiveModelContext buildEffectiveModelContext(String dir, Predicate<Path> accept)
throws ReactorException {
if(dir.contains(File.pathSeparator)) {
return ContextHelper.getFromDir(Arrays.stream(dir.split(File.pathSeparator)).map(s -> FileSystems.getDefault().getPath(s)), accept);
Expand Down
10 changes: 5 additions & 5 deletions common/src/main/java/com/mrv/yangtools/common/ContextHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

package com.mrv.yangtools.common;

import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -40,11 +40,11 @@ public class ContextHelper {
* @return YANG context
* @throws ReactorException in case of parsing errors
*/
public static SchemaContext getFromDir(Path dir, Predicate<Path> accept) throws ReactorException {
public static EffectiveModelContext getFromDir(Path dir, Predicate<Path> accept) throws ReactorException {
return getFromDir(Stream.of(dir), accept);
}

public static SchemaContext getFromDir(Stream<Path> dirs, Predicate<Path> accept) throws ReactorException {
public static EffectiveModelContext getFromDir(Stream<Path> dirs, Predicate<Path> accept) throws ReactorException {
return getCtx(dirs, accept);
}

Expand All @@ -54,7 +54,7 @@ public static SchemaContext getFromDir(Stream<Path> dirs, Predicate<Path> accept
* @return YANG context in case of parsing errors
* @throws ReactorException in case of problem with YANG modules parsing
*/
public static SchemaContext getFromClasspath(Predicate<Path> accept) throws ReactorException {
public static EffectiveModelContext getFromClasspath(Predicate<Path> accept) throws ReactorException {
return getCtx(Arrays.stream(System.getProperty("java.class.path", ".").split(File.pathSeparator)).map(s -> Paths.get(s.replaceFirst("^/(.:/)", "$1"))), accept);
}

Expand All @@ -65,7 +65,7 @@ public static SchemaContext getFromClasspath(Predicate<Path> accept) throws Reac
* @return YANG context
* @throws ReactorException in case of parsing errors
*/
public static SchemaContext getCtx(Stream<Path> dirs, Predicate<Path> accept) throws ReactorException {
public static EffectiveModelContext getCtx(Stream<Path> dirs, Predicate<Path> accept) throws ReactorException {

SchemaBuilder builder = new SchemaBuilder().accepts(accept);

Expand Down
41 changes: 14 additions & 27 deletions common/src/main/java/com/mrv/yangtools/common/SchemaBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@

package com.mrv.yangtools.common;

import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.impl.DefaultReactors;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
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.reactor.CrossSourceStatementReactor.BuildAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -68,32 +71,16 @@ public SchemaBuilder add(Path path) throws IOException {
return this;
}


public SchemaContext build() throws ReactorException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
SchemaContext resolveSchemaContext;
EffectiveModelContext build() throws ReactorException {
final BuildAction reactor = DefaultReactors.defaultReactor().newBuild();
log.info("Inspecting all defined yangs {}", yangs);
final List<InputStream> yangsStreams = new ArrayList<>();

try {
for (Path y : yangs) {
try {
yangsStreams.add(new FileInputStream(y.toFile()));
} catch (FileNotFoundException e) {
throw new IllegalStateException(y + " is not a file");
}
for (final Path path : yangs) {
try {
reactor.addSource(YangStatementStreamSource.create(YangTextSchemaSource.forFile(path.toFile())));
} catch (final IOException | YangSyntaxErrorException e) {
throw new IllegalStateException(path + " is not a valid YANG file");
}
resolveSchemaContext = reactor.buildEffective(new ArrayList<InputStream>(yangsStreams));
return resolveSchemaContext;
} finally {

yangsStreams.forEach(s -> {
try {
s.close();
} catch (IOException e) {
//ignore
}
});
}
return reactor.buildEffective();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import com.mrv.yangtools.codegen.SwaggerGenerator;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -51,7 +51,7 @@ public static SwaggerGenerator getGenerator(File dir, Predicate<Module> toSelect

Predicate<Path> acc = p -> matcher.matches(p.getFileName());

final SchemaContext ctx = dir == null ? getFromClasspath(acc) : getFromDir(dir.toPath(), acc);
final EffectiveModelContext ctx = dir == null ? getFromClasspath(acc) : getFromDir(dir.toPath(), acc);
if(ctx.getModules().isEmpty()) throw new IllegalArgumentException(String.format("No YANG modules found in %s", dir == null ? "classpath" : dir.toString()));
log.info("Context parsed {}", ctx);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.stream.Collectors;

import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -55,7 +55,7 @@ public static IoCSwaggerGenerator getGenerator(File dir, Predicate<Module> toSel

Predicate<Path> acc = p -> matcher.matches(p.getFileName());

final SchemaContext ctx = dir == null ? getFromClasspath(acc) : getFromDir(dir.toPath(), acc);
final EffectiveModelContext ctx = dir == null ? getFromClasspath(acc) : getFromDir(dir.toPath(), acc);
if(ctx.getModules().isEmpty()) throw new IllegalArgumentException(String.format("No YANG modules found in %s", dir == null ? "classpath" : dir.toString()));
log.info("Context parsed {}", ctx);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import java.util.Set;

import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;

import com.mrv.yangtools.codegen.IoCSwaggerGenerator;

public interface SwaggerGeneratorFactory {

public IoCSwaggerGenerator createSwaggerGenerator(SchemaContext ctx, Set<Module> modulesToGenerate);
public IoCSwaggerGenerator createSwaggerGenerator(EffectiveModelContext ctx, Set<Module> modulesToGenerate);
}
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
<packaging>pom</packaging>

<properties>
<logback.version>1.2.9</logback.version>
<logback.version>1.2.11</logback.version>
<swagger.codegen.version>2.2.1</swagger.codegen.version>
<swagger.version>1.6.6</swagger.version>
<yangtools.version>1.2.1</yangtools.version>
<yangtools.version>6.0.7</yangtools.version>
<guice.version>4.1.0</guice.version>
</properties>

Expand Down Expand Up @@ -141,14 +141,14 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand Down
6 changes: 6 additions & 0 deletions swagger-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
</dependency>


<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-data-util</artifactId>
<version>${yangtools.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.ModuleLike;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -63,7 +63,7 @@
*/
public class IoCSwaggerGenerator {
private static final Logger log = LoggerFactory.getLogger(IoCSwaggerGenerator.class);
private final SchemaContext ctx;
private final EffectiveModelContext ctx;
private final Set<org.opendaylight.yangtools.yang.model.api.Module> modules;
private final Swagger target;
private final Set<String> moduleNames;
Expand Down Expand Up @@ -113,7 +113,7 @@ public enum Strategy {optimizing, unpacking}
* @param modulesToGenerate modules that will be transformed to swagger API
*/
@Inject
public IoCSwaggerGenerator(@Assisted SchemaContext ctx, @Assisted Set<Module> modulesToGenerate) {
public IoCSwaggerGenerator(@Assisted EffectiveModelContext ctx, @Assisted Set<Module> modulesToGenerate) {
Objects.requireNonNull(ctx);
Objects.requireNonNull(modulesToGenerate);
if(modulesToGenerate.isEmpty()) throw new IllegalStateException("No modules to generate has been specified");
Expand All @@ -122,7 +122,7 @@ public IoCSwaggerGenerator(@Assisted SchemaContext ctx, @Assisted Set<Module> mo
target = new Swagger();
converter = new AnnotatingTypeConverter(ctx);
moduleUtils = new ModuleUtils(ctx);
this.moduleNames = modulesToGenerate.stream().map(ModuleIdentifier::getName).collect(Collectors.toSet());
this.moduleNames = modulesToGenerate.stream().map(ModuleLike::getName).collect(Collectors.toSet());
//assign default strategy
strategy(Strategy.optimizing);

Expand Down Expand Up @@ -298,12 +298,12 @@ public Swagger generate() {
}

log.info("Generating swagger for yang modules: {}",
modules.stream().map(ModuleIdentifier::getName).collect(Collectors.joining(",","[", "]")));
modules.stream().map(ModuleLike::getName).collect(Collectors.joining(",","[", "]")));

modules.forEach(m -> {
mNames.add(m.getName());
if(m.getDescription() != null && !m.getDescription().isEmpty()) {
mDescs.add(m.getDescription());
if(m.getDescription().isPresent()) {
mDescs.add(m.getDescription().get());
}
dataObjectsBuilder.processModule(m);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import io.swagger.models.Swagger;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;

import java.util.Collection;

Expand All @@ -23,7 +23,7 @@
public interface PathHandlerBuilder {
PathHandler forModule(Module module);

void configure(SchemaContext ctx, Swagger target, DataObjectBuilder builder);
void configure(EffectiveModelContext ctx, Swagger target, DataObjectBuilder builder);

void addTagGenerator(TagGenerator generator);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -51,7 +51,7 @@ public class PathSegment implements Iterable<PathSegment> {
* To create a root segment of path
* @param ctx YANG context
*/
public PathSegment(SchemaContext ctx) {
public PathSegment(EffectiveModelContext ctx) {
this(NULL);
this.converter = new TypeConverter(ctx) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
*/
public class SwaggerGenerator {
private static final Logger log = LoggerFactory.getLogger(SwaggerGenerator.class);
private final SchemaContext ctx;
private final Set<org.opendaylight.yangtools.yang.model.api.Module> modules;
private final EffectiveModelContext ctx;
private final Collection<? extends org.opendaylight.yangtools.yang.model.api.Module> modules;
private final Swagger target;
private final Set<String> moduleNames;
private final ModuleUtils moduleUtils;
Expand Down Expand Up @@ -103,7 +103,7 @@ public enum Strategy {optimizing, unpacking}
* @param ctx context for generation
* @param modulesToGenerate modules that will be transformed to swagger API
*/
public SwaggerGenerator(SchemaContext ctx, Set<org.opendaylight.yangtools.yang.model.api.Module> modulesToGenerate) {
public SwaggerGenerator(EffectiveModelContext ctx, Collection<? extends org.opendaylight.yangtools.yang.model.api.Module> modulesToGenerate) {
Objects.requireNonNull(ctx);
Objects.requireNonNull(modulesToGenerate);

Expand All @@ -114,7 +114,7 @@ public SwaggerGenerator(SchemaContext ctx, Set<org.opendaylight.yangtools.yang.m
if(modulesToGenerate.isEmpty()) {
log.error("No modules has been specified for swagger generation");
if(log.isInfoEnabled()) {
String msg = ctx.getModules().stream().map(ModuleIdentifier::getName).collect(Collectors.joining(", "));
String msg = ctx.getModules().stream().map(ModuleLike::getName).collect(Collectors.joining(", "));
log.info("Modules in the context are: {}", msg);
}
throw new IllegalStateException("No modules to generate has been specified");
Expand All @@ -124,7 +124,7 @@ public SwaggerGenerator(SchemaContext ctx, Set<org.opendaylight.yangtools.yang.m
target = new Swagger();
converter = new AnnotatingTypeConverter(ctx);
moduleUtils = new ModuleUtils(ctx);
this.moduleNames = modulesToGenerate.stream().map(ModuleIdentifier::getName).collect(Collectors.toSet());
this.moduleNames = modulesToGenerate.stream().map(ModuleLike::getName).collect(Collectors.toSet());
//assign default strategy
strategy(Strategy.optimizing);

Expand Down Expand Up @@ -300,12 +300,12 @@ public Swagger generate() {


log.info("Generating swagger for yang modules: {}",
modules.stream().map(ModuleIdentifier::getName).collect(Collectors.joining(",","[", "]")));
modules.stream().map(ModuleLike::getName).collect(Collectors.joining(",","[", "]")));

modules.forEach(m -> {
mNames.add(m.getName());
if(m.getDescription() != null && !m.getDescription().isEmpty()) {
mDescs.add(m.getDescription());
if(m.getDescription().isPresent()) {
mDescs.add(m.getDescription().get());
}
dataObjectsBuilder.processModule(m);

Expand Down
Loading